---
type: doc
title: Swatch
description: A color or pattern beside an option or filter value.
---

> Fulldev UI React extension for an official shadcn/ui project. The `@fulldev` registry in `components.json` points at `https://ui.full.dev/r/react/styles/{style}/{name}.json`; see [installation](/react/docs/installation.md).

```tsx title="Usage of @fulldev/swatch (react/gallery/ui/swatch.tsx, not installed)"
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLegend, FieldSet } from "@/components/ui/field"
import { Label } from "@/components/ui/label"
import { Swatch } from "@/components/ui/swatch"

const colors = [
  { value: "navy", label: "Navy", color: "#1e3a5f" },
  { value: "sand", label: "Sand", color: "#d8c7a6" },
  { value: "white", label: "White", color: "#ffffff" },
]

export default function Demo() {
  return (
    <div className="flex flex-col gap-10 p-6">
      <FieldSet>
        <FieldLegend variant="label">Color</FieldLegend>
        <FieldGroup className="gap-3">
          {colors.map(({ value, label, color }) => (
            <Field key={value} orientation="horizontal">
              <Checkbox id={`color-${value}`} name="color" value={value} />
              <Label htmlFor={`color-${value}`}>
                <Swatch color={color} />
                {label}
              </Label>
            </Field>
          ))}
        </FieldGroup>
      </FieldSet>
    </div>
  )
}
```

## Installation

```bash
npx shadcn@latest add @fulldev/swatch
```

## Usage

```tsx
import { Swatch } from "@/components/ui/swatch"
```

```tsx
<Swatch color="#1e3a5f" />
<Swatch image="/swatches/denim.webp" />
```

`color` sets the background color and `image` the URL of a pattern or photo,
such as a Shopify swatch. A swatch is decorative, so it renders with
`aria-hidden="true"`: keep the value's name in text, or give the control around
it an `aria-label`. Set its size with a `size-*` class.

## API Reference

Source: [`react/src/components/ui/swatch.tsx`](https://github.com/fulldotdev/ui/blob/main/react/src/components/ui/swatch.tsx)

## Install what this page shows

```bash
npx shadcn@latest add @fulldev/swatch
```
