Color Picker
A composable color picker: ColorPicker holds the color and shares it with parts laid out in any way.
Overview
Without children, ColorPicker is a swatch that opens the default panel in a popover.
Parts
- `ColorPickerTrigger` + `ColorPickerContent`: a popover.
- `ColorPickerPanel`: a column of controls, or a standalone inline picker.
- `ColorPickerArea`: OKLCH chroma × lightness at the hue (the part sRGB can't show is left blank), or HSB saturation × brightness.
- `ColorPickerWheel`: a hue ring whose children fill the square inside it.
- `ColorPickerSlider`: any channel of OKLCH, HSL, HSB or RGB, or alpha; horizontal or vertical, painted with the colors it reaches.
- `ColorPickerFields`: a format menu with hex or per-channel fields;
ColorPickerChannelInputfor a single channel. - `ColorPickerInput`: a text field taking any CSS color (Escape reverts), with a swatch that opens the popover against it.
- `ColorPickerSwatches`: presets, Tailwind's palette by default;
ColorPickerSwatchfor one. - Extras:
ColorPickerValue,ColorPickerCopy,ColorPickerEyeDropper,ColorPickerPreviewandColorPickerFixContrast. - `useColorPicker`: reads and sets the color from custom parts.
Value
- Events:
onChangefires while dragging andonChangeEndonce an interaction ends. - `format`: what they emit —
oklchby default,hex,rgborhsl;alphaadds opacity controls. - Forms:
namesubmits the value with a form (a hidden input), and a form reset restores the starting color.
Contrast
Given a background (contrastWith), every part shows contrast: the area hatches what fails AA and draws the AA and AAA thresholds across it, tracks hatch and mark them, presets failing AA are hatched, the preview shows the WCAG ratio, and "Fix to AA/AAA" jumps to the nearest passing lightness keeping the hue.
labels translates every text it shows or announces.
Installation
CLI
Manual
- 1
Register the @fma-ds namespace in components.json (once)
- 2
Add the item
Files land in
components/fma-ds/color-picker.tsx; npm and registry dependencies are installed along with them.
Dependencies
- npm
- cn@^0.5.0culori@^4.0.2lucide-react@^1.61.0react-aria-components@^1.22.1
- Registry
- @fma-ds/button@fma-ds/copy-button@fma-ds/input@fma-ds/input-group@fma-ds/popover@fma-ds/select@fma-ds/color-contrast