|
| 1 | +import * as React from 'react'; |
| 2 | +import { |
| 3 | + FormApi, |
| 4 | + Config, |
| 5 | + Decorator, |
| 6 | + FormState, |
| 7 | + FormSubscription, |
| 8 | + FieldSubscription |
| 9 | +} from 'final-form'; |
| 10 | + |
| 11 | +export interface ReactContext { |
| 12 | + reactFinalForm: FormApi; |
| 13 | +} |
| 14 | + |
| 15 | +export interface FieldRenderProps<T extends HTMLElement> { |
| 16 | + input: { |
| 17 | + name: string; |
| 18 | + onBlur: (event?: React.FocusEvent<T>) => void; |
| 19 | + onChange: (event: React.ChangeEvent<T>) => void; |
| 20 | + onFocus: (event?: React.FocusEvent<T>) => void; |
| 21 | + value: any; |
| 22 | + checked?: boolean; |
| 23 | + }; |
| 24 | + meta: Partial<{ |
| 25 | + // TODO: Make a diff of `FieldState` without all the functions |
| 26 | + active: boolean; |
| 27 | + data: object; |
| 28 | + dirty: boolean; |
| 29 | + dirtySinceLastSubmit: boolean; |
| 30 | + error: any; |
| 31 | + initial: any; |
| 32 | + invalid: boolean; |
| 33 | + pristine: boolean; |
| 34 | + submitError: any; |
| 35 | + submitFailed: boolean; |
| 36 | + submitSucceeded: boolean; |
| 37 | + submitting: boolean; |
| 38 | + touched: boolean; |
| 39 | + valid: boolean; |
| 40 | + visited: boolean; |
| 41 | + }>; |
| 42 | +} |
| 43 | + |
| 44 | +export interface SubsetFormApi { |
| 45 | + batch: (fn: () => void) => void; |
| 46 | + blur: (name: string) => void; |
| 47 | + change: (name: string, value: any) => void; |
| 48 | + focus: (name: string) => void; |
| 49 | + initialize: (values: object) => void; |
| 50 | + mutators: { [key: string]: (...args: any[]) => any }; |
| 51 | + reset: () => void; |
| 52 | +} |
| 53 | + |
| 54 | +export interface FormRenderProps extends FormState, SubsetFormApi { |
| 55 | + batch: (fn: () => void) => void; |
| 56 | + form: FormApi; |
| 57 | + handleSubmit: ( |
| 58 | + event?: React.SyntheticEvent<HTMLFormElement> |
| 59 | + ) => Promise<object | undefined> | undefined; |
| 60 | +} |
| 61 | + |
| 62 | +export interface FormSpyRenderProps extends FormState, SubsetFormApi { |
| 63 | + form: FormApi; |
| 64 | +} |
| 65 | + |
| 66 | +export interface RenderableProps<T> { |
| 67 | + children?: ((props: T) => React.ReactNode) | React.ReactNode; |
| 68 | + component?: React.ComponentType<T> | string; |
| 69 | + render?: (props: T) => React.ReactNode; |
| 70 | +} |
| 71 | + |
| 72 | +export interface FormProps extends Config, RenderableProps<FormRenderProps> { |
| 73 | + subscription?: FormSubscription; |
| 74 | + decorators?: Decorator[]; |
| 75 | + initialValuesEqual?: (a?: object, b?: object) => boolean; |
| 76 | +} |
| 77 | + |
| 78 | +export interface FieldProps<T extends HTMLElement> |
| 79 | + extends RenderableProps<FieldRenderProps<T>> { |
| 80 | + allowNull?: boolean; |
| 81 | + format?: ((value: any, name: string) => any) | null; |
| 82 | + formatOnBlur?: boolean; |
| 83 | + parse?: ((value: any, name: string) => any) | null; |
| 84 | + name: string; |
| 85 | + isEqual?: (a: any, b: any) => boolean; |
| 86 | + subscription?: FieldSubscription; |
| 87 | + validate?: (value: any, allValues: object) => any; |
| 88 | + value?: any; |
| 89 | + [otherProp: string]: any; |
| 90 | +} |
| 91 | + |
| 92 | +export interface FormSpyProps extends RenderableProps<FormSpyRenderProps> { |
| 93 | + onChange?: (formState: FormState) => void; |
| 94 | + subscription?: FormSubscription; |
| 95 | +} |
| 96 | + |
| 97 | +export const Field: React.ComponentType<FieldProps<any>>; |
| 98 | +export const Form: React.ComponentType<FormProps>; |
| 99 | +export const FormSpy: React.ComponentType<FormSpyProps>; |
| 100 | +export const version: string; |
| 101 | + |
| 102 | +export function withReactFinalForm<T>( |
| 103 | + component: React.ComponentType<T> |
| 104 | +): React.ComponentType<T & ReactContext>; |
0 commit comments