# VariationPicker

One choice among a product's colours or sizes. Image options for colours, text options for sizes.

Code: `components/ui/variation-picker.tsx`. Figma: Product Variation Option, node 2100:626. Live: https://design.id-hub.dk/components/variation-picker

```tsx
import { VariationPicker } from '@/components/ui/variation-picker';

<VariationPicker
  label="Størrelse"
  name="size"
  defaultValue="M"
  options={[{ value: 'S', label: 'S' }, { value: 'M', label: 'M' }, { value: 'L', label: 'L' }]}
/>
```

| Prop | Type | Default | What it does |
| --- | --- | --- | --- |
| label (required) | `string` |  | What is being chosen, such as "Størrelse". Read aloud, not shown. |
| name (required) | `string` |  | The form field name. One picker is one radio group. |
| options (required) | `VariationOption[]` |  | { value, label, image?, disabled? }. With image it is a colour option, without it a text option. |
| value | `string` |  | The chosen value. With onChange the picker is controlled. |
| defaultValue | `string` |  | The value chosen from the start, uncontrolled. |
| onChange | `(value: string) => void` |  | Called with the new value. |
| more | `number` |  | How many more options there are than the ones shown, such as 9 for "+9". Shown as a last tile. |
| moreHref | `string` |  | Where the tile with the rest leads, such as the full list. Without it the tile is plain text. |
| moreLabel | `(count: number) => string` |  | What the tile with the rest says to a screen reader. Danish by default. |

Do:
- Use one picker per choice: one for colour, one for size.
- Give every image option a label with the colour's name.
- Brackets, the corners from the logo, are used only here, to mark the chosen variant. Never around headlines, messages or text.
- Show the first options and the rest as "+9" with more, when a product has more colours than fit.

Do not:
- Do not use it for navigation or filters.
- Do not show a price or stock inside an option.

Accessibility:
- Each option is a native radio button in a fieldset: arrow keys move, a form posts the value.
- The chosen option is marked by four corners from the logo and by Ink text. Figma draws Default and Selected; the hover ground is ours until Peter draws one.
- Figma sets an unchosen option's text in text/weak (Ash, about 2:1 on White). Here it stays Stone, which holds 4.5:1, until Peter answers the question on the variant selector in docs/SPOERGSMAAL-TIL-PETER.md.
- The tile with the rest reads as "9 flere", not as "+9", and is a link when it leads somewhere.

Tokens it uses:
- color.neutral.0
- color.neutral.50
- color.neutral.500
- color.neutral.900
- space.seam
- type.body.sm
- component.variation-option.size
- component.variation-option.padding
- component.variation-option.radius
- component.variation-option.corner-size
- component.variation-option.corner-inset
- component.variation-option.corner-radius
- color.surface.glass
- color.text.muted
- space.inline.1

---

Drawn in Figma: one of the 8 components that may be used anywhere, the public site included. All of them: https://design.id-hub.dk/components.md. Token values: https://design.id-hub.dk/tokens.md.

Index of everything, as text: https://design.id-hub.dk/llms.txt. Never invent a colour, a size, a component or a product fact: if it is not here, it does not exist yet.
