-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add switches typescript demo (#15384)
Adding TypeScript example for switches demo. Issue #14897
- Loading branch information
1 parent
a494652
commit 3044cb4
Showing
1 changed file
with
31 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,31 @@ | ||
import React from 'react'; | ||
import Switch from '@material-ui/core/Switch'; | ||
|
||
function Switches() { | ||
const [state, setState] = React.useState({ | ||
checkedA: true, | ||
checkedB: true, | ||
}); | ||
|
||
const handleChange = (name: string) => (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setState({ ...state, [name]: event.target.checked }); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Switch checked={state.checkedA} onChange={handleChange('checkedA')} value="checkedA" /> | ||
<Switch | ||
checked={state.checkedB} | ||
onChange={handleChange('checkedB')} | ||
value="checkedB" | ||
color="primary" | ||
/> | ||
<Switch value="checkedC" /> | ||
<Switch disabled value="checkedD" /> | ||
<Switch disabled checked value="checkedE" /> | ||
<Switch defaultChecked value="checkedF" color="default" /> | ||
</div> | ||
); | ||
} | ||
|
||
export default Switches; |