ColorSwatch

data-display

Color palette swatch grid with selection state, optional labels and hex values, role=listbox pattern, and token-driven styling. Supports selected ring, scale hover, and checker pattern for alpha colors.

Import

typescript
import { ColorSwatch } from "packages/ui/src";

Props

ColorSwatchProps

PropTypeRequired
colorsColorSwatchColor[]Yes
selectedstringNo
onSelect(color) => void, showLabel?: booleanNo

Examples

Color Swatch

Color palette swatches with selection, labels, and hex values.

Interactive Selection

Primary#a78bfa
Hover#8b5cf6
Active#7c3aed
Muted#6366f1
Success#10b981
Warning#f59e0b
Error#ef4444
Neutral#6b7280

Without Labels

Brand Colors

Dark#0a0a14
Card#13131f
Elevated#1e1e2e
Text#e2e8f0
Muted#a1a1aa

Metadata

Component Metadata
Familydata-display
FrameworksNext.js, Astro/EmDash
DescriptionColor palette swatch grid with selection state, optional labels and hex values, role=listbox pattern, and token-driven styling. Supports selected ring, scale hover, and checker pattern for alpha colors.
PropsColorSwatchProps (colors: ColorSwatchColor[], selected?: string, onSelect?: (color) => void, showLabel?: boolean)
Statesno-selection, color-selected, with-labels, without-labels
A11y
  • Container has role=listbox with aria-label
  • Each swatch has role=option with aria-selected
  • Swatch buttons have aria-label with color name/value
Responsive
  • Flex-wrap by default
  • Gap-controlled spacing
Motion
  • Scale transform on hover
  • Box-shadow transition on select
Token Dependencies
  • components.colorSwatch.size
  • components.colorSwatch.borderRadius
  • components.colorSwatch.border
  • components.colorSwatch.selectedRing
  • components.colorSwatch.labelColor
  • components.colorSwatch.labelFontSize
  • components.colorSwatch.hexColor
  • components.colorSwatch.hexFontSize
  • components.colorSwatch.gap
  • components.colorSwatch.tooltipBackground
  • components.colorSwatch.tooltipColor
  • components.colorSwatch.tooltipFontSize
  • components.colorSwatch.checkerBackground
Content Slotscolors (ColorSwatchColor[]), labels (string[])
CMS Bindings
  • Color values from CMS token set
  • Color labels from CMS config
Test Cases
  • Renders swatch buttons
  • Has role=listbox
  • Swatch has role=option
  • Selected swatch has selected class
  • Clicking calls onSelect
  • Shows labels when showLabel is true
  • Shows hex values
  • Passes className through