ColorPicker
Overviewimport { ColorDot, ColorPicker, ColorSlider, ColorSpectrum } from '@nili/ui';This is the library’s own overview page, rendered live. Switch the language or the theme in the header and it follows.
Color Dot
A swatch button. Ten palette colours, or any CSS colour through value. aria-label is required — a coloured circle has no accessible name of its own.
import { ColorDot } from "@nili/ui"
export function Example() {
const [selected, setSelected] = useState("blue")
return (
<>
{palette.map((color) => (
<ColorDot
key={color}
color={color}
aria-label={color}
selected={selected === color}
onClick={() => setSelected(color)}
/>
))}
{/* an arbitrary colour */}
<ColorDot value="#0E121B" aria-label="Ink" />
</>
)
}Color Picker
Spectrum, hue track and a hex field. Uncontrolled with defaultValue, or controlled with value plus onChange — which fires with a hex string, including the alpha pair when opacity is on.
#335CFFimport { ColorPicker } from "@nili/ui"
export function Example() {
const [color, setColor] = useState("#335CFF")
return <ColorPicker value={color} onChange={setColor} />
}Opacity and swatches
withOpacity adds the alpha track and switches the hex field to eight digits. swatches is the row of recent or brand colours under the controls.
import { ColorPicker } from "@nili/ui"
export function Example() {
return (
<ColorPicker
withOpacity
defaultValue="#7D52F4CC"
swatches={["#335CFF", "#1FC16B", "#FB3748", "#F6B51E", "#7D52F4"]}
/>
)
}Footer and labels
footer sits under the hex field — a confirm button, usually, when the picker lives in a popover. Every visible string is a prop, so the component ships no translation stack of its own.
import { ColorPicker, Button } from "@nili/ui"
export function Example() {
return (
<ColorPicker
withOpacity
defaultValue="#FB3748"
swatches={swatches}
labels={{
spectrum: "Saturation and brightness",
hue: "Hue",
opacity: "Opacity",
hex: "Hex value",
swatches: "Saved colours",
eyedropper: "Pick a colour from the screen",
}}
footer={<Button size="xs" fullWidth>Apply</Button>}
/>
)
}ColorDot
extends Omit< ComponentPropsWithoutRef<'button'>, 'color' >
Variant axes — from the component’s cva definition
| Prop | Type | Default | Notes |
|---|---|---|---|
| color | gray | blue | orange | red | green | yellow | purple | sky | pink | teal | — | One of the ten palette colours, or a raw CSS colour via `value`. |
Other props
| Prop | Type | Default | Notes |
|---|---|---|---|
| children | ReactNode | — | |
| disabled | boolean | — | |
| required | boolean | — | |
| readOnly | boolean | — | |
| value | string | — | Arbitrary colour. Wins over `color`. |
| defaultValue | string | — | |
| name | string | — | |
| aria-label* | string | — | Accessible name — a coloured circle has none. |
| selected | boolean | false |
ColorDotSwatch
internalColorPicker
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' | 'defaultValue' >
Other props
| Prop | Type | Default | Notes |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| value | string | — | Controlled hex, e.g. `'#335CFF'` or `'#335CFF80'`. |
| defaultValue | string | #335CFF | |
| onChange | (hex: string) => void | — | |
| withOpacity | boolean | true | Show the alpha track. |
| swatches | string[] | — | Swatch row under the controls. |
| footer | ReactNode | — | Rendered under the hex field — a confirm button, for instance. |
| labels | { format?: string; eyedropper?: string; spectrum?: string; hue?: string; opacity?: string; hex?: string; swatches?: string; } | — |
ColorSlider
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' >
Variant axes — from the component’s cva definition
| Prop | Type | Default | Notes |
|---|---|---|---|
| type | hue | opacity | hue |
Other props
| Prop | Type | Default | Notes |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| value* | number | — | |
| onChange* | (value: number) => void | — | |
| baseColor | string | #000 | For the opacity track, the colour the gradient fades to. |
| thumbColor | string | — | Fill of the thumb. Figma paints it with the picked colour. |
| label | string | — |
ColorSpectrum
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' >
Other props
| Prop | Type | Default | Notes |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| hue* | number | — | |
| saturation* | number | — | |
| brightness* | number | — | |
| onChange* | (next: { saturation: number; brightness: number }) => void | — | |
| label | string | Saturation and brightness |