Skip to content
Eskais UI

Forms

Color Picker

UI SDK ColorPicker styled: an area (painted on a canvas in OKLCH, every pixel a colour inside the gamut), hue and alpha sliders, a swatch, a text field for any CSS colour, channel inputs, presets and an eye dropper with a tooltip.

Example

Installation

npx shadcn@latest add @eskais/color-picker
npm packageslucide-react

Usage

Import
import {  ColorPicker,  ColorPickerArea,  ColorPickerAreaCanvas,  ColorPickerAreaThumb,  ColorPickerChannelInput,  ColorPickerEyeDropper,  ColorPickerInput,  ColorPickerSlider,  ColorPickerSliderThumb,  ColorPickerSwatch,  ColorPickerSwatches,  ColorPickerSwatchItem,  colorPickerLabels,  createColorPickerController,} from "@/components/ui/color-picker"import { useColorAreaCanvas } from "@/components/ui/use-color-area-canvas"import { useHeldColor } from "@/components/ui/use-held-color"import {  areaChromaMax,  areaColor,  areaPoint,  isOklchInGamut,  mapToGamut,  maxChroma,  oklchToLinear,  paintArea,} from "@/lib/oklch-gamut"

In OKLCH the area paints its whole box: inside the gamut each point is its own colour, and past the edge it shows the colour the picker holds there, so the thumb always sits on the colour chosen. A thumb dragged or stepped past the edge stays where it was left, and the value is the closest colour inside.

API reference

ColorPicker

PropTypeDefault
labelsPartial<ColorPickerLabels>–

Also takes every prop of UI SDK ColorPicker.

ColorPickerAreaCanvas

Takes every prop of UI SDK ColorPickerAreaCanvas.

ColorPickerSliderThumb

Takes every prop of UI SDK ColorPickerSliderThumb.

ColorPickerChannelInput

Takes every prop of UI SDK ColorPickerChannelInput.

ColorPickerEyeDropper

PropTypeDefault
tooltipControlTooltipOption–

Also takes every prop of UI SDK ColorPickerEyeDropper.

ColorPickerSwatchItem

Takes every prop of UI SDK ColorPickerSwatchItem.

Other exports

colorPickerLabelscreateColorPickerControlleruseColorAreaCanvasuseHeldColorareaChromaMaxareaColorareaPointisOklchInGamutmapToGamutmaxChromaoklchToLinearpaintAreatype ColorPickerLabelstype ColorPickerPropstype ColorChanneltype ColorFormattype ColorPickerControllertype ColorPickerSpacetype ColorPickerValueChangeReasontype Endingtype KeySteptype AreaGamuttype Oklch

Accessibility

  • The area's thumb is a slider screen readers hear as both channels; each slider names its channel; arrow keys step them.
  • The text field takes any CSS colour on Enter or blur, and goes back to the value when the text isn't one.
  • Presets are one tab stop with arrow keys between them; the eye dropper is an icon button with a tooltip, hidden where unsupported.

Agent actions

Agents find it by its label and set any CSS colour with setValue.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.