Color Picker

ColorPicker

The ColorPicker component allows users to select colors using an interactive color picker interface with HEX/RGB input modes and optional alpha channel support.

The picker displays a color swatch that opens a popup with:

  • Saturation and brightness selector
  • Hue slider
  • Alpha slider (when enabled)
  • Color input fields (HEX or RGB modes)

Basic usage

import {ColorPicker} from '@gravity-ui/uikit';

function BasicColorPicker() {
  const [color, setColor] = React.useState('#ff0000');

  return <ColorPicker value={color} onUpdate={(newColor) => setColor(newColor)} />;
}

With alpha channel

The ColorPicker supports alpha transparency when withAlpha is enabled. This adds a transparency slider and switches to HEXA/RGBA color formats:

import {ColorPicker} from '@gravity-ui/uikit';

function ColorPickerWithAlpha() {
  const [color, setColor] = React.useState('#ff0000ff');

  return <ColorPicker value={color} onUpdate={(newColor) => setColor(newColor)} withAlpha={true} />;
}

Compact mode

For space-constrained layouts, you can render only the color swatch without displaying the color value text:

import {ColorPicker} from '@gravity-ui/uikit';

function CompactColorPicker() {
  return (
    <ColorPicker
      defaultValue="#00ff00"
      compact={true}
      onUpdate={(newColor) => console.log('New color:', newColor)}
    />
  );
}

Controlled and uncontrolled states

The ColorPicker supports both controlled and uncontrolled usage patterns:

// Uncontrolled
<ColorPicker
  defaultValue="#ffbe5c"
  onUpdate={(color) => console.log('Color changed:', color)}
/>

// Controlled
<ColorPicker
  value={color}
  onUpdate={setColor}
/>

You can also control the open state of the picker popup:

// Controlled open state
<ColorPicker value={color} open={isOpen} onOpenChange={setIsOpen} onUpdate={setColor} />

Properties

NameDescriptionTypeDefault
sizeThe ColorPicker size"s" "m" "l" "xl""m"
valueColor value for controlled state (HEX or HEXA string)string
defaultValueDefault color value for uncontrolled statestring"#000000"
onUpdateCallback when user updates the color. Receives a HEX(A) string.(value: string) => void
popupPlacementPlacement of the popupPopupPlacement['bottom-start', 'bottom-end', 'left-start', 'left-end', 'top-start', 'top-end']
openControlled state for popup open/closeboolean
defaultOpenDefault state for popup open/closebooleanfalse
onOpenChangeCallback for popup open/close state change(open: boolean) => void
withAlphaEnables alpha channel support for HEXA/RGBA mode and transparency sliderbooleanfalse
compactRenders only the picker button without displaying the color value textbooleanfalse

Color formats

The ColorPicker always returns color values in HEX format:

  • When withAlpha={false}: Returns 6-digit HEX (e.g., #ff0000)
  • When withAlpha={true}: Returns 8-digit HEXA (e.g., #ff0000ff)

Inside the picker popup, users can switch between HEX and RGB input modes to enter colors in their preferred format.