UIComponentsReact
A small square that shows one color, named by it.
Built on the headless Color Swatch.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/color-swatch.jsonIt also adds utils. The app needs its setup first: Installation.
Usage
Pass color, any CSS color string, or null for none. The swatch is an image named by the color (for example "Dark blue"), draws a checkerboard under a transparent color and has a dashed border while empty. Inside a Color Picker it shows the picker's color unless color is given; the name comes from the headless Color Swatch.
import { ColorSwatch } from '@/components/ui/color-swatch'Examples
Default
Four swatches: red, blue, a half transparent blue and none.
shadcn/ui has no Color Swatch, so this item takes Base UI's component ID as its slug. The square is 24px; change its size with className.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Color Swatch's API reference.