Skip to content
Alea0.1

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).

PropTypeDefaultDescription
classNamestring-Extra class names for the root element.
contrastWithstring-Check this color against a background and show the WCAG ratio.
labelReactNode-The visible label above the picker.
showFieldbooleantrueShow the hex field. Default true.
swatchesstring[]-Preset colors to pick from (hex).

ContrastBadge props

The contrast of a color pair with its WCAG verdict: AAA, AA, AA large or fail.

PropTypeDefaultDescription
backgroundrequiredstring-The background color (any CSS color).
foregroundrequiredstring-The text color (any CSS color).
largeboolean-Large text (24 px, or 18.66 px bold) needs 3:1 instead of 4.5:1.
showSamplebooleantrueShow 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

KeyDoes
Arrow keysMove the thumb
Shift + arrowsBigger steps

Do and don't

Do

  • Offer the brand swatches.

Don't

  • Don't let people pick text colors without the contrast check.
Tested with axe, keyboard and screen reader roles