import React from 'react'; import { ChevronRightIcon } from '@heroicons/react/24/outline'; import { Badge } from '../../Badge'; import { Tags } from '../../../types/Tags'; import { Link } from '../../Link/Link'; // Set types for as props type NewsItemTypeProps = 'li' | 'div'; export interface NewsItemProps { as?: NewsItemTypeProps; children?: React.ReactNode; title: string; link?: string; image?: string; alt?: string; date?: string | any; excerpt?: string; tags?: Tags; } export const NewsItem = ({ as: Component = 'div', title, link, image, alt, date, excerpt, tags, }: NewsItemProps) => { const formatedDate = new Date(date).toLocaleString('en-US', { month: 'long', day: '2-digit', year: 'numeric', }); return ( {image && (
{alt}
)}
{date && (

{formatedDate}

)}

{title}

{excerpt && (

{excerpt.length > 170 ? `${excerpt.substring(0, 170)}...` : excerpt} {' '} Read more

)} {tags && (
{tags?.category?.map(tag => ( {tag.name} ))}
)}
); };