---
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" },
]
---
<FieldSet class="w-full max-w-xs">
<FieldLegend variant="label">Color</FieldLegend>
<FieldGroup class="gap-3">
{colors.map(({ value, label, color }) => (
<Field orientation="horizontal">
<Checkbox id={`color-${value}`} name="color" value={value} />
<Label for={`color-${value}`}>
<Swatch color={color} />
{label}
</Label>
</Field>
))}
</FieldGroup>
</FieldSet>Installation
npx shadcn@latest add @fulldev/swatch
Usage
import { Swatch } from "@/components/ui/swatch"
<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. A faint inner ring keeps white and black visible on any
background. Set its size with a size-* class.
API Reference
| Prop | Type | Default |
|---|---|---|
color | string | undefined |
image | string | undefined |
Source: src/components/ui/swatch