āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/sadmann7/diceui/components/color-picker ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
npx shadcn@latest add "https://diceui.com/r/color-picker"
```package-install
@radix-ui/react-popover @radix-ui/react-select @radix-ui/react-slider @radix-ui/react-slot class-variance-authority lucide-react
```
</Step>
<Step>
Copy the refs composition utilities into your `lib/compose-refs.ts` file.
<ComponentSource name="compose-refs" />
</Step>
<Step>
Copy and paste the following code into your project.
<ComponentSource name="color-picker" />
</Step>
</Steps>
Import the parts, and compose them together.
import {
ColorPicker,
ColorPickerAlphaSlider,
ColorPickerArea,
ColorPickerContent,
ColorPickerEyeDropper,
ColorPickerFormatSelect,
ColorPickerHueSlider,
ColorPickerInput,
ColorPickerSwatch,
ColorPickerTrigger,
} from "@/components/ui/color-picker";
<ColorPicker>
<ColorPickerTrigger>
<ColorPickerSwatch />
</ColorPickerTrigger>
<ColorPickerContent>
<ColorPickerArea />
<div className="flex items-center gap-2">
<ColorPickerEyeDropper />
<div className="flex flex-1 flex-col gap-2">
<ColorPickerHueSlider />
<ColorPickerAlphaSlider />
</div>
</div>
<div className="flex items-center gap-2">
<ColorPickerFormatSelect />
<ColorPickerInput />
</div>
</ColorPickerContent>
</ColorPicker>
Use the inline prop to render the color picker inline instead of in a popover.
A color picker with controlled state management.
<ComponentTabs name="color-picker-controlled-demo" />A color picker with form integration.
<ComponentTabs name="color-picker-form-demo" />The main container component for the color picker.
<AutoTypeTable path="./types/docs/color-picker.ts" name="RootProps" />
The trigger button that opens the color picker popover.
<AutoTypeTable path="./types/docs/color-picker.ts" name="TriggerProps" />
The content container for the color picker components.
<AutoTypeTable path="./types/docs/color-picker.ts" name="ContentProps" />
The 2D color area for selecting hue and saturation.
<AutoTypeTable path="./types/docs/color-picker.ts" name="AreaProps" />
A color swatch that displays the current color.
<AutoTypeTable path="./types/docs/color-picker.ts" name="SwatchProps" />
A slider for adjusting the hue value of the color.
<AutoTypeTable path="./types/docs/color-picker.ts" name="HueSliderProps" />
A slider for adjusting the alpha (transparency) value of the color.
<AutoTypeTable path="./types/docs/color-picker.ts" name="AlphaSliderProps" />
A button that activates the browser's native eye dropper tool to pick colors from the screen.
<AutoTypeTable path="./types/docs/color-picker.ts" name="EyeDropperProps" />
<DataAttributesTable attributes={[ { title: "[data-disabled]", value: "Present when the component is disabled.", }, ]} />
Note: The EyeDropper component only renders when the browser supports the native EyeDropper API. It will return null in unsupported browsers.
A select dropdown for choosing the color format (hex, rgb, hsl, hsb).
<AutoTypeTable path="./types/docs/color-picker.ts" name="FormatSelectProps" />
An input field that displays and allows editing of the color value in the selected format.
<AutoTypeTable path="./types/docs/color-picker.ts" name="InputProps" />
<KeyboardShortcutsTable shortcuts={[ { keys: ["Tab"], description: "Moves focus to the next focusable element.", }, { keys: ["Shift + Tab"], description: "Moves focus to the previous focusable element.", }, { keys: ["Enter", "Space"], description: "Opens the color picker when focus is on the trigger.", }, { keys: ["Escape"], description: "Closes the color picker and moves focus to the trigger.", }, { keys: ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], description: "Adjusts the color value when focus is on sliders or the color area.", }, ]} />
The EyeDropper component requires browser support for the native EyeDropper API:
The component gracefully handles unsupported browsers by not rendering the eye dropper button.
The color picker supports the following color formats:
#3b82f6)rgb(59, 130, 246))hsl(217, 91%, 60%))hsb(217, 76%, 96%))All formats support alpha channel for transparency when not using the withoutAlpha prop.
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā