import { FieldValues } from './fields'; import { Control } from './form'; import { FieldArrayPath, FieldArrayPathValue } from './path'; import { RegisterOptions, Validate } from './validator'; export type UseFieldArrayProps = FieldArrayPath, TKeyName extends string = 'id'> = { name: TFieldArrayName; keyName?: TKeyName; control?: Control; rules?: { validate?: Validate[], TFieldValues> | Record[], TFieldValues>>; } & Pick, 'maxLength' | 'minLength' | 'required'>; shouldUnregister?: boolean; }; /** * `useFieldArray` returned `fields` with unique id */ export type FieldArrayWithId = FieldArrayPath, TKeyName extends string = 'id'> = FieldArray & Record; export type FieldArray = FieldArrayPath> = FieldArrayPathValue extends ReadonlyArray | null | undefined ? U : never; /** * `useFieldArray` focus option, ability to toggle focus on and off with `shouldFocus` and setting focus by either field index or name. */ export type FieldArrayMethodProps = { shouldFocus?: boolean; focusIndex?: number; focusName?: string; }; /** * Swap field array by supplying from and to index * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param indexA - from index * @param indexB - to index * * @example * ```tsx * * ``` */ export type UseFieldArraySwap = (indexA: number, indexB: number) => void; /** * Move field array by supplying from and to index * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param indexA - from index * @param indexB - to index * * @example * ```tsx * * ``` */ export type UseFieldArrayMove = (indexA: number, indexB: number) => void; /** * Prepend field/fields to the start of the fields and optionally focus. The input value will be registered during this action. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param value - prepend items or items * @param options - focus options * * @example * ```tsx * * * * ``` */ export type UseFieldArrayPrepend = FieldArrayPath> = (value: FieldArray | FieldArray[], options?: FieldArrayMethodProps) => void; /** * Append field/fields to the end of your fields and focus. The input value will be registered during this action. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param value - append items or items. * @param options - focus options * * @example * ```tsx * * * * ``` */ export type UseFieldArrayAppend = FieldArrayPath> = (value: FieldArray | FieldArray[], options?: FieldArrayMethodProps) => void; /** * Remove field/fields at particular position. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param index - index to remove at, or remove all when no index provided. * * @example * ```tsx * * * ``` */ export type UseFieldArrayRemove = (index?: number | number[]) => void; /** * Insert field/fields at particular position and focus. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param index - insert position * @param value - insert field or fields * @param options - focus options * * @example * ```tsx * * * * ``` */ export type UseFieldArrayInsert = FieldArrayPath> = (index: number, value: FieldArray | FieldArray[], options?: FieldArrayMethodProps) => void; /** * Update field/fields at particular position. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param index - insert position * @param value - insert field or fields * * @example * ```tsx * * * ``` */ export type UseFieldArrayUpdate = FieldArrayPath> = (index: number, value: FieldArray) => void; /** * Replace the entire field array values. * * @remarks * [API](https://react-hook-form.com/docs/usefieldarray) • [Demo](https://codesandbox.io/s/calc-i231d) * * @param value - the entire field values. * * @example * ```tsx * * ``` */ export type UseFieldArrayReplace = FieldArrayPath> = (value: FieldArray | FieldArray[]) => void; export type UseFieldArrayReturn = FieldArrayPath, TKeyName extends string = 'id'> = { swap: UseFieldArraySwap; move: UseFieldArrayMove; prepend: UseFieldArrayPrepend; append: UseFieldArrayAppend; remove: UseFieldArrayRemove; insert: UseFieldArrayInsert; update: UseFieldArrayUpdate; replace: UseFieldArrayReplace; fields: FieldArrayWithId[]; }; //# sourceMappingURL=fieldArray.d.ts.map