Color Picker
Installation
Add the component with the CLI.
npx shadcn@latest add @intentui/color-picker
Composed components
When you install this component via the CLI, it automatically loads all composed components, so you don’t need to add them individually.
Manual installation
Install the dependencies, then copy the component source into your project.
npm install react-aria-components @heroicons/react cn
Anatomy
Compose ColorPicker with a custom button and Popover. Wrap the button and popover in PopoverTrigger so open state and trigger wiring are handled for you. Keep the selected color state on ColorPicker separately from the popover.
"use client"
import { parseColor } from "@react-stately/color"
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { ColorArea } from "@/components/ui/color-area"
import { ColorField } from "@/components/ui/color-field"
import { ColorPicker } from "@/components/ui/color-picker"
import { ColorSlider, ColorSliderTrack } from "@/components/ui/color-slider"
import { ColorSwatch } from "@/components/ui/color-swatch"
import { ColorThumb } from "@/components/ui/color-thumb"
import { Input } from "@/components/ui/input"
import { Popover, PopoverBody, PopoverTrigger } from "@/components/ui/popover"
export default function ColorPickerExample() {
const [color, setColor] = useState(parseColor("#0d6efd"))
return (
<ColorPicker value={color} onChange={setColor} defaultValue="rgb(120,140,200)">
<PopoverTrigger>
<Button intent="plain" data-slot="control">
<ColorSwatch />
Select color
</Button>
<Popover aria-label="Choose color" className="[--gutter:--spacing(1)]">
<PopoverBody>
<div className="space-y-(--gutter)">
<ColorArea
colorSpace="rgb"
defaultValue="rgb(120,140,200)"
xChannel="red"
yChannel="green"
xName="red"
yName="green"
/>
<ColorSlider colorSpace="hsb" channel="hue">
<ColorSliderTrack>
<ColorThumb />
</ColorSliderTrack>
</ColorSlider>
<ColorField aria-label="Color">
<Input />
</ColorField>
</div>
</PopoverBody>
</Popover>
</PopoverTrigger>
</ColorPicker>
)
}See the Popover anatomy for PopoverTrigger and controlled open state.
Examples
Controlled
Control the selected color with the value prop to sync it with your application's state.
Disabled
Disable the color picker by setting the isDisabled prop, making it non-interactive.
Component API
ColorPicker
ColorPicker extends the React Aria Components <ColorPicker> component.
classNamestringEyeDropper
EyeDropper extends the Intent UI <Button> component.
See the React Aria for the full API reference.
