Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Color Swatch

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

color-swatch.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/color-swatch.json

It 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.

Its preview and code are at the top of the page.

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.