File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
2424 euiPaletteColorBlindBehindText ,
2525 getSecureRelForTarget ,
2626 isColorDark ,
27+ wcagContrastMin ,
2728} from '../../services' ;
2829import { EuiInnerText } from '../inner_text' ;
2930import { EuiIcon , IconType } from '../icon' ;
@@ -149,8 +150,7 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
149150 } ;
150151
151152 let textColor = null ;
152- const wcagContrastBase = 4.5 ; // WCAG AA contrast level
153- let wcagContrast = null ;
153+ let contrastRatio = null ;
154154 let colorHex = null ;
155155
156156 try {
@@ -176,17 +176,17 @@ export const EuiBadge: FunctionComponent<EuiBadgeProps> = ({
176176 textColor = setTextColor ( euiTheme , color ) ;
177177
178178 // Check the contrast
179- wcagContrast = getColorContrast ( textColor , color ) ;
179+ contrastRatio = getColorContrast ( textColor , color ) ;
180180
181- if ( wcagContrast < wcagContrastBase ) {
181+ if ( contrastRatio < wcagContrastMin ) {
182182 // It's low contrast, so lets show a warning in the console
183183 console . warn (
184184 'Warning: ' ,
185185 color ,
186186 ' badge has low contrast of ' ,
187- wcagContrast . toFixed ( 2 ) ,
187+ contrastRatio . toFixed ( 2 ) ,
188188 '. Should be above ' ,
189- wcagContrastBase ,
189+ wcagContrastMin ,
190190 '.'
191191 ) ;
192192 }
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import chroma from 'chroma-js';
1010import { shade , tint , lightness as getLightness } from './manipulation' ;
1111import { getOn } from '../theme/utils' ;
1212
13+ export const wcagContrastMin = 4.5 ; // WCAG AA minimum contrast ratio for normal (non-large) text
14+
1315/**
1416 * Creates a new color that meets or exceeds WCAG level AA
1517 * @param foreground - Color to manipulate
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ export {
6969 lightness ,
7070 makeHighContrastColor ,
7171 makeDisabledContrastColor ,
72+ wcagContrastMin ,
7273} from './color' ;
7374
7475export type { EuiSetColorMethod } from './color_picker' ;
You can’t perform that action at this time.
0 commit comments