envoc-form
Version:
Envoc form components
25 lines (24 loc) • 1.59 kB
TypeScript
import { ElementType } from 'react';
import { FieldProps } from '../Field/Field';
import { ValidationFunction } from '../Validation/ValidationFunction';
export declare type FieldArrayProps<TForm extends object, TProp extends keyof TForm> = TForm[TProp] extends Array<any> | undefined | null ? {
/** Name of the field, used on submission. If using codegen this must be the provided dto. */
name: TProp;
/** Label of the field. */
label?: string;
/** Whether the field should be disabled. */
disabled?: boolean;
/** Function to validate the value. */
validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
children: (formBuilder: ArrayFormBuilderProp<TForm[TProp]>) => JSX.Element;
} : never;
export declare type ArrayFormBuilderProp<TValue extends Array<any> | undefined | null> = TValue extends Array<infer TForm> | undefined | null ? TForm extends object ? {
Field: <TProp extends keyof TForm, TRenderComponent extends ElementType>(props: FieldProps<TForm, TProp, TRenderComponent>) => JSX.Element;
FieldArray: <TProp extends keyof TForm>(props: FieldArrayProps<TForm, TProp>) => JSX.Element;
} : never : never;
/**
* An array of fields that allows the user to add multiple instances of the same field.
*
* Includes "Add Item" and "Remove Item" buttons to allow the user to speicify the number of fields.
*/
export default function FieldArray<TForm extends object, TProp extends keyof TForm>({ name, label, validate, disabled, children, ...rest }: FieldArrayProps<TForm, TProp>): JSX.Element;