# Color Swatch

Display and select a named color value. (CSS only.)

Reference: https://timeless.build/docs/components/color-swatch/

## Markup

```html
<div class="ui-color-swatch" style="--ui-color-swatch: oklch(62% 0.18 32)">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand red</span>
  <span data-ui-part="value">oklch(62% 0.18 32)</span>
  
</div>
```

## Install

```js
import '@timelessui/components/css/tokens.css'
import '@timelessui/components/css/core/color-swatch.css'
import '@timelessui/components/css/themes/atmosphere/tokens.css'
import '@timelessui/components/css/themes/atmosphere/color-swatch.css'
```

## Anatomy

Parts are authored in your own markup and identified by the selector below. Required parts
must be present for the component to work. Private `data-ui-internal-*` hooks are written by
the runtime and must never be authored.

| Part | Required | Selector | Purpose |
| --- | --- | --- | --- |
| `chip` | No | `[data-ui-part~='chip']` | The color area. Set the color through `--ui-swatch-color`. |
| `label` | No | `[data-ui-part~='label']` | Human-readable color name. |
| `value` | No | `[data-ui-part~='value']` | The raw CSS color value. |
| `warning` | No | `[data-ui-part~='warning']` | Out-of-gamut or contrast warning. |

## Styling

Root identity: `ui-color-swatch`.
Required stylesheets: `tokens.css`, `core/color-swatch.css`, `themes/atmosphere/tokens.css`, `themes/atmosphere/color-swatch.css`.

This component adds no custom properties of its own. Restyle it through the design tokens at https://timeless.build/docs/styling/theming/ or your own CSS.

Design tokens this component reads (18), global and set at the theme level: `--ui-accent`, `--ui-bg-surface`, `--ui-bg-surface-raised`, `--ui-checkerboard`, `--ui-disabled-opacity`, `--ui-duration-fast`, `--ui-ease-standard`, `--ui-fg`, `--ui-fg-muted`, `--ui-focus`, `--ui-font-mono`, `--ui-line`, `--ui-line-strong`, `--ui-radius-md`, `--ui-radius-sm`, `--ui-space-2`, `--ui-space-3`, `--ui-warning`.

## Accessibility

Keep the native elements, roles, and relationships shown in the markup. Timeless adds only the
state and keyboard coordination the platform does not already provide, and it never supplies
your accessible names — those depend on your content.

This component declares no keyboard contract, because it has none of its own: the markup above
is native elements and native ARIA, and everything a keyboard or a screen reader does with it
comes from the platform. Nothing here manages focus, and nothing here adds a role you did not
author. So the accessibility of this component is the accessibility of the markup — which is why
the markup is the part worth copying exactly.

## Before JavaScript runs

This primitive is CSS only. There is nothing to register and nothing to wait for.

## Color Palette

Lay several swatches out as a selectable grid across CSS color formats.

```html
<div style="display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr))">
  <button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand red, oklch(62% 0.18 32)" style="--ui-color-swatch: oklch(62% 0.18 32)">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand red</span>
  <span data-ui-part="value">oklch(62% 0.18 32)</span>
  
</button>
  <button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand amber, hwb(38 6% 8%)" style="--ui-color-swatch: hwb(38 6% 8%)">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand amber</span>
  <span data-ui-part="value">hwb(38 6% 8%)</span>
  
</button>
  <button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand lime, color(display-p3 0.63 0.86 0.2)" style="--ui-color-swatch: color(display-p3 0.63 0.86 0.2)">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand lime</span>
  <span data-ui-part="value">color(display-p3 0.63 0.86 0.2)</span>
  
</button>
  <button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand teal, lch(70% 45 190)" style="--ui-color-swatch: lch(70% 45 190)">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand teal</span>
  <span data-ui-part="value">lch(70% 45 190)</span>
  
</button>
  <button class="ui-color-swatch" type="button" aria-pressed="true" aria-label="Select Brand blue, #3366cc" style="--ui-color-swatch: #3366cc">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand blue</span>
  <span data-ui-part="value">#3366cc</span>
  
</button>
  <button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand violet, oklch(52% 0.24 300)" style="--ui-color-swatch: oklch(52% 0.24 300)">
  <span data-ui-part="chip" aria-hidden="true"></span>
  <span data-ui-part="label">Brand violet</span>
  <span data-ui-part="value">oklch(52% 0.24 300)</span>
  
</button>
</div>
```
