formik-fields
Version:
An extension to the great formik-library
34 lines (33 loc) • 1.45 kB
TypeScript
import { FormikConfig, FormikProps } from 'formik';
import * as React from 'react';
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export declare type fieldKeys<Values> = (keyof Values & string)[];
export declare type CFormikProps<Values> = Omit<FormikProps<Values>, 'isValidating'>;
export interface FormikFieldState<Value> {
name: string;
value: Value;
isTouched: boolean;
error: any;
setValue(val: Value, shouldValidate?: boolean): void;
setIsTouched(isTouched: boolean, shouldValidate?: boolean): void;
handleChange(e: React.ChangeEvent<HTMLInputElement>): void;
handleBlur(): void;
}
export declare type FormikFieldsState<Values> = {
[K in keyof Values & string]: FormikFieldState<Values[K]>;
};
export interface FormikFieldDefinition<T> {
initialValue: T;
validate?(value: T): any;
}
export declare type FormikFieldsDefinition<Values> = {
[K in keyof Values & string]: FormikFieldDefinition<Values[K]>;
};
export declare type FormikRenderType<Values> = (props: FormikFieldsState<Values>, formikBag: CFormikProps<Values>) => React.ReactNode;
export interface FormikFieldsConfig<Values> extends Omit<FormikConfig<Values>, 'render' | 'initialValues' | 'children' | 'component'> {
fields: FormikFieldsDefinition<Values>;
render?: FormikRenderType<Values>;
children?: FormikRenderType<Values>;
initialValues?: Values;
}
export {};