Components
Color picker

Color Picker

The Color Picker is a versatile and feature-rich color selection tool for your applications. It provides support for different color spaces, user interaction, and accessibility.

Saved Colors

Usage

To get started, import the necessary components from the package:

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaGradient,
  ColorPickerAreaThumb,
  ColorPickerChannelInput,
  ColorPickerChannelSliderBackground,
  ColorPickerChannelSliderThumb,
  ColorPickerChannelSliderTrack,
  ColorPickerContent,
  ColorPickerEyeDropperTrigger,
  ColorPickerSwatch,
  ColorPickerSwatchBackground,
  ColorPickerSwatchGroup,
} from '@ark-ui/react'

Here is an example of how to use the Color Picker component:

import { useState } from 'react'
import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaGradient,
  ColorPickerAreaThumb,
  ColorPickerChannelInput,
  ColorPickerChannelSliderBackground,
  ColorPickerChannelSliderThumb,
  ColorPickerChannelSliderTrack,
  ColorPickerContent,
  ColorPickerEyeDropperTrigger,
  ColorPickerSwatch,
  ColorPickerSwatchBackground,
  ColorPickerSwatchGroup,
} from '@ark-ui/react'

const Basic = () => (
  <ColorPicker defaultValue="hsl(10, 81%, 59%)">
    {(api) => {
      const [hue, saturation, lightness] = api.channels
      return (
        <ColorPickerContent>
          <output>
            <ColorPickerSwatch value={api.value} readOnly />
          </output>
          <ColorPickerArea xChannel={saturation} yChannel={lightness}>
            <ColorPickerAreaGradient />
            <ColorPickerAreaThumb />
          </ColorPickerArea>

          <ColorPickerChannelSliderTrack channel={hue}>
            <ColorPickerChannelSliderBackground />
            <ColorPickerChannelSliderThumb />
          </ColorPickerChannelSliderTrack>

          <ColorPickerChannelSliderTrack channel="alpha">
            <ColorPickerChannelSliderBackground />
            <ColorPickerChannelSliderThumb />
          </ColorPickerChannelSliderTrack>

          <ColorPickerChannelInput channel={hue} />
          <ColorPickerChannelInput channel={saturation} />
          <ColorPickerChannelInput channel={lightness} />
          <ColorPickerChannelInput channel="alpha" />

          <ColorPickerSwatchGroup>
            <ColorPickerSwatch value="#123123">
              <ColorPickerSwatchBackground />
            </ColorPickerSwatch>
            <ColorPickerSwatch value="#ff1321">
              <ColorPickerSwatchBackground />
            </ColorPickerSwatch>
          </ColorPickerSwatchGroup>

          <ColorPickerEyeDropperTrigger>Pick color</ColorPickerEyeDropperTrigger>
        </ColorPickerContent>
      )
    }}
  </ColorPicker>
)

Controlled Color Picker

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

import { useState } from 'react'
import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaGradient,
  ColorPickerAreaThumb,
  ColorPickerChannelInput,
  ColorPickerChannelSliderBackground,
  ColorPickerChannelSliderThumb,
  ColorPickerChannelSliderTrack,
  ColorPickerContent,
  ColorPickerEyeDropperTrigger,
  ColorPickerSwatch,
  ColorPickerSwatchBackground,
  ColorPickerSwatchGroup,
} from '@ark-ui/react'

const Controlled = () => {
  const [color, setColor] = useState('hsl(10, 81%, 59%)')

  return (
    <ColorPicker value={color} onValueChange={(details) => setColor(details.value)}>
      <ColorPickerContent>{/* ... */}</ColorPickerContent>
    </ColorPicker>
  )
}

Conclusion

The Color Picker component offers a flexible and powerful solution for integrating color selection into your applications. With its comprehensive set of features and customizability, it can accommodate a wide range of use cases and designs.

Previous

Checkbox

Next

Combobox