-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm.stories.tsx
153 lines (138 loc) · 3.97 KB
/
Form.stories.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { Button } from '@chakra-ui/react';
import { Meta, Story } from '@storybook/react';
import { AutoComplete } from './Fields/AutoComplete';
import { Checkbox } from './Fields/Checkbox';
import { DayPicker } from './Fields/DayPicker';
import { PinInput } from './Fields/PinInput';
import { Radio, RadioGroup } from './Fields/Radio';
import { Slider } from './Fields/Slider';
import { TextArea } from './Fields/TextArea';
import { TextInput } from './Fields/TextInput';
import { FieldWrapper } from './FieldWrapper';
import { Form } from './Form';
type FormValues = {
name: string;
bio: string;
dob: string;
code: string;
gender: string;
age: string;
country: string;
children: string | string[];
};
const MyForm = () => {
return (
<Form<FormValues>
initialValues={{
name: '',
bio: '',
dob: '',
code: '',
gender: '',
children: '',
age: '',
country: '',
}}
onSubmit={async (values) => {
alert(JSON.stringify(values, null, 2));
}}
withDebugger
>
{() => (
<>
<FieldWrapper
name="name"
helper="Seu nome completo"
required
label="Nome"
as={(fieldProps) => <TextInput {...fieldProps} />}
/>
<FieldWrapper
name="bio"
helper="Nos conte um pouco mais sobre você"
required
label="Bio"
as={(fieldProps) => <TextArea {...fieldProps} />}
/>
<FieldWrapper
name="dob"
required
label="Data de nascimento"
as={(fieldProps) => <DayPicker {...fieldProps} />}
/>
<FieldWrapper
name="code"
helper="Codigo de 5 digitos"
required
label="Código de ativação"
as={(fieldProps) => <PinInput pinAmount={5} {...fieldProps} />}
/>
<FieldWrapper
name="gender"
label="Gênero"
as={(fieldProps) => (
<RadioGroup {...fieldProps} inline>
<Radio value="1">Masculino</Radio>
<Radio value="2">Feminino</Radio>
<Radio value="3">Prefiro não me identificar</Radio>
</RadioGroup>
)}
/>
<FieldWrapper
name="children"
label="Filhos"
helper="Quantidade de filhos"
as={(fieldProps) => (
<Checkbox
{...fieldProps}
options={[
{ value: '1', label: 'Um' },
{ value: '2', label: 'Dois' },
{ value: '3', label: 'Tres' },
]}
/>
)}
/>
<FieldWrapper
name="age"
required
label="Idade"
as={(fieldProps) => <Slider {...fieldProps} />}
/>
<FieldWrapper
name="country"
required
as={(fieldProps) => (
<AutoComplete
{...fieldProps}
label="Local de nascimento"
placeholder="Digite"
items={[
{ value: 'ghana', label: 'Ghana' },
{ value: 'nigeria', label: 'Nigeria' },
{ value: 'kenya', label: 'Kenya' },
{ value: 'southAfrica', label: 'South Africa' },
{ value: 'unitedStates', label: 'United States' },
{ value: 'canada', label: 'Canada' },
{ value: 'germany', label: 'Germany' },
]}
/>
)}
/>
<Button type="submit">Enviar</Button>
</>
)}
</Form>
);
};
const meta: Meta = {
title: 'Components/Form',
component: MyForm,
parameters: {
controls: { expanded: true },
},
};
export default meta;
const Template: Story = () => <MyForm />;
export const Basic = Template.bind({});
Basic.args = {};