Skip to content

Commit

Permalink
[docs] Simplify checkbox examples (mui#20052)
Browse files Browse the repository at this point in the history
  • Loading branch information
tacigar authored and EsoterikStare committed Mar 30, 2020
1 parent 6753041 commit c24aa5f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 48 deletions.
18 changes: 6 additions & 12 deletions docs/src/pages/components/checkboxes/CheckboxLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ export default function CheckboxLabels() {
checkedG: true,
});

const handleChange = name => event => {
setState({ ...state, [name]: event.target.checked });
const handleChange = event => {
setState({ ...state, [event.target.value]: event.target.checked });
};

return (
<FormGroup row>
<FormControlLabel
control={
<Checkbox checked={state.checkedA} onChange={handleChange('checkedA')} value="checkedA" />
}
control={<Checkbox checked={state.checkedA} onChange={handleChange} value="checkedA" />}
label="Secondary"
/>
<FormControlLabel
control={
<Checkbox
checked={state.checkedB}
onChange={handleChange('checkedB')}
onChange={handleChange}
value="checkedB"
color="primary"
/>
Expand All @@ -57,7 +55,7 @@ export default function CheckboxLabels() {
control={
<Checkbox
checked={state.checkedF}
onChange={handleChange('checkedF')}
onChange={handleChange}
value="checkedF"
indeterminate
/>
Expand All @@ -66,11 +64,7 @@ export default function CheckboxLabels() {
/>
<FormControlLabel
control={
<GreenCheckbox
checked={state.checkedG}
onChange={handleChange('checkedG')}
value="checkedG"
/>
<GreenCheckbox checked={state.checkedG} onChange={handleChange} value="checkedG" />
}
label="Custom color"
/>
Expand Down
18 changes: 6 additions & 12 deletions docs/src/pages/components/checkboxes/CheckboxLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@ export default function CheckboxLabels() {
checkedG: true,
});

const handleChange = (name: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
setState({ ...state, [name]: event.target.checked });
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setState({ ...state, [event.target.value]: event.target.checked });
};

return (
<FormGroup row>
<FormControlLabel
control={
<Checkbox checked={state.checkedA} onChange={handleChange('checkedA')} value="checkedA" />
}
control={<Checkbox checked={state.checkedA} onChange={handleChange} value="checkedA" />}
label="Secondary"
/>
<FormControlLabel
control={
<Checkbox
checked={state.checkedB}
onChange={handleChange('checkedB')}
onChange={handleChange}
value="checkedB"
color="primary"
/>
Expand All @@ -57,7 +55,7 @@ export default function CheckboxLabels() {
control={
<Checkbox
checked={state.checkedF}
onChange={handleChange('checkedF')}
onChange={handleChange}
value="checkedF"
indeterminate
/>
Expand All @@ -66,11 +64,7 @@ export default function CheckboxLabels() {
/>
<FormControlLabel
control={
<GreenCheckbox
checked={state.checkedG}
onChange={handleChange('checkedG')}
value="checkedG"
/>
<GreenCheckbox checked={state.checkedG} onChange={handleChange} value="checkedG" />
}
label="Custom color"
/>
Expand Down
20 changes: 8 additions & 12 deletions docs/src/pages/components/checkboxes/CheckboxesGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default function CheckboxesGroup() {
antoine: false,
});

const handleChange = name => event => {
setState({ ...state, [name]: event.target.checked });
const handleChange = event => {
setState({ ...state, [event.target.value]: event.target.checked });
};

const { gilad, jason, antoine } = state;
Expand All @@ -37,17 +37,15 @@ export default function CheckboxesGroup() {
<FormLabel component="legend">Assign responsibility</FormLabel>
<FormGroup>
<FormControlLabel
control={<Checkbox checked={gilad} onChange={handleChange('gilad')} value="gilad" />}
control={<Checkbox checked={gilad} onChange={handleChange} value="gilad" />}
label="Gilad Gray"
/>
<FormControlLabel
control={<Checkbox checked={jason} onChange={handleChange('jason')} value="jason" />}
control={<Checkbox checked={jason} onChange={handleChange} value="jason" />}
label="Jason Killian"
/>
<FormControlLabel
control={
<Checkbox checked={antoine} onChange={handleChange('antoine')} value="antoine" />
}
control={<Checkbox checked={antoine} onChange={handleChange} value="antoine" />}
label="Antoine Llorca"
/>
</FormGroup>
Expand All @@ -57,17 +55,15 @@ export default function CheckboxesGroup() {
<FormLabel component="legend">Pick two</FormLabel>
<FormGroup>
<FormControlLabel
control={<Checkbox checked={gilad} onChange={handleChange('gilad')} value="gilad" />}
control={<Checkbox checked={gilad} onChange={handleChange} value="gilad" />}
label="Gilad Gray"
/>
<FormControlLabel
control={<Checkbox checked={jason} onChange={handleChange('jason')} value="jason" />}
control={<Checkbox checked={jason} onChange={handleChange} value="jason" />}
label="Jason Killian"
/>
<FormControlLabel
control={
<Checkbox checked={antoine} onChange={handleChange('antoine')} value="antoine" />
}
control={<Checkbox checked={antoine} onChange={handleChange} value="antoine" />}
label="Antoine Llorca"
/>
</FormGroup>
Expand Down
20 changes: 8 additions & 12 deletions docs/src/pages/components/checkboxes/CheckboxesGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function CheckboxesGroup() {
antoine: false,
});

const handleChange = (name: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
setState({ ...state, [name]: event.target.checked });
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setState({ ...state, [event.target.value]: event.target.checked });
};

const { gilad, jason, antoine } = state;
Expand All @@ -39,17 +39,15 @@ export default function CheckboxesGroup() {
<FormLabel component="legend">Assign responsibility</FormLabel>
<FormGroup>
<FormControlLabel
control={<Checkbox checked={gilad} onChange={handleChange('gilad')} value="gilad" />}
control={<Checkbox checked={gilad} onChange={handleChange} value="gilad" />}
label="Gilad Gray"
/>
<FormControlLabel
control={<Checkbox checked={jason} onChange={handleChange('jason')} value="jason" />}
control={<Checkbox checked={jason} onChange={handleChange} value="jason" />}
label="Jason Killian"
/>
<FormControlLabel
control={
<Checkbox checked={antoine} onChange={handleChange('antoine')} value="antoine" />
}
control={<Checkbox checked={antoine} onChange={handleChange} value="antoine" />}
label="Antoine Llorca"
/>
</FormGroup>
Expand All @@ -59,17 +57,15 @@ export default function CheckboxesGroup() {
<FormLabel component="legend">Pick two</FormLabel>
<FormGroup>
<FormControlLabel
control={<Checkbox checked={gilad} onChange={handleChange('gilad')} value="gilad" />}
control={<Checkbox checked={gilad} onChange={handleChange} value="gilad" />}
label="Gilad Gray"
/>
<FormControlLabel
control={<Checkbox checked={jason} onChange={handleChange('jason')} value="jason" />}
control={<Checkbox checked={jason} onChange={handleChange} value="jason" />}
label="Jason Killian"
/>
<FormControlLabel
control={
<Checkbox checked={antoine} onChange={handleChange('antoine')} value="antoine" />
}
control={<Checkbox checked={antoine} onChange={handleChange} value="antoine" />}
label="Antoine Llorca"
/>
</FormGroup>
Expand Down

0 comments on commit c24aa5f

Please sign in to comment.