@@ -16,12 +16,49 @@ const COLORS_WITH_BACKDROPS = [
16
16
'inkLighter' ,
17
17
] ;
18
18
19
+ const NEW_DESIGN_LANGUAGE_COLORS = [
20
+ 'base' ,
21
+ 'disabled' ,
22
+ 'hovered' ,
23
+ 'pressed' ,
24
+ 'subdued' ,
25
+ 'critical' ,
26
+ 'warning' ,
27
+ 'highlight' ,
28
+ 'interactive' ,
29
+ 'success' ,
30
+ 'primary' ,
31
+ 'primaryDisabled' ,
32
+ 'primaryHovered' ,
33
+ 'primaryPressed' ,
34
+ ] ;
35
+
19
36
// This is needed for the polaris
20
37
// styleguide to generate the props explorer
21
38
interface Props extends IconProps { }
22
39
23
- export function Icon ( { source, color, backdrop, accessibilityLabel} : Props ) {
40
+ export function Icon ( {
41
+ source,
42
+ color : colorFromProps ,
43
+ backdrop,
44
+ accessibilityLabel,
45
+ } : Props ) {
24
46
const i18n = useI18n ( ) ;
47
+ const { newDesignLanguage} = useFeatures ( ) ;
48
+
49
+ const color =
50
+ colorFromProps == null && newDesignLanguage === true
51
+ ? 'base'
52
+ : colorFromProps ;
53
+
54
+ let sourceType : 'function' | 'placeholder' | 'external' ;
55
+ if ( typeof source === 'function' ) {
56
+ sourceType = 'function' ;
57
+ } else if ( source === 'placeholder' ) {
58
+ sourceType = 'placeholder' ;
59
+ } else {
60
+ sourceType = 'external' ;
61
+ }
25
62
26
63
if ( color && backdrop && ! COLORS_WITH_BACKDROPS . includes ( color ) ) {
27
64
// eslint-disable-next-line no-console
@@ -33,45 +70,49 @@ export function Icon({source, color, backdrop, accessibilityLabel}: Props) {
33
70
) ;
34
71
}
35
72
36
- const { newDesignLanguage} = useFeatures ( ) ;
73
+ if (
74
+ color &&
75
+ sourceType === 'external' &&
76
+ newDesignLanguage === true &&
77
+ NEW_DESIGN_LANGUAGE_COLORS . includes ( color )
78
+ ) {
79
+ // eslint-disable-next-line no-console
80
+ console . warn (
81
+ 'Recoloring external SVGs is not supported with colors in the new design langauge. Set the intended color on your SVG instead.' ,
82
+ ) ;
83
+ }
37
84
38
85
const className = classNames (
39
86
styles . Icon ,
40
87
color && styles [ variationName ( 'color' , color ) ] ,
41
- color == null &&
42
- newDesignLanguage &&
43
- styles [ variationName ( 'color' , 'base' ) ] ,
44
88
color && color !== 'white' && styles . isColored ,
45
89
backdrop && styles . hasBackdrop ,
46
90
newDesignLanguage && styles . newDesignLanguage ,
47
91
) ;
48
92
49
- let contentMarkup : React . ReactNode ;
50
- if ( typeof source === 'function' ) {
51
- const SourceComponent = source ;
52
- contentMarkup = (
93
+ const SourceComponent = source ;
94
+ const contentMarkup = {
95
+ function : (
53
96
< SourceComponent
54
97
className = { styles . Svg }
55
98
focusable = "false"
56
99
aria-hidden = "true"
57
100
/>
58
- ) ;
59
- } else if ( source === 'placeholder' ) {
60
- contentMarkup = < div className = { styles . Placeholder } /> ;
61
- } else {
62
- contentMarkup = (
101
+ ) ,
102
+ placeholder : < div className = { styles . Placeholder } /> ,
103
+ external : (
63
104
< img
64
105
className = { styles . Img }
65
106
src = { `data:image/svg+xml;utf8,${ source } ` }
66
107
alt = ""
67
108
aria-hidden = "true"
68
109
/>
69
- ) ;
70
- }
110
+ ) ,
111
+ } ;
71
112
72
113
return (
73
114
< span className = { className } aria-label = { accessibilityLabel } >
74
- { contentMarkup }
115
+ { contentMarkup [ sourceType ] }
75
116
</ span >
76
117
) ;
77
118
}
0 commit comments