# Palette Swatches

> A colour palette as swatches: each colour with its name and role, the HEX and OKLCH values (click to copy) and its WCAG contrast as text on a light and on a dark background, rated AAA, AA, AA large or fails.

Component · Media · Halo kit · [Live page](https://ui.twentyfirst.media/halo/components/PaletteSwatches/)

A colour palette as swatches: each colour with its name and role, the HEX and OKLCH values (click to
copy) and its WCAG contrast as text on a light and on a dark background, rated AAA, AA, AA large or fails.

- `colors` are data (`#rrggbb`), shown as they are: a brand's palette, not the kit's theme.
- `light` and `dark` set the backgrounds the contrast is measured against (default white and near black).
- `compact` shows small chips with name and values only; `contrast={false}` hides the contrast rows.
- The maths is exported: `contrastRatio(a, b)`, `wcagLevel(ratio)`, `hexToOklch(hex)` and `formatOklch(hex)`.

## Example

```tsx
import { PaletteSwatches } from "@twentyfirstmedia/halo";

export default function Preview() {
  return (
    <PaletteSwatches
      label="Harbour Coffee palette"
      colors={[
        { name: "Harbour", value: "#1d4e5f", role: "Primary" },
        { name: "Crema", value: "#c8955a", role: "Accent" },
        { name: "Foam", value: "#f4efe6", role: "Background" },
        { name: "Roast", value: "#2b211c", role: "Text" },
        { name: "Mint leaf", value: "#5fa38a", role: "Success" },
      ]}
    />
  );
}
```

## Props

### PaletteSwatches

| Prop | Type | Notes |
| --- | --- | --- |
| `surface?` | `Surface` | `"glass"` for a translucent surface over a map, photo or video; `"solid"` opts out inside a glass provider. |
| `colors` | `PaletteColor[]` | Required |
| `label?` | `string` | Accessible name (default "Palette"). |
| `light?` | `string` | Background for the light contrast (default white). |
| `dark?` | `string` | Background for the dark contrast (default near black). |
| `contrast?` | `boolean` | `false` hides the contrast rows. |
| `compact?` | `boolean` | Small chips with name and values only. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
