Components

Color Swatch

A primitive component for displaying a single color swatch with an optional hover label

Overview

ColorSwatch is a primitive building block used to visually represent a single color value. It is designed to be highly composable and works seamlessly with `ColorSwatchLabel` to display a tooltip on hover.

While it is primarily used inside `ColorPalette`, you can use it independently to build custom color grids, asymmetric compositions, or any other visual color representation.

Installation

>_
npx shadcn@latest add @tokenui/color-swatch

Usage

Sky 500
Blue 500
Indigo 500

Composition

Compose `ColorSwatch` inside a CSS Grid for advanced layouts.

White Mink
Matt Black
Sequoia Dusk
Roycroft Bottle Green
Gentle Doe
Champagne Pink

#MindfulPalettes no 056 by @AlexCristache

Since ColorContrast hooks directly into the swatch's context, you can easily display calculated accessibility scores.

For more advanced examples, manual override options (like APCA), and API details, check out the Color Contrast documentation.

Red
WCAG:4.2:1
Teal
WCAG:1.5:1

Corners and Center Placement

You can place text, badges, or numbers freely across the swatch using the `ColorSwatchPart` primitive. It allows setting content in the corners and the center.

Primary
1
#6200EE
Secondary
2
#03DAC6
Surface
3
#FFFFFF

API Reference

ColorSwatch

A single color swatch element. By default, it flexes to fill its container and expands slightly on hover.

Prop

Type

ColorSwatchPart

Used within ColorSwatch to position text or visual elements around the swatch freely.

Prop

Type

ColorSwatchLabel

Label displayed hovering inside a ColorSwatch element on pointer hover.

Prop

Type