Skip to content

Commit 4a61acd

Browse files
essurajmbrookes
authored andcommitted
[Button] Make the outlined variant better leverage the color (#12473)
1 parent f21551e commit 4a61acd

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

packages/material-ui/src/Button/Button.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export type ButtonClassKey =
2626
| 'flatPrimary'
2727
| 'flatSecondary'
2828
| 'outlined'
29+
| 'outlinedPrimary'
30+
| 'outlinedSecondary'
2931
| 'colorInherit'
3032
| 'contained'
3133
| 'containedPrimary'

packages/material-ui/src/Button/Button.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const styles = theme => ({
1919
padding: '8px 16px',
2020
borderRadius: theme.shape.borderRadius,
2121
color: theme.palette.text.primary,
22-
transition: theme.transitions.create(['background-color', 'box-shadow'], {
22+
transition: theme.transitions.create(['background-color', 'box-shadow', 'border'], {
2323
duration: theme.transitions.duration.short,
2424
}),
2525
'&:hover': {
@@ -80,6 +80,20 @@ export const styles = theme => ({
8080
theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'
8181
}`,
8282
},
83+
/* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
84+
outlinedPrimary: {
85+
border: `1px solid ${fade(theme.palette.primary.main, 0.5)}`,
86+
'&:hover': {
87+
border: `1px solid ${theme.palette.primary.main}`,
88+
},
89+
},
90+
/* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
91+
outlinedSecondary: {
92+
border: `1px solid ${fade(theme.palette.secondary.main, 0.5)}`,
93+
'&:hover': {
94+
border: `1px solid ${theme.palette.secondary.main}`,
95+
},
96+
},
8397
/* Styles applied to the root element if `variant="[contained | fab]"`. */
8498
contained: {
8599
color: theme.palette.getContrastText(theme.palette.grey[300]),
@@ -228,6 +242,8 @@ function Button(props) {
228242
[classes.raisedPrimary]: (contained || fab) && color === 'primary',
229243
[classes.raisedSecondary]: (contained || fab) && color === 'secondary',
230244
[classes.outlined]: variant === 'outlined',
245+
[classes.outlinedPrimary]: variant === 'outlined' && color === 'primary',
246+
[classes.outlinedSecondary]: variant === 'outlined' && color === 'secondary',
231247
[classes[`size${capitalize(size)}`]]: size !== 'medium',
232248
[classes.disabled]: disabled,
233249
[classes.fullWidth]: fullWidth,

packages/material-ui/src/styles/MuiThemeProvider.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ describe('<MuiThemeProvider />', () => {
8686
assert.notStrictEqual(markup.match('Hello World'), null);
8787
assert.strictEqual(sheetsRegistry.registry.length, 3);
8888
assert.strictEqual(sheetsRegistry.toString().length > 4000, true);
89-
assert.strictEqual(sheetsRegistry.registry[0].classes.root, 'MuiTouchRipple-root-28');
89+
assert.strictEqual(sheetsRegistry.registry[0].classes.root, 'MuiTouchRipple-root-30');
9090
assert.deepEqual(
9191
sheetsRegistry.registry[1].classes,
9292
{
93-
disabled: 'MuiButtonBase-disabled-26',
94-
focusVisible: 'MuiButtonBase-focusVisible-27',
95-
root: 'MuiButtonBase-root-25',
93+
disabled: 'MuiButtonBase-disabled-28',
94+
focusVisible: 'MuiButtonBase-focusVisible-29',
95+
root: 'MuiButtonBase-root-27',
9696
},
9797
'the class names should be deterministic',
9898
);

pages/api/button.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ This property accepts the following keys:
4747
| <span class="prop-name">flatPrimary</span> | Styles applied to the root element for backwards compatibility with legacy variant naming.
4848
| <span class="prop-name">flatSecondary</span> | Styles applied to the root element for backwards compatibility with legacy variant naming.
4949
| <span class="prop-name">outlined</span> | Styles applied to the root element if `variant="outlined"`.
50+
| <span class="prop-name">outlinedPrimary</span> | Styles applied to the root element if `variant="outlined"` and `color="primary"`.
51+
| <span class="prop-name">outlinedSecondary</span> | Styles applied to the root element if `variant="outlined"` and `color="secondary"`.
5052
| <span class="prop-name">contained</span> | Styles applied to the root element if `variant="[contained \| fab]"`.
5153
| <span class="prop-name">containedPrimary</span> | Styles applied to the root element if `variant="[contained \| fab]"` and `color="primary"`.
5254
| <span class="prop-name">containedSecondary</span> | Styles applied to the root element if `variant="[contained \| fab]"` and `color="secondary"`.

0 commit comments

Comments
 (0)