import { useCallback } from 'react'; import { useDropzone } from 'react-dropzone'; import { Upload, Image as ImageIcon } from 'lucide-react'; import { cn } from '../lib/utils'; interface ImageUploadProps { onUpload: (file: File) => void; preview: string | null; label: string; description: string; } export function ImageUpload({ onUpload, preview, label, description }: ImageUploadProps) { const onDrop = useCallback( (acceptedFiles: File[]) => { if (acceptedFiles.length > 0) { onUpload(acceptedFiles[0]); } }, [onUpload] ); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, accept: { 'image/*': ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'], }, maxFiles: 1, }); return (
{preview ? (
Uploaded preview

Click or drop to replace

) : (

{isDragActive ? 'Drop image here' : 'Drop or click to upload'}

{description}

)}
); }