Skip to content

Color picker

color-picker

A full colour editor: a saturation and brightness area, hue and opacity rails, a hex field, numeric channels, screen sampling and preset swatches — all composed from parts, opened from a trigger chip that previews the value.

Install

$npxshadcnadd@forme/color-picker

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import {
  ColorPicker,
  ColorPickerAlpha,
  ColorPickerArea,
  ColorPickerContent,
  ColorPickerHexInput,
  ColorPickerHue,
  ColorPickerTrigger,
} from "@/components/forme/color-picker/color-picker";

<ColorPicker defaultValue="#ec4899" label="Accent colour">
  <ColorPickerTrigger />
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerHue />
    <ColorPickerAlpha />
    <ColorPickerHexInput />
  </ColorPickerContent>
</ColorPicker>

When to use

Reach for it

  • Picking a colour rather than choosing one from a fixed palette — for a short list, a ColorSelector is faster to use and to scan.
  • onValueCommit for anything that saves or re-renders the page, so a drag is one update instead of hundreds.
  • A duplicate of the current value beside the editor, so the choice can be read back after the panel closes.

Use something else

  • alpha when the value ends up in a place that cannot render transparency — an email, a token with no alpha channel — since the last two hex digits will be silently dropped.
  • A picker for a decision the design already made; a preset row alone is less work for everyone.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

ColorPicker

A colour picker: a trigger chip that opens a saturation/brightness area, a hue rail, an opacity rail, a hex field and optional numeric channels.

PropTypeDefaultDescription
valuestring—Controlled hex colour, #rgb, #rrggbb or #rrggbbaa.
defaultValuestring"#3478f6"The colour when uncontrolled. Default: #3478f6
onValueChange(value: string) => void—Fires on every change while dragging or typing, as a lowercase hex.
onValueCommit(value: string) => void—Fires once an interaction settles: pointer release, key, preset or field commit.
alphabooleantrueAllow transparency. When false the value is always opaque. Default true.
namestring—Submits the hex value with a form under this name.
openboolean—Controlled open state for the trigger and its panel.
defaultOpenbooleanfalseWhether the panel starts open when uncontrolled. Default false
onOpenChange(open: boolean) => void—Called when the panel opens or closes.
labelstring—Accessible name for the picker as a whole.
disabledbooleanfalse

Also takes every prop of <div> attributes.

ColorPickerArea

Saturation across, brightness up. The thumb is a 2D slider: one control, two values, stepping with the arrows and jumping with Home/End on saturation.

PropTypeDefaultDescription
labelstring"Saturation and brightness"Accessible name for the 2D control. Default "Saturation and brightness"

Also takes every prop of <div> attributes.

ColorPickerHue

PropTypeDefaultDescription
labelstring"Hue"Accessible name for the hue rail. Default "Hue"
classNamestring—

ColorPickerAlpha

Renders nothing when the picker has alpha={false}.

PropTypeDefaultDescription
labelstring"Opacity"Accessible name for the opacity rail. Default "Opacity"
classNamestring—

ColorPickerChannels

Numeric RGB or HSL fields, plus opacity when alpha is enabled. Arrow keys nudge.

PropTypeDefaultDescription
format"rgb" | "hsl""rgb"Which channels to edit. Default "rgb"

Also takes every prop of <div> attributes.

ColorPickerEyeDropper

Samples a colour from anywhere on screen.

PropTypeDefaultDescription
childrenReactNode—

Also takes every prop of <button> attributes.

ColorPickerPreset

PropTypeDefaultDescription
value*string—The hex this preset applies.
labelstring—Accessible colour name. Defaults to the hex.

Also takes every prop of <button> attributes.

ColorPickerTrigger

Opens the panel. Its colour chip previews the value the panel edits.

PropTypeDefaultDescription
childrenReactNode—Replaces the hex label beside the chip.

Also takes every prop of <button> attributes.

The other parts

  • ColorPickerSwatchTakes <span> attributes
  • ColorPickerHexInputTakes <input> attributes
  • ColorPickerPresetsTakes <div> attributes
  • ColorPickerContentTakes Base UI Popover.Popup and Pick<ComponentProps<typeof PopoverPrimitive.Positioner>, "side" | "sideOffset" | "align">

Accessibility

  • The area is a 2D slider with one accessible name and a value text naming both axes, because two separate sliders would not say they belong together.
  • Every rail takes arrows, Page Up and Page Down, Home and End; the loupe and the thumb's white ring are decorative and hidden from the tree.
  • The panel is a popover dialog: it takes focus on open, closes on Escape and on an outside press, and returns focus to the trigger.

Motion

  • The thumb glides on a spring while dragging so the control feels like it has mass, and the loupe lifts with a small overshoot to say it is picked up.
  • The preset ring hops along an arc between swatches; a straight spring would pass through the swatch in between.
  • Reduced motion keeps every position change and drops the lift, the hop and the entrance.

Responsive behaviour

  • The trigger is a fit-content chip, so it sits in a form row without stretching; the panel is 288px and will not fit beside a narrow control, so place it where it has room below.
  • The numeric channel fields share the row evenly and stay legible down to four of them.