-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeScript demo for SwitchLabels componenet
- Loading branch information
Brandon Herrera
authored and
Brandon Herrera
committed
Apr 19, 2019
1 parent
c5f562c
commit a61b120
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import FormGroup from '@material-ui/core/FormGroup'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import Switch from '@material-ui/core/Switch'; | ||
|
||
function SwitchLabels() { | ||
const [state, setState] = React.useState({ | ||
checkedA: true, | ||
checkedB: true, | ||
}); | ||
|
||
const handleChange = (name: string) => (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setState({ ...state, [name]: event.target.checked }); | ||
}; | ||
|
||
return ( | ||
<FormGroup row> | ||
<FormControlLabel | ||
control={ | ||
<Switch checked={state.checkedA} onChange={handleChange('checkedA')} value="checkedA" /> | ||
} | ||
label="Secondary" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={state.checkedB} | ||
onChange={handleChange('checkedB')} | ||
value="checkedB" | ||
color="primary" | ||
/> | ||
} | ||
label="Primary" | ||
/> | ||
<FormControlLabel control={<Switch value="checkedC" />} label="Uncontrolled" /> | ||
<FormControlLabel disabled control={<Switch value="checkedD" />} label="Disabled" /> | ||
<FormControlLabel disabled control={<Switch checked value="checkedE" />} label="Disabled" /> | ||
</FormGroup> | ||
); | ||
} | ||
|
||
export default SwitchLabels; |