import { useBaseField } from "../../base/base-field" ; import { FieldMeta , FieldMetaWithoutError , FieldOptions , FieldProps , } from "../../base/base-field/types" ; export type FileFieldProps = Omit < FieldProps < FileList , HTMLInputElement > , "value" > ; export function useFileField ( options ? ) { const checkForErrors = ( meta ) => { const error = options ?. validate ?. ( meta ) ; const isEmpty = checkIfEmpty ( meta . value ) ; const requiredErrorMessage = options ?. isRequired && isEmpty ? `${ options . label ?? "This field" } is required` : undefined ; return error ?? requiredErrorMessage ; } ; const extractValue = ( target ) => { const newValue = target . files ; return options ?. transform ?. ( newValue ?? undefined ) ?? newValue ; } ; const checkIfEmpty = ( value ) => { return value == null || value ?. length == 0 ; } ; const initialValue = options ?. initialValue ; const isRequired = Boolean ( options ?. isRequired ) ; const [ { value , ... restProps } , meta ] = useBaseField ( { checkForErrors , extractValue , checkIfEmpty , initialValue , isRequired , } ) ; return [ { ... restProps , type : "file" } , meta ] ; }