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

CreateTheme: MUI 6: how to combine colorSchemes with theme.palette.augmentColor(...) #44351

Closed
wouter-leistra opened this issue Nov 8, 2024 · 4 comments
Assignees
Labels
customization: theme Centered around the theming features package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement v6.x migration

Comments

@wouter-leistra
Copy link

wouter-leistra commented Nov 8, 2024

We are updating our MUI material UI theme to follow version 6 recommendations and stumbled upon the documentation that colorSchemes is the preferred way going forward. I adjusted my theme with light and dark themes palettes but we have some custom colors we like to augment. The documentation on augmentColors specifies to use the initial theme to create an updated theme with createTheme(theme, {...}) where you specify the custom colors. But I don't get it to work with dark and light theme palettes for these custom colors as specifying just palette on the second theme creation overrides the initial theme as stated in the documentation and spreading theme.colorSchemes.light.palette gives TypeScript errors that Theme doesn't have this property.

Can someone help me to find a way to get custom augmented colors to work with colorSchemes for light and dark?

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 Nov 8, 2024
@wouter-leistra wouter-leistra changed the title CreateTheme: MUI 6: how to combine colorSchemes with theme.palette.augmentedColor(...) CreateTheme: MUI 6: how to combine colorSchemes with theme.palette.augmentColor(...) Nov 8, 2024
@siriwatknp
Copy link
Member

Sure, can you provide a Code Sandbox/Stackblitz that replicate your setup and the type errors?

@siriwatknp siriwatknp added package: material-ui Specific to @mui/material customization: theme Centered around the theming features v6.x migration and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 11, 2024
@wouter-leistra
Copy link
Author

I figured it out already, my initial theme has all the color schemes and
everything. But all problems go away if your first create some factory
theme with same tonalOffset and contrastThreshold as the actual desired
theme like

const baseTheme = createTheme({ tonalOffset: 0.2, contrastThreshold: 4.5 });

And after that line specify your own theme using the baseTheme for
augmentColor

const myTheme = createTheme({ 
  colorSchemes: {
    light: {
      palette: {
        myCustomColor: baseTheme.palette.augmentColor (...)
      }
    }
  });

I had the order the wrong way around and didn't catch that.

@DiegoAndai DiegoAndai moved this to In progress in Material UI Nov 11, 2024
@siriwatknp
Copy link
Member

@wouter-leistra Thanks for letting me know. If you find other issue related to v6 migration, feel free to open a new one.
Have a great day!

@github-project-automation github-project-automation bot moved this from In progress to Done in Material UI Nov 11, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@wouter-leistra How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@siriwatknp siriwatknp added the support: question Community support but can be turned into an improvement label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement v6.x migration
Projects
Status: Done
Development

No branches or pull requests

2 participants