-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Allow custom color variants for Chips #26695
Comments
Can you provide a codesandbox, so that we can reproduce? Here is the template for Chip. https://codesandbox.io/s/og19w?file=/demo.js |
Try here: https://codesandbox.io/embed/dazzling-bartik-j1gh6?fontsize=14&hidenavigation=1&theme=dark I commented out the broken chip. |
You need to add all of the properties to the palette const theme = createTheme({
palette: {
neutral: {
main: "#546e7a",
light: '#90a4ae',
dark: '#37474f',
contrastText: '#ffffff',
}
}
}); https://codesandbox.io/embed/dazzling-bartik-j1gh6?fontsize=14&hidenavigation=1&theme=dark will add the to the documentation. |
@siriwatknp We might be able to do more about it in the future. Assuming that we push #12827 further. I believe we will need to move all the color transformations to the vs. diff --git a/packages/material-ui/src/styles/ThemeProvider.js b/packages/material-ui/src/styles/ThemeProvider.js
index d13c4406f2..cdaf612d64 100644
--- a/packages/material-ui/src/styles/ThemeProvider.js
+++ b/packages/material-ui/src/styles/ThemeProvider.js
@@ -2,7 +2,7 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import { ThemeProvider as MuiThemeProvider } from '@material-ui/private-theming';
import { exactProp } from '@material-ui/utils';
-import { ThemeContext as StyledEngineThemeContext } from '@material-ui/styled-engine';
+import { ThemeContext as StyledEngineThemeContext, GlobalStyles } from '@material-ui/styled-engine';
import useTheme from './useTheme';
function InnerThemeProvider(props) {
@@ -28,9 +28,19 @@ InnerThemeProvider.propTypes = {
function ThemeProvider(props) {
const { children, theme: localTheme } = props;
+ const secondary = localTheme.palette.secondary.main;
+ localTheme.palette.secondary.main = 'var(--mui-palette-secondary-main)';
+
return (
<MuiThemeProvider theme={localTheme}>
- <InnerThemeProvider>{children}</InnerThemeProvider>
+ <InnerThemeProvider>
+ <GlobalStyles styles={{
+ ":host, :root": {
+ '--mui-palette-secondary-main': secondary,
+ },
+ }} />
+ {children}
+ </InnerThemeProvider>
</MuiThemeProvider>
);
} cc @mnajdova |
Note that this API is also available: const defaultTheme = createTheme();
const theme = createTheme({
palette: {
neutral: defaultTheme.palette.augmentColor({
color: {
main: "#E2410D"
}
})
}
}); https://codesandbox.io/s/billowing-platform-17k8o?file=/src/App.tsx:231-420 |
Please allow custom color variants for Chips.
Allowing custom color variants is a known issue: #13875
There is a fix already quoted here: #13875 (comment)
It works for Buttons but it does not work for Chips.
The text was updated successfully, but these errors were encountered: