import React, { Fragment, PureComponent } from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import { green } from '@material-ui/core/colors'; import { Switch, Typography, Grid, FormControl, FormLabel, FormControlLabel, FormGroup, FormHelperText, } from '@material-ui/core'; const styles = theme => ({ demo: { height: 'auto', }, divider: { display: 'block', margin: `${theme.spacing(3)}px 0`, }, field: { margin: `${theme.spacing(3)}px 5px`, }, formControl: { margin: theme.spacing(3), }, group: { margin: `${theme.spacing(1)}px 0`, }, switchBase: { color: green[50], '&$checked': { color: green[500], '& + $bar': { backgroundColor: green[500], }, }, }, bar: {}, checked: {}, size: { width: 40, height: 40, }, sizeIcon: { fontSize: 20, }, }); class RadioButton extends PureComponent { state = { checkedA: true, checkedB: true, checkedF: true, gilad: true, jason: false, antoine: true, }; handleChange = name => event => { this.setState({ [name]: event.target.checked }); }; render() { const { classes } = this.props; return ( Basic usage
Switch with label Switch can also be used with a label description thanks to the FormControlLabel component.
)} label="Secondary" /> )} label="Primary" /> } label="Uncontrolled" /> } label="Disabled" /> } label="Disabled" /> )} label="Custom color" />
Switch in Form Group FormGroup is a helpful wrapper used to group selection controls components that provides an easier API. However, we encourage you to use a Checkbox instead.
Assign responsibility )} label="Gilad Gray" /> )} label="Jason Killian" /> )} label="Antoine Llorca" /> Be careful
); } } RadioButton.propTypes = { classes: PropTypes.object.isRequired, }; export default withStyles(styles)(RadioButton);