Color picker

DarkInspect

A swatch that grows into a picker, for choosing one exact colour: a condition's colour or a brand field in the admin. Saturation and brightness on the area, hue and opacity on their sliders, or a typed value in hex, RGB, HSL or OKLCH, the format button morphing the text between them. The eyedropper shows where the browser has one (Chromium on a desktop). Saved swatches can be added, applied, dragged, moved with Alt and the arrows, and removed with Delete, and a contrast readout grades the colour against the background it will sit on. uiarc's Color picker (MIT), on our tokens and Tabler.

When to use

  • One exact colour, where the hex is the value: a condition, a category, a brand field.
  • Wherever the colour will sit on a known surface: pass it as background, so the contrast readout tells the truth.

For a choice between a few fixed colours, use a choice list or chips instead.

API reference

PropTypeDefaultDescription
valuestring—The colour, controlled: hex, rgb(), hsl() or oklch().
defaultValuestring"#2F6BFF"The starting colour, uncontrolled.
onValueChange(hex: string) => void—Receives the colour as uppercase hex, with two alpha digits when it is not opaque.
backgroundstring"#FFFFFF"The surface the colour will sit on, for the WCAG contrast readout.
labelstring"Color"The name on the swatch, such as Condition.
swatchesColorSwatch[]—Saved swatches, controlled: { id, color }.
defaultSwatchesColorSwatch[]—Saved swatches to start from, uncontrolled.
onSwatchesChange(swatches: ColorSwatch[]) => void—Called when a swatch is added, moved or removed.
maxSwatchesnumber7The most saved swatches; saving past it drops the oldest.
defaultFormat"hex" | "rgb" | "hsl" | "oklch""hex"The format the text field shows first.