VariantSelector
A flexible variant selector that supports both single and multiple selection modes. Renders card-style items that can display images or colors.
Usage
import { VariantSelector, VariantSelectorItem } from "@desk/ui/compositions/variant-selector";Best practices
Fill it with
VariantSelectorItemchildren — they read selection from context and call back through it;value/defaultValuematches each item'svalue.modeis a discriminated prop:"single"renders arole="radiogroup"and givesonValueChangeastring,"multiple"renders a<fieldset>and astring[]— keepvalue/defaultValuetypes matching the mode.Use
VariantSelectorfor image/colour swatch pickers; for a labelled icon-over-text option grid useIconCard, and for plain radio/checkbox lists useRadioGroup/Checkbox.
Props
VariantSelector
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | Child elements | |
| className | string | CSS class name | |
| defaultValue | string | string[] | Initial value | |
| mode | "single" | "multiple" | Component mode | |
| onValueChange | ((value: string) => void) | ((value: string[]) => void) | Value change handler | |
| value | string | string[] | Current value |
VariantSelectorItem
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | CSS class name | |
| color | string | Color value | |
| disabled | boolean | Whether disabled (blocks interaction) | |
| highlighted | boolean | Whether this option is highlighted (compatible with a hovered unavailable option) | |
| image | ReactNode | ||
| label | string | Label text | |
| onMouseEnter | () => void | Called when mouse enters this item | |
| onMouseLeave | () => void | Called when mouse leaves this item | |
| unavailable | boolean | Whether unavailable (visual styling only, still clickable) | |
| value | string | Current value |
Composition
Builds on