/
KitchenSink.story.tsx
141 lines (137 loc) · 3.81 KB
/
KitchenSink.story.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
import React from 'react';
import Button from '@material-ui/core/Button';
import { Formik, Field, Form } from 'formik';
import { LinearProgress, FormControlLabel, Radio } from '@material-ui/core';
import { action } from '@storybook/addon-actions';
import MenuItem from '@material-ui/core/MenuItem';
import InputLabel from '@material-ui/core/InputLabel';
import FormControl from '@material-ui/core/FormControl';
import Wrapper from './Wrapper';
import FormValues from './FormValues';
import { CheckboxWithLabel, TextField, Select, RadioGroup } from '../src/main';
interface Values {
email: string;
password: string;
dateTime: string;
date: string;
rememberMe: boolean;
age: string;
}
const initialValues: Values = {
email: '',
password: '',
dateTime: '',
date: '',
rememberMe: false,
age: '',
};
export default () => (
<Wrapper title="Kitchen Sink">
<Formik<Values>
initialValues={initialValues}
validate={values => {
const errors: Partial<Values> = {};
if (!values.email) {
errors.email = 'Required';
} else if (
!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)
) {
errors.email = 'Invalid email address';
}
return errors;
}}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
setSubmitting(false);
action('submit')(values);
}, 2000);
}}
render={({ submitForm, isSubmitting, values }) => (
<Form>
<Field
type="email"
label="Email"
name="email"
component={TextField}
/>
<br />
<Field
type="password"
label="Password"
name="password"
component={TextField}
/>
<br />
<Field
Label={{ label: 'Remember Me' }}
name="rememberMe"
component={CheckboxWithLabel}
/>
<br />
<FormControl>
<InputLabel htmlFor="age-simple">Age</InputLabel>
<Field
name="age"
component={Select}
inputProps={{
name: 'age',
id: 'age-simple',
}}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Field>
</FormControl>
<br />
<Field
InputLabelProps={{ shrink: true }}
type="datetime-local"
label="Date Time"
name="dateTime"
component={TextField}
/>
<br />
<Field
InputLabelProps={{ shrink: true }}
type="date"
label="Date"
name="date"
component={TextField}
/>
<br />
<Field name="activity" label="Radio Group" component={RadioGroup}>
<FormControlLabel
value="painting"
control={<Radio disabled={isSubmitting} />}
label="Painting"
disabled={isSubmitting}
/>
<FormControlLabel
value="drawing"
control={<Radio disabled={isSubmitting} />}
label="Drawing"
disabled={isSubmitting}
/>
</Field>
<br />
{isSubmitting && <LinearProgress />}
<br />
<Button
variant="contained"
color="primary"
disabled={isSubmitting}
onClick={submitForm}
>
Submit
</Button>
<br />
<FormValues values={values} />
</Form>
)}
/>
</Wrapper>
);