VariantPicker
The options a product comes in, such as colour, size and format.
Size: 50×70Size guide
Format: Print
View code
<VariantPicker target="product">
<VariantPicker.Axis label="Frame" value={frame.name}>
{frames.map((option) => (
<VariantPicker.Swatch href={variantHref({ frame: option.id })} name={option.name} color={option.color} selected={option.id === frame.id} unavailable={!option.inStock} unavailableLabel="sold out" />
))}
</VariantPicker.Axis>
<VariantPicker.Axis label="Size" value={size.label} aside={<a href="/size-guide">Size guide</a>}>
{sizes.map((option) => (
<VariantPicker.Choice href={variantHref({ size: option.id })} label={option.label} selected={option.id === size.id} />
))}
</VariantPicker.Axis>
<VariantPicker.Axis label="Format" value={format.label}>
<VariantPicker.Choice variant="card" href={variantHref({ format: "print" })} label="Print" detail="$45" selected />
<VariantPicker.Choice variant="card" href={variantHref({ format: "digital" })} label="Digital" detail="Instant download" />
</VariantPicker.Axis>
</VariantPicker>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { VariantPicker } from "@sdxc/ui/commerce";Renders the picker, a column of axes. Its target reaches every option link as
data-rmx-target, so a choice reloads that frame in place: the page keeps its scroll and
the address changes to the variant without a new history entry per pick.
Composition
The parts the component publishes, each a static property of the host.
VariantPickerVariantPicker.AxisRenders one axis: a row with its label, the current choice and an aside, over the options in a group named by that row.VariantPicker.SwatchRenders a round colour swatch as a link, ringed when selected and struck diagonally when unavailable.VariantPicker.ChoiceRenders a choice as a link: a pill for a size, or a card with a detail and note for a format.
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Required | Description |
|---|---|---|---|
children | RemixNode | Yes | |
target | string | No | A frame's name every option link loads into, so choosing swaps that frame in place. |
Also accepts everything in Omit<TagProps<"div">, "children">.
VariantPicker.Axis
| Prop | Type | Required | Description |
|---|---|---|---|
label | RemixNode | Yes | The axis's name, such as "Colour". |
value | RemixNode | No | The current choice's name, shown after the label. |
aside | RemixNode | No | Content at the row's end, such as a "Size guide" link. |
children | RemixNode | Yes |
VariantPicker.Swatch
| Prop | Type | Required | Description |
|---|---|---|---|
href | string | Yes | |
name | string | Yes | The colour's name; it is the link's accessible name and tooltip. |
color | string | Yes | Any CSS colour or gradient. |
selected | boolean | No | |
unavailable | boolean | No | Strikes the swatch through; it still links, so its page can offer a notice. |
unavailableLabel | string | No | Added to the accessible name when unavailable, such as "sold out". |
VariantPicker.Choice
| Prop | Type | Required | Description |
|---|---|---|---|
href | string | Yes | |
label | RemixNode | Yes | |
detail | RemixNode | No | A second line in a card, such as its price or "Instant download". |
note | RemixNode | No | A small line under a card's detail, such as "Only 2 left". |
selected | boolean | No | |
unavailable | boolean | No | Strikes the choice through; it still links, so its page can offer a notice. |
unavailableLabel | string | No | Read after the label when unavailable, such as "sold out". |
variant | "pill" | "card" | No | A compact pill for sizes, or a card for formats with a detail line. @default "pill" |