This repository was archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
82 lines (76 loc) · 2.09 KB
/
types.ts
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
import type {
AnyObject,
FieldState,
FieldSubscription,
FieldValidator,
} from 'final-form'
import type { UseFieldConfig } from 'react-final-form'
export type FormErrorFunctionParams<InputValue = unknown> = {
label: string
name: string
value: InputValue
allValues: AnyObject
meta?: FieldState<InputValue>
}
type RequiredErrors = {
TOO_LOW:
| ((params: FormErrorFunctionParams & { min: number }) => string)
| string
TOO_HIGH:
| ((params: FormErrorFunctionParams & { max: number }) => string)
| string
MIN_LENGTH:
| ((params: FormErrorFunctionParams & { minLength: number }) => string)
| string
MAX_LENGTH:
| ((params: FormErrorFunctionParams & { maxLength: number }) => string)
| string
REGEX:
| ((
params: FormErrorFunctionParams & { regex: (RegExp | RegExp[])[] },
) => string)
| string
REQUIRED: ((params: FormErrorFunctionParams) => string) | string
MAX_DATE:
| ((params: FormErrorFunctionParams & { maxDate: Date }) => string)
| string
MIN_DATE:
| ((params: FormErrorFunctionParams & { minDate: Date }) => string)
| string
}
export type FormErrors = RequiredErrors
export type ValidatorProps = {
required?: boolean
min?: number
minLength?: number
max?: number
maxLength?: number
regex?: (RegExp | RegExp[])[]
maxDate?: Date
minDate?: Date
}
export type ValidatorObject<InputValue = unknown> = {
validate: (
value: InputValue,
allValues?: AnyObject,
meta?: FieldState<InputValue>,
) => boolean
error: keyof RequiredErrors
}
export type BaseFieldProps<FieldValue, InputValue = unknown> = {
parse?: UseFieldConfig<FieldValue, InputValue>['parse']
format?: UseFieldConfig<FieldValue, InputValue>['format']
formatOnBlur?: boolean
subscription?: FieldSubscription
validateFields?: string[]
defaultValue?: FieldValue
data?: AnyObject
allowNull?: boolean
initialValue?: FieldValue
multiple?: boolean
isEqual?: (a: InputValue, b: InputValue) => boolean
validate?: FieldValidator<FieldValue>
afterSubmit?: () => void
beforeSubmit?: () => void | boolean
value?: FieldValue
}