Skip to Content
zjkm-ui
Components

Swatch Picker

Pick a colour from round swatches.

Colour
Props
<SwatchPicker legend="Colour" swatches={swatches} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/swatch-picker.json
import { 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

PropTypeDefaultDescription
legendstringNames the group.
swatches{ name: string; color: string }[]The colours.
namestringForm field name.
defaultValuestringthe firstStarting swatch's name.
onChange(swatch) => voidCalled when the choice changes.
classNamestringClasses for the wrapper.

With reduced motion, the chosen swatch doesn't grow.

On this page