-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the default theme when creating a theme with extendTheme #35236
Comments
It doesn't look like this bug report has enough info for one of us to reproduce it. Please provide a CodeSandbox (https://mui.com/r/issue-template) or a link to a repository on GitHub. Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve |
Yes, sorry, I wasn't clear. The <ThemeProvider theme={outerTheme => createTheme({ ...outerTheme, typography: { fontSize: 12 } })}>
...
</ThemeProvider> |
I believe you can do the following: import { Experimental_CssVarsProvider as CssVarsProvider } from '@mui/material/styles';
import { experimental_extendTheme as extendTheme } from '@mui/material/styles';
const defaultTheme = extendTheme();
const theme = extendTheme({
colorSchemes: {
light: {
palette: {
extra: { main: '#d14836', contrastText: '#fff' },
},
},
dark: {
palette: {
extra: defaultTheme.colorSchemes.dark.palette.primary,
},
},
},
});
export default function App() {
<CssVarsProvider theme={theme}>...</CssVarsProvider>;
} Does this work for you?
Do you have two <ThemeProvider theme={theme}>
<div> // your components
.....
<ThemeProvider
theme={(outerTheme) => createTheme({ ...outerTheme, typography: { fontSize: 12 } })}
></ThemeProvider>
</div>
</ThemeProvider>; |
Yes, like described here in the docs: https://mui.com/material-ui/customization/theming/#nesting-the-theme |
I think @siriwatknp is working on it in #35277. You can also see the discussion here: #30485 (comment) |
@thorn0 Since you are using Referring to https://mui.com/material-ui/experimental-api/css-theme-variables/customization/#adding-new-theme-tokens, you can do this: const theme = extendTheme({
colorSchemes: {
light: {
palette: {
extra: { main: '#d14836', contrastText: '#fff' },
},
},
dark: {
palette: {
// when mode changes to `dark`, the value of `var(--mui-palette-primary-main)` will be `theme.colorSchemes.dark.palette.primary`.
extra: 'var(--mui-palette-primary-main)',
},
},
},
}); Note that if you have custom const theme = extendTheme({
cssVarPrefix: 'custom',
colorSchemes: {
light: {
palette: {
extra: { main: '#d14836', contrastText: '#fff' },
},
},
dark: {
palette: {
// when mode changes to `dark`, the value of `var(--mui-palette-primary-main)` will be `theme.colorSchemes.dark.palette.primary`.
extra: 'var(--custom-palette-primary-main)',
},
},
},
}); |
@siriwatknp What's the recommended way to migrate the following code? <ThemeProvider theme={outerTheme => createTheme({ ...outerTheme, typography: { fontSize: 12 } })}>
...
</ThemeProvider> |
Do you mind sharing the full code via CodeSandbox? That way I can explain which part you have to change. |
Duplicates
Latest version
Summary 馃挕
The parent theme is passed to
createTheme
, so that its values can be arbitrarily used in the new theme. This doesn't seem to be possible with the newextendTheme
API.Examples 馃寛
Motivation 馃敠
No response
The text was updated successfully, but these errors were encountered: