1 | import * as React from 'react';
|
2 |
|
3 |
|
4 |
|
5 | export interface FormikValues {
|
6 | [field: string]: any;
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export declare type FormikErrors<Values> = {
|
13 | [K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormikErrors<Values[K][number]>[] | string | string[] : string | string[] : Values[K] extends object ? FormikErrors<Values[K]> : string;
|
14 | };
|
15 |
|
16 |
|
17 |
|
18 | export declare type FormikTouched<Values> = {
|
19 | [K in keyof Values]?: Values[K] extends any[] ? Values[K][number] extends object ? FormikTouched<Values[K][number]>[] : boolean : Values[K] extends object ? FormikTouched<Values[K]> : boolean;
|
20 | };
|
21 |
|
22 |
|
23 |
|
24 | export interface FormikState<Values> {
|
25 |
|
26 | values: Values;
|
27 |
|
28 | errors: FormikErrors<Values>;
|
29 |
|
30 | touched: FormikTouched<Values>;
|
31 |
|
32 | isSubmitting: boolean;
|
33 |
|
34 | isValidating: boolean;
|
35 |
|
36 | status?: any;
|
37 |
|
38 | submitCount: number;
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 | export interface FormikComputedProps<Values> {
|
44 |
|
45 | readonly dirty: boolean;
|
46 |
|
47 | readonly isValid: boolean;
|
48 |
|
49 | readonly initialValues: Values;
|
50 |
|
51 | readonly initialErrors: FormikErrors<Values>;
|
52 |
|
53 | readonly initialTouched: FormikTouched<Values>;
|
54 |
|
55 | readonly initialStatus?: any;
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 | export interface FormikHelpers<Values> {
|
61 |
|
62 | setStatus: (status?: any) => void;
|
63 |
|
64 | setErrors: (errors: FormikErrors<Values>) => void;
|
65 |
|
66 | setSubmitting: (isSubmitting: boolean) => void;
|
67 |
|
68 | setTouched: (touched: FormikTouched<Values>, shouldValidate?: boolean) => void;
|
69 |
|
70 | setValues: (values: React.SetStateAction<Values>, shouldValidate?: boolean) => void;
|
71 |
|
72 | setFieldValue: (field: string, value: any, shouldValidate?: boolean) => void;
|
73 |
|
74 | setFieldError: (field: string, message: string | undefined) => void;
|
75 |
|
76 | setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => void;
|
77 |
|
78 | validateForm: (values?: any) => Promise<FormikErrors<Values>>;
|
79 |
|
80 | validateField: (field: string) => void;
|
81 |
|
82 | resetForm: (nextState?: Partial<FormikState<Values>>) => void;
|
83 |
|
84 | submitForm: () => Promise<void>;
|
85 |
|
86 | setFormikState: (f: FormikState<Values> | ((prevState: FormikState<Values>) => FormikState<Values>), cb?: () => void) => void;
|
87 | }
|
88 |
|
89 |
|
90 |
|
91 | export interface FormikHandlers {
|
92 |
|
93 | handleSubmit: (e?: React.FormEvent<HTMLFormElement>) => void;
|
94 |
|
95 | handleReset: (e?: React.SyntheticEvent<any>) => void;
|
96 | handleBlur: {
|
97 |
|
98 | (e: React.FocusEvent<any>): void;
|
99 |
|
100 | <T = string | any>(fieldOrEvent: T): T extends string ? (e: any) => void : void;
|
101 | };
|
102 | handleChange: {
|
103 |
|
104 | (e: React.ChangeEvent<any>): void;
|
105 |
|
106 | <T = string | React.ChangeEvent<any>>(field: T): T extends React.ChangeEvent<any> ? void : (e: string | React.ChangeEvent<any>) => void;
|
107 | };
|
108 | getFieldProps: <Value = any>(props: any) => FieldInputProps<Value>;
|
109 | getFieldMeta: <Value>(name: string) => FieldMetaProps<Value>;
|
110 | getFieldHelpers: <Value = any>(name: string) => FieldHelperProps<Value>;
|
111 | }
|
112 |
|
113 |
|
114 |
|
115 | export interface FormikSharedConfig<Props = {}> {
|
116 |
|
117 | validateOnChange?: boolean;
|
118 |
|
119 | validateOnBlur?: boolean;
|
120 |
|
121 | validateOnMount?: boolean;
|
122 |
|
123 | isInitialValid?: boolean | ((props: Props) => boolean);
|
124 | /** Should Formik reset the form when new initialValues change */
|
125 | enableReinitialize?: boolean;
|
126 | }
|
127 | /**
|
128 | * <Formik /> props
|
129 | */
|
130 | export interface FormikConfig<Values> extends FormikSharedConfig {
|
131 | /**
|
132 | * Form component to render
|
133 | */
|
134 | component?: React.ComponentType<FormikProps<Values>> | React.ReactNode;
|
135 | /**
|
136 | * Render prop (works like React router's <Route render={props =>} />)
|
137 | * @deprecated
|
138 | */
|
139 | render?: (props: FormikProps<Values>) => React.ReactNode;
|
140 | |
141 |
|
142 |
|
143 | children?: ((props: FormikProps<Values>) => React.ReactNode) | React.ReactNode;
|
144 | /**
|
145 | * Initial values of the form
|
146 | */
|
147 | initialValues: Values;
|
148 | /**
|
149 | * Initial status
|
150 | */
|
151 | initialStatus?: any;
|
152 | /** Initial object map of field names to specific error for that field */
|
153 | initialErrors?: FormikErrors<Values>;
|
154 | /** Initial object map of field names to whether the field has been touched */
|
155 | initialTouched?: FormikTouched<Values>;
|
156 | /**
|
157 | * Reset handler
|
158 | */
|
159 | onReset?: (values: Values, formikHelpers: FormikHelpers<Values>) => void;
|
160 | |
161 |
|
162 |
|
163 | onSubmit: (values: Values, formikHelpers: FormikHelpers<Values>) => void | Promise<any>;
|
164 | |
165 |
|
166 |
|
167 | validationSchema?: any | (() => any);
|
168 | /**
|
169 | * Validation function. Must return an error object or promise that
|
170 | * throws an error object where that object keys map to corresponding value.
|
171 | */
|
172 | validate?: (values: Values) => void | object | Promise<FormikErrors<Values>>;
|
173 |
|
174 | innerRef?: React.Ref<FormikProps<Values>>;
|
175 | }
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | export declare type FormikProps<Values> = FormikSharedConfig & FormikState<Values> & FormikHelpers<Values> & FormikHandlers & FormikComputedProps<Values> & FormikRegistration & {
|
181 | submitForm: () => Promise<any>;
|
182 | };
|
183 |
|
184 | export interface FormikRegistration {
|
185 | registerField: (name: string, fns: {
|
186 | validate?: FieldValidator;
|
187 | }) => void;
|
188 | unregisterField: (name: string) => void;
|
189 | }
|
190 |
|
191 |
|
192 |
|
193 | export declare type FormikContextType<Values> = FormikProps<Values> & Pick<FormikConfig<Values>, 'validate' | 'validationSchema'>;
|
194 | export interface SharedRenderProps<T> {
|
195 | |
196 |
|
197 |
|
198 | component?: string | React.ComponentType<T | void>;
|
199 | |
200 |
|
201 |
|
202 | render?: (props: T) => React.ReactNode;
|
203 | |
204 |
|
205 |
|
206 | children?: (props: T) => React.ReactNode;
|
207 | }
|
208 | export declare type GenericFieldHTMLAttributes = JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea'];
|
209 |
|
210 | export interface FieldMetaProps<Value> {
|
211 |
|
212 | value: Value;
|
213 |
|
214 | error?: string;
|
215 |
|
216 | touched: boolean;
|
217 |
|
218 | initialValue?: Value;
|
219 |
|
220 | initialTouched: boolean;
|
221 |
|
222 | initialError?: string;
|
223 | }
|
224 |
|
225 | export interface FieldHelperProps<Value> {
|
226 |
|
227 | setValue: (value: Value, shouldValidate?: boolean) => void;
|
228 |
|
229 | setTouched: (value: boolean, shouldValidate?: boolean) => void;
|
230 |
|
231 | setError: (value: string | undefined) => void;
|
232 | }
|
233 |
|
234 | export interface FieldInputProps<Value> {
|
235 |
|
236 | value: Value;
|
237 |
|
238 | name: string;
|
239 |
|
240 | multiple?: boolean;
|
241 |
|
242 | checked?: boolean;
|
243 |
|
244 | onChange: FormikHandlers['handleChange'];
|
245 |
|
246 | onBlur: FormikHandlers['handleBlur'];
|
247 | }
|
248 | export declare type FieldValidator = (value: any) => string | void | Promise<string | void>;
|