Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Simplify checkbox examples #20052

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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