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

[POC] Feat dynamic button colors #17233

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 15 additions & 29 deletions packages/material-ui/src/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ import { capitalize } from '../utils/helpers';
export const styles = theme => ({
/* Styles applied to the root element. */
root: {
lineHeight: 1.75, // To remove with v4.
...theme.typography.button,
boxSizing: 'border-box',
minWidth: 64,
padding: '6px 16px',
borderRadius: theme.shape.borderRadius,
color: theme.palette.text.primary,
transition: theme.transitions.create(['background-color', 'box-shadow', 'border'], {
duration: theme.transitions.duration.short,
}),
'&:hover': {
textDecoration: 'none',
backgroundColor: fade(theme.palette.text.primary, theme.palette.action.hoverOpacity),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: 'transparent',
Expand All @@ -44,23 +41,13 @@ export const styles = theme => ({
/* Styles applied to the root element if `variant="text"`. */
text: {
padding: '6px 8px',
},
/* Styles applied to the root element if `variant="text"` and `color="primary"`. */
textPrimary: {
color: theme.palette.primary.main,
color: props => theme.palette[props.color || theme.palette.text.primary].main,
'&:hover': {
backgroundColor: fade(theme.palette.primary.main, theme.palette.action.hoverOpacity),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
},
/* Styles applied to the root element if `variant="text"` and `color="secondary"`. */
textSecondary: {
color: theme.palette.secondary.main,
'&:hover': {
backgroundColor: fade(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
backgroundColor: props =>
fade(
theme.palette[props.color || theme.palette.text.primary].main,
theme.palette.action.hoverOpacity,
),
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
backgroundColor: 'transparent',
Expand All @@ -69,18 +56,22 @@ export const styles = theme => ({
},
/* Styles applied to the root element if `variant="outlined"`. */
outlined: {
color: props => theme.palette[props.color || theme.palette.text.primary].main,
padding: '5px 16px',
border: `1px solid ${
theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'
}`,
border: props =>
`1px solid ${
props.color
? fade(theme.palette[props.color].main, 0.5)
: theme.palette.type === 'light'
? 'rgba(0, 0, 0, 0.23)'
: 'rgba(255, 255, 255, 0.23)'
}`,
'&$disabled': {
border: `1px solid ${theme.palette.action.disabled}`,
},
},
/* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
outlinedPrimary: {
color: theme.palette.primary.main,
border: `1px solid ${fade(theme.palette.primary.main, 0.5)}`,
'&:hover': {
border: `1px solid ${theme.palette.primary.main}`,
backgroundColor: fade(theme.palette.primary.main, theme.palette.action.hoverOpacity),
Expand All @@ -92,8 +83,6 @@ export const styles = theme => ({
},
/* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
outlinedSecondary: {
color: theme.palette.secondary.main,
border: `1px solid ${fade(theme.palette.secondary.main, 0.5)}`,
'&:hover': {
border: `1px solid ${theme.palette.secondary.main}`,
backgroundColor: fade(theme.palette.secondary.main, theme.palette.action.hoverOpacity),
Expand All @@ -102,9 +91,6 @@ export const styles = theme => ({
backgroundColor: 'transparent',
},
},
'&$disabled': {
border: `1px solid ${theme.palette.action.disabled}`,
},
},
/* Styles applied to the root element if `variant="contained"`. */
contained: {
Expand Down