materialuiupgraded
Version:
Material-UI's workspace package
108 lines (99 loc) • 4.08 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import FormatAlignLeftIcon from '@material-ui/icons/FormatAlignLeft';
import FormatAlignCenterIcon from '@material-ui/icons/FormatAlignCenter';
import FormatAlignRightIcon from '@material-ui/icons/FormatAlignRight';
import FormatAlignJustifyIcon from '@material-ui/icons/FormatAlignJustify';
import FormatBoldIcon from '@material-ui/icons/FormatBold';
import FormatItalicIcon from '@material-ui/icons/FormatItalic';
import FormatUnderlinedIcon from '@material-ui/icons/FormatUnderlined';
import FormatColorFillIcon from '@material-ui/icons/FormatColorFill';
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
import Typography from '@material-ui/core/Typography';
import Grid from '@material-ui/core/Grid';
import ToggleButton from '@material-ui/lab/ToggleButton';
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
const styles = theme => ({
toggleContainer: {
height: 56,
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`,
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-start',
margin: `${theme.spacing.unit}px 0`,
background: theme.palette.background.default,
},
});
class ToggleButtons extends React.Component {
state = {
alignment: 'left',
formats: ['bold'],
};
handleFormat = (event, formats) => this.setState({ formats });
handleAlignment = (event, alignment) => this.setState({ alignment });
render() {
const { classes } = this.props;
const { alignment, formats } = this.state;
return (
<Grid container spacing={16}>
<Grid item xs={12} sm={6}>
<div className={classes.toggleContainer}>
<ToggleButtonGroup value={alignment} exclusive onChange={this.handleAlignment}>
<ToggleButton value="left">
<FormatAlignLeftIcon />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon />
</ToggleButton>
<ToggleButton value="justify" disabled>
<FormatAlignJustifyIcon />
</ToggleButton>
</ToggleButtonGroup>
</div>
<Typography variant="caption" gutterBottom>
Exclusive Selection
</Typography>
<Typography variant="caption">
Text justification toggle buttons present options for left, right, center, full, and
justified text with only one item available for selection at a time. Selecting one
option deselects any other.
</Typography>
</Grid>
<Grid item xs={12} sm={6}>
<div className={classes.toggleContainer}>
<ToggleButtonGroup value={formats} onChange={this.handleFormat}>
<ToggleButton value="bold">
<FormatBoldIcon />
</ToggleButton>
<ToggleButton value="italic">
<FormatItalicIcon />
</ToggleButton>
<ToggleButton value="underlined">
<FormatUnderlinedIcon />
</ToggleButton>
<ToggleButton disabled value="color">
<FormatColorFillIcon />
<ArrowDropDownIcon />
</ToggleButton>
</ToggleButtonGroup>
</div>
<Typography variant="caption" gutterBottom>
Multiple Selection
</Typography>
<Typography variant="caption">
Logically-grouped options, like Bold, Italic, and Underline, allow multiple options to
be selected.
</Typography>
</Grid>
</Grid>
);
}
}
ToggleButtons.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(ToggleButtons);