Components · Form Controls
Color Picker
Pick a colour from swatches or type a hex, with an optional contrast hint against a background.
import { ColorPicker } from '@nexub/react';Usage
Brand, label or theme colours from a small palette.
A text or accent colour that must stay readable on a known background (`contrastAgainst`).
Free-form colour mixing (hue, saturation, alpha): not covered.
A few named options where the colour is incidental: use Select or RadioGroup.
Playground
Props
<ColorPicker aria-label="Label colour" value={color} onValueChange={setColor} />Examples
Default
Contrast hint
Named swatches
States
defaultdisabledinvalidreadOnlysize="sm"size="md"size="lg"
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | — | The colour as #rrggbb. |
| defaultValue | string | '#000000' | The colour as #rrggbb. |
| onValueChange | ((hex: string) => void) | — | Called with a lowercase #rrggbb. |
| swatches | ColorSwatch[] | neutrals and hues | The colours offered. A label is read out instead of the hex. Defaults to neutrals and hues. |
| contrastAgainst | string | — | A background hex: shows the WCAG 2.x contrast ratio and whether it passes AA for text (4.5:1). |
| disabled | boolean | — | Field states. Read-only stays focusable but does not open. |
| readOnly | boolean | — | Field states. Read-only stays focusable but does not open. |
| invalid | boolean | — | Field states. Read-only stays focusable but does not open. |
| name | string | — | A hidden input posts the value with a plain form. |
| size | 'sm' | 'md' | 'lg' | 'md' | Height of the trigger. |
| sheet | false | true | 'auto' | 'auto' (a bottom sheet below 768px) | The popover as a bottom sheet below 768px. |
| aria-describedby | string | — | |
| aria-invalid | false | true | 'true' | 'false' | — | |
| aria-label | string | — | |
| aria-labelledby | string | — | |
| className | string | — | |
| id | string | — |
Accessibility
Keyboard
- Enter / Space
Opens the popover with focus on the picked swatch.
- Arrow keys
Move between swatches and pick (six per row).
- Home / End
First and last swatch.
- Tab
Moves to the hex field. Enter or leaving it applies the hex.
- Escape
Closes the popover.
Notes
The trigger is a `combobox` named by `aria-label`; its text is the hex.
Swatches are a `radiogroup` with one tab stop. An invalid hex keeps the last colour and marks the field invalid.
The contrast hint is announced politely when it changes.