import { useBaseFieldArray } from "../../base/base-field-array" ; import { FieldArrayActions , FieldArrayData , FieldArrayOptions , FieldArrayMeta } from "../../base/base-field-array/types" ; import { FieldMetaWithoutError } from "../../base/base-field/types" ; import { FileFieldProps } from "../file-field" ; export type FileFieldArrayProps = Omit < FieldArrayData < FileList | null | undefined , HTMLInputElement > , "props" > & { props : FileFieldProps ; } ; export function useFileFieldArray ( options ? ) { const checkForErrors = ( itemMeta , allMeta ) => { const error = options ?. validate ?. ( itemMeta , allMeta ) ; const requiredErrorMessage = options ?. isRequired && itemMeta . value . length == 0 ? `${ 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 [ _data , meta , actions ] = useBaseFieldArray ( { checkForErrors , extractValue , checkIfEmpty , initialValue , defaultValue : undefined , isRequired , } ) ; const data = _data . map ( ( d ) => { const { value , ... restProps } = d . props ; return { ... d , props : { ... restProps , type : "file" } , } ; } ) ; return [ data , meta , actions ] ; }