|
| 1 | +import React from 'react'; |
| 2 | +import { makeStyles } from '@material-ui/core/styles'; |
| 3 | +import FormatAlignLeftIcon from '@material-ui/icons/FormatAlignLeft'; |
| 4 | +import FormatAlignCenterIcon from '@material-ui/icons/FormatAlignCenter'; |
| 5 | +import FormatAlignRightIcon from '@material-ui/icons/FormatAlignRight'; |
| 6 | +import FormatAlignJustifyIcon from '@material-ui/icons/FormatAlignJustify'; |
| 7 | +import FormatBoldIcon from '@material-ui/icons/FormatBold'; |
| 8 | +import FormatItalicIcon from '@material-ui/icons/FormatItalic'; |
| 9 | +import FormatUnderlinedIcon from '@material-ui/icons/FormatUnderlined'; |
| 10 | +import FormatColorFillIcon from '@material-ui/icons/FormatColorFill'; |
| 11 | +import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; |
| 12 | +import Typography from '@material-ui/core/Typography'; |
| 13 | +import Grid from '@material-ui/core/Grid'; |
| 14 | +import ToggleButton from '@material-ui/lab/ToggleButton'; |
| 15 | +import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; |
| 16 | + |
| 17 | +const useStyles = makeStyles(theme => ({ |
| 18 | + toggleContainer: { |
| 19 | + margin: theme.spacing(2, 0), |
| 20 | + }, |
| 21 | +})); |
| 22 | + |
| 23 | +export default function ToggleButtons() { |
| 24 | + const [alignment, setAlignment] = React.useState('left'); |
| 25 | + const [formats, setFormats] = React.useState(() => ['bold']); |
| 26 | + |
| 27 | + const handleFormat = (event: React.MouseEvent<HTMLElement>, newFormats: string[]) => { |
| 28 | + setFormats(newFormats); |
| 29 | + }; |
| 30 | + |
| 31 | + const handleAlignment = (event: React.MouseEvent<HTMLElement>, newAlignment: string) => { |
| 32 | + setAlignment(newAlignment); |
| 33 | + }; |
| 34 | + |
| 35 | + const classes = useStyles(); |
| 36 | + |
| 37 | + return ( |
| 38 | + <Grid container spacing={2}> |
| 39 | + <Grid item sm={12} md={6}> |
| 40 | + <div className={classes.toggleContainer}> |
| 41 | + <ToggleButtonGroup |
| 42 | + value={alignment} |
| 43 | + exclusive |
| 44 | + onChange={handleAlignment} |
| 45 | + aria-label="text alignment" |
| 46 | + > |
| 47 | + <ToggleButton value="left" aria-label="left aligned"> |
| 48 | + <FormatAlignLeftIcon /> |
| 49 | + </ToggleButton> |
| 50 | + <ToggleButton value="center" aria-label="centered"> |
| 51 | + <FormatAlignCenterIcon /> |
| 52 | + </ToggleButton> |
| 53 | + <ToggleButton value="right" aria-label="right aligned"> |
| 54 | + <FormatAlignRightIcon /> |
| 55 | + </ToggleButton> |
| 56 | + <ToggleButton value="justify" aria-label="justified" disabled> |
| 57 | + <FormatAlignJustifyIcon /> |
| 58 | + </ToggleButton> |
| 59 | + </ToggleButtonGroup> |
| 60 | + </div> |
| 61 | + <Typography gutterBottom>Exclusive Selection</Typography> |
| 62 | + <Typography> |
| 63 | + Text justification toggle buttons present options for left, right, center, full, and |
| 64 | + justified text with only one item available for selection at a time. Selecting one option |
| 65 | + deselects any other. |
| 66 | + </Typography> |
| 67 | + </Grid> |
| 68 | + <Grid item sm={12} md={6}> |
| 69 | + <div className={classes.toggleContainer}> |
| 70 | + <ToggleButtonGroup value={formats} onChange={handleFormat} arial-label="text formatting"> |
| 71 | + <ToggleButton value="bold" aria-label="bold"> |
| 72 | + <FormatBoldIcon /> |
| 73 | + </ToggleButton> |
| 74 | + <ToggleButton value="italic" aria-label="italic"> |
| 75 | + <FormatItalicIcon /> |
| 76 | + </ToggleButton> |
| 77 | + <ToggleButton value="underlined" aria-label="underlined"> |
| 78 | + <FormatUnderlinedIcon /> |
| 79 | + </ToggleButton> |
| 80 | + <ToggleButton value="color" aria-label="color" disabled> |
| 81 | + <FormatColorFillIcon /> |
| 82 | + <ArrowDropDownIcon /> |
| 83 | + </ToggleButton> |
| 84 | + </ToggleButtonGroup> |
| 85 | + </div> |
| 86 | + <Typography gutterBottom>Multiple Selection</Typography> |
| 87 | + <Typography> |
| 88 | + Logically-grouped options, like Bold, Italic, and Underline, allow multiple options to be |
| 89 | + selected. |
| 90 | + </Typography> |
| 91 | + </Grid> |
| 92 | + </Grid> |
| 93 | + ); |
| 94 | +} |
0 commit comments