Skip to content

Swatch Picker

Tactile colour tiles lift into selection with a small checkmark.

LIVE PREVIEWInteract with the component
Just React. No extra dependencies.

Copy the component and its CSS module into your project.

CSS Modules

Usage

Matches your current playground settings.

jsx
import SwatchPicker from "./SwatchPicker";
export default function Example() {
return (
<SwatchPicker
items={[
{
"value": "clay",
"label": "Clay",
"color": "#bd8b75"
},
{
"value": "linen",
"label": "Linen",
"color": "#ded0b8"
},
{
"value": "moss",
"label": "Moss",
"color": "#929b83"
},
{
"value": "ink",
"label": "Ink",
"color": "#637483"
},
{
"value": "lilac",
"label": "Lilac",
"color": "#b5a1c7"
}
]}
defaultValue={"clay"}
label={"Choose your finish"}
size={48}
/>
);
}

Using Swatch Picker

Supply each swatch's value, label, and colour through items. The labels should distinguish choices without relying on colour alone.

Use value with onValueChange for a controlled picker, or defaultValue for local state. size determines the individual tile size.

Props

NameTypeRequiredDefaultDescription
itemsobject[]No[]Array of { value, label, color, disabled? }. Values must be unique strings.
valuestringNoundefinedOptional controlled selected value.
defaultValuestringNoundefinedInitial uncontrolled value; otherwise the first enabled item is selected.
onValueChangefunctionNoundefinedCalled with the selected value.
labelstringNo"Choose a colour"Visible legend and accessible group label.
sizenumberNo48Swatch edge length in pixels, clamped to at least 28. Tiles wrap in narrow containers.
classNamestringNo""Additional classes merged with the component styles.
styleCSSPropertiesNoundefinedInline styles for caller-defined sizing, typography, and appearance.

Related components

A recessed password field pairs a reveal control with an optional strength indicator.

Editable tags collect inside a softly framed input with individual remove controls.

A recessed search field expands into a polished capsule as you type.

Faceted stars lift into selection with a small marker beneath the chosen rating.