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
- 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
formatyour app stores, such as hex for a theme file or OKLCH for design tokens, so the value doesn’t need converting. - Save on
onValueCommitrather than every change, so a drag doesn’t send dozens of requests.
- 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>.
| Prop | Type | Default |
|---|---|---|
defaultValue / valueThe color as CSS, uncontrolled or controlled. | string | — |
onValueChangeCalled on every step of a drag or key. | (value, details) => void | — |
onValueCommitCalled once an interaction ends. For saving. | (value, details) => void | — |
spaceWhich channels the area and sliders edit. | 'hsv' | 'hsl' | 'srgb' | 'oklch' | 'hsv' |
formatHow the value is written. Hex for hsv by default. | 'hex' | 'hsl' | 'rgb' | 'oklch' | — |
gamutThe colors the value may hold. | 'srgb' | 'p3' | false | 'srgb' |
disabled / readOnlyStops changes; read-only stays focusable. | boolean | — |
nameSubmits the value with a form. | string | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerArea
Edits two channels at once, with its thumb. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
x / yThe channels across and up. Defaults follow the space. | ColorChannel | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerSlider
Edits one channel, with its thumb. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
channelThe channel it edits. | 'hue' | 'alpha' | … | — |
orientationThe axis. | 'horizontal' | 'vertical' | 'horizontal' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerInput
Reads any CSS color, drawn as an InputGroup.
| Prop | Type | Default |
|---|---|---|
sizeControl height. | 'sm' | 'md' | 'lg' | 'md' |
swatchShows a small swatch before the text. | boolean | true |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerChannelInput
Edits one channel as a number.
| Prop | Type | Default |
|---|---|---|
channelThe channel it edits. | ColorChannel | — |
sizeControl height. | 'sm' | 'md' | 'lg' | 'md' |
suffixA unit after the number, such as %. | ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerEyeDropper
A ghost icon Button that picks from the screen. Hidden where unsupported.
| Prop | Type | Default |
|---|---|---|
sizeButton size. | 'sm' | 'md' | 'lg' | 'md' |
aria-labelNames the button. | string | 'Pick a color from the screen' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerSwatches / ColorPickerSwatchItem
A wrapping list of presets. Each item takes a value, any CSS color.
| Prop | Type | Default |
|---|---|---|
valueOn an item: the color it picks. | string | — |
sxStyleX 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.
| Prop | Type | Default |
|---|---|---|
childrenOn ColorPickerValue: writes the value another way. | (value: string) => ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
ColorPickerRow
A row for inputs and buttons. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |