PeakUI

ColorSwatchPicker

A list of color swatches to choose from

Usage

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

Anatomy

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

export default () => (
  <ColorSwatchPicker>
    <ColorSwatchPicker.Item color="#0485F7">
      <ColorSwatchPicker.Swatch />
      <ColorSwatchPicker.Indicator />
    </ColorSwatchPicker.Item>
  </ColorSwatchPicker>
);

Examples

Sizes

Shapes

Stack

Disabled

Customization

Tailwind CSS

<ColorSwatchPicker className="gap-4" aria-label="Palette">
  <ColorSwatchPicker.Item color="#0485F7">
    <ColorSwatchPicker.Swatch />
  </ColorSwatchPicker.Item>
</ColorSwatchPicker>

Global CSS

@layer components {
  .color-swatch-picker {
    @apply gap-3;
  }
}

Styling Reference

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

CSS Classes

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

Base Classes

  • .color-swatch-picker - Wrapping row of swatches
  • .color-swatch-picker__item - One selectable swatch
  • .color-swatch-picker__swatch - The coloured fill
  • .color-swatch-picker__indicator - Check shown when selected

Layout Classes

  • .color-swatch-picker--grid - Wrapping row (default)
  • .color-swatch-picker--stack - Single column

Size Classes

  • .color-swatch-picker--xs - Extra small (16px)
  • .color-swatch-picker--sm - Small (24px)
  • .color-swatch-picker--md - Medium (32px, default)
  • .color-swatch-picker--lg - Large (36px)
  • .color-swatch-picker--xl - Extra large (40px)

Shape Classes

  • .color-swatch-picker--circle - Circular items (default)
  • .color-swatch-picker--square - Rounded square items

Slots

  • [data-slot="color-swatch-picker"]
  • [data-slot="color-swatch-picker-item"]
  • [data-slot="color-swatch-picker-swatch"]
  • [data-slot="color-swatch-picker-indicator"]
  • [data-slot="color-swatch-picker-checkmark"]

CSS Variables

VariablePurpose
--color-swatch-currentThe item colour, set by ColorSwatchPicker.Item; colours the selected ring

Interactive States

  • Focus: :focus-visible or [data-focus-visible="true"] on .color-swatch-picker__item
  • Selected: [data-selected="true"] on .color-swatch-picker__item shows the ring and the check
  • Hover: :hover on .color-swatch-picker__swatch enlarges the swatch
  • Disabled: [data-disabled="true"] on .color-swatch-picker__item

API Reference

ColorSwatchPicker

PropTypeDefaultDescription
size"xs" | "sm" | "md" | "lg" | "xl""md"Size of the items
variant"circle" | "square""circle"Shape of the items
layout"grid" | "stack""grid"Row that wraps, or a single column
valuestring | Color-The selected colour (controlled)
defaultValuestring | Color-The initially selected colour (uncontrolled)
onChange(value: Color) => void-Called when the selection changes
classNamestring | ((values: ColorSwatchPickerRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria ColorSwatchPicker prop, including aria-label

ColorSwatchPicker.Item

PropTypeDefaultDescription
colorstring | Color-The colour of the item
isDisabledbooleanfalseDisables the item
classNamestring | ((values: ColorSwatchPickerItemRenderProps) => string)-Additional classes, or a function of the render props
styleCSSProperties | ((values: ColorSwatchPickerItemRenderProps) => CSSProperties)-Inline styles, merged over the item colour
...restEvery React Aria ColorSwatchPickerItem prop

ColorSwatchPicker.Swatch

PropTypeDefaultDescription
classNamestring | ((values: ColorSwatchRenderProps) => string)-Additional classes, or a function of the render props
...restEvery React Aria ColorSwatch prop

ColorSwatchPicker.Indicator

PropTypeDefaultDescription
childrenReactNode | ((values: ColorSwatchPickerItemRenderProps) => ReactNode)A check markReplaces the check; black on light colours, white on dark ones
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to "span"
classNamestring-Additional classes
...restEvery attribute of the rendered element

Render Props

children, className and style functions on ColorSwatchPicker.Item receive these values:

PropTypeDescription
colorColorThe colour of the item
isSelectedbooleanWhether the item is selected
isDisabledbooleanWhether the item is disabled
isFocusVisiblebooleanWhether the item has keyboard focus

On this page