-
-
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.
[FormControlLabel] Add labelPlacement prop (#12303)
- Loading branch information
Showing
6 changed files
with
128 additions
and
45 deletions.
There are no files selected for viewing
117 changes: 79 additions & 38 deletions
117
docs/src/pages/demos/selection-controls/CheckboxesGroup.js
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 |
---|---|---|
@@ -1,62 +1,103 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import FormLabel from '@material-ui/core/FormLabel'; | ||
import FormControl from '@material-ui/core/FormControl'; | ||
import FormGroup from '@material-ui/core/FormGroup'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import FormHelperText from '@material-ui/core/FormHelperText'; | ||
import Checkbox from '@material-ui/core/Checkbox'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
display: 'flex', | ||
}, | ||
formControl: { | ||
margin: theme.spacing.unit * 3, | ||
}, | ||
}); | ||
|
||
class CheckboxesGroup extends React.Component { | ||
state = { | ||
gilad: true, | ||
jason: false, | ||
antoine: true, | ||
antoine: false, | ||
}; | ||
|
||
handleChange = name => event => { | ||
this.setState({ [name]: event.target.checked }); | ||
}; | ||
|
||
render() { | ||
const { classes } = this.props; | ||
const { gilad, jason, antoine } = this.state; | ||
const error = Object.values(this.state).filter(v => v).length !== 2; | ||
|
||
return ( | ||
<FormControl component="fieldset"> | ||
<FormLabel component="legend">Assign responsibility</FormLabel> | ||
<FormGroup> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={this.state.gilad} | ||
onChange={this.handleChange('gilad')} | ||
value="gilad" | ||
/> | ||
} | ||
label="Gilad Gray" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={this.state.jason} | ||
onChange={this.handleChange('jason')} | ||
value="jason" | ||
/> | ||
} | ||
label="Jason Killian" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={this.state.antoine} | ||
onChange={this.handleChange('antoine')} | ||
value="antoine" | ||
/> | ||
} | ||
label="Antoine Llorca" | ||
/> | ||
</FormGroup> | ||
<FormHelperText>Be careful</FormHelperText> | ||
</FormControl> | ||
<div className={classes.root}> | ||
<FormControl component="fieldset" className={classes.formControl}> | ||
<FormLabel component="legend">Assign responsibility</FormLabel> | ||
<FormGroup> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox checked={gilad} onChange={this.handleChange('gilad')} value="gilad" /> | ||
} | ||
label="Gilad Gray" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox checked={jason} onChange={this.handleChange('jason')} value="jason" /> | ||
} | ||
label="Jason Killian" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={antoine} | ||
onChange={this.handleChange('antoine')} | ||
value="antoine" | ||
/> | ||
} | ||
label="Antoine Llorca" | ||
/> | ||
</FormGroup> | ||
<FormHelperText>Be careful</FormHelperText> | ||
</FormControl> | ||
<FormControl required error={error} component="fieldset" className={classes.formControl}> | ||
<FormLabel component="legend">Pick two</FormLabel> | ||
<FormGroup> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox checked={gilad} onChange={this.handleChange('gilad')} value="gilad" /> | ||
} | ||
label="Gilad Gray" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox checked={jason} onChange={this.handleChange('jason')} value="jason" /> | ||
} | ||
label="Jason Killian" | ||
/> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={antoine} | ||
onChange={this.handleChange('antoine')} | ||
value="antoine" | ||
/> | ||
} | ||
label="Antoine Llorca" | ||
/> | ||
</FormGroup> | ||
<FormHelperText>You can display an error</FormHelperText> | ||
</FormControl> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default CheckboxesGroup; | ||
CheckboxesGroup.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(CheckboxesGroup); |
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
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
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
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
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