-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfixture.tsx
83 lines (79 loc) · 2.19 KB
/
fixture.tsx
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
import { InputText, InputTextProps } from './components/InputText'
import {
getEmptyOption,
getOptionWithDifferentLabel,
InputSelectOption
} from './utils'
import { InputSelect, InputSelectProps } from './components/InputSelect'
import { FormProps } from './Form'
export type FakeForm = {
num1?: number
str1?: string
num2?: number
str2?: string
sel1?: InputSelectOption<number, string> | InputSelectOption
catchall?: number[] | null
}
export const getFormInitialState = (
override?: Partial<FakeForm>
): FakeForm => ({
num1: 1,
str1: '1',
num2: 2,
str2: '2',
catchall: [1],
...override
})
export type InputComponentProps = InputTextProps | InputSelectProps
export const getFormProps = (): FormProps<
FakeForm,
{},
InputComponentProps
> => ({
onFormSubmit: () => Promise.resolve(),
onFormChange: () => Promise.resolve(),
formValues: getFormInitialState(),
fieldConfigs: {
num1: {
Component: InputText,
generateProps: () => ({ required: true }),
getError: (f) => ((f?.num1 || Infinity) > 100 ? 'Exceeds max' : null)
},
str1: {
Component: InputText,
getError: (f) =>
f.str1 === 'error text' ? 'String can not be "error text"' : null,
generateProps: ({ formValues: f }) => ({
required: !!f.num1,
disabled: f.str2 === 'this will trigger str1 to error'
})
},
num2: { Component: InputText, staticProps: { type: 'number' } },
str2: {
Component: InputText,
generateProps: ({ formValues: f }) => ({ disabled: !f.num2 })
},
sel1: {
Component: InputSelect,
getActualValue: (v: InputSelectOption) => v && v.value,
staticProps: {
label: 'select label',
options: [
getEmptyOption(),
getOptionWithDifferentLabel('sel1 val1', 'this is fine'),
getOptionWithDifferentLabel('sel1 val2', 'this is fine too')
],
required: false
}
},
catchall: {
Component: InputSelect,
getActualValue: (v: InputSelectOption) => v && v.value,
staticProps: {
isMulti: undefined
},
generateProps: () => ({ required: true })
}
},
layout: [['num1', 'str1'], ['num2', 'str2'], ['sel1']]
})