Skip to content
synccn

Color Picker

Saturation area, hue strip, hex field and swatches.

#2f7ed8

Installation

$ pnpm dlx shadcn@latest add @synccn/color-picker

First time in this project? Connect synccn with one command.

Usage

import { ColorPicker } from "@/components/ui/color-picker";<ColorPicker value={hex} onValueChange={setHex} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

  • value
    string

    Controlled hex colour.

  • defaultValue
    string

    Default "#2f7ed8"

    Initial hex colour when uncontrolled.

  • onValueChange
    (hex: string) => void

    Called with the new hex colour.

  • swatches
    string[]

    Default SWATCHES

    Preset colours shown under the picker.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Accessibility

  • The saturation area and hue bar are sliders; the hex field accepts typed values for precise input.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: slider
  • ARIA attributes: aria-label, aria-valuemax, aria-valuemin, aria-valuenow, aria-valuetext
  • Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight