UNPKG

2.03 kBTypeScriptView Raw
1import * as React from 'react';
2import { FormikProps, GenericFieldHTMLAttributes, FieldMetaProps, FieldHelperProps, FieldInputProps, FieldValidator } from './types';
3export interface FieldProps<V = any, FormValues = any> {
4 field: FieldInputProps<V>;
5 form: FormikProps<FormValues>;
6 meta: FieldMetaProps<V>;
7}
8export interface FieldConfig<V = any> {
9 /**
10 * Field component to render. Can either be a string like 'select' or a component.
11 */
12 component?: string | React.ComponentType<FieldProps<V>> | React.ComponentType | React.ForwardRefExoticComponent<any>;
13 /**
14 * Component to render. Can either be a string e.g. 'select', 'input', or 'textarea', or a component.
15 */
16 as?: React.ComponentType<FieldProps<V>['field']> | string | React.ComponentType | React.ForwardRefExoticComponent<any>;
17 /**
18 * Render prop (works like React router's <Route render={props =>} />)
19 * @deprecated
20 */
21 render?: (props: FieldProps<V>) => React.ReactNode;
22 /**
23 * Children render function <Field name>{props => ...}</Field>)
24 */
25 children?: ((props: FieldProps<V>) => React.ReactNode) | React.ReactNode;
26 /**
27 * Validate a single field value independently
28 */
29 validate?: FieldValidator;
30 /**
31 * Field name
32 */
33 name: string;
34 /** HTML input type */
35 type?: string;
36 /** Field value */
37 value?: any;
38 /** Inner ref */
39 innerRef?: (instance: any) => void;
40}
41export declare type FieldAttributes<T> = GenericFieldHTMLAttributes & FieldConfig<T> & T & {
42 name: string;
43};
44export declare type FieldHookConfig<T> = GenericFieldHTMLAttributes & FieldConfig<T>;
45export declare function useField<Val = any>(propsOrFieldName: string | FieldHookConfig<Val>): [FieldInputProps<Val>, FieldMetaProps<Val>, FieldHelperProps<Val>];
46export declare function Field({ validate, name, render, children, as: is, // `as` is reserved in typescript lol
47component, ...props }: FieldAttributes<any>): any;