-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[material-ui] Replace JS color manipulation with native color syntax #43942
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
Conversation
Netlify deploy preview
Bundle size report
|
Sounds good to me.
I'll find some color examples
The first one looks correct to me, the colors are static. It should not change. |
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/customization/css-theme-variables/native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/migration/upgrade-to-v7/upgrade-to-native-color.md
Outdated
Show resolved
Hide resolved
docs/data/material/migration/upgrade-to-v7/upgrade-to-native-color.md
Outdated
Show resolved
Hide resolved
Co-authored-by: mapache-salvaje <71297412+mapache-salvaje@users.noreply.github.com> Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
Nice catch! fixed. |
|
@DiegoAndai I added the color difference example to https://deploy-preview-43942--material-ui.netlify.app/material-ui/customization/css-theme-variables/native-color/#caveats |
|
Thanks @siriwatknp. I think we should use the primary color for the default color shown:
|
docs/data/material/customization/css-theme-variables/ThemeColorFunctions.js
Show resolved
Hide resolved
The primary color has no different. I think the point of the demo is to show a color that produces different result at first glance. For the default colors of Material UI, there is no difference. That's why I put this information in the caveat. |
I'm not sure we should optimize for showing the most changed color either. The one we have now has different text color, which sure, showcases the differences, but most colors are very similar. In the end, we want to reassure users that even though there's a difference, it's minimal. Picking the color with most difference is not a good strategy for that message. |
Then, should I remove the demo instead and proceed with the PR? It's minor so might be better to wait until users start using this feature. |
@mapache-salvaje Any thought about the caveat demo? |
DiegoAndai
left a comment
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.
@siriwatknp I agree, the demo is not important enough to block the feature. Good to go on my side.


Deploy preview
closes #40104
closes #36007
closes #37901
closes #43540
closes #43324
closes #43180
closes #43382
closes #41729
closes #41728
For detailed proposal, check out #43943
For Reviewer
Core Theme System Changes
createPalette.jsaccept internalcolorSpaceto mix light, dark, and contrastText with pure CSS.createThemeNoVarsattach color functions to the theme object.createThemeWithVars.jssupport a new flagnativeColorthrough CSS theme variables feature. (internal color space is set to OKLCH for perceptual uniformity)Component Migrations (30+ components)
All components now use
theme.alpha(),theme.lighten()andtheme.darken()instead of direct alpha imports for backward compat.The changes are ensured by the visual regression tests.
Documentation & Interactive Demos
Codemod Implementation
Replace the usage of the
alpha,lighten, anddarkenfunctions from@mui/system/colorManipulatorto use thethemeobject instead.Key Technical Decisions
nativeColorSyntaxflag, ensuring zero breaking changesOverview
This PR introduces native CSS color manipulation support through CSS relative colors and
color-mix(), eliminating JavaScript-based color calculations when the feature is enabled. The implementation leverages modern CSS color spaces, with OKLCH as the default for perceptually uniform color manipulations, while maintaining full backward compatibility.What's Changed
nativeColorSyntaxflag to enable native CSS color featurestheme.alpha(),theme.lighten(), andtheme.darken()adapter functions for backward compatability.Key Features
🎨 Native CSS Color Manipulation
When
nativeColorSyntaxis enabled:🔧 Theme Color Manipulators
theme.alpha(color, coefficient)The new alpha function uses relative color to adjust the alpha channel value:
theme.lighten(color, coefficient)&theme.darken(color, coefficient)These functions use CSS
color-mix()when native color syntax is enabled:🌈 Cross-Color Space Compatibility
https://deploy-preview-43942--material-ui.netlify.app/material-ui/customization/css-theme-variables/native-color-syntax/#modern-color-spaces
https://deploy-preview-43942--material-ui.netlify.app/material-ui/customization/css-theme-variables/native-color-syntax/#aliasing-color-variables
✨ Automatic contrast calculation
Use relative color based on the color-contrast research.
https://deploy-preview-43942--material-ui.netlify.app/material-ui/customization/css-theme-variables/native-color-syntax/#contrast-color-function
Migration Strategy
Added an upgrade guide for users who want to start using native color syntax https://deploy-preview-43942--material-ui.netlify.app/material-ui/migration/upgrade-to-native-color-syntax/
Performance
From a quick benchmark using the blog template comparing between JS color manipulation and Native color syntax, there is no significant difference in terms of runtime performance.