'use client' import {DragEvent, ReactNode, useRef, useState} from "react"; import {ImagePlus} from "lucide-react"; interface ImageDropZoneProps { onFileSelect: (file: File) => void; accept?: string; label?: ReactNode; } const acceptedTypes: string[] = ['image/png', 'image/jpeg', 'image/webp']; function ImageDropZone({onFileSelect, accept = "image/png, image/jpeg, image/webp", label}: ImageDropZoneProps) { const inputRef = useRef(null); const [isDragging, setIsDragging] = useState(false); function handleDragOver(e: DragEvent): void { e.preventDefault(); setIsDragging(true); } function handleDragLeave(e: DragEvent): void { e.preventDefault(); setIsDragging(false); } function handleDrop(e: DragEvent): void { e.preventDefault(); setIsDragging(false); const file: File | undefined = e.dataTransfer.files?.[0]; if (file && acceptedTypes.includes(file.type)) { onFileSelect(file); } } function handleClick(): void { inputRef.current?.click(); } function handleInputChange(e: React.ChangeEvent): void { const file: File | undefined = e.target.files?.[0]; if (file) { onFileSelect(file); } } return (
{label && {label}}
); } export default ImageDropZone;