import type { FieldValues } from './fields'; import type { UseFormReturn } from './form'; import type { FieldArrayPath, FieldArrayPathValue } from './path'; export type UseFieldArrayProps = FieldArrayPath> = { name: TFieldArrayName; form?: UseFormReturn; }; /** * `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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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://reacty-form.com/docs/usefieldarray) * * @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=field-array.d.ts.map