Components

Color Picker

Chooses a color from an area, sliders, typed CSS or presets, inline or from a popover. Built on ui-sdk’s Color Picker.

Usage

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerInput,
  ColorPickerSlider,
} from 'nyctoui/color-picker'

<ColorPicker aria-label="Label color" defaultValue="#0090ff">
  <ColorPickerArea />
  <ColorPickerSlider channel="hue" />
  <ColorPickerInput aria-label="Hex" />
</ColorPicker>

The value is a CSS color string. Every part is optional and edits the same color: use the ones the job needs, in the order you want. The area and sliders draw their own thumbs; arrow keys move them, Shift by ten. The text input reads any CSS color on Enter, such as rebeccapurple or an oklch() value. The eye dropper hides itself in browsers that can’t pick from the screen.

Good for

  • Choosing a brand color in a website builder’s theme settings.
  • Setting a label or tag color in a project management tool, from a few presets.
  • Picking fill and stroke in a design or diagram editor.
  • Choosing a calendar’s color in a calendar app.

Anatomy

<ColorPicker>
  <ColorPickerArea />
  <ColorPickerSlider />
  <ColorPickerRow>
    <ColorPickerInput />
    <ColorPickerChannelInput />
    <ColorPickerEyeDropper />
  </ColorPickerRow>
  <ColorPickerSwatches>
    <ColorPickerSwatchItem />
  </ColorPickerSwatches>
  <ColorPickerSwatch />
  <ColorPickerValue />
</ColorPicker>

Examples

Popover

Put a Popover inside the picker to open it from a button. ColorPickerSwatch and ColorPickerValue show the color in the trigger.

OKLCH

With space="oklch" the area edits chroma and lightness, painted pixel by pixel up to the edge of what the screen can show. A drag past that edge settles on the closest color inside it.

Presets only

Swatches alone make a compact picker for labels and projects. The list is one tab stop; arrow keys move between colors.

Disabled

Best practices

Do
  • Use only the parts the job needs: presets alone for tag colors, the area and sliders for a design tool.
  • Offer presets from your own palette when colors should stay on brand or readable.
  • Pick the format your app stores, such as hex for a theme file or OKLCH for design tokens, so the value doesn’t need converting.
  • Save on onValueCommit rather than every change, so a drag doesn’t send dozens of requests.
Don’t
  • Give people a full picker when a handful of named colors would do. Free choice leads to unreadable labels.
  • Rely on the swatch alone to say which color is chosen; show its value or name too.

API reference

ColorPicker

Holds the color and lays its parts out in a column. Renders a <div role=group>.

PropTypeDefault
defaultValue / value
The color as CSS, uncontrolled or controlled.
string—
onValueChange
Called on every step of a drag or key.
(value, details) => void—
onValueCommit
Called once an interaction ends. For saving.
(value, details) => void—
space
Which channels the area and sliders edit.
'hsv' | 'hsl' | 'srgb' | 'oklch''hsv'
format
How the value is written. Hex for hsv by default.
'hex' | 'hsl' | 'rgb' | 'oklch'—
gamut
The colors the value may hold.
'srgb' | 'p3' | false'srgb'
disabled / readOnly
Stops changes; read-only stays focusable.
boolean—
name
Submits the value with a form.
string—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerArea

Edits two channels at once, with its thumb. Renders a <div>.

PropTypeDefault
x / y
The channels across and up. Defaults follow the space.
ColorChannel—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerSlider

Edits one channel, with its thumb. Renders a <div>.

PropTypeDefault
channel
The channel it edits.
'hue' | 'alpha' | …—
orientation
The axis.
'horizontal' | 'vertical''horizontal'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerInput

Reads any CSS color, drawn as an InputGroup.

PropTypeDefault
size
Control height.
'sm' | 'md' | 'lg''md'
swatch
Shows a small swatch before the text.
booleantrue
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerChannelInput

Edits one channel as a number.

PropTypeDefault
channel
The channel it edits.
ColorChannel—
size
Control height.
'sm' | 'md' | 'lg''md'
suffix
A unit after the number, such as %.
ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerEyeDropper

A ghost icon Button that picks from the screen. Hidden where unsupported.

PropTypeDefault
size
Button size.
'sm' | 'md' | 'lg''md'
aria-label
Names the button.
string'Pick a color from the screen'
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerSwatches / ColorPickerSwatchItem

A wrapping list of presets. Each item takes a value, any CSS color.

PropTypeDefault
value
On an item: the color it picks.
string—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerSwatch / ColorPickerValue

The current color as a square, and as text. ColorPickerValue takes a function child to format it.

PropTypeDefault
children
On ColorPickerValue: writes the value another way.
(value: string) => ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

ColorPickerRow

A row for inputs and buttons. Renders a <div>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—