Experimental CSS color-mix #43943
siriwatknp
announced in
Early feedback
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
color-mixProblems
#nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()Potential fixes
color-mix()in theme palette #40104color="inherit"don't use the proper color for the text decoration #36007Proposal
The values created by
alpha, darken, lightenfunctions in the theme and components will be replaced by CSScolor-mix, e.g.The consumer can enable the feature from the theme by providing a new field
experimentalColorMix(it works with/without CSS theme variables feature)POC
Preview (open the Devtool): https://deploy-preview-43942--material-ui.netlify.app/experiments/material-ui/color-mix/
PR: #43942
Warning
The result of
color-mix()will be slightly different from thedarkenandlightencolor manipulator functions.Also, using different
experimentalColorMixvalues could produce different result too.Side effect
Because
color-mixcannot generate a contrast text, the usage ofpalette.getContrastText()will have to be replaced with plain value (could be from thecontrastTexttoken or thevar(--mui-palette-text-primary))Implementation
The feature must be an experimental API because v6 supports iOS 15.4 which does not work with
color-mixyet.Based on the prior POC, the color-mix is used when CSS theme variables feature is enabled but it should not limited to CSS variables. I propose to be independent of CSS variables.
Theme tokens
For the palette creation, when the flag is enabled, the
lightanddark(if not provided) will be generated usingcolor-mixComponents
The basic approach is to add ternary condition like this:
But I think it will be hard to maintain and increase a lot of lines in the codebase.
A better approach is to create new functions to the theme to abstract the logic from the components:
The
theme.alphawill take care of the result based on CSS theme variables and Color mix features.Codemod
A codemod will be created to transform the codebase and also published for the consumers (e.g. MUI X and Toolpad) to reuse the same patterns.
Beta Was this translation helpful? Give feedback.
All reactions