Examples

Brand colour with presets

Preview
Brand colour

Selected: #2f6fed

Example.tsx
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.

Preview
Example.tsx
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

ColorPicker props
PropTypeDefault
value / defaultValue
Any CSS colour.
string'#3366ff'
onValueChange
While changing, as #rrggbb (or #rrggbbaa with withAlpha).
(hex) => void—
onValueChangeEnd
When a drag or key press ends.
(hex) => void—
withAlpha
Adds an opacity slider.
booleanfalse
swatches
Preset colours.
readonly string[]—
label / aria-label
Names the group.
—
disabled
boolean—
messages
Translate 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.

AttributeValues
[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.
Keyboard interactions
KeyAction
← → ↑ ↓Adjust the focused area or slider
Page Up / Page DownLarger steps
Enter in the hex fieldApply 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.