UNPKG

2.72 kBTypeScriptView Raw
1import * as React from 'react';
2import { FormikHelpers, FormikProps, FormikSharedConfig, FormikValues, FormikTouched, FormikErrors } from './types';
3/**
4 * State, handlers, and helpers injected as props into the wrapped form component.
5 * Used with withFormik()
6 *
7 * @deprecated Use `OuterProps & FormikProps<Values>` instead.
8 */
9export declare type InjectedFormikProps<Props, Values> = Props & FormikProps<Values>;
10/**
11 * Formik helpers + { props }
12 */
13export declare type FormikBag<P, V> = {
14 props: P;
15} & FormikHelpers<V>;
16/**
17 * withFormik() configuration options. Backwards compatible.
18 */
19export interface WithFormikConfig<Props, Values extends FormikValues = FormikValues, DeprecatedPayload = Values> extends FormikSharedConfig<Props> {
20 /**
21 * Set the display name of the component. Useful for React DevTools.
22 */
23 displayName?: string;
24 /**
25 * Submission handler
26 */
27 handleSubmit: (values: Values, formikBag: FormikBag<Props, Values>) => void;
28 /**
29 * Map props to the form values
30 */
31 mapPropsToValues?: (props: Props) => Values;
32 /**
33 * Map props to the form status
34 */
35 mapPropsToStatus?: (props: Props) => any;
36 /**
37 * Map props to the form touched state
38 */
39 mapPropsToTouched?: (props: Props) => FormikTouched<Values>;
40 /**
41 * Map props to the form errors state
42 */
43 mapPropsToErrors?: (props: Props) => FormikErrors<Values>;
44 /**
45 * @deprecated in 0.9.0 (but needed to break TS types)
46 */
47 mapValuesToPayload?: (values: Values) => DeprecatedPayload;
48 /**
49 * A Yup Schema or a function that returns a Yup schema
50 */
51 validationSchema?: any | ((props: Props) => any);
52 /**
53 * Validation function. Must return an error object or promise that
54 * throws an error object where that object keys map to corresponding value.
55 */
56 validate?: (values: Values, props: Props) => void | object | Promise<any>;
57}
58export declare type CompositeComponent<P> = React.ComponentClass<P> | React.StatelessComponent<P>;
59export interface ComponentDecorator<TOwnProps, TMergedProps> {
60 (component: CompositeComponent<TMergedProps>): React.ComponentType<TOwnProps>;
61}
62export interface InferableComponentDecorator<TOwnProps> {
63 <T extends CompositeComponent<TOwnProps>>(component: T): T;
64}
65/**
66 * A public higher-order component to access the imperative API
67 */
68export declare function withFormik<OuterProps extends object, Values extends FormikValues, Payload = Values>({ mapPropsToValues, ...config }: WithFormikConfig<OuterProps, Values, Payload>): ComponentDecorator<OuterProps, OuterProps & FormikProps<Values>>;