Data & Media
@hacline/ui/color-pickerColorPicker
Pick colors via a color area, hue slider, text input, or preset swatches.
Usage
Drag the color area and hue slider, or type a CSS color and press Enter. This example edits colors in HSV while format="hex" determines the output format.
"use client";
import {
ColorPicker,
ColorPickerArea,
ColorPickerAreaThumb,
ColorPickerInput,
ColorPickerSlider,
ColorPickerSliderThumb,
ColorPickerSwatch,
ColorPickerSwatches,
ColorPickerSwatchItem,
} from "@/components/ui/hacline/components/color-picker";
const colors = [
{ color: "#446bb0", label: "Ocean blue" },
{ color: "#297754", label: "Pine green" },
{ color: "#b35c2b", label: "Terracotta" },
];
export const Example = () => (
<ColorPicker
aria-label="Project color"
className="max-w-xs"
defaultValue="#446bb0"
format="hex"
space="hsv"
>
<ColorPickerArea x="saturation" y="brightness">
<ColorPickerAreaThumb aria-label="Color saturation and brightness" />
</ColorPickerArea>
<ColorPickerSlider channel="hue">
<ColorPickerSliderThumb aria-label="Hue" />
</ColorPickerSlider>
<div className="flex items-center gap-2">
<ColorPickerSwatch />
<ColorPickerInput aria-label="CSS color value" />
</div>
<ColorPickerSwatches aria-label="Project preset colors">
{colors.map(({ color, label }) => (
<ColorPickerSwatchItem aria-label={label} key={color} value={color} />
))}
</ColorPickerSwatches>
</ColorPicker>
);Adjusting Opacity
Set a slider's channel to alpha, and inspect the alpha-enabled CSS representation in the color input.
"use client";
import {
ColorPicker,
ColorPickerInput,
ColorPickerSlider,
ColorPickerSliderThumb,
ColorPickerSwatch,
} from "@/components/ui/hacline/components/color-picker";
export const Example = () => (
<ColorPicker
aria-label="Highlight background color"
className="max-w-xs"
defaultValue="rgb(32 86 172 / 0.6)"
format="srgb"
>
<div className="flex items-center gap-2">
<ColorPickerSwatch />
<ColorPickerInput aria-label="Background RGBA value" />
</div>
<ColorPickerSlider channel="alpha">
<ColorPickerSliderThumb aria-label="Opacity" />
</ColorPickerSlider>
</ColorPicker>
);Parts
| Part | Description |
|---|---|
ColorPickerArea | A surface for two channels, x and y. Its background comes from --color-area-background where gradients draw it, or a ColorPickerAreaCanvas. |
ColorPickerAreaCanvas | Paints the area pixel by pixel, for channels no gradient draws, like OKLCH's chroma by lightness. Colors outside the gamut stay transparent. |
ColorPickerAreaThumb | The area's thumb: a slider screen readers hear as both channels. |
ColorPickerChannelInput | A number input for one channel, in the units people read it in. |
ColorPickerEyeDropper | A button that picks a color from the screen, where the browser can. Elsewhere it's disabled, with data-unsupported. |
ColorPickerInput | A text input that reads any CSS color on Enter or blur. Text that isn't one goes back to the value. |
ColorPickerSlider | A track for one channel, drawn by --color-slider-background. |
ColorPickerSliderThumb | The slider's thumb, at --color-slider-thumb-position. |
ColorPickerSwatch | The color itself, as --color-picker-color, named for screen readers. |
ColorPickerSwatches | A list of preset colors. Arrow keys move between them. |
ColorPickerSwatchItem | A preset color, as --color-picker-color. Pressing it sets the value. |
Props
Prop
Type