import { Controller, type FieldValues, type Path, type RegisterOptions, useFormContext, } from "react-hook-form"; import { FileDropZone } from "../FileDropZone.tsx"; interface FileFieldProps { name: Path; label?: string; hint?: string; showLimit?: boolean; disabled?: boolean; rules?: RegisterOptions>; /** Side effect run after the field value changes (e.g. derive a title). */ onValueChange?: (file: File | null) => void; } /** `Controller`-wrapped {@link FileDropZone} bound to react-hook-form. */ export function FileField({ name, label, hint, showLimit, disabled, rules, onValueChange, }: FileFieldProps) { const { control, formState: { errors } } = useFormContext(); const error = errors[name]; return (
{label && {label}} ( { field.onChange(file); onValueChange?.(file); }} hint={hint} showLimit={showLimit} disabled={disabled} /> )} /> {error?.message && ( {String(error.message)} )}
); }