Color utilities
Colors and accessibility
Never rely solely on color to convey meaning. Colors can be overridden by system forced colors, or can be difficult to distinguish for different users. Always combine color context with accompanying icons or copy to indicate states such as error, activity, etc.
Background colors
To all but ensure proper contrast of text to background, we recommend using our pre-defined shades of background colors based on the EuiTheme brand colors. You can also use EuiPanel for the same effect plus more options like padding and rounded corners.
useEuiBackgroundColorCSS()[color]
style hook
Returns an object of the available color keys containing the css string of the computed background version for the given color
.
This is best used to map component prop styles to padding output.
tsx code block:color: 'transparent' | 'plain' | 'subdued' | 'accent' | 'accentSecondary' | 'primary' | 'success' | 'warning' | 'danger';
tsx code block:const colorStyles = useEuiBackgroundColorCSS(); const cssStyles = [colorStyles['accent']]; <span css={cssStyles}> /* Your content */ </span>
Utilities
Contrast
Note that color contrast cannot be accurately detected when using transparency (colors with alpha channels).
makeHighContrastColor(foreground, ratio)(background)
function
Use this function to calculate the appropriate foreground color (usually text) based on a background color.
text code block:foreground: string; ratio?: number = 4.5; background?: string = euiTheme.colors.body;
tsx code block:css` color: ${makeHighContrastColor(foreground)(background)}; `
If you want to use the same background color that the EUI theme uses for all of its contrast calculations, you can pass in the euiTheme
as the background.
tsx code block: