PeakUI

ColorArea

Two-channel color selection on a gradient area

Usage

import {ColorArea} from "@peakui/react";

Anatomy

import {ColorArea} from "@peakui/react";

export default () => (
  <ColorArea colorSpace="hsb" xChannel="saturation" yChannel="brightness">
    <ColorArea.Thumb />
  </ColorArea>
);

Examples

With Dots

RGB Channels

Disabled

Customization

Tailwind CSS

<ColorArea className="max-w-full rounded-lg" xChannel="saturation" yChannel="brightness">
  <ColorArea.Thumb />
</ColorArea>

Global CSS

@layer components {
  .color-area {
    @apply max-w-64;
  }

  .color-area__thumb {
    @apply size-5;
  }
}

Styling Reference

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

CSS Classes

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

Base Classes

  • .color-area - Gradient area, square, up to 224px wide
  • .color-area__thumb - Draggable thumb with a white border

Modifier Classes

  • .color-area--show-dots - Dot grid over the gradient

Slots

  • [data-slot="color-area"]
  • [data-slot="color-area-thumb"]

CSS Variables

VariablePurpose
--color-area-backgroundThe gradient, set by the component from the current value
--color-area-thumb-colorThe thumb fill, set by the component from the current value
--color-area-ringThe inset ring on the area and the thumb
--color-area-thumb-borderThe thumb border colour

Interactive States

  • Focus: :focus-visible or [data-focus-visible="true"] on .color-area__thumb
  • Dragging: [data-dragging="true"] on .color-area__thumb enlarges the thumb
  • Disabled: [data-disabled="true"] on .color-area and .color-area__thumb

API Reference

ColorArea

PropTypeDefaultDescription
showDotsbooleanfalseOverlays a dot grid on the gradient
xChannelColorChannel-The channel on the horizontal axis
yChannelColorChannel-The channel on the vertical axis
colorSpace"rgb" | "hsl" | "hsb"-The color space of the area
valuestring | Color-The current color (controlled)
defaultValuestring | Color-The initial color (uncontrolled)
onChange(value: Color) => void-Called as the thumb moves
onChangeEnd(value: Color) => void-Called when a drag or key press ends
isDisabledbooleanfalseDisables the area
classNamestring | ((values: ColorAreaRenderProps) => string)-Additional classes, or a function of the render props
styleCSSProperties | ((values: ColorAreaRenderProps) => CSSProperties)-Inline styles, or a function of the render props
...restEvery React Aria ColorArea prop, including aria-label

ColorArea.Thumb

PropTypeDefaultDescription
classNamestring | ((values: ColorThumbRenderProps) => string)-Additional classes, or a function of the render props
styleCSSProperties | ((values: ColorThumbRenderProps) => CSSProperties)-Inline styles, or a function of the render props
...restEvery React Aria ColorThumb prop

Render Props

className and style functions on ColorArea.Thumb receive these values:

PropTypeDescription
isDraggingbooleanWhether the thumb is being dragged
isDisabledbooleanWhether the thumb is disabled
isFocusVisiblebooleanWhether the thumb has keyboard focus
defaultStyleCSSPropertiesThe position and colour RAC computes

On this page