oklch-pickerPlaygroundGitHub

API

Every prop, read from the published type declarations at build time, so this table cannot disagree with what you actually get.

Props

PropTypeDefaultNotes
value *string | null | undefined-`oklch(L C H)` or hex.
onChange *(colour: string) => void-Called with a canonical, gamut-clamped `oklch(L C H)` string.
presetsstring[]-
recentsstring[]-Recently used colours, most recent first. Omit to let the picker keep its own list for the session; pass one to store them yourself, in a backend, or shared between pickers.
onRecentsChange(recents: string[]) => void-Called with the new list when a colour is committed, for the controlled form above. Fires on commit, so on a pointer release, a preset, or a hex entry. Not on every value a drag passes through.
maxRecentsnumber8How many recents to keep. Ignored when `recents` is controlled: the list you pass is the list that renders.
layoutPickerLayout"chart"Visual arrangement. `chart` (the default) shows one large lightness x chroma plot above all three sliders; `side-by-side` adds a right rail for the readout and presets; `compact` drops the charts entirely and inlines each label with its slider; `stacked` gives every axis its own thin chart.
partsPickerPartsall on except gamutSwitchTurn parts off, e.g. `{ charts: false, name: false }`. All on by default.
labelsPartial<Record<LabelKey, string>>EnglishOverride for translation. Keys are the three axes, `outOfGamut`, and `outOf:<gamut id>` for a wider space's own notice.
gamutGamutSRGBThe output space: what the sliders reach, what is clamped, and what is emitted. Defaults to sRGB. Import wider spaces from `@oklch-picker/core/gamuts`; omitting this ships none of that code.
referencesGamut[][SRGB] when gamut is widerSpaces to outline on the charts without clamping to them. Defaults to sRGB whenever `gamut` is wider, so the safe region stays visible.
gamutChoicesGamut[]gamut + referencesWhat the switcher offers, when `parts.gamutSwitch` is on. Defaults to the output gamut plus its references.
onGamutChange(gamut: Gamut) => void-Called when a switcher button is pressed. Omit to leave the buttons inert. The app is driving `gamut` as a prop either way.
classPrefixstring"oklch-picker"Class prefix for every element, so styles can be overridden.
classNamestring-

* required.

Names in each framework

The table above uses the React names. The others follow their own idiom for the value binding; everything else is identical.

FrameworkValueChange
React / PreactvalueonChange
Vuev-model, or :value + @change
Sveltebind:value
SolidvalueonChange
No frameworkvalue attribute or propertychange event

Events on the custom element

The element emits three events, each carrying its payload indetail. It deliberately stops its inner inputs' events, so a listener above the host only ever sees these:

EventdetailFires
change{ colour: string }On every value change, canonical and gamut-clamped
gamutchange{ gamut: Gamut }When a switcher button is pressed
recentschange{ recents: string[] }On commit, not during a drag

Colour utilities

The maths is exported separately and documented on its own page.