diff --git a/src/components/Icon/Icon.tsx b/src/components/Icon/Icon.tsx index 8e8a21d113e..506548dd10e 100644 --- a/src/components/Icon/Icon.tsx +++ b/src/components/Icon/Icon.tsx @@ -16,12 +16,49 @@ const COLORS_WITH_BACKDROPS = [ 'inkLighter', ]; +const NEW_DESIGN_LANGUAGE_COLORS = [ + 'base', + 'disabled', + 'hovered', + 'pressed', + 'subdued', + 'critical', + 'warning', + 'highlight', + 'interactive', + 'success', + 'primary', + 'primaryDisabled', + 'primaryHovered', + 'primaryPressed', +]; + // This is needed for the polaris // styleguide to generate the props explorer interface Props extends IconProps {} -export function Icon({source, color, backdrop, accessibilityLabel}: Props) { +export function Icon({ + source, + color: colorFromProps, + backdrop, + accessibilityLabel, +}: Props) { const i18n = useI18n(); + const {newDesignLanguage} = useFeatures(); + + const color = + colorFromProps == null && newDesignLanguage === true + ? 'base' + : colorFromProps; + + let sourceType: 'function' | 'placeholder' | 'external'; + if (typeof source === 'function') { + sourceType = 'function'; + } else if (source === 'placeholder') { + sourceType = 'placeholder'; + } else { + sourceType = 'external'; + } if (color && backdrop && !COLORS_WITH_BACKDROPS.includes(color)) { // eslint-disable-next-line no-console @@ -33,45 +70,49 @@ export function Icon({source, color, backdrop, accessibilityLabel}: Props) { ); } - const {newDesignLanguage} = useFeatures(); + if ( + color && + sourceType === 'external' && + newDesignLanguage === true && + NEW_DESIGN_LANGUAGE_COLORS.includes(color) + ) { + // eslint-disable-next-line no-console + console.warn( + 'Recoloring external SVGs is not supported with colors in the new design langauge. Set the intended color on your SVG instead.', + ); + } const className = classNames( styles.Icon, color && styles[variationName('color', color)], - color == null && - newDesignLanguage && - styles[variationName('color', 'base')], color && color !== 'white' && styles.isColored, backdrop && styles.hasBackdrop, newDesignLanguage && styles.newDesignLanguage, ); - let contentMarkup: React.ReactNode; - if (typeof source === 'function') { - const SourceComponent = source; - contentMarkup = ( + const SourceComponent = source; + const contentMarkup = { + function: (