-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Add support for CSS variables #32600
Conversation
@material-ui/core: parsed: +0.12% , gzip: +0.07% |
@@ -38,40 +38,48 @@ const ToggleButtonRoot = styled(ButtonBase, { | |||
})(({ theme, ownerState }) => { | |||
const selectedColor = | |||
ownerState.color === 'standard' | |||
? theme.palette.text.primary | |||
: theme.palette[ownerState.color].main; | |||
? (theme.vars || theme).palette.text.primaryChannel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more readable if we create selectedColor
& selectedColorChannel
and use those below. Note that theme.palette.text.primaryChannel
does not even exists, this is why the tests are failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the changes as you suggested and the tests have been passed
@@ -38,40 +38,48 @@ const ToggleButtonRoot = styled(ButtonBase, { | |||
})(({ theme, ownerState }) => { | |||
const selectedColor = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create selecteColorChannel
like @mnajdova suggested:
// ToggleButton.js
import { colorChannel } from '@mui/system';
...
let selectedColor = ownerState.color === 'standard'
? theme.palette.text.primary
: theme.palette[ownerState.color].main;
const selectedColorChannel = colorChannel(selectedColor);
if (theme.vars) {
selectedColor = ownerState.color === 'standard'
? theme.vars.palette.text.primary
: theme.vars.palette[ownerState.color].main;
}
Then replace the alpha(...)
like this:
backgroundColor: theme.vars ? `rgba(${selectedColor} / ${theme.palette.action.selectedOpacity})` : alpha(selectedColor, theme.palette.action.selectedOpacity),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have already updated the code as you and @mnajdova suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩 Looks great, thanks for your contribution!
One of #32049
cc: @mui/contributors