ContrastChecker component determines if contrast for text styles is sufficient (WCAG 2.0 AA) when used with a given background color.
ContrastChecker also accounts for font sizes.
A notice will be rendered if the color combination of text and background colors are low.
Checks the contrast of a 13px dark gray font against a light gray background.
import { ContrastChecker } from '@wordpress/block-editor';
const Example = () => {
return (
<ContrastChecker
fontSize={ 13 }
textColor="#111"
backgroundColor="#eee"
/>
);
};The background color to check the contrast of text against.
- Type:
String - Required: No
A fallback background color value, in case backgroundColor is not available.
- Type:
String - Required: No
A fallback text color value, in case textColor is not available.
- Type:
String - Required: No
The font-size (as a px value) of the text to check the contrast against.
- Type:
Number - Required: No
Whether the text is large (approximately 24px or higher).
- Type:
Boolean - Required: No
The text color to check the contrast of the background against.
- Type:
String - Required: No
Custom warning message to display (and announce) instead of the default contrast guidance when the color combination has insufficient contrast. Useful for providing panel-specific, more concise copy.
- Type:
String - Required: No