Skip to content

ColorPicker

Color selection control with presets and multiple format support.

import { ColorPicker } from 'asterui'

Basic ColorPicker

Simple color picker with saturation/lightness panel and hue slider.

import { ColorPicker } from 'asterui'

function App() {
  return (
      <ColorPicker defaultValue="#6366f1" />
    )
}

export default App

With Text Display

Color picker showing the hex value below the picker.

#10B981
import { ColorPicker } from 'asterui'

function App() {
  return (
      <ColorPicker defaultValue="#10b981" showText />
    )
}

export default App

Custom Presets

Color picker with custom preset color swatches.

import { ColorPicker } from 'asterui'

function App() {
  const presets = [
    '#f43f5e', '#ec4899', '#d946ef', '#a855f7',
    '#8b5cf6', '#6366f1', '#3b82f6', '#0ea5e9',
    '#06b6d4', '#14b8a6', '#10b981', '#22c55e',
  ]
  
  return (
      <ColorPicker defaultValue="#6366f1" presets={presets} />
    )
}

export default App

Sizes

Color pickers in different sizes.

import { ColorPicker, Space } from 'asterui'

function App() {
  return (
      <Space direction="vertical" size="md">
        <ColorPicker size="xs" defaultValue="#f43f5e" mode="picker" />
        <ColorPicker size="sm" defaultValue="#6366f1" mode="picker" />
        <ColorPicker size="md" defaultValue="#10b981" mode="picker" />
        <ColorPicker size="lg" defaultValue="#a855f7" mode="picker" />
      </Space>
    )
}

export default App

Controlled

Controlled color picker with state management.

#6366F1
import { ColorPicker, Space } from 'asterui'
import { useState } from 'react'

function App() {
  const [color, setColor] = useState('#6366f1')
  
  return (
      <Space direction="vertical" size="sm">
        <ColorPicker value={color} onChange={setColor} showText />
        <div
          className="w-full h-16 rounded-lg"
          style={{ backgroundColor: color }}
        />
      </Space>
    )
}

export default App

Display Modes

Picker only, swatches only, or both.

Picker only
Swatches only
import { ColorPicker, Space, Typography } from 'asterui'

function App() {
  const { Text } = Typography
  
  return (
      <Space direction="vertical" size="lg">
        <Space direction="vertical" size="xs">
          <Text size="sm" muted>Picker only</Text>
          <ColorPicker mode="picker" defaultValue="#6366f1" />
        </Space>
        <Space direction="vertical" size="xs">
          <Text size="sm" muted>Swatches only</Text>
          <ColorPicker mode="swatches" defaultValue="#6366f1" />
        </Space>
      </Space>
    )
}

export default App
PropertyDescriptionTypeDefault
valueControlled color value (hex)string-
defaultValueInitial color value (uncontrolled)string'#000000'
onChangeCallback when color changes(color: string) => void-
modeDisplay mode'swatches' | 'picker' | 'both''both'
presetsPreset color swatchesstring[]Default palette
showTextShow hex value below pickerbooleanfalse
allowClearShow clear button to reset colorbooleanfalse
disabledDisable the pickerbooleanfalse
sizePicker size'xs' | 'sm' | 'md' | 'lg''md'
data-testidTest ID prefix for child elementsstring'colorpicker'
classNameAdditional CSS classesstring-
  • Saturation/lightness panel has role="slider" with aria-valuetext
  • Hue slider has role="slider" with aria-valuemin, aria-valuemax, and aria-valuenow
  • Color presets use role="listbox" and role="option" with aria-selected
  • Full keyboard navigation: Arrow keys adjust color values, Shift+Arrow for larger steps
  • Visible focus indicators on interactive elements
  • All interactive elements have descriptive aria-label attributes