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] Add support for CSS variables #32600

Merged
merged 5 commits into from
May 6, 2022

Conversation

Ariyapong
Copy link
Contributor

One of #32049

cc: @mui/contributors

@Ariyapong Ariyapong changed the title Add support for CSS variables [ToggleButton] Add support for CSS variables May 4, 2022
@mui-bot
Copy link

mui-bot commented May 4, 2022

Details of bundle changes

@material-ui/core: parsed: +0.12% , gzip: +0.07%
@material-ui/lab: parsed: +0.16% , gzip: +0.10%

Generated by 🚫 dangerJS against c351d3b

@ZeeshanTamboli ZeeshanTamboli added component: toggle button This is the name of the generic UI component, not the React module! new feature New feature or request labels May 4, 2022
@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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 =
Copy link
Member

@siriwatknp siriwatknp May 4, 2022

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),

Copy link
Contributor Author

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.

@Ariyapong Ariyapong requested a review from mnajdova May 5, 2022 16:30
Copy link
Member

@siriwatknp siriwatknp left a 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!

@siriwatknp siriwatknp merged commit 7973936 into mui:master May 6, 2022
@Ariyapong Ariyapong deleted the toggle-button-css-variables branch May 7, 2022 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: toggle button This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants