import React, { SyntheticEvent, useMemo } from 'react'; import { IconButton } from 'react-file-utils'; import { OGAPIResponse } from 'getstream'; import { sanitizeURL, trimURL, PropsWithElementAttributes } from '../utils'; import { AvatarIcon, CloseIcon } from './Icons'; export type CardProps = PropsWithElementAttributes< { alt?: string; handleClose?: (e: SyntheticEvent) => void; image?: string | null; nolink?: boolean; } & Pick, HTMLAnchorElement >; export const Card = ({ alt, images = [], image: imageURL, handleClose, description, nolink, url, title, className, style, }: CardProps) => { const sanitizedURL = useMemo(() => sanitizeURL(url), [url]); const trimmedURL = useMemo(() => trimURL(sanitizedURL), [sanitizedURL]); const [{ image }] = !imageURL && images.length ? images : [{ image: imageURL }]; return ( {handleClose && image ? ( ) : null} {image !== undefined && (
{image === null ? ( ) : ( {alt )}
)}

{title}

{trimmedURL}

{description}

{handleClose && image === undefined && (
)}
); };