PeakUI

ColorPicker

A composable color picker container with popover

Usage

import {ColorPicker, ColorSwatch, Label} from "@peakui/react";

Anatomy

The ColorPicker is a container: it owns the value and the popover, and the editors composed inside it (ColorArea, ColorSlider, ColorSwatchPicker, ColorField) read and write that value through the picker's state.

import {ColorPicker, ColorSlider, ColorSwatch, Label} from "@peakui/react";

export default () => (
  <ColorPicker defaultValue="#0485F7">
    <ColorPicker.Trigger>
      <ColorSwatch />
      <Label>Pick a color</Label>
    </ColorPicker.Trigger>
    <ColorPicker.Popover>
      <ColorSlider channel="hue" colorSpace="hsb">
        <Label>Hue</Label>
        <ColorSlider.Output />
        <ColorSlider.Track>
          <ColorSlider.Thumb />
        </ColorSlider.Track>
      </ColorSlider>
    </ColorPicker.Popover>
  </ColorPicker>
);

Examples

Controlled

With Swatches

Customization

Tailwind CSS

Global CSS

@layer components {
  .color-picker {
    @apply inline-flex;
  }

  .color-picker__trigger {
    @apply inline-flex items-center gap-4 rounded-lg;
  }

  .color-picker__popover {
    @apply p-4 rounded-xl;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ColorPicker component uses these CSS classes (view source styles):

Base & Element Classes

  • .color-picker - Base container
  • .color-picker__trigger - Trigger button
  • .color-picker__popover - Popover container

Slots

  • [data-slot="color-picker"]
  • [data-slot="color-picker-trigger"]
  • [data-slot="color-picker-popover"]

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Focus: :focus-visible or [data-focus-visible="true"] on trigger
  • Disabled: :disabled, [data-disabled="true"] or [aria-disabled="true"] on trigger

API Reference

ColorPicker

Inherits from React Aria ColorPicker.

PropTypeDefaultDescription
valuestring | Color-The current color value (controlled)
defaultValuestring | Color-The default color value (uncontrolled)
onChange(color: Color) => void-Handler called when the color changes
childrenReactNode-Content of the color picker (Trigger, Popover)
classNamestring-Additional class name for the wrapper element
...restEvery React Aria ColorPicker attribute is accepted, including isDisabled and aria-label

ColorPicker.Trigger

PropTypeDefaultDescription
classNamestring-Additional classes
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-Trigger content, or a function of the render props
...restEvery React Aria Button attribute is accepted

ColorPicker.Popover

PropTypeDefaultDescription
placement"bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right" | "right top" | "right bottom" | "end" | "end top" | "end bottom""bottom left"Placement of the popover relative to the trigger
classNamestring-Additional classes
childrenReactNode-Popover content
...restEvery React Aria Popover attribute is accepted

Color

Represents a color value. See React Aria Color for the full API.

MethodDescription
toString(format)Converts the color to a string in the given format (hex, rgb, hsl, hsb, css)
toFormat(format)Converts the color to the given format and returns a new Color
getChannelValue(channel)Returns the numeric value for a given channel
withChannelValue(channel, value)Sets the numeric value for a channel and returns a new Color

parseColor

import {parseColor} from "react-aria-components";

// Parse from string
const color = parseColor("#ff0000");
const hslColor = parseColor("hsl(0, 100%, 50%)");

On this page