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

[core] Simplify createPalette #44075

Merged
merged 3 commits into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/mui-material/src/styles/createPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,15 @@ export default function createPalette(palette) {
return color;
};

const modes = { dark: getDark(), light: getLight() };
let modeHydrated;
if (mode === 'light') {
modeHydrated = getLight();
} else if (mode === 'dark') {
modeHydrated = getDark();
}

if (process.env.NODE_ENV !== 'production') {
if (!modes[mode]) {
if (!modeHydrated) {
console.error(`MUI: The palette mode \`${mode}\` is not supported.`);
}
}
Expand Down Expand Up @@ -310,7 +315,7 @@ export default function createPalette(palette) {
// E.g., shift from Red 500 to Red 300 or Red 700.
tonalOffset,
// The light and dark mode object.
...modes[mode],
...modeHydrated,
},
other,
);
Expand Down