Skip to content

Commit

Permalink
Add TypeScript demo for SwitchLabels componenet
Browse files Browse the repository at this point in the history
  • 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.
42 changes: 42 additions & 0 deletions docs/src/pages/demos/selection-controls/SwitchLabels.tsx
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;

0 comments on commit a61b120

Please sign in to comment.