PeakUI

ColorSwatch

A visual preview of a color value

Usage

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

Examples

Sizes

Shapes

Transparency

Render Function

render replaces the rendered element; the swatch's props and custom property flow into it.

Accessibility

Use colorName to provide a custom accessible name for the color, and aria-label to add context about how the color is used.

Customization

Tailwind CSS

Global CSS

@layer components {
  .color-swatch {
    @apply border-2 border-white;
  }
}

Styling Reference

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

CSS Classes

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

Base Classes

  • .color-swatch - Base swatch styles with checkered background for transparency

Shape Classes

  • .color-swatch--circle - Circular shape (default)
  • .color-swatch--square - Square shape with rounded corners

Size Classes

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

Slots

  • [data-slot="color-swatch"]

CSS Variables

VariablePurpose
--color-swatch-currentThe swatch's color, set from the color prop

API Reference

ColorSwatch

PropTypeDefaultDescription
colorstring | Color-The color value to display (hex, rgb, hsl, etc.)
colorNamestring-Accessible name for the color (overrides auto-generated description)
shape"circle" | "square""circle"Shape of the swatch
size"xs" | "sm" | "md" | "lg" | "xl""md"Size of the swatch
classNamestring | ((values: ColorSwatchRenderProps) => string)-Additional classes, or a function of the render props
styleCSSProperties | ((values: ColorSwatchRenderProps) => CSSProperties)-Inline styles, or a function of the render props
renderDOMRenderFunction<keyof React.JSX.IntrinsicElements, ColorSwatchRenderProps>-Replaces the rendered element with a custom render function
aria-labelstring-Context about how the color is used; appended to the color's own description
...restEvery <div> attribute is accepted, including aria-labelledby and id

Render Props

className and style functions receive these values:

PropTypeDescription
colorColorThe parsed color value, from the color prop

The color object provides methods like color.toString("css"), color.toString("hex") and color.getChannelValue("alpha").

On this page