import { useState, useRef } from 'react'; const ACCEPTED = '.pdf,.docx,.pptx,.txt,.md'; const fmtSize = (bytes) => { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; }; export default function DropZone({ onFile, disabled }) { const [dragging, setDragging] = useState(false); const [chosen, setChosen] = useState(null); const inputRef = useRef(null); const handleFile = (file) => { if (!file) return; setChosen(file); onFile(file); }; const onDragOver = (e) => { e.preventDefault(); setDragging(true); }; const onDragLeave = () => setDragging(false); const onDrop = (e) => { e.preventDefault(); setDragging(false); const file = e.dataTransfer.files[0]; if (file) handleFile(file); }; const onChange = (e) => handleFile(e.target.files[0]); return (
📄
{dragging ? 'Drop it here!' : 'Click or drag file here'}
PDF · DOCX · PPTX · TXT · MD
{chosen && (
📎 {chosen.name} {fmtSize(chosen.size)}
)}
); }