Components
Swatch Picker
Pick a colour from round swatches.
<SwatchPicker legend="Colour" swatches={swatches} />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/swatch-picker.jsonimport { SwatchPicker } from "@/components/swatch-picker"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Pick a colour from round swatches. Each swatch is a radio named after its colour, so screen readers say "Ocean", not a hex code.
import { SwatchPicker } from "@/components/swatch-picker";
const swatches = [
{ name: "Ocean", color: "#0ea5e9" },
{ name: "Forest", color: "#16a34a" },
];
export function Colour() {
return <SwatchPicker legend="Colour" swatches={swatches} onChange={(s) => console.log(s.color)} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
legend | string | Names the group. | |
swatches | { name: string; color: string }[] | The colours. | |
name | string | Form field name. | |
defaultValue | string | the first | Starting swatch's name. |
onChange | (swatch) => void | Called when the choice changes. | |
className | string | Classes for the wrapper. |
With reduced motion, the chosen swatch doesn't grow.