Color Picker
Choose a hex color with a swatch, hue slider, and channel fields.
Used for buttons, links and focus rings.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/color-pickerComplete the one-time setup first. Registry JSON lists source files and dependencies.
For this page’s examples, also install:
pnpm dlx shadcn@4.18.0 add @siteplane/button @siteplane/form @siteplane/inputField is installed with Input.
Usage
import { ColorPicker } from "@/siteplane/components/color-picker";
<ColorPicker aria-label="Brand color" />;Controlled color
The callback emits a lowercase hex string.
Sizes and swatch-only trigger
Hide the text value with showValue={false}; keep a meaningful accessible label. disabled blocks the picker and leaves its value out of form submission.
Custom color swatch
Set variant="swatch" to draw the trigger as a Color Swatch Picker swatch, for a palette that ends in a custom color. Pressing the swatch opens the picker. Pass selected while the custom color is the one chosen in the row, and indicator to show the selection as a check or a ring, as on Color Swatch Picker. onOpenChange lets the row choose the custom color as soon as the picker opens.
Form integration
Inside a Field, the picker submits its lowercase hex value under the field’s name. It always holds a color, so required never blocks submission.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
value / default | string | defaultValue: "#000000" | Controlled color or uncontrolled initial hex; an omitted hash is accepted. |
on | (value: string) => void | — | Emits lowercase hex. |
open / default | boolean | uncontrolled / false | Controlled or initial open state of the picker. |
on | (open: boolean) => void | — | Called when the picker opens or closes. |
show | boolean | true | Displays the current value beside the swatch. The swatch variant never shows it. |
variant | default | swatch | default | default is an outlined button with the color and its hex value. swatch is a bare swatch of the current color, drawn like a Color Swatch Picker swatch. |
selected | boolean | false | Swatch variant only: marks the swatch as the chosen color of its row. It shows the indicator and sets aria-current. |
indicator | check | ring | check | Swatch variant only: how a selected swatch shows it, as on Color Swatch Picker. |
size | sm | md | lg | xl | provider / lg | Control dimensions. |
disabled | boolean | false | Disables trigger, fields, and submitted value; a disabled Field also disables the picker. |
name / form | string | — | Hidden input name and associated form id; a Field name takes precedence. |
read | boolean | false | Shows and submits the color; the controls open for reading and copying, but the color does not change. |
required | boolean | false | Sets required on the hidden form input. The picker always holds a color, so it never blocks submission. |
id / class | string / string / CSSProperties / number | — | Applied to the visible trigger. |
aria-label / aria-labelledby / aria-describedby / aria-invalid | string / string / string / AriaAttributes[aria-invalid] | Generated color label if unnamed | Applied to the trigger; inside a Field, FieldLabel, FieldDescription and FieldError are connected automatically. |
labels | Partial<ColorPickerLabels> | English | Accessible names of the controls in the popover; see the keys below. |
The keys of labels, each with its English default, are controls (Color controls, the popover), saturation (Color saturation and brightness), hue (Color hue), hex (Hex color value), copy (Copy hex value), copied (Copied hex value, while the check shows), copyFailed (Copy unavailable, when the clipboard refuses), and red, green and blue (R color channel, G color channel, B color channel). The letters R, G and B beside the channel fields stay as they are.
Exported types: ColorPickerProps, ColorPickerLabels. These describe the contracts above.
Usage notes
Inside a Field, FieldLabel names the trigger and clicking it focuses the trigger; outside a Field, pass aria-label or aria-labelledby. The picker takes only the props above; it owns its hidden form input. Use readOnly to show a color that cannot change and disabled to switch the picker off. Invalid hex falls back to the normalized default, then black. This control does not expose alpha, locale, or popup placement props.