ColorPicker
Color picker with HSB area, hue + optional alpha sliders, hex/RGB/HSL text fields, eyedropper, and saved swatches; renders as a popover or inline panel.
Built on React Aria ColorPicker — slider thumbs expose aria-valuenow and respond to arrow keys; format fields are labelled inputs.
import { ColorPicker } from '@arshad-shah/cynosure-react';
export default function Example() {
return <ColorPicker label="Brand colour" defaultValue="#6366F1" />;
}
import { ColorPicker } from "@arshad-shah/cynosure-react";
<ColorPicker label="Brand colour" defaultValue="#6366F1" />defaultValue and value accept either a CSS color string or a React Aria Color instance.
Variants
Section titled “Variants”popover (default) renders a swatch trigger that opens the panel in a Popover. inline drops the trigger and renders the panel in place.
import { ColorPicker } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ width: 320 }}>
<ColorPicker variant="inline" defaultValue="#6366F1" alpha eyedropper />
</div>
);
}
sm, md (default), and lg scale the area, sliders, and panel.
import { ColorPicker, Inline } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<Inline gap="3" align="center">
<ColorPicker size="sm" label="Small" defaultValue="#6366F1" />
<ColorPicker size="md" label="Medium" defaultValue="#10B981" />
<ColorPicker size="lg" label="Large" defaultValue="#EC4899" />
</Inline>
);
}
With alpha
Section titled “With alpha”Set alpha to add an alpha slider with a checker-pattern background and an A column in the text fields.
import { ColorPicker } from '@arshad-shah/cynosure-react';
export default function Example() {
return <ColorPicker label="Overlay" defaultValue="hsba(220, 80%, 90%, 0.6)" alpha />;
}
Format
Section titled “Format”Pick the starting format with defaultFormat ("hex", "rgb", or "hsl"). Users can switch between them with the in-panel segmented control.
import { ColorPicker } from '@arshad-shah/cynosure-react';
export default function Example() {
return (
<div style={{ width: 320 }}>
<ColorPicker variant="inline" defaultValue="#6366F1" defaultFormat="rgb" />
</div>
);
}
Saved swatches
Section titled “Saved swatches”Pass a controlled swatches array plus onSwatchesChange to render a saved-colors grid; users can save the current color and re-pick any saved swatch.
import { ColorPicker } from '@arshad-shah/cynosure-react';
import { useState } from 'react';
export default function Example() {
const [swatches, setSwatches] = useState<string[]>([
'#ef4444',
'#f59e0b',
'#10b981',
'#0ea5e9',
'#6366f1',
'#ec4899',
]);
return (
<div style={{ width: 340 }}>
<ColorPicker
variant="inline"
defaultValue="#ef4444"
swatches={swatches}
onSwatchesChange={setSwatches}
maxSwatches={12}
/>
</div>
);
}
Accessibility
Section titled “Accessibility”- Wraps React Aria’s
ColorPicker,ColorArea, andColorSliderprimitives — full keyboard support with arrow keys, Page Up/Down, and Home/End on each thumb. - The eyedropper button uses the browser’s
EyeDropperAPI when available; it’s hidden automatically on unsupported browsers. - Each format text field is a labelled input —
aria-labelon the picker trigger defaults to thelabelprop when it’s a string. - The trigger swatch reflects the current color including alpha when enabled.
Recipes
Section titled “Recipes”- Use
variant="inline"inside a settings panel where you don’t want a separate trigger. - Cap saved-color history with
maxSwatchesso the grid doesn’t grow unbounded. - Set
eyedropper={false}when shipping to browsers that lackEyeDropperif you’d rather hide the slot than rely on auto-detection. - Pass a controlled
valueof typeColorto read back any format viacolor.toString("rgb")/color.toString("hex").