Forms
ColorPicker and ContrastBadge
Pick a color by area, hue, hex or presets, and check its WCAG contrast as you go.
Ant Design: ColorPicker
import { ColorPicker, ContrastBadge, contrastRatio } from '@alea/ui';
Examples
ColorPicker
Area, hue, hex, presets, and the contrast against the page.
Accent
ContrastBadge
The ratio and the WCAG verdict for any pair.
Props
ColorPicker props
Pick a color by area, hue, hex or presets, with a live contrast check (Ant's ColorPicker, plus WCAG).
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Extra class names for the root element. |
contrastWith | string | - | Check this color against a background and show the WCAG ratio. |
label | ReactNode | - | The visible label above the picker. |
showField | boolean | true | Show the hex field. Default true. |
swatches | string[] | - | Preset colors to pick from (hex). |
ContrastBadge props
The contrast of a color pair with its WCAG verdict: AAA, AA, AA large or fail.
| Prop | Type | Default | Description |
|---|---|---|---|
backgroundrequired | string | - | The background color (any CSS color). |
foregroundrequired | string | - | The text color (any CSS color). |
large | boolean | - | Large text (24 px, or 18.66 px bold) needs 3:1 instead of 4.5:1. |
showSample | boolean | true | Show the colors as a sample. Default true. |
Accessibility
- The color area is two sliders and the hue a third, all keyboard operable.
- ContrastBadge says the ratio and the verdict in words, not only color.
Keyboard
| Key | Does |
|---|---|
| Arrow keys | Move the thumb |
| Shift + arrows | Bigger steps |
Do and don't
Do
- Offer the brand swatches.
Don't
- Don't let people pick text colors without the contrast check.