import React, { useRef } from 'react'; import { Button } from '@/components/ui/button'; import { Paperclip, X } from 'lucide-react'; import { cn } from '@/lib/utils'; interface FileAttachmentProps { onFileSelect: (file: File) => void; onFileRemove?: (file: File) => void; selectedFiles?: File[]; disabled?: boolean; accept?: string; multiple?: boolean; className?: string; } export function FileAttachment({ onFileSelect, onFileRemove, selectedFiles = [], disabled = false, accept, multiple = false, className }: FileAttachmentProps) { const fileInputRef = useRef(null); const handleButtonClick = () => { fileInputRef.current?.click(); }; const handleFileChange = (event: React.ChangeEvent) => { const files = event.target.files; if (files) { Array.from(files).forEach(file => { onFileSelect(file); }); } // Reset input so the same file can be selected again if (fileInputRef.current) { fileInputRef.current.value = ''; } }; const handleRemoveFile = (file: File) => { if (onFileRemove) { onFileRemove(file); } }; return (
{selectedFiles.length > 0 && (
{selectedFiles.map((file, index) => (
{file.name} {onFileRemove && ( )}
))}
)}
); }