import { useCallback, useState, type DragEvent } from "react"; import { Upload, FileImage } from "lucide-react"; import { cn } from "@/lib/utils"; interface DropzoneProps { onFiles?: (files: File[]) => void; accept?: string; multiple?: boolean; /** Files that have already been dropped (for showing count & list). */ currentFiles?: File[]; } export function Dropzone({ onFiles, accept, multiple = true, currentFiles = [] }: DropzoneProps) { const [isDragging, setIsDragging] = useState(false); const handleDrag = useCallback((e: DragEvent) => { e.preventDefault(); e.stopPropagation(); if (e.type === "dragenter" || e.type === "dragover") setIsDragging(true); else if (e.type === "dragleave") setIsDragging(false); }, []); const handleDrop = useCallback( (e: DragEvent) => { e.preventDefault(); e.stopPropagation(); setIsDragging(false); const files = Array.from(e.dataTransfer.files); if (files.length > 0) onFiles?.(files); }, [onFiles] ); const handleClick = () => { const input = document.createElement("input"); input.type = "file"; input.multiple = multiple; if (accept) input.accept = accept; input.onchange = (e) => { const files = Array.from((e.target as HTMLInputElement).files || []); if (files.length > 0) onFiles?.(files); }; input.click(); }; const hasMultipleFiles = currentFiles.length > 1; return (
Drop files here or click the upload button
{/* Show file count badge and list when multiple files are dropped */} {hasMultipleFiles && (