import { forwardRef } from "react"; /** * Attachment * * name: string - filename, e.g. "report.pdf" * type: string - MIME type, e.g. "image/png"; image types render a thumbnail * src: string - thumbnail URL for image types * alt: string - alt text for the thumbnail (default: "File thumbnail preview") * icon: ReactNode - overrides the default file icon; add aria-hidden="true" if decorative * onClose: function - renders a close/remove button * closeLabel: string - aria-label for the close button (default: "Remove file") * disabled: boolean - hides the close button and applies disabled styles */ const Attachment = forwardRef(function Attachment( { name, type, src, alt = "File thumbnail preview", icon, onClose, closeLabel = "Remove file", disabled = false, className = "", ...props }, ref ) { const isImage = type?.startsWith("image/"); const showThumbnail = isImage && src; return (
{/* Thumb */}
{showThumbnail ? ( {alt} ) : ( icon ?? )}
{/* Meta */}
{name}
{type}
{/* Close */} {onClose && !disabled && ( )}
); }); export default Attachment; // --------------------------------------------------------------------------- // Internal icons // --------------------------------------------------------------------------- const CloseIcon = () => (