Prototyper UI
Components

Color Picker

An OKLCH-native color picker with area, sliders, swatches, and eye dropper

Loading...

Installation

npx shadcn@latest add https://prototyper-ui.com/r/color-picker.json

This will add the following files to your project:

  • components/ui/color-picker.tsx
  • lib/color-utils.ts

Usage

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerContent,
  ColorPickerInput,
  ColorPickerSlider,
  ColorPickerTrigger,
} from "@/components/ui/color-picker"

<ColorPicker defaultValue="#6366f1">
  <ColorPickerTrigger />
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerSlider channel="hue" />
    <ColorPickerInput />
  </ColorPickerContent>
</ColorPicker>

Anatomy

<ColorPicker>
  <ColorPickerTrigger />
  <ColorPickerContent>
    <ColorPickerArea>
      <ColorPickerAreaThumb />
    </ColorPickerArea>
    <ColorPickerSlider channel="hue">
      <ColorPickerSliderThumb />
    </ColorPickerSlider>
    <ColorPickerSlider channel="alpha">
      <ColorPickerSliderThumb />
    </ColorPickerSlider>
    <ColorPickerEyeDropper />
    <ColorPickerInput />
    <ColorPickerSwatches>
      <ColorPickerSwatch />
    </ColorPickerSwatches>
  </ColorPickerContent>
</ColorPicker>
Sub-componentdata-slotPurposeRequired
ColorPickercolor-pickerRoot context provider, manages color stateYes
ColorPickerTriggercolor-picker-triggerButton that opens the popoverNo
ColorPickerContentcolor-picker-contentPopover panel containing controlsNo
ColorPickerAreacolor-picker-area2D lightness × chroma gradientYes
ColorPickerAreaThumbcolor-picker-area-thumbDraggable dot in the areaNo
ColorPickerSlidercolor-picker-slider1D channel slider (hue or alpha)Yes
ColorPickerSliderThumbcolor-picker-slider-thumbSlider thumbNo
ColorPickerInputcolor-picker-inputText input for hex/color valuesNo
ColorPickerEyeDroppercolor-picker-eye-dropperEyeDropper API button (progressive)No
ColorPickerSwatchescolor-picker-swatchesGrid container for preset colorsNo
ColorPickerSwatchcolor-picker-swatchClickable preset color buttonNo

Examples

With Swatches

Loading...

Alpha Channel

Loading...

Inline

Loading...

Form Integration

Loading...

Disabled

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the color picker:

Slot nameElement
color-pickerRoot wrapper
color-picker-triggerTrigger button with swatch preview
color-picker-contentPopover panel
color-picker-area2D color gradient canvas
color-picker-area-thumbDraggable dot on the area
color-picker-sliderHue or alpha slider track
color-picker-slider-thumbSlider thumb circle
color-picker-inputHex text input
color-picker-eye-dropperEyeDropper button
color-picker-swatchesSwatches grid container
color-picker-swatchIndividual swatch button

Customization Examples

/* Make the color area taller */
[data-slot="color-picker-area"] {
  @apply aspect-[4/3];
}

/* Larger swatches */
[data-slot="color-picker-swatch"] {
  @apply size-8 rounded-full;
}
{/* Wider popover panel */}
<ColorPickerContent className="w-80">
  {/* ... */}
</ColorPickerContent>

API Reference

ColorPicker

Root component that manages color state and provides context.

PropTypeDefaultDescription
valuestring-Controlled CSS color string
defaultValuestring"#6366f1"Uncontrolled initial color
onValueChange(value: string) => void-Called on every change (live)
onValueCommit(value: string) => void-Called on pointer up or Enter
outputFormat"hex" | "oklch" | "rgb" | "hsl""hex"Format for emitted color strings
namestring-Hidden input name for form submission
disabledbooleanfalseDisable all interactions
enableAlphabooleanfalseShow alpha channel controls
openboolean-Controlled popover open state
onOpenChange(open: boolean) => void-Callback when popover opens/closes
classNamestring-Additional CSS classes
childrenReact.ReactNode-Color picker content

ColorPickerTrigger

Button that shows a swatch preview and opens the popover.

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-Custom trigger content (defaults to hex value)
...propsPopoverPrimitive.Trigger.Props-All Base UI Popover.Trigger props

ColorPickerContent

Popover panel wrapping the color controls.

PropTypeDefaultDescription
sideOffsetnumber8Distance from trigger
align"start" | "center" | "end""start"Alignment relative to trigger
classNamestring-Additional CSS classes
...propsPopoverPrimitive.Popup.Props-All Base UI Popover.Popup props

ColorPickerArea

2D gradient area for selecting lightness (Y) and chroma (X).

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-Custom thumb (defaults to ColorPickerAreaThumb)

ColorPickerAreaThumb

Draggable dot positioned within the color area.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

ColorPickerSlider

1D slider for hue or alpha channel.

PropTypeDefaultDescription
channel"hue" | "alpha"-Which channel to control
classNamestring-Additional CSS classes
childrenReact.ReactNode-Custom thumb (defaults to ColorPickerSliderThumb)

ColorPickerSliderThumb

Slider thumb circle.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

ColorPickerInput

Text input for typing color values directly.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

ColorPickerEyeDropper

Button that activates the browser EyeDropper API. Only renders when the API is available.

PropTypeDefaultDescription
classNamestring-Additional CSS classes

ColorPickerSwatches

Grid container for preset color buttons.

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReact.ReactNode-ColorPickerSwatch elements

ColorPickerSwatch

Clickable preset color button.

PropTypeDefaultDescription
valuestring-CSS color string for this preset
classNamestring-Additional CSS classes

Accessibility

Keyboard Interactions

KeyAction
Arrow keysMove thumb in the color area or adjust slider value
Shift + Arrow keysFine-step adjustment
HomeSet chroma to minimum (area) or slider to minimum
EndSet chroma to maximum (area) or slider to maximum
PageUpSet lightness to maximum (area only)
PageDownSet lightness to minimum (area only)
EnterConfirm text input value
TabMove focus between area, sliders, input, and swatches

ARIA Attributes

  • The color area and sliders use role="slider" with aria-valuemin, aria-valuemax, and aria-valuenow.
  • aria-valuetext on the area provides a human-readable description of the current color position.
  • aria-label is set on each slider to identify the channel (Hue, Alpha).
  • The EyeDropper button is a standard <button> element and only renders when the API is supported.

On this page