@@ -14,16 +14,11 @@ import {
1414 euiTextTruncate ,
1515 mathWithUnits ,
1616} from '../../../global_styling' ;
17- import { UseEuiTheme , tint } from '../../../services' ;
17+ import { UseEuiTheme , tint , isColorDark , hexToRgb } from '../../../services' ;
1818
1919export const euiBetaBadgeStyles = ( euiThemeContext : UseEuiTheme ) => {
2020 const { euiTheme, colorMode } = euiThemeContext ;
2121
22- const textColor =
23- colorMode === 'DARK' ? euiTheme . colors . ghost : euiTheme . colors . ink ;
24- const invertedTextColor =
25- colorMode === 'DARK' ? euiTheme . colors . ink : euiTheme . colors . ghost ;
26-
2722 return {
2823 euiBetaBadge : css `
2924 display : inline-block;
@@ -39,22 +34,20 @@ export const euiBetaBadgeStyles = (euiThemeContext: UseEuiTheme) => {
3934
4035 & : focus {
4136 ${ euiFocusRing ( euiThemeContext , 'outset' , {
42- color : textColor ,
37+ color :
38+ colorMode === 'DARK' ? euiTheme . colors . ghost : euiTheme . colors . ink ,
4339 } ) }
4440 }
4541 ` ,
4642 // Colors
4743 accent : css `
48- background-color : ${ euiTheme . colors . accentText } ;
49- color : ${ invertedTextColor } ;
44+ ${ getBadgeColors ( euiTheme . colors . accentText , euiThemeContext ) }
5045 ` ,
5146 subdued : css `
52- background-color : ${ tint ( euiTheme . colors . lightShade , 0.3 ) } ;
53- color : ${ textColor } ;
47+ ${ getBadgeColors ( tint ( euiTheme . colors . lightShade , 0.3 ) , euiThemeContext ) }
5448 ` ,
5549 hollow : css `
56- background-color : ${ euiTheme . colors . emptyShade } ;
57- color : ${ textColor } ;
50+ ${ getBadgeColors ( euiTheme . colors . emptyShade , euiThemeContext ) }
5851 box-shadow : inset 0 0 0 ${ euiTheme . border . width . thin }
5952 ${ euiTheme . border . color } ;
6053 ` ,
@@ -94,3 +87,18 @@ export const euiBetaBadgeStyles = (euiThemeContext: UseEuiTheme) => {
9487 ` ,
9588 } ;
9689} ;
90+
91+ // Util for detecting text color based on badge bg color
92+ export const getBadgeColors = (
93+ backgroundColor : string ,
94+ { euiTheme } : UseEuiTheme
95+ ) => {
96+ const textColor = isColorDark ( ...hexToRgb ( backgroundColor ) )
97+ ? euiTheme . colors . ghost
98+ : euiTheme . colors . ink ;
99+
100+ return `
101+ background-color: ${ backgroundColor } ;
102+ color: ${ textColor } ;
103+ ` ;
104+ } ;
0 commit comments