Color Swatch
Overview
A read-only color preview block with support for transparent and OKLCH values. SColorSwatch combines the Aria ColorSwatchRoot/ColorSwatchChecker/ColorSwatchFill primitives with the colorSwatchVariants style recipe (3 slots, 6 sizes × 2 shapes).
Use a color swatch to display a color value (with an optional transparency checker) inside pickers, tables, or labels.
Usage
Features
- 🧩 Aria/styled split —
ColorSwatchCompactcomposes checker + fill;SColorSwatchonly injects styles and forwards props/slots - 🖼️ Transparency checker — renders a checkerboard behind translucent/alpha colors
- 🎨 OKLCH + transparent support — accepts any
ColorValue, includingoklchand alpha colors - 🏷️ Accessible label —
role="img"witharia-labelfromlabel; empty colors markeddata-no-color - 🔵 Shape —
shape="square"(default) or"circle" - 📐 6 sizes — xs–2xl
size; per-slotuioverrides - 🔌 Slot scope — the default slot exposes
{ color, alpha }(RGB string + 0–1 alpha)
Component family
SColorSwatch(styled) — the entry wrapper;colorSwatchVariantsrecipe with dynamic slot forwardingColorSwatchRoot(Aria) — the accessible preview root (role="img",color/label)ColorSwatchChecker(Aria) — the transparency checkerboardColorSwatchFill(Aria) — the solid color fillColorSwatchCompact(Aria) — the aggregated composite; composes checker + fill
Demo
Basic
API
Aria Layer
5ColorSwatch
Props
| Prop | Type | Default | Description |
|---|---|---|---|
class | ClassValue | — | Additional class names applied to the root element. |
size | ThemeSize | — | Visual size of the component. |
ui | Partial<ColorSwatchUi> | — | Per-slot class overrides for the component. |
shape | ColorSwatchShape | — | Shape of the component. |
checkerProps | ColorSwatchCheckerProps | — | Props for the checker element of the ColorSwatch component. |
fillProps | ColorSwatchFillProps | — | Props for the fill element of the ColorSwatch component. |
color | import("@soybeanjs/colord").AnyColor | — | Theme color of the component. |
label | string | — | Label text rendered by the component. |
asChild | boolean | — | Change the default rendered element for the one passed as a child, merging their props and behavior. |
as | AsTag | Component | 'div' | The element or component this component should render as. Can be overwrite by `asChild` |
Slots
| Slot Name | Parameters | Description |
|---|---|---|
default | ColorSwatchSlotProps | — |
ColorSwatchChecker
ColorSwatchCompact
Props
| Prop | Type | Default | Description |
|---|---|---|---|
checkerProps | ColorSwatchCheckerProps | — | Props for the checker element of the ColorSwatch component. |
fillProps | ColorSwatchFillProps | — | Props for the fill element of the ColorSwatch component. |
color | import("@soybeanjs/colord").AnyColor | — | Theme color of the component. |
label | string | — | Label text rendered by the component. |
asChild | boolean | — | Change the default rendered element for the one passed as a child, merging their props and behavior. |
as | AsTag | Component | 'div' | The element or component this component should render as. Can be overwrite by `asChild` |
Slots
| Slot Name | Parameters | Description |
|---|---|---|
default | ColorSwatchSlotProps | — |
ColorSwatchFill
ColorSwatchRoot
Props
| Prop | Type | Default | Description |
|---|---|---|---|
color | import("@soybeanjs/colord").AnyColor | — | Theme color of the component. |
label | string | — | Label text rendered by the component. |
asChild | boolean | — | Change the default rendered element for the one passed as a child, merging their props and behavior. |
as | AsTag | Component | 'div' | The element or component this component should render as. Can be overwrite by `asChild` |
Slots
| Slot Name | Parameters | Description |
|---|---|---|
default | ColorSwatchSlotProps | — |
Notes
Architecture and benchmark differences
ColorSwatchCompact owns the checker/fill composition while every primitive stays style-free and only the UI wrapper injects the colorSwatchVariants classes. This mirrors radix-ui-color/shadcn-ui headless split. Ant Design, Element Plus, Mantine and Naive UI render a plain colored <span> for swatches; VeanUI exposes an accessible role="img" preview with a transparency checker, shape/size control and a slot scope exposing the parsed color/alpha.
| Capability | VeanUI | shadcn/ui | Ant Design | Element Plus | Mantine | Naive UI |
|---|---|---|---|---|---|---|
| Aria/styled split | ✅ | ✅ | — | — | — | — |
| Transparency checker | ✅ | ✅ | — | — | — | — |
| OKLCH / alpha support | ✅ | ✅ | ✅ | ✅ | ✅ | — |
| Accessible role/img | ✅ | ✅ | — | — | — | — |
| Shape (square/circle) | ✅ | ✅ | ✅ | ✅ | ✅ | — |
| Sizes (6) | ✅ | — | — | — | — | — |
— = unsupported or a different interaction model.
Cautions
- Provide
labelfor an accessible name; empty colors are markeddata-no-color(rendered muted). coloraccepts a color string orColorValue(includingoklch/alpha); the fill uses the resolved CSS color.- The default slot receives
{ color, alpha }(RGB string + 0–1 alpha) for custom overlays/labels. shapeswitches between square (rounded-md) and circle (rounded-full).- This is a read-only preview; use
color-picker/color-swatch-pickerfor selection.
Roadmap
N/A — color-swatch is feature-complete for the current parity set.
FAQ
How do I show a color swatch?
Pass color and an optional label:
<SColorSwatch color="#7c3aed" label="Accent" />How do I make it circular?
Set shape="circle":
<SColorSwatch color="#06b6d4" shape="circle" />How do I access the parsed color/alpha?
Use the default slot scope:
<SColorSwatch :color="color">
<template #default="{ alpha }">{{ (alpha * 100).toFixed(0) }}%</template>
</SColorSwatch>