Color Picker

HSV color picker with a 2D saturation/brightness area, hue and optional alpha sliders whose thumbs spring to a clicked point and follow drags 1:1, a validated hex field, preset swatches with a gliding selection ring and a ColorPickerPopover trigger mode; keyboard accessible, dependency-free color math.

Preview

Color Picker preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/color-picker
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

hsvToRgb

h
number
—
s
number
—
v
number
—
a
number
—

ColorPicker

value?
string

Controlled hex color (`#rrggbb`, or `#rrggbbaa` with `alpha`).

—
defaultValue?
string

Uncontrolled initial color. Default `#6366f1`.

#6366f1
onChange?
((hex: string) => void)

Receives lowercase hex; 8-digit only when `alpha` is on and alpha < 1.

—
alpha?
boolean

Show the alpha slider and emit 8-digit hex when translucent.

false
swatches?
string[]

Preset colors. Pass `[]` to hide the row.

[ "#ef4444", "#f97316", "#eab308", "#22c55e", "#06b6d4", "#3b82f6", "#6366f1", "#a855f7", "#ec4899", "#18181b", ]
showInput?
boolean

Show the hex text field. Default true.

true
eyeDropper?
boolean

Show an eyedropper button where the browser supports the EyeDropper API. Default true.

true
disabled?
boolean
false
className?
string
—

ColorPickerPopover

open?
boolean

Controlled open state.

—
defaultOpen?
boolean
—
onOpenChange?
((open: boolean) => void)
—
label?
string

Visible label next to the swatch in the trigger.

—
side?
"bottom" | "top"
bottom
align?
"end" | "start"
start
className?
string
—
pickerClassName?
string

Class for the picker inside the panel.

—
disabled?
boolean
—
value?
string

Controlled hex color (`#rrggbb`, or `#rrggbbaa` with `alpha`).

—
defaultValue?
string

Uncontrolled initial color. Default `#6366f1`.

#6366f1
onChange?
((hex: string) => void)

Receives lowercase hex; 8-digit only when `alpha` is on and alpha < 1.

—
alpha?
boolean

Show the alpha slider and emit 8-digit hex when translucent.

—
swatches?
string[]

Preset colors. Pass `[]` to hide the row.

—
showInput?
boolean

Show the hex text field. Default true.

—
eyeDropper?
boolean

Show an eyedropper button where the browser supports the EyeDropper API. Default true.

—

Updated