mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
94.05k stars 32.32k forks source link

[colorManipulator] lighten/darken a CSS var() color #43324

Open kiddliu opened 3 months ago

kiddliu commented 3 months ago

Summary

Hi, I'm working on my own design system implementation with MUI v6 (base + system). Previously, with utilities in colorManipulator I can easily lighten/darken a color defined in palette. With CSS variables, now it's difficult and I have to augment the palette a lot. For alpha the solution is with pure CSS function rgba, probably for lighten/darken I should go with the same way? Or, by getComputedStyle I can run the same function just as before?

Examples

-      color: darken(theme.palette.primary.main),
+      color: darken(theme.vars.palette.primary.main),

Motivation

No response

Search keywords: colorManipulator lighten darken var CSS color

oliviertassinari commented 3 months ago

Almost the same as #43180 no?

kiddliu commented 3 months ago

You save my day @oliviertassinari ...any plan when to update the colorManipulator implementation?

oliviertassinari commented 3 months ago

I'm working on my own design system implementation with MUI v6 (base + system).

@kiddliu Do you mean that you are using Base UI + MUI System and skipping Material UI?

kiddliu commented 3 months ago

Yes...I did start with Material UI and later because of several design differences it seems that building the library with headless Base UI is a better solution. Now most of the components are still of Material, and some unique ones are created with Base UI and System

RickyRoller commented 1 week ago

You can use color-mix Darken

color: ${({ theme }) => darken(theme.palette.primary.default, 0.5)}
color: ${({ theme }) => `color-mix(in srgb, ${theme.vars.palette.primary.default} 50%, black)`};

Lighten

color: ${({ theme }) => lighten(theme.palette.primary.default, 0.5)};
color: ${({ theme }) => `color-mix(in srgb, ${theme.vars.palette.primary.default} 50%, white)`};

https://caniuse.com/?search=color-%20mix