Velocity X Components

E-Commerce

Variant Swatch Picker

Colour swatch and size button picker with per-combination availability so unavailable sizes show struck-through instead of disappearing.

Subscription Included with the Velocity Components subscription.
bash
$ velocityx add variant-swatch-picker

Built for react. Needs react, react-dom already installed as peer dependencies. An Astro-only project needs @astrojs/react wired up first — this won't run on its own in plain Astro.

Full docs for Variant Swatch Picker →

Needs a licence key — subscribe here, then velocityx loginonce.

react v1.0.0 react react-dom
Variant Swatch Picker

Colour — Black

Size — US 9

Props

NameTypeRequiredDefaultDescription
colors{ id, label, swatch (css colour or image url), image? }[]No[]
sizes{ id, label }[]No[]
selectedColorstringYes
selectedSizestringYes
onSelectColor(id) => voidYes
onSelectSize(id) => voidYes
isAvailable(colorId, sizeId) => booleanNo() => true

File this creates

The CLI writes this path into your project, relative to its root — nothing else moves.

text
components/velocity/variant-swatch-picker/VariantSwatchPicker.jsx

Using the Variant Swatch Picker component

Install it with velocityx add variant-swatch-picker. The CLI writes the source straight into your project — no runtime dependency, no registry lock-in, and it themes itself from the same primary-*/accent-* scale as the rest of the library.

More from E-Commerce.