-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[SvgIcon] Custom color not supported #26192
Comments
It seems that we have a couple of possible options. Not sure
diff --git a/packages/material-ui/src/SvgIcon/SvgIcon.js b/packages/material-ui/src/SvgIcon/SvgIcon.js
index d977b6dce1..f3f9363bf4 100644
--- a/packages/material-ui/src/SvgIcon/SvgIcon.js
+++ b/packages/material-ui/src/SvgIcon/SvgIcon.js
@@ -62,7 +62,7 @@ const SvgIconRoot = experimentalStyled(
error: theme.palette.error.main,
disabled: theme.palette.action.disabled,
inherit: undefined,
- }[styleProps.color],
+ }[styleProps.color] || theme.palette[styleProps.color].main,
}));
const SvgIcon = React.forwardRef(function SvgIcon(inProps, ref) {
diff --git a/packages/material-ui-system/src/index.js b/packages/material-ui-system/src/index.js
index 759fa55570..b4f03d5002 100644
--- a/packages/material-ui-system/src/index.js
+++ b/packages/material-ui-system/src/index.js
@@ -17,7 +17,7 @@ export { default as sizing } from './sizing';
export * from './sizing';
export { default as spacing } from './spacing';
export * from './spacing';
-export { default as style } from './style';
+export { default as style, getPath } from './style';
export { default as typography } from './typography';
export * from './typography';
export {
diff --git a/packages/material-ui/src/SvgIcon/SvgIcon.js b/packages/material-ui/src/SvgIcon/SvgIcon.js
index d977b6dce1..9ff348c82b 100644
--- a/packages/material-ui/src/SvgIcon/SvgIcon.js
+++ b/packages/material-ui/src/SvgIcon/SvgIcon.js
@@ -1,6 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
+import { getPath } from '@material-ui/system';
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
import capitalize from '../utils/capitalize';
import useThemeProps from '../styles/useThemeProps';
@@ -62,7 +63,7 @@ const SvgIconRoot = experimentalStyled(
error: theme.palette.error.main,
disabled: theme.palette.action.disabled,
inherit: undefined,
- }[styleProps.color],
+ }[styleProps.color] || getPath(theme, `palette.${styleProps.color}`) || styleProps.color,
}));
const SvgIcon = React.forwardRef(function SvgIcon(inProps, ref) { |
Hi, can this issue be addressed? Otherwise the whole point of using the color palette is lost. |
Are there any updates regarding this matter? It would be beneficial to have the option to select any color from the palette, such as color='success.main'. I noticed this feature was recently added to the Typography component, so why not implement the same functionality for SvgIcon as well? |
I'm facing this issue as well at this moment... |
Current Behavior 😯
I can't use a custom palette color.
Expected Behavior 🤔
I can use a custom palette color
Steps to Reproduce 🕹
Steps:
Context 🔦
Reported by @ahfarmer in #13875 (comment).
It's actually the same for the
Icon
component.Your Environment 🌎
v5.0.0-alpha.32
The text was updated successfully, but these errors were encountered: