ColorPicker

A customizable color picker with hex, rgb, and hsl formats, eye dropper, and preset colors.

Installation

CLI

Loading...

Dependencies

This component requires the following npm packages:

Loading...

Registry Dependencies

This component also requires: https://ui.shadcn.com/r/styles/base-vega/button.json, https://ui.shadcn.com/r/styles/base-vega/input.json, https://ui.shadcn.com/r/styles/base-vega/popover.json, https://ui.shadcn.com/r/styles/base-vega/utils.json

Usage

ColorPicker is a customizable compound component for selecting colors. It supports hex, rgb, and hsl formats, includes an eye dropper tool, and provides a flexible API for building custom color selection interfaces.

The component uses a compound component pattern, allowing you to customize the trigger, content, and individual controls independently. It supports both controlled and uncontrolled usage patterns.

Examples

Controlled with Presets

Control both the color value and popover open state, with preset color options for quick selection.

Preset Colors

Current color:#3b82f6
Picker state:Closed

Minimal Setup

Use only the essential components for a simpler color picker interface.

Custom Format

Set a default color format (hex, rgb, or hsl) for display and input.

API Reference

ColorPicker Props

PropTypeDefaultDescription
valuestring-The controlled value of the selected color (hex, rgb, or hsl format).
defaultValuestring"#000000"The default value of the selected color.
onValueChange(value: string) => void-Callback fired when the color selection changes.
openboolean-The controlled open state of the popover.
defaultOpenbooleanfalseThe default open state of the popover.
onOpenChange(open: boolean) => void-Callback fired when the popover open state changes.
defaultFormat"hex" | "rgb" | "hsl""hex"The default color format for display and input.
disabledboolean-Whether the color picker is disabled.
children*ReactNode-The trigger element and popover content.

ColorPickerTrigger Props

PropTypeDefaultDescription
children*ReactNode-The trigger element (usually a Button).
...propsPopoverTriggerProps-All PopoverTrigger props are supported. Note: asChild is always set to true internally.

ColorPickerContent Props

PropTypeDefaultDescription
...propsPopoverContentProps-All PopoverContent props are supported.

ColorPickerSwatch Props

PropTypeDefaultDescription
...propsdiv-All standard div props are supported.

Sub-components

The following sub-components are available for customizing the color picker interface:

  • ColorPickerArea - 2D color selection area
  • ColorPickerHueSlider - Hue slider control
  • ColorPickerFormatSelect - Format selector (hex/rgb/hsl)
  • ColorPickerInput - Manual color input field
  • ColorPickerEyeDropper - Eye dropper tool (browser support required)

Source Code

Loading...