Color Swatch
Content & statusBrick 0.1.12

Color Swatch

Color Swatch provides a finished passive preview for one CSS color or a compact mix of colors. Its checkerboard reveals alpha without requiring application CSS.

Live example

Built from the published package

Interactive
Indigo
Coral at 55%
Campaign palette
Choose with confidence

Know when Color Swatch is the right part

Use it when

Use Color Swatch beside color names and values, inside a semantic preset control, or in palettes and design-token documentation. Use Color Picker when the user must edit or select the value.

Choose another path when

Do not use Color Swatch as a color input, selection owner, contrast validator, or the only carrier of meaning. Use the appropriate semantic control and keep visible text for color names and states.

Installation and imports

tsx
import { ColorSwatch } from "@flowstack-ui/brick/color-swatch";
import "@flowstack-ui/brick/styles.css";

For modular CSS, load the foundation once and the component stylesheet:

tsx
import "@flowstack-ui/brick/styles/core.css";
import "@flowstack-ui/brick/styles/color-swatch.css";

Quick start

tsx
<ColorSwatch.Root value="#5b5bd6" />

Visual recipes and states

Small, medium, and large sizes are 1rem, 1.5rem, and 2rem. The checkerboard stays visible beneath alpha colors. Mix divides one swatch evenly into conic segments. Color Swatch owns no interactive states.

Examples

tsx
<ColorSwatch.Root value="rgb(91 91 214 / 60%)" />
<ColorSwatch.Mix values={["#5b5bd6", "#e5484d", "#30a46c"]} label="Brand palette" />
Public contract

API

Start with the public parts and root options below. Components with multiple parts separate each area into its own named subsection.

PartPropValuesDefault
RootvalueAny valid CSS colorrequired
MixvaluesTwo or more valid CSS colorsrequired
bothsizesm, md, lgmd
bothlabellocalized string-
sizeColorSwatchSizesm, md, lgmd

Public exports are ColorSwatch, ColorSwatchRoot, ColorSwatchMix, ColorSwatchRootProps, ColorSwatchMixProps, and ColorSwatchSize.

Shared responsibility

Accessibility

Without label, a swatch is aria-hidden because adjacent text or its owning control must carry meaning. With label, it becomes role="img" with that accessible name. Color alone must never communicate selection, validation, or action.

Responsive behavior

The swatch is content-sized, uses logical dimensions, and does not change across breakpoints. The owning Stack, Grid, control, palette, or Block owns responsive arrangement.

Stable visual contract

Styling and tokens

Customization

Prefer size before overriding the size variable. Set semantic color strings through value or values; do not replace the checkerboard or use custom CSS merely to create a standard swatch.

Tokens and CSS hooks

Stable hooks are .brick-color-swatch, .brick-color-swatch--mix, data-slot, and data-size. Public variables are --brick-color-swatch-size, --brick-color-swatch-value, --brick-color-swatch-border-color, and --brick-color-swatch-radius.

Advanced reference

Open these details only when you need to inspect DOM ownership, native forwarding, or lower-level composition.

Maintainer resources

Tests, playground evidence, source notes, and release history remain available without crowding the plug-and-play guide.