Color PickerPro
Pro
Allows users to select, preview, and edit colors using visual controls and numeric color values.
Color Picker Playground
Color Picker Playground
Preview
Code
#
%
HEX
Recently Used
Controls
Format:
HEX
RGB
HSL
HSB
Opacity Slider:
Color Swatches:
EyeDropper Sampler:
Copy Button:
Disabled:
Installation
You can add the color picker component to your project manually:
1
Install the following dependencies:
npm
pnpm
yarn
bun
npm install class-variance-authority clsx tailwind-merge @phosphor-icons/react2
Copy and paste the following code into your project.
Loading...
3
Update the import paths to match your project setup.
Update the import aliases (e.g. @/components, @/utils) in the copied files to match your project's path configuration.
Basic Usage
import { useState } from 'react';
import { ColorPicker } from '@versaui/ui/components/ColorPicker';
function Example() {
const [color, setColor] = useState('#9423D9');
return (
<ColorPicker
value={color}
onValueChange={setColor}
format="Hex"
opacitySlider={true}
/>
);
}Subcomponents Usage
Standalone Color Input
import { useState } from 'react';
import { ColorInput } from '@versaui/ui/components/ColorPicker';
function InputExample() {
const [hex, setHex] = useState('9423D9');
return (
<ColorInput
mode="Hex"
hexValue={hex}
onHexChange={setHex}
colorString={`#${hex}`}
colorPreview={true}
copyColor={true}
size="Default"
/>
);
}Color Sliders (Hue & Opacity)
import { useState } from 'react';
import { ColorSlider } from '@versaui/ui/components/ColorPicker';
function SlidersExample() {
const [hue, setHue] = useState(277);
const [opacity, setOpacity] = useState(0.85);
return (
<div className="space-y-4">
<ColorSlider type="Hue" value={hue} onChange={setHue} />
<ColorSlider type="Opacity" value={opacity} color="rgb(148, 35, 217)" onChange={setOpacity} />
</div>
);
}Color Swatches & Swatch Group
import { ColorSwatch, ColorSwatchGroup } from '@versaui/ui/components/ColorPicker';
function SwatchesExample() {
return (
<ColorSwatchGroup
title="Presets"
selectedColor="#615FFF"
onSelectColor={(color) => console.log(color)}
/>
);
}Accessibility
- Built using WAI-ARIA Slider specification (
role="slider",aria-valuenow,aria-valuemin,aria-valuemax). - Full keyboard support for
ColorArea(Arrow keys for 1% shifts, Shift + Arrow keys for 10% shifts) andColorSlider(Arrow keys, Shift + Arrow keys for 10% steps, Home / End for bounds). - Token-based focus ring (
--focus-ring-primary) on interactive spectrum and sliders with 4px handle stroke when focused. - Accessible button semantics for
ColorSwatch,ColorSampler, andCopyColor.
Component Props
ColorPicker Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | undefined | Controlled hex or rgba color string. |
defaultValue | string | '#9423D9' | Default color string for uncontrolled mode. |
onValueChange | (color: string) => void | undefined | Callback fired on color change. |
format | 'Hex' | 'RGB' | 'HSL' | 'HSB' | 'Hex' | Active color input format. |
onFormatChange | (format: 'Hex' | 'RGB' | 'HSL' | 'HSB') => void | undefined | Callback fired on format change. |
colorPreview | boolean | true | Renders the preview color swatch in the color input bar. |
opacitySlider | boolean | true | Renders the opacity slider. |
colorGroup | boolean | true | Renders preset/recently used swatches. |
colorSampler | boolean | true | Renders the EyeDropper sampling button. |
copyColor | boolean | true | Renders the copy color action button. |
presetColors | string[] | undefined | Custom array of preset color strings. |
disabled | boolean | false | Disables all color picker controls. |
ColorInput Props
| Prop | Type | Default | Description |
|---|---|---|---|
mode | 'Hex' | 'RGB' | 'HSL' | 'HSB' | 'Hex' | Input color mode. |
size | 'Default' | 'Small' | 'Default' | Height and border radius size variant. |
colorPreview | boolean | true | Embedded left color preview swatch. |
opacityInput | boolean | true | Embedded opacity percentage input. |
copyColor | boolean | true | Embedded right copy action button. |
hexValue | string | '9423D9' | Controlled 6-digit hex string. |
colorString | string | 'rgba(148, 35, 217, 0.84)' | Full formatted color string for preview swatch and copy action. |
opacityValue | number | 84 | Opacity percentage value (0 - 100). |
onHexChange | (hex: string) => void | undefined | Callback fired on valid hex input change. |
onOpacityChange | (opacityPct: number) => void | undefined | Callback fired on opacity percentage change. |
onCopyColor | (formattedColor: string) => void | undefined | Callback fired on color copy action. |
disabled | boolean | false | Disables input interaction. |