-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add a customization example with ToggleButton (#17401)
- Loading branch information
1 parent
a0c9713
commit 8d5a09a
Showing
3 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
docs/src/pages/components/toggle-button/CustomizedDividers.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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react'; | ||
import { makeStyles, 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 Divider from '@material-ui/core/Divider'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import ToggleButton from '@material-ui/lab/ToggleButton'; | ||
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
paper: { | ||
display: 'flex', | ||
border: `1px solid ${theme.palette.divider}`, | ||
flexWrap: 'wrap', | ||
}, | ||
divider: { | ||
alignSelf: 'stretch', | ||
height: 'auto', | ||
margin: theme.spacing(1, 0.5), | ||
}, | ||
})); | ||
|
||
const StyledToggleButtonGroup = withStyles(theme => ({ | ||
grouped: { | ||
margin: theme.spacing(0.5), | ||
border: 'none', | ||
padding: theme.spacing(0, 1), | ||
'&:not(:first-child)': { | ||
borderRadius: theme.shape.borderRadius, | ||
}, | ||
'&:first-child': { | ||
borderRadius: theme.shape.borderRadius, | ||
}, | ||
}, | ||
}))(ToggleButtonGroup); | ||
|
||
export default function CustomizedDividers() { | ||
const [alignment, setAlignment] = React.useState('left'); | ||
const [formats, setFormats] = React.useState(() => ['italic']); | ||
|
||
const handleFormat = (event, newFormats) => { | ||
setFormats(newFormats); | ||
}; | ||
|
||
const handleAlignment = (event, newAlignment) => { | ||
setAlignment(newAlignment); | ||
}; | ||
|
||
const classes = useStyles(); | ||
|
||
return ( | ||
<div> | ||
<Paper elevation={0} className={classes.paper}> | ||
<StyledToggleButtonGroup | ||
size="small" | ||
value={alignment} | ||
exclusive | ||
onChange={handleAlignment} | ||
aria-label="text alignment" | ||
> | ||
<ToggleButton value="left" aria-label="left aligned"> | ||
<FormatAlignLeftIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="center" aria-label="centered"> | ||
<FormatAlignCenterIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="right" aria-label="right aligned"> | ||
<FormatAlignRightIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="justify" aria-label="justified" disabled> | ||
<FormatAlignJustifyIcon /> | ||
</ToggleButton> | ||
</StyledToggleButtonGroup> | ||
<Divider orientation="vertical" className={classes.divider} /> | ||
<StyledToggleButtonGroup | ||
size="small" | ||
value={formats} | ||
onChange={handleFormat} | ||
arial-label="text formatting" | ||
> | ||
<ToggleButton value="bold" aria-label="bold"> | ||
<FormatBoldIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="italic" aria-label="italic"> | ||
<FormatItalicIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="underlined" aria-label="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="color" aria-label="color" disabled> | ||
<FormatColorFillIcon /> | ||
<ArrowDropDownIcon /> | ||
</ToggleButton> | ||
</StyledToggleButtonGroup> | ||
</Paper> | ||
</div> | ||
); | ||
} |
107 changes: 107 additions & 0 deletions
107
docs/src/pages/components/toggle-button/CustomizedDividers.tsx
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from 'react'; | ||
import { makeStyles, withStyles, Theme, createStyles } 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 Divider from '@material-ui/core/Divider'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import ToggleButton from '@material-ui/lab/ToggleButton'; | ||
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
paper: { | ||
display: 'flex', | ||
border: `1px solid ${theme.palette.divider}`, | ||
flexWrap: 'wrap', | ||
}, | ||
divider: { | ||
alignSelf: 'stretch', | ||
height: 'auto', | ||
margin: theme.spacing(1, 0.5), | ||
}, | ||
}), | ||
); | ||
|
||
const StyledToggleButtonGroup = withStyles(theme => ({ | ||
grouped: { | ||
margin: theme.spacing(0.5), | ||
border: 'none', | ||
padding: theme.spacing(0, 1), | ||
'&:not(:first-child)': { | ||
borderRadius: theme.shape.borderRadius, | ||
}, | ||
'&:first-child': { | ||
borderRadius: theme.shape.borderRadius, | ||
}, | ||
}, | ||
}))(ToggleButtonGroup); | ||
|
||
export default function CustomizedDividers() { | ||
const [alignment, setAlignment] = React.useState('left'); | ||
const [formats, setFormats] = React.useState(() => ['italic']); | ||
|
||
const handleFormat = (event: React.MouseEvent<HTMLElement>, newFormats: string[]) => { | ||
setFormats(newFormats); | ||
}; | ||
|
||
const handleAlignment = (event: React.MouseEvent<HTMLElement>, newAlignment: string) => { | ||
setAlignment(newAlignment); | ||
}; | ||
|
||
const classes = useStyles(); | ||
|
||
return ( | ||
<div> | ||
<Paper elevation={0} className={classes.paper}> | ||
<StyledToggleButtonGroup | ||
size="small" | ||
value={alignment} | ||
exclusive | ||
onChange={handleAlignment} | ||
aria-label="text alignment" | ||
> | ||
<ToggleButton value="left" aria-label="left aligned"> | ||
<FormatAlignLeftIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="center" aria-label="centered"> | ||
<FormatAlignCenterIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="right" aria-label="right aligned"> | ||
<FormatAlignRightIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="justify" aria-label="justified" disabled> | ||
<FormatAlignJustifyIcon /> | ||
</ToggleButton> | ||
</StyledToggleButtonGroup> | ||
<Divider orientation="vertical" className={classes.divider} /> | ||
<StyledToggleButtonGroup | ||
size="small" | ||
value={formats} | ||
onChange={handleFormat} | ||
arial-label="text formatting" | ||
> | ||
<ToggleButton value="bold" aria-label="bold"> | ||
<FormatBoldIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="italic" aria-label="italic"> | ||
<FormatItalicIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="underlined" aria-label="underlined"> | ||
<FormatUnderlinedIcon /> | ||
</ToggleButton> | ||
<ToggleButton value="color" aria-label="color" disabled> | ||
<FormatColorFillIcon /> | ||
<ArrowDropDownIcon /> | ||
</ToggleButton> | ||
</StyledToggleButtonGroup> | ||
</Paper> | ||
</div> | ||
); | ||
} |
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