Variant Selector
ProNewColor swatches that name the selected color, and size pills with a struck-through sold-out state, both as radio groups.
Installation
pnpm dlx shadcn@latest add @viewport/variant-selector
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
<SwatchPicker>
| Prop | Type | Default |
|---|---|---|
| label* | stringWhat is being chosen, e.g. "Color". Shown above the swatches with the selected name. | — |
| options* | Swatch[] | — |
| value* | string | — |
| onValueChange* | (value: string) => void | — |
| className | string | — |
<OptionPicker>
| Prop | Type | Default |
|---|---|---|
| label* | stringWhat is being chosen, e.g. "Size". | — |
| options* | Option[] | — |
| value* | string | — |
| onValueChange* | (value: string) => void | — |
| aside | React.ReactNodeA link beside the label, e.g. to a size guide. | — |
| className | string | — |
Accessibility
- Radio groups: arrow keys move and select.
- The selected color's name is written out, so the choice never depends on telling shades apart.
- Sold-out options say so in their name and cannot be chosen.
- Respects prefers-reduced-motion.