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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
import React, { Fragment, PureComponent } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';
import CheckBoxIcon from '@material-ui/icons/CheckBox';
import Favorite from '@material-ui/icons/Favorite';
import FavoriteBorder from '@material-ui/icons/FavoriteBorder';
import { green } from '@material-ui/core/colors';
import {
Checkbox,
Typography,
Grid,
FormControl,
FormLabel,
FormControlLabel,
FormHelperText,
FormGroup,
} from '@material-ui/core';
const styles = theme => ({
demo: {
height: 'auto',
},
divider: {
display: 'block',
margin: `${theme.spacing(3)}px 0`,
},
field: {
margin: `${theme.spacing(3)}px 5px`,
},
root: {
color: green[600],
'&$checked': {
color: green[500],
},
},
checked: {},
size: {
width: 40,
height: 40,
},
sizeIcon: {
fontSize: 20,
},
});
class Checkboxes extends PureComponent {
state = {
checkedA: true,
checkedB: true,
checkedF: true,
checkedG: true,
gilad: true,
jason: false,
antoine: true,
};
handleChange = name => event => {
this.setState({ [name]: event.target.checked });
};
render() {
const { classes } = this.props;
return (
<Fragment>
<Grid
container
alignItems="flex-start"
justify="space-around"
direction="row"
spacing={3}
>
<Grid
item
md={3}
className={classes.demo}
>
<Typography variant="button" className={classes.divider}>Basic usage</Typography>
<div>
<Checkbox
checked={this.state.checkedA}
onChange={this.handleChange('checkedA')}
value="checkedA"
/>
<Checkbox
checked={this.state.checkedB}
onChange={this.handleChange('checkedB')}
value="checkedB"
color="primary"
/>
<Checkbox value="checkedC" />
<Checkbox disabled value="checkedD" />
<Checkbox disabled checked value="checkedE" />
<Checkbox
checked={this.state.checkedF}
onChange={this.handleChange('checkedF')}
value="checkedF"
indeterminate
/>
<Checkbox defaultChecked color="default" value="checkedG" />
</div>
</Grid>
<Grid
item
md={5}
className={classes.demo}
>
<Typography variant="button" className={classes.divider}>Checkbox with label</Typography>
<Typography className={classes.divider}>Checkbox can also be used with a label description thanks to the FormControlLabel component.</Typography>
<div>
<FormGroup row>
<FormControlLabel
control={(
<Checkbox
checked={this.state.checkedA}
onChange={this.handleChange('checkedA')}
value="checkedA"
/>
)}
label="Secondary"
/>
<FormControlLabel
control={(
<Checkbox
checked={this.state.checkedB}
onChange={this.handleChange('checkedB')}
value="checkedB"
color="primary"
/>
)}
label="Primary"
/>
<FormControlLabel control={<Checkbox value="checkedC" />} label="Uncontrolled" />
<FormControlLabel disabled control={<Checkbox value="checkedD" />} label="Disabled" />
<FormControlLabel
disabled
control={<Checkbox checked value="checkedE" />}
label="Disabled"
/>
<FormControlLabel
control={(
<Checkbox
checked={this.state.checkedF}
onChange={this.handleChange('checkedF')}
value="checkedF"
indeterminate
/>
)}
label="Indeterminate"
/>
<FormControlLabel
control={(
<Checkbox
checked={this.state.checkedG}
onChange={this.handleChange('checkedG')}
value="checkedG"
classes={{
root: classes.root,
checked: classes.checked,
}}
/>
)}
label="Custom color"
/>
<FormControlLabel
control={
<Checkbox icon={<FavoriteBorder />} checkedIcon={<Favorite />} value="checkedH" />
}
label="Custom icon"
/>
<FormControlLabel
control={(
<Checkbox
className={classes.size}
icon={<CheckBoxOutlineBlankIcon className={classes.sizeIcon} />}
checkedIcon={<CheckBoxIcon className={classes.sizeIcon} />}
value="checkedI"
/>
)}
label="Custom size"
/>
</FormGroup>
</div>
</Grid>
<Grid
item
md={4}
className={classes.demo}
>
<Typography variant="button" className={classes.divider}>Checkbox in Form Group</Typography>
<Typography className={classes.divider}>FormGroup is a helpful wrapper used to group selection controls components that provides an easier API.</Typography>
<div>
<FormControl component="fieldset">
<FormLabel component="legend">Assign responsibility</FormLabel>
<FormGroup>
<FormControlLabel
control={(
<Checkbox
checked={this.state.gilad}
onChange={this.handleChange('gilad')}
value="gilad"
/>
)}
label="Gilad Gray"
/>
<FormControlLabel
control={(
<Checkbox
checked={this.state.jason}
onChange={this.handleChange('jason')}
value="jason"
/>
)}
label="Jason Killian"
/>
<FormControlLabel
control={(
<Checkbox
checked={this.state.antoine}
onChange={this.handleChange('antoine')}
value="antoine"
/>
)}
label="Antoine Llorca"
/>
</FormGroup>
<FormHelperText>Be careful</FormHelperText>
</FormControl>
</div>
</Grid>
</Grid>
</Fragment>
);
}
}
Checkboxes.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(Checkboxes);
|