import React, { useState } from 'react'; import { SilkeButton } from '../silke-button'; import { SilkeIcon } from '../silke-icon/silke-icon'; import { SilkePopover } from '../silke-popover/silke-popover'; import { getFileIcon, truncateFilename } from './file-utils'; import { imageValueToDataUrl } from './image-utils'; import styles from './silke-command-text-field.module.scss'; import { isImage, SilkeFileValue, SilkeImageValue } from './utils'; interface AttachmentChipProps { attachment: SilkeImageValue | SilkeFileValue; disabled?: boolean; onRemove?: () => void; } export function AttachmentChip({ attachment, disabled, onRemove }: AttachmentChipProps) { const name = isImage(attachment) ? attachment.name || 'Image' : attachment.name; const [showPreview, setShowPreview] = useState(false); return (
{isImage(attachment) ? ( <>
setShowPreview((v) => !v)} role="button" tabIndex={0} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); setShowPreview((v) => !v); } }} > {name}
setShowPreview(false)} >
{name}
) : ( )} {truncateFilename(name)} {!disabled && onRemove && ( { e.stopPropagation(); onRemove(); }} aria-label={`Remove ${name}`} /> )}
); }