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

[colorManipulator] Replace colorManipulator with CSS Relative Color Syntax (RCS) #43180

Open
oliviertassinari opened this issue Aug 4, 2024 · 1 comment
Assignees
Labels
customization: css Design CSS customizability enhancement This is not a bug, nor a new feature package: system Specific to @mui/system performance

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 4, 2024

Summary

The codebase rely on logic like

export function alpha(color, value) {

which comes with bundle size. However, CSS Relative Color Syntax (RCS) https://lea.verou.me/specs/#relative-colors-rcs is coming. We will be able to rely on it. This should save bundle size and improve the customization experience as it will be clearer in the Browser devtool inspector tool where the color is coming from.

Examples

--color-lighterer: oklch(from var(--color) calc(l + 0.2) c h);
--color-alpha-50: oklab(from var(--color) l a b / 50%);

On the colorspace we want to use, oklch looks like a solid option: https://www.smashingmagazine.com/2023/08/oklch-color-spaces-gamuts-css/. It has a limit though: w3c/csswg-drafts#9449, to be careful.

To see how this fit with color-mix(.


If this is successful, we could also look doing the same for the color contrast utils. Actually, we might even need to consider both problems at the same time. https://lea.verou.me/blog/2024/contrast-color/ is a great dive into the topic. A must read (e.g. APAC vs. legal requirement).

Motivation

Is likely part of solving #40104, and #37901.

Search keywords: -

@oliviertassinari oliviertassinari added performance status: waiting for maintainer These issues haven't been looked at yet by a maintainer enhancement This is not a bug, nor a new feature customization: css Design CSS customizability labels Aug 4, 2024
@siriwatknp
Copy link
Member

siriwatknp commented Aug 7, 2024

Nice, in my POC the color-mix() works great. With RCS, the getContrastText could be removed!

I will find a time to create another POC after v6 stable. I'd love to have:

createTheme({
  colorSpace: 'oklch',
  palette: {
    primary: {
      main: 'var(--external-color)',
    }
  }
})

@oliviertassinari oliviertassinari changed the title Replace colorManipulator with CSS Relative Color Syntax (RCS) [colorManipulator] Replace colorManipulator with CSS Relative Color Syntax (RCS) Aug 18, 2024
@oliviertassinari oliviertassinari added the package: system Specific to @mui/system label Aug 18, 2024
@siriwatknp siriwatknp removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: css Design CSS customizability enhancement This is not a bug, nor a new feature package: system Specific to @mui/system performance
Projects
None yet
Development

No branches or pull requests

2 participants