Color Picker

A component that allows users to select a color from a color picker.

Preview Component

Please note, the API of this component is currently in a preview phase and is subject to change.

Anatomy

To set up the color picker correctly, you’ll need to understand its anatomy and how we name its parts.

Each part includes a data-part attribute to help identify them in the DOM.

Examples

Learn how to use the ColorPicker component in your project. Let’s take a look at the most basic example

import { ColorPicker } from '@ark-ui/react'

const Basic = () => {
  return (
    <ColorPicker.Root defaultValue="#eb5e41">
      {(api) => (
        <>
          <ColorPicker.Label>Color</ColorPicker.Label>
          <ColorPicker.Control>
            <ColorPicker.ChannelInput channel="hex" />
            <ColorPicker.ChannelInput channel="alpha" />
            <ColorPicker.ValueText />
            <ColorPicker.Trigger>
              <ColorPicker.TransparencyGrid />
              <ColorPicker.Swatch value={api.value} />
            </ColorPicker.Trigger>
          </ColorPicker.Control>
          <ColorPicker.Positioner>
            <ColorPicker.Content>
              <ColorPicker.FormatTrigger>Toggle ColorFormat</ColorPicker.FormatTrigger>
              <ColorPicker.FormatSelect />
              <ColorPicker.Area>
                <ColorPicker.AreaBackground />
                <ColorPicker.AreaThumb />
              </ColorPicker.Area>
              <ColorPicker.ChannelSlider channel="hue">
                <ColorPicker.ChannelSliderTrack />
                <ColorPicker.ChannelSliderThumb />
              </ColorPicker.ChannelSlider>
              <ColorPicker.ChannelSlider channel="alpha">
                <ColorPicker.TransparencyGrid />
                <ColorPicker.ChannelSliderTrack />
                <ColorPicker.ChannelSliderThumb />
              </ColorPicker.ChannelSlider>
              <ColorPicker.SwatchGroup>
                <ColorPicker.SwatchTrigger value="red">
                  <ColorPicker.Swatch value="red">
                    <ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
                  </ColorPicker.Swatch>
                </ColorPicker.SwatchTrigger>
                <ColorPicker.SwatchTrigger value="blue">
                  <ColorPicker.Swatch value="blue">
                    <ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
                  </ColorPicker.Swatch>
                </ColorPicker.SwatchTrigger>
                <ColorPicker.SwatchTrigger value="green">
                  <ColorPicker.Swatch value="green">
                    <ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
                  </ColorPicker.Swatch>
                </ColorPicker.SwatchTrigger>
              </ColorPicker.SwatchGroup>
              <ColorPicker.View format="rgba">
                <ColorPicker.ChannelInput channel="hex" />
                <ColorPicker.ChannelInput channel="alpha" />
              </ColorPicker.View>
              <ColorPicker.View format="hsla">
                <ColorPicker.ChannelInput channel="hue" />
                <ColorPicker.ChannelInput channel="saturation" />
                <ColorPicker.ChannelInput channel="lightness" />
              </ColorPicker.View>
              <ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
            </ColorPicker.Content>
          </ColorPicker.Positioner>
        </>
      )}
    </ColorPicker.Root>
  )
}

Controlled Color Picker

To create a controlled Color Picker component, manage the state of the current color using the value prop and update it when the onValueChange or onValueChangeEnd event handler is called:

import { ColorPicker } from '@ark-ui/react'
import { useState } from 'react'

