/** * AttachmentGallery - Shows uploaded files with thumbnails and remove options */ import { useState } from "react"; import { FileText, Image, Trash2 } from "lucide-react"; export interface AttachmentItem { id: string; file: File; preview?: string; // Data URL for preview type: "image" | "pdf" | "other"; } interface AttachmentGalleryProps { attachments: AttachmentItem[]; onRemoveAttachment: (id: string) => void; className?: string; } export function AttachmentGallery({ attachments, onRemoveAttachment, className = "", }: AttachmentGalleryProps) { if (attachments.length === 0) return null; return (
{attachments.map((attachment) => ( onRemoveAttachment(attachment.id)} /> ))}
); } interface AttachmentPreviewProps { attachment: AttachmentItem; onRemove: () => void; } function AttachmentPreview({ attachment, onRemove }: AttachmentPreviewProps) { const [isHovered, setIsHovered] = useState(false); const renderPreview = () => { switch (attachment.type) { case "image": return attachment.preview ? ( {attachment.file.name} ) : (
); case "pdf": return (
PDF
); default: return (
FILE
); } }; return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} title={attachment.file.name} > {renderPreview()} {/* Dark overlay with centered delete icon on hover */}
{/* File name tooltip */}
{attachment.file.name}
); }