Color Swatch Picker
Select a named color or image from an application-owned palette.
Shown on the label in lists and filters.
Installation
pnpm dlx shadcn@4.18.0 add @siteplane/color-swatch-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 { ColorSwatchPicker } from "@/siteplane/components/color-swatch-picker";
<ColorSwatchPicker
aria-label="Color"
options={[{ value: "green", label: "Green", color: "#22c55e" }]}
/>;Controlled selection
The value is the option key, not its CSS color.
Selection ring
A selected swatch shows a check by default, drawn in like the Checkbox check and instantly under reduced motion. Set indicator="ring" to draw an accent ring around it instead, so the swatch keeps its full color.
Image swatches
Give an option an image instead of a color and the picture fills the swatch. The color is optional and shows until the image has loaded. Use indicator="ring" so the selection doesn’t cover the picture.
Gets a notification when the draft is ready.
Read-only and disabled
Read-only preserves selection and is announced as read-only; disabled also removes the submitted value.
Form integration
Inside a Field, the picker submits the selected option’s value under the field’s name. With required, the form isn’t submitted until a color is chosen, and FieldError explains why.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
options | readonly ColorSwatchPickerOption[] | Required | Each option has label (accessible name), value (unique string), and optional disabled, plus a color (CSS color), an image (image URL), or both. An image fills the swatch; a color shows behind it until the image has loaded. imageSize and imagePosition (CSS background-size and background-position) show part of the image. |
value / default | string | — | Controlled option key or uncontrolled initial key. |
on | (value: string) => void | — | Emits selected option key. |
indicator | check | ring | check | How the selected swatch shows it: a check inside the swatch, or an accent ring around it. |
disabled / read | boolean | false | Disable interaction, prevent changes, or require selection. readOnly and required are exposed on the listbox as aria-readonly and aria-required; a disabled Field also disables the picker. |
name / form | string | — | Native form field name / form id; a Field name takes precedence. |
input | React.Ref<HTMLInputElement> | — | Reference to the visually hidden form input. |
size | sm | md | lg | xl | provider / lg | Control dimensions; swatches are 28, 32, 36 and 40 px. |
class | div props | — | Applied to the collection root; inside a Field, FieldLabel, FieldDescription and FieldError are connected automatically. |
Exported types: ColorSwatchPickerProps, ColorSwatchPickerOption and ColorSwatchIndicator. These describe the contracts above.
Usage notes
Native reset restores uncontrolled selection. Inside a Field, FieldLabel names the group and clicking it focuses the selected swatch; outside a Field, pass aria-label or aria-labelledby. Each option label is announced. Keyboard navigation follows React Aria ColorSwatchPicker. Swatches are round by default; the radius of SiteplaneUIProvider squares them off (none) or rounds them only slightly (sm). To end a palette with a custom color, use the swatch trigger of Color Picker. Arbitrary children and native onChange are not part of this wrapper.