-
-
Notifications
You must be signed in to change notification settings - Fork 482
/
types.js.flow
126 lines (112 loc) · 3.25 KB
/
types.js.flow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// @flow
import * as React from 'react'
import type {
FormApi,
Config,
Decorator,
FormState,
FormSubscription,
FormValuesShape,
FieldSubscription,
FieldValidator
} from 'final-form'
type SupportedInputs = 'input' | 'select' | 'textarea'
export type ReactContext<FormValues: FormValuesShape> = {
reactFinalForm: FormApi<FormValues>
}
export type FieldInputProps = {
name: string,
onBlur: (?SyntheticFocusEvent<*>) => void,
onChange: (SyntheticInputEvent<*> | any) => void,
onFocus: (?SyntheticFocusEvent<*>) => void,
value: any,
type?: string,
checked?: boolean,
multiple?: boolean
}
export type FieldRenderProps = {
input: FieldInputProps,
meta: {
active?: boolean,
data?: Object,
dirty?: boolean,
dirtySinceLastSubmit?: boolean,
error?: any,
initial?: any,
invalid?: boolean,
length?: number,
modified?: boolean,
modifiedSinceLastSubmit?: boolean,
pristine?: boolean,
submitError?: any,
submitFailed?: boolean,
submitSucceeded?: boolean,
submitting?: boolean,
touched?: boolean,
valid?: boolean,
validating?: boolean,
visited?: boolean
}
}
export type SubmitEvent = {
preventDefault?: $PropertyType<SyntheticEvent<EventTarget>, 'preventDefault'>,
stopPropagation?: $PropertyType<
SyntheticEvent<EventTarget>,
'stopPropagation'
>
}
export type FormRenderProps<FormValues: FormValuesShape> = {
handleSubmit: (?SubmitEvent) => ?Promise<?Object>,
form: FormApi<FormValues>
} & FormState<FormValues>
export type FormSpyRenderProps<FormValues: FormValuesShape> = {
form: FormApi<FormValues>
} & FormState<FormValues>
export type RenderableProps<T> = {
component?: React.ComponentType<*> | SupportedInputs,
children?: ((props: T) => React.Node) | React.Node,
render?: (props: T) => React.Node
}
export type FormProps<FormValues: FormValuesShape> = {
subscription?: FormSubscription,
decorators?: Decorator<FormValues>[],
form?: FormApi<FormValues>,
initialValuesEqual?: (?Object, ?Object) => boolean
} & Config<FormValues> &
RenderableProps<FormRenderProps<FormValues>>
export type UseFieldAutoConfig = {
afterSubmit?: () => void,
allowNull?: boolean,
beforeSubmit?: () => void | false,
children?: $PropertyType<RenderableProps<*>, 'children'>,
component?: $PropertyType<RenderableProps<*>, 'component'>,
data?: Object,
defaultValue?: any,
format?: (value: any, name: string) => any,
formatOnBlur?: boolean,
initialValue?: any,
isEqual?: (a: any, b: any) => boolean,
multiple?: boolean,
parse?: (value: any, name: string) => any,
type?: string,
validate?: FieldValidator,
validateFields?: string[],
value?: any
}
export type UseFieldConfig = {
subscription?: FieldSubscription
} & UseFieldAutoConfig
export type FieldProps = UseFieldConfig & {
name: string
} & RenderableProps<FieldRenderProps>
export type UseFormStateParams<FormValues: FormValuesShape> = {
onChange?: (formState: FormState<FormValues>) => void,
subscription?: FormSubscription
}
export type FormSpyProps<
FormValues: FormValuesShape
> = UseFormStateParams<FormValues> &
RenderableProps<FormSpyRenderProps<FormValues>>
export type FormSpyPropsWithForm<FormValues: FormValuesShape> = {
reactFinalForm: FormApi<FormValues>
} & FormSpyProps<FormValues>