envoc-form
Version:
Envoc form components
29 lines (28 loc) • 2.29 kB
TypeScript
import { ComponentProps, ElementType, LegacyRef } from 'react';
import { InjectedFieldProps } from './InjectedFieldProps';
import { NormalizationFunction } from '../Normalization/NormalizationFunction';
import { ValidationFunction } from '../Validation/ValidationFunction';
export declare type RenderComponent<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? TRenderComponent : never;
export declare type RenderComponentProps<TValue, TRenderComponent extends ElementType> = Partial<ComponentProps<TRenderComponent>> extends Partial<InjectedFieldProps<TValue | undefined | null>> ? ComponentProps<TRenderComponent> : never;
/** A specific Field instance to be rendered by the given TRenderComponent or by whatever default is reasonable */
export declare type FieldProps<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType> = {
/** Name of the field. Used on submission. */
name: TProp;
/** Component to be rendered. Usually this is a type of input group e.g. `<StringInputGroup/>` */
Component: RenderComponent<TForm[TProp], TRenderComponent>;
/** Id of the field. */
id?: string;
/** Whether the field should be disabled. */
disabled?: boolean;
/** Client side validation functions */
validate?: ValidationFunction<TForm[TProp]> | ValidationFunction<TForm[TProp]>[];
/** Function to modify the field value without making the form dirty. (e.g. phone number) */
normalize?: NormalizationFunction<TForm[TProp]>;
} & Omit<RenderComponentProps<TForm[TProp], TRenderComponent>, keyof InjectedFieldProps<TForm[TProp]>>;
/**
* Renders whatever Component is passed - injecting the formik values needed to finish wiring up that individual field.
* Should no Component be used then the default will be provided by the default lookup based on typeof(TForm[TProp])
*/
declare function Field<TForm extends object, TProp extends keyof TForm, TRenderComponent extends ElementType>({ name, Component, id, disabled, validate, normalize, ...rest }: FieldProps<TForm, TProp, TRenderComponent>, ref: LegacyRef<any>): JSX.Element;
declare const _default: typeof Field;
export default _default;