<!-- 04_VISUAL/xwui/xwui-lib/xwui-lib-basic/src/display/XWUILegend/XWUILegend.md -->
# XWUILegend

The key of a chart, a map layer set or a status scheme: a list of marks (dot, square, line, dash, bar, ring or an icon) with their words, an optional figure and a second line. Turn `interactive` on and each entry becomes a toggle button that switches its series on and off. Colour comes from the XWUI hue tokens (`--xwui-hue-*`) or the role tones, never a literal, and a `pattern` (hatch, dots, cross) gives a filled mark a second cue so colour is never the only one. Replaces the `legend()` and `legendRow()` helpers every page kit re-implements and the roughly fifty `*__legend` classes; `XWUIGISLegend` stays map specific.

## Basic Usage

```example
file: examples/BasicUsage.ts
html: examples/BasicUsage.html
title: Basic Usage
description: A chart key: three series, each with its own mark shape and hue, one with a pattern twin.
```

## Status Key

```example
file: examples/StatusKey.ts
html: examples/StatusKey.html
title: Status Key
description: A vertical key of status tones with a figure at the end of each row.
```

## Toggle Series

```example
file: examples/ToggleSeries.ts
html: examples/ToggleSeries.html
title: Toggle Series
description: Chips that switch a chart series on and off.
```

## Data

`items[]`, in order. Entries without an `id` or a `label`, and repeated ids, are dropped.

| Field | Default | What it does |
| --- | --- | --- |
| `id`, `label` | required | Stable id (reported by `toggle`), visible words and accessible name. |
| `hue` | primary accent | A palette hue NAME (`teal`, `indigo`, `rose`: any `--xwui-hue-<name>`, so a product may declare its own) or a role tone: `primary`, `success`, `warning`, `error`, `info`, `neutral`. A value that is not a plain identifier is ignored. |
| `swatch` | config `swatch` | `dot`, `square`, `line`, `dash`, `bar`, `ring` or `icon`. |
| `icon` | none | Icon name for `swatch: 'icon'`; without it the mark falls back to the config shape. |
| `value` | none | A figure at the end of the row. A number is formatted (Western digits unless `numberingSystem` says otherwise); a string is shown as given (`'42%'`). |
| `description` | none | A second, quieter line under the label. |
| `pattern` | none | `hatch`, `dots` or `cross` over a filled mark (`dot`, `square`, `bar`). Strokes, rings and icons already differ by shape and take none. |
| `off` | `false` | The series is off: hollow mark, struck-through label, and a text twin (plain legends) or `aria-pressed="false"` (interactive). |
| `disabled` | `false` | Interactive only: shown, cannot be toggled. |

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `orientation` | `'horizontal'` | `'horizontal'` wraps onto further lines; `'vertical'` stacks, rows span the width so the figures line up at the end. |
| `align` | `'start'` | Where entries sit on the main axis. Horizontal: `start`, `center`, `end`, `between` (spread). Vertical: `center` and `end` shrink the rows and place the column; `start` and `between` keep them full width. |
| `size` | `'md'` | `'sm'`, `'md'`, `'lg'`: type size; the marks are em based and follow it. |
| `variant` | `'plain'` | `'chips'` draws each entry as a pill. |
| `interactive` | `false` | Entries become native `<button>`s with `aria-pressed` that emit `toggle`. |
| `swatch` | `'square'` | Mark shape of entries that name none. |
| `title` | none | Visible heading above the list. |
| `ariaLabel` | title, else pack `xwui.legend.title` | Accessible name of the list. |
| `emptyText` | none | Status text when there are no entries. Unset: an empty legend draws nothing. |
| `locale`, `numberingSystem` | page language, `'latn'` | Number formatting. |
| `className` | none | Extra class on the root. |

CSS knobs: `--xwui-legend-ink` (mark colour, set per entry), `--xwui-legend-gap` (space between entries of a row).

## Events and methods

`onToggle(({ id, off }) => void)` returns a disposer and fires for a user switch only. `setItems(items)`, `setOff(id, off)` (host driven: no event, returns whether anything changed), `toggle(id)` (what a click does: flips and emits; interactive legends only), `isOff(id)`, `updateConfig(patch)`, `updateData(patch)`, `getElement()`, `destroy()`. Static `XWUILegend.projectView(data, config)` composes it into a parent view tree. Custom element `<xwui-legend>` with `items` as data and the options above as attributes.

## Accessibility and RTL

A real list (`ul role="list"`, named by `ariaLabel`, `title` or "Legend"). The mark is decorative (`aria-hidden`); the words are always present, so nothing depends on colour or shape. An interactive entry is a native button: Tab order (no roving tabindex), Enter and Space toggle, `aria-pressed="true"` means shown, `false` hidden, a disabled entry is skipped, focus stays on the pressed button across the update. A switched-off entry in a plain legend carries a visually hidden "Hidden" (locale key `xwui.legend.off`). Targets grow to the large size on coarse pointers, motion stops under `prefers-reduced-motion`, forced colours keep the mark ink. Logical properties only: under a parent `dir="rtl"` the mark sits at the inline start, the figure at the end, and labels are `dir="auto"` and isolated so mixed-script text cannot reorder around the figure.

```api
```
