ChromaKit logo

ChromaKit

DemoDocsGitHub

ColorPicker

The batteries-included component: color area, hue and alpha sliders, format-switchable inputs, presets, history, and copy — all configurable through props.

Controlled vs. uncontrolled

Pass value + onChange for a controlled picker, or defaultValue alone to let ChromaKit manage state. onChange fires continuously; onChangeComplete fires when the interaction settles.

Presets

Props

Every ColorValue passed to onChange contains all formats pre-converted, so you never convert manually.

PropTypeDefaultDescription
valuestringControlled color in any supported format (hex, rgb, oklch…).
defaultValuestring'#6366F1'Initial color for uncontrolled mode.
onChange(color: ColorValue) => voidFires on every change (drag, typing) with all formats.
onChangeComplete(color: ColorValue) => voidFires when a change settles (pointer up).
formatsColorFormat[]all 11 formatsWhich format tabs the inputs expose.
showAlphabooleantrueShow the alpha (transparency) slider.
showInputsbooleantrueShow the numeric / text input fields.
showPreviewbooleantrueShow the color preview swatch.
showPresetsbooleantrueShow the preset color swatches section.
showCopyButtonbooleantrueShow the copy-to-clipboard button.
presetsstring[]built-inCustom preset colors.
presetGroupsPresetGroup[] | Record<string, string[]>built-inNamed preset groups selectable from a dropdown.
enableHistorybooleantrueRemember recent colors in localStorage.
historySizenumber10Maximum number of colors kept in history.
widthnumberPicker width in pixels. Auto when omitted.
heightnumberColor-area height in pixels. Stretches to match the controls when omitted.
classNamestringExtra classes on the root — the theming hook (see Theming).

The ColorValue object

onChange and onChangeComplete both receive this fully-converted object.

interface ColorValue {
  hex: string;    // "#ff6b6b"
  hex8: string;   // "#ff6b6bff"
  rgb: RGB;       // { r, g, b }
  rgba: RGBA;     // { r, g, b, a }
  hsl: HSL;       // { h, s, l }
  hsla: HSLA;     // { h, s, l, a }
  hsv: HSV;       // { h, s, v }
  hsva: HSVA;     // { h, s, v, a }
  oklab: OKLAB;   // { L, a, b }
  oklch: OKLCH;   // { L, C, h }
  oklcha: OKLCHA; // { L, C, h, a }
}

Custom presets

Supply your own swatches with the presets array, or named groups via presetGroups.

Presets

Format control

Restrict the input tabs to the formats your app cares about.

Presets