Forms
ColorPicker
An inline colour picker: saturation and brightness area, hue and opacity sliders, a hex field and preset swatches, built on React Aria’s colour hooks.
import { ColorPicker } from '@reactloom/ui';Examples
Brand colour with presets
Brand colour
Selected: #2f6fed
import { ColorPicker, Stack, Text } from '@reactloom/ui';
import { useState } from 'react';
export default function Example() {
const [colour, setColour] = useState('#2f6fed');
return (
<Stack gap="3">
<ColorPicker label="Brand colour" value={colour} onValueChange={setColour} swatches={['#2f6fed', '#0f9d58', '#f4b400', '#db4437', '#7e57c2', '#212121']} />
<Text size="sm">
Selected: <code>{colour}</code>
</Text>
</Stack>
);
}In a popover, with opacity
Put the picker in a Popover for a compact trigger.
import { ColorPicker, PopoverContent, PopoverRoot, PopoverTrigger } from '@reactloom/ui';
import { useState } from 'react';
export default function Example() {
const [colour, setColour] = useState('#db4437cc');
return (
<PopoverRoot>
{/* PopoverTrigger is a Button: pass Button props to it. */}
<PopoverTrigger
variant="secondary"
startIcon={<span aria-hidden="true" style={{ display: 'inline-block', inlineSize: 14, blockSize: 14, borderRadius: 3, background: colour, boxShadow: 'inset 0 0 0 1px rgb(0 0 0 / .2)' }} />}
>
Highlight colour
</PopoverTrigger>
<PopoverContent aria-label="Highlight colour" size="auto">
<ColorPicker aria-label="Highlight colour" value={colour} onValueChange={setColour} withAlpha />
</PopoverContent>
</PopoverRoot>
);
}API reference
| Prop | Type | Default |
|---|---|---|
value / defaultValueAny CSS colour. | string | '#3366ff' |
onValueChangeWhile changing, as #rrggbb (or #rrggbbaa with withAlpha). | (hex) => void | — |
onValueChangeEndWhen a drag or key press ends. | (hex) => void | — |
withAlphaAdds an opacity slider. | boolean | false |
swatchesPreset colours. | readonly string[] | — |
label / aria-labelNames the group. | | — |
disabled | boolean | — |
messagesTranslate the part names. | Partial<ColorPickerMessages> | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-disabled] | present when on |
Theme tokens it reads
--pl-radius-md
Accessibility
- The area is two sliders (saturation, brightness); screen readers hear colour names such as “dark vibrant blue”, not only numbers.
- Swatches are buttons named with their colour and pressed when selected.
- The hex field accepts typing and paste.
| Key | Action |
|---|---|
| ← → ↑ ↓ | Adjust the focused area or slider |
| Page Up / Page Down | Larger steps |
| Enter in the hex field | Apply the typed colour |
Usage guidelines
Do
- Offer swatches for brand or theme colours.
- Check contrast where the colour will be used.
Don’t
- Don’t rely on colour alone to convey a choice elsewhere in the UI.