Skip to content

Add support for CSS color-mix() in theme palette #40104

@chimericdream

Description

@chimericdream

Summary 💡

I wanted to use CSS's color-mix function for my theme palette colors to simplify the process of creating all of the main/light/dark variants. However, it appears that the decomposeColor function doesn't yet support this.

Examples 🌈

const DARKEN_PERCENT = 33;
const LIGHTEN_PERCENT = 33;

const makeColor = (color: string, contrast: string) => ({
    main: color,
    light: `color-mix(in hsl, ${color} ${LIGHTEN_PERCENT}%, #fff)`,
    dark: `color-mix(in hsl, ${color} ${DARKEN_PERCENT}%, #000)`,
    contrastText: contrast,
});

export const theme = createTheme({
    palette: {
        mode: 'dark',
        primary: makeColor(..., '#fff'),
        secondary: makeColor(..., '#000'),
        error: makeColor(..., '#000'),
        warning: makeColor(..., '#000'),
        info: makeColor(..., '#000'),
        success: makeColor(..., '#fff'),
    },
    ...
});

Motivation 🔦

Allowing us to use the native color-mix CSS function simplifies the creation of new themes.

Metadata

Metadata

Assignees

Labels

customization: cssDesign CSS customizability.customization: themeHigher level theming customizability.type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions