SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

VariantPicker

The options a product comes in, such as colour, size and format.

View code
tsx
<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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
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.

  • VariantPicker
  • VariantPicker.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.

PropTypeRequiredDescription
childrenRemixNodeYes
targetstringNoA 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

PropTypeRequiredDescription
labelRemixNodeYesThe axis's name, such as "Colour".
valueRemixNodeNoThe current choice's name, shown after the label.
asideRemixNodeNoContent at the row's end, such as a "Size guide" link.
childrenRemixNodeYes

VariantPicker.Swatch

PropTypeRequiredDescription
hrefstringYes
namestringYesThe colour's name; it is the link's accessible name and tooltip.
colorstringYesAny CSS colour or gradient.
selectedbooleanNo
unavailablebooleanNoStrikes the swatch through; it still links, so its page can offer a notice.
unavailableLabelstringNoAdded to the accessible name when unavailable, such as "sold out".

VariantPicker.Choice

PropTypeRequiredDescription
hrefstringYes
labelRemixNodeYes
detailRemixNodeNoA second line in a card, such as its price or "Instant download".
noteRemixNodeNoA small line under a card's detail, such as "Only 2 left".
selectedbooleanNo
unavailablebooleanNoStrikes the choice through; it still links, so its page can offer a notice.
unavailableLabelstringNoRead after the label when unavailable, such as "sold out".
variant"pill" | "card"NoA compact pill for sizes, or a card for formats with a detail line. @default "pill"
@sdxc/ui

Can’t find it? Contact us