const Controlled = () => {
  const [currentValue, setCurrentValue] = useState('hsl(20, 100%, 50%)')

  return (
    <ColorPicker.Root
      format="hsla"
      value={currentValue}
      onValueChange={(details) => setCurrentValue(details.valueAsString)}
      onValueChangeEnd={(details) => console.log(details.valueAsString)}
    >
      {(api) => (
        <>
          <ColorPicker.Label>Color</ColorPicker.Label>
          <ColorPicker.Control>
            <ColorPicker.ChannelInput channel="hex" />
            <ColorPicker.ChannelInput channel="alpha" />
            <ColorPicker.ValueText />
            <ColorPicker.Trigger>
              <ColorPicker.TransparencyGrid />
              <ColorPicker.Swatch value={api.value} />
            </ColorPicker.Trigger>
          </ColorPicker.Control>
          <ColorPicker.Positioner>
            <ColorPicker.Content>
              <ColorPicker.Area>
                <ColorPicker.AreaBackground />
                <ColorPicker.AreaThumb />
              </ColorPicker.Area>
              <ColorPicker.ChannelSlider channel="hue">
                <ColorPicker.ChannelSliderTrack />
                <ColorPicker.ChannelSliderThumb />
              </ColorPicker.ChannelSlider>
              <ColorPicker.ChannelSlider channel="alpha">
                <ColorPicker.TransparencyGrid />
                <ColorPicker.ChannelSliderTrack />
                <ColorPicker.ChannelSliderThumb />
              </ColorPicker.ChannelSlider>
              <ColorPicker.SwatchGroup>
                <ColorPicker.SwatchTrigger value="red">
                  <ColorPicker.Swatch value="red">
                    <ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
                  </ColorPicker.Swatch>
                </ColorPicker.SwatchTrigger>
                <ColorPicker.SwatchTrigger value="blue">
                  <ColorPicker.Swatch value="blue">
                    <ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
                  </ColorPicker.Swatch>
                </ColorPicker.SwatchTrigger>
                <ColorPicker.SwatchTrigger value="green">
                  <ColorPicker.Swatch value="green">
                    <ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
                  </ColorPicker.Swatch>
                </ColorPicker.SwatchTrigger>
              </ColorPicker.SwatchGroup>
              <ColorPicker.View format="rgba">
                <ColorPicker.ChannelInput channel="hex" />
                <ColorPicker.ChannelInput channel="alpha" />
              </ColorPicker.View>
              <ColorPicker.View format="hsla">
                <ColorPicker.ChannelInput channel="hue" />
                <ColorPicker.ChannelInput channel="saturation" />
                <ColorPicker.ChannelInput channel="lightness" />
              </ColorPicker.View>
              <ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
            </ColorPicker.Content>
          </ColorPicker.Positioner>
        </>
      )}
    </ColorPicker.Root>
  )
}

API Reference

Root

PropTypeDefault
asChild
boolean
closeOnSelect
boolean
defaultValue
string
dir
'ltr' | 'rtl'
disabled
boolean
format
ColorFormat
getRootNode
() => Node | ShadowRoot | Document
id
string
ids
Partial<{ root: string control: string trigger: string label: string input: string content: string area: string areaGradient: string areaThumb: string channelInput(id: string): string channelSliderTrack(id: ColorChannel): string channelSliderThumb(id: ColorChannel): string }>
initialFocusEl
HTMLElement | (() => MaybeElement)
lazyMount
booleanfalse
name
string
onExitComplete
() => void
onFocusOutside
(event: FocusOutsideEvent) => void
onFormatChange
(details: FormatChangeDetails) => void
onInteractOutside
(event: InteractOutsideEvent) => void
onOpenChange
(details: OpenChangeDetails) => void
onPointerDownOutside
(event: PointerDownOutsideEvent) => void
onValueChange
(details: ValueChangeDetails) => void
onValueChangeEnd
(details: ValueChangeDetails) => void
open
boolean
positioning
PositioningOptions
present
boolean
readOnly
boolean
unmountOnExit
booleanfalse
value
string

Area

PropTypeDefault
asChild
boolean
xChannel
ColorChannel
yChannel
ColorChannel

View

PropTypeDefault
format
ColorFormat
asChild
boolean

Label

PropTypeDefault
asChild
boolean

Swatch

PropTypeDefault
value
string | Color
asChild
boolean
respectAlpha
boolean

Content

PropTypeDefault
asChild
boolean

Control

PropTypeDefault
asChild
boolean

Trigger

PropTypeDefault
asChild
boolean

AreaThumb

PropTypeDefault
asChild
boolean

ValueText

PropTypeDefault
asChild
boolean

Positioner

PropTypeDefault
asChild
boolean

SwatchGroup

PropTypeDefault
asChild
boolean

ChannelInput

PropTypeDefault
channel
ExtendedColorChannel
asChild
boolean
orientation
Orientation

FormatSelect

PropTypeDefault
asChild
boolean

ChannelSlider

PropTypeDefault
channel
ColorChannel
asChild
boolean
orientation
Orientation

FormatTrigger

PropTypeDefault
asChild
boolean

SwatchTrigger

PropTypeDefault
value
string | Color
asChild
boolean
disabled
boolean

AreaBackground

PropTypeDefault
asChild
boolean

SwatchIndicator

PropTypeDefault
asChild
boolean

TransparencyGrid

PropTypeDefault
asChild
boolean
size
string

EyeDropperTrigger

PropTypeDefault
asChild
boolean

ChannelSliderThumb

PropTypeDefault
asChild
boolean

ChannelSliderTrack

PropTypeDefault
asChild
boolean