@@ -46,7 +46,7 @@ export interface TokenProps {
4646 iconType : IconType ;
4747 /**
4848 * For best results use one of the vis color names (or 'gray').
49- * Or supply your own HEX color (can be used with fill 'dark' or fill 'none' only ).
49+ * Or supply your own HEX color. The `fill='light'` (lightened background) will always be overridden by ` fill='dark'` (solid background ).
5050 * Default: `gray` for glyphs or one of the vis colors for prefab token types
5151 */
5252 color ?: TokenColor | string ;
@@ -77,6 +77,9 @@ export type EuiTokenProps = CommonProps &
7777 TokenProps &
7878 Omit < HTMLAttributes < HTMLSpanElement > , 'title' > ;
7979
80+ const isTokenColor = ( color : string ) : color is TokenColor =>
81+ COLORS . includes ( color as TokenColor ) ;
82+
8083export const EuiToken : FunctionComponent < EuiTokenProps > = ( {
8184 iconType,
8285 color,
@@ -119,8 +122,6 @@ export const EuiToken: FunctionComponent<EuiTokenProps> = ({
119122 const euiTheme = useEuiTheme ( ) ;
120123 const styles = euiTokenStyles ( euiTheme ) ;
121124
122- const isTokenColor = COLORS . includes ( finalColor as TokenColor ) ;
123-
124125 let cssStyles = [
125126 styles . euiToken ,
126127 styles [ finalShape ] ,
@@ -130,7 +131,7 @@ export const EuiToken: FunctionComponent<EuiTokenProps> = ({
130131
131132 let finalStyle = style ;
132133
133- if ( isTokenColor ) {
134+ if ( isTokenColor ( finalColor ) ) {
134135 cssStyles = [ ...cssStyles , styles [ finalColor as TokenColor ] ] ;
135136 } else if ( finalFill === 'none' ) {
136137 // When a custom HEX color is passed and the token doesn't have any fill (no background),
@@ -140,7 +141,7 @@ export const EuiToken: FunctionComponent<EuiTokenProps> = ({
140141 } else {
141142 // When a custom HEX color is passed and the token has a fill (light or dark),
142143 // the background gets the custom color and the icon gets white or black based on the passed color
143- // The fill='light' (transparent background) will always be overridden by fill='dark' (opaque background)
144+ // The fill='light' (lightened background) will always be overridden by fill='dark' (opaque background)
144145 // to better handle custom colors
145146 const isFinalColorDark = isColorDark ( ...hexToRgb ( finalColor ) ) ;
146147 const lightOrDarkColor = isFinalColorDark ? '#FFFFFF' : '#000000' ;
0 commit comments