Xzero UI
Pro library

Color picker

A swatch that grows into a picker with format morphing, eyedropper, saved swatches, and contrast readout.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/color-picker
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/color-picker

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { useState } from "react";
import { ColorPicker } from "@/components/xzero/color-picker/color-picker";
import type { ColorSwatch } from "@/components/xzero/color-picker/color-picker";

export function BrandColor() {
  const [color, setColor] = useState("#2F6BFF");
  const [swatches, setSwatches] = useState<ColorSwatch[]>([
    { id: "ink", color: "#17171A" },
    { id: "sky", color: "#3A8DFF" },
  ]);

  return (
    <ColorPicker
      label="Accent"
      value={color}
      onValueChange={setColor}
      background="#FFFFFF"
      swatches={swatches}
      onSwatchesChange={setSwatches}
    />
  );
}

API reference

ColorPicker

A swatch trigger that grows into a picker with a saturation area, hue and opacity sliders, a typed value, contrast readout, and saved swatches.

PropTypeDefaultDescription
valuestring–Controlled color in hex, rgb(), hsl(), or oklch().
defaultValuestring"#2F6BFF"Uncontrolled starting color.
onValueChange(hex: string) => void–Receives the color as uppercase hex, with two alpha digits when it is not opaque.
backgroundstring"#FFFFFF"The background the color will sit on, for the WCAG contrast readout.
labelstring"Color"Name shown on the swatch, such as "Accent".
swatchesColorSwatch[]–Controlled saved swatches: { id, color }.
defaultSwatchesColorSwatch[]–Uncontrolled starting swatches. Defaults to none.
onSwatchesChange(swatches: ColorSwatch[]) => void–Called when swatches are added, reordered, or removed.
maxSwatchesnumber7Most saved swatches. Saving past it drops the oldest.
defaultFormat"hex" | "rgb" | "hsl" | "oklch""hex"Format shown in the text field first.
classNamestring–Extra class on the root.

parseColor

Reads hex, rgb(), hsl(), and oklch() in modern or comma syntax into { h, s, v, a }. Returns null for anything else.

PropTypeDefaultDescription
input (required)string–Color text.
huenumber0Hue to keep for grays, where hue is undefined.

toHex

Formats { h, s, v, a } as uppercase hex, adding alpha digits below full opacity.

PropTypeDefaultDescription
hsva (required)Hsva–Hue in degrees, saturation, value, and alpha from 0 to 1.

Keyboard interactions

KeysAction
Arrow keysMove the saturation and brightness thumb in 2D, or the focused hue or opacity slider; Shift takes steps of ten.
PageUp / PageDownStep a slider by ten.
Home / EndMove a slider to its minimum or maximum; in the swatch row, jump to the first or last swatch.
EnterApplies the typed value in the text field; an invalid value shakes the field and shows an error.
Alt + ArrowLeft / ArrowRightMoves the focused swatch.
Delete / BackspaceRemoves the focused swatch.
EscapeDiscards a typed draft first, then closes the panel and returns focus to the trigger.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in pickers

Guidance for AI tools

Color picker: A swatch that grows into a picker with format morphing, eyedropper, saved swatches, and contrast readout. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components