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

[experimental_extendTheme] Unable to use custom css variable in theme #41304

Closed
asingh1098 opened this issue Feb 28, 2024 · 2 comments
Closed
Assignees
Labels
package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement

Comments

@asingh1098
Copy link

asingh1098 commented Feb 28, 2024

I want to use custom css variables in mui's extend theme api like this :

import { experimental_extendTheme as extendTheme } from "@mui/material/styles";

export const theme = extendTheme({
  colorSchemes: {
    light: {
      palette: {
        primary: {
          main: 'var(--primary-color)',   // <-- This doesn't work 🚨
        },
      },
    },
  },
});

Unfortunately, its giving me error :

Uncaught Error: MUI: Unsupported `var(--warning-color)` color.
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().

Is there any way to refer to custom css variable in extend theme?

Search keywords:

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 28, 2024
@brijeshb42
Copy link
Contributor

What's your use case ? You want to use theme.palette.primary.main to refer to the css variable everywhere ? Are you trying to override the default theme with your own color ?

@brijeshb42 brijeshb42 added status: waiting for author Issue with insufficient information package: material-ui Specific to @mui/material and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 29, 2024
@siriwatknp
Copy link
Member

As a workaround, you can use plain CSS file to override the primary.main variable.

// overrides.css
:root {
  --mui-palette-primary-main: var(--primary);
}

In the future, what you propose is possible. See #41237

@siriwatknp siriwatknp added support: question Community support but can be turned into an improvement and removed status: waiting for author Issue with insufficient information labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

3 participants