Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ToggleButton] Reduce gap with ButtonGroup #20967

Merged
merged 2 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/pages/api-docs/toggle-button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ Any other props supplied will be provided to the root element (native element).
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiToggleButtonGroup-root</span> | Styles applied to the root element.
| <span class="prop-name">grouped</span> | <span class="prop-name">.MuiToggleButtonGroup-grouped</span> | Styles applied to the children.
| <span class="prop-name">groupedSizeSmall</span> | <span class="prop-name">.MuiToggleButtonGroup-groupedSizeSmall</span> | Styles applied to the children if `size="small"`.
| <span class="prop-name">groupedSizeLarge</span> | <span class="prop-name">.MuiToggleButtonGroup-groupedSizeLarge</span> | Styles applied to the children if `size="large"`.

You can override the style of the component thanks to one of these customization points:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const useStyles = makeStyles((theme) => ({
flexWrap: 'wrap',
},
divider: {
alignSelf: 'stretch',
height: 'auto',
margin: theme.spacing(1, 0.5),
},
}));
Expand All @@ -31,7 +29,6 @@ const StyledToggleButtonGroup = withStyles((theme) => ({
grouped: {
margin: theme.spacing(0.5),
border: 'none',
padding: theme.spacing(0, 1),
'&:not(:first-child)': {
borderRadius: theme.shape.borderRadius,
},
Expand Down Expand Up @@ -78,7 +75,7 @@ export default function CustomizedDividers() {
<FormatAlignJustifyIcon />
</ToggleButton>
</StyledToggleButtonGroup>
<Divider orientation="vertical" className={classes.divider} />
<Divider flexItem orientation="vertical" className={classes.divider} />
<StyledToggleButtonGroup
size="small"
value={formats}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const useStyles = makeStyles((theme: Theme) =>
flexWrap: 'wrap',
},
divider: {
alignSelf: 'stretch',
height: 'auto',
margin: theme.spacing(1, 0.5),
},
}),
Expand All @@ -33,7 +31,6 @@ const StyledToggleButtonGroup = withStyles((theme) => ({
grouped: {
margin: theme.spacing(0.5),
border: 'none',
padding: theme.spacing(0, 1),
'&:not(:first-child)': {
borderRadius: theme.shape.borderRadius,
},
Expand Down Expand Up @@ -80,7 +77,7 @@ export default function CustomizedDividers() {
<FormatAlignJustifyIcon />
</ToggleButton>
</StyledToggleButtonGroup>
<Divider orientation="vertical" className={classes.divider} />
<Divider flexItem orientation="vertical" className={classes.divider} />
<StyledToggleButtonGroup
size="small"
value={formats}
Expand Down
54 changes: 36 additions & 18 deletions docs/src/pages/components/toggle-button/ToggleButtonSizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,54 @@ export default function ToggleButtonSizes() {
setAlignment(newAlignment);
};

const children = [
<ToggleButton key={1} value="left">
<FormatAlignLeftIcon />
</ToggleButton>,
<ToggleButton key={2} value="center">
<FormatAlignCenterIcon />
</ToggleButton>,
<ToggleButton key={3} value="right">
<FormatAlignRightIcon />
</ToggleButton>,
<ToggleButton key={4} value="justify" disabled>
<FormatAlignJustifyIcon />
</ToggleButton>,
];

return (
<Grid container spacing={2} direction="column" alignItems="center">
<Grid item>
<ToggleButtonGroup size="small" value={alignment} exclusive onChange={handleChange}>
{children}
<ToggleButton value="left">
<FormatAlignLeftIcon fontSize="small" />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon fontSize="small" />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon fontSize="small" />
</ToggleButton>
<ToggleButton value="justify">
<FormatAlignJustifyIcon fontSize="small" />
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid item>
<ToggleButtonGroup size="medium" value={alignment} exclusive onChange={handleChange}>
{children}
<ToggleButton value="left">
<FormatAlignLeftIcon />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon />
</ToggleButton>
<ToggleButton value="justify">
<FormatAlignJustifyIcon />
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid item>
<ToggleButtonGroup size="large" value={alignment} exclusive onChange={handleChange}>
{children}
<ToggleButton value="left">
<FormatAlignLeftIcon />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon />
</ToggleButton>
<ToggleButton value="justify">
<FormatAlignJustifyIcon />
</ToggleButton>
</ToggleButtonGroup>
</Grid>
</Grid>
Expand Down
54 changes: 36 additions & 18 deletions docs/src/pages/components/toggle-button/ToggleButtonSizes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,54 @@ export default function ToggleButtonSizes() {
setAlignment(newAlignment);
};

const children = [
<ToggleButton key={1} value="left">
<FormatAlignLeftIcon />
</ToggleButton>,
<ToggleButton key={2} value="center">
<FormatAlignCenterIcon />
</ToggleButton>,
<ToggleButton key={3} value="right">
<FormatAlignRightIcon />
</ToggleButton>,
<ToggleButton key={4} value="justify" disabled>
<FormatAlignJustifyIcon />
</ToggleButton>,
];

return (
<Grid container spacing={2} direction="column" alignItems="center">
<Grid item>
<ToggleButtonGroup size="small" value={alignment} exclusive onChange={handleChange}>
{children}
<ToggleButton value="left">
<FormatAlignLeftIcon fontSize="small" />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon fontSize="small" />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon fontSize="small" />
</ToggleButton>
<ToggleButton value="justify">
<FormatAlignJustifyIcon fontSize="small" />
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid item>
<ToggleButtonGroup size="medium" value={alignment} exclusive onChange={handleChange}>
{children}
<ToggleButton value="left">
<FormatAlignLeftIcon />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon />
</ToggleButton>
<ToggleButton value="justify">
<FormatAlignJustifyIcon />
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid item>
<ToggleButtonGroup size="large" value={alignment} exclusive onChange={handleChange}>
{children}
<ToggleButton value="left">
<FormatAlignLeftIcon />
</ToggleButton>
<ToggleButton value="center">
<FormatAlignCenterIcon />
</ToggleButton>
<ToggleButton value="right">
<FormatAlignRightIcon />
</ToggleButton>
<ToggleButton value="justify">
<FormatAlignJustifyIcon />
</ToggleButton>
</ToggleButtonGroup>
</Grid>
</Grid>
Expand Down
95 changes: 19 additions & 76 deletions docs/src/pages/components/toggle-button/ToggleButtons.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,37 @@
import React from 'react';
import { makeStyles } 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 useStyles = makeStyles((theme) => ({
toggleContainer: {
margin: theme.spacing(2, 0),
},
}));

export default function ToggleButtons() {
const [alignment, setAlignment] = React.useState('left');
const [formats, setFormats] = React.useState(() => ['bold']);

const handleFormat = (event, newFormats) => {
setFormats(newFormats);
};

const handleAlignment = (event, newAlignment) => {
setAlignment(newAlignment);
};

const classes = useStyles();

return (
<Grid container spacing={2}>
<Grid item sm={12} md={6}>
<div className={classes.toggleContainer}>
<ToggleButtonGroup
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>
</ToggleButtonGroup>
</div>
<Typography gutterBottom>Exclusive Selection</Typography>
<Typography>
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 sm={12} md={6}>
<div className={classes.toggleContainer}>
<ToggleButtonGroup value={formats} onChange={handleFormat} aria-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>
</ToggleButtonGroup>
</div>
<Typography gutterBottom>Multiple Selection</Typography>
<Typography>
Logically-grouped options, like Bold, Italic, and Underline, allow multiple options to be
selected.
</Typography>
</Grid>
</Grid>
<ToggleButtonGroup
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>
</ToggleButtonGroup>
);
}
Loading