import { useRef, useState } from 'react' interface FileDropZoneProps { onFile: (text: string, filename: string) => void accept?: string } export default function FileDropZone({ onFile, accept = '.fasta,.fa,.faa,.txt,.csv', }: FileDropZoneProps) { const [dragging, setDragging] = useState(false) const inputRef = useRef(null) function readFile(file: File) { const reader = new FileReader() reader.onload = () => onFile(String(reader.result ?? ''), file.name) reader.readAsText(file) } return (
inputRef.current?.click()} onDragOver={(e) => { e.preventDefault() setDragging(true) }} onDragLeave={() => setDragging(false)} onDrop={(e) => { e.preventDefault() setDragging(false) const file = e.dataTransfer.files?.[0] if (file) readFile(file) }} >
Drag & drop a file, or click to browse
FASTA (.fasta / .fa) or plain text (.txt)
{ const file = e.target.files?.[0] if (file) readFile(file) e.target.value = '' }} />
) }