Color Swatch

Shows a sample of a color.

Usage

Code
import { ColorSwatch } from '@leverui/components';
Code
<ColorSwatch />

Examples

Sizes

Use the size prop to change the size of the color swatch.

Alpha

Here's an example of how to create a color swatch with an alpha channel.

With Badge

Here's an example of how to compose the ColorSwatch with a Badge.

#bada55

Mixed Colors

Use the ColorSwatchMix to create a color swatch that contains multiple colors, but retains the size of a single color swatch.

Palette

Here's an example of composing multiple swatches to create a palette.

Props

ColorSwatch

PropDefaultTypeDescription
value—stringCSS color to show. Also set as data-value.
sizemd'2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'inherit' | 'full'Swatch size. Responsive.
shaperounded'square' | 'circle' | 'rounded'Swatch shape. Responsive.
asspanNative tagHTML tag to render.
asChild—Solid render functionRender your own element with the swatch's props.
unstyled—booleanTurn off the default swatch styles.

ColorSwatchMix

Takes the same size, shape, as, asChild, and unstyled props, plus items: up to four CSS colors shown in one swatch. More than four throws an error. With three colors, the last fills both columns of the grid.

Not interactive: no role, no keyboard. For an accessible name, put a text label next to it, or add aria-label when the color carries meaning on its own.

A transparent color shows the checkerboard behind it.

ColorSwatchPropsProvider sets default props for the swatches inside it. A prop on a swatch wins.

Customize with CSS

Classes: .leverui-color-swatch, and .leverui-color-swatch__mix-grid for the mix grid.

Attributes: data-size, data-shape, plus the usual attributes for each breakpoint.

Variables: --leverui-swatch-color, --leverui-swatch-size, --leverui-swatch-radius. Checkerboard: --leverui-swatch-checker-size, --leverui-swatch-checker-bg, --leverui-swatch-checker-fg.