// Adapted from Kibo UI (MIT), with owned React/CSS APIs. See THIRD_PARTY_NOTICES.md. "use client"; import { useState, type CSSProperties, type ReactNode } from "react"; import { useDropzone, type DropzoneOptions } from "./_ynrlib/dropzone.js"; export type DropzoneProps = DropzoneOptions & { className?: string; style?: CSSProperties; label?: string; children?: ReactNode; }; export function Dropzone({ className = "", style, label = "Choose files or drop them here", children, onDrop, disabled, ...options }: DropzoneProps) { const [files, setFiles] = useState([]); const [errors, setErrors] = useState([]); const { getRootProps, getInputProps, isDragActive } = useDropzone({ ...options, disabled, onDrop: (accepted, rejected, event) => { if (accepted.length) setFiles(accepted); setErrors( rejected.flatMap((file) => file.errors.map((error) => `${file.file.name}: ${error.message}`), ), ); onDrop?.(accepted, rejected, event); }, }); return (
{children ?? ( <> {label} {options.accept ? Object.keys(options.accept).join(", ") : "All file types"} {options.maxSize ? ` · Up to ${options.maxSize} bytes` : ""} )}
{files.length > 0 && (
    {files.map((file, i) => (
  • {file.name} · {file.size} bytes
  • ))}
)}
{errors.map((error, i) => (

{error}

))}
); }