Back to components
ElementForm & InputFree

Variant Swatches React component

Product option pickers for colour and size: round colour swatches with a ring that glides to the pick, size chips with a sliding fill, the chosen value named in the label, sold-out options struck through, and a low-stock warning when only a few are left.

About the Variant Swatches component

Variant Swatches is a product option picker: round color swatches for colors and text chips for sizes or any other option. The selected swatch gets a ring and the selected chip a fill that slide between options, the group heading shows the picked name (Color · Sand), hovering a color shows its name in a tooltip, and a warning like "Only 3 left" appears when stock runs low.

groups takes a list of option groups, each with a name, a type (color or size) and options with value, label and optional color, soldOut and stock. Sold-out colors are struck through diagonally and sold-out chips crossed out; both stay visible but cannot be picked. value or defaultValue holds the choice per group name, like { Color: "black", Size: "s" }, and onValueChange reports it. lowStock sets the warning threshold (3 by default) and size picks sm, md or lg.

When to use it

Use Variant Swatches on product pages and quick-add dialogs wherever shoppers pick a colour, size or other option. Seeing sold-out and low-stock options up front saves a disappointed add-to-cart.

Keep the option names short (they appear in the label and tooltip) and update the product image when the colour changes.

Installation

Add the Variant Swatches component to your project with the shadcn CLI. It lands in components/variant-swatches.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/variant-swatches

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Related components

Content Switch
Free
Floating Label Input
Free
Input Group
Free
Blockquote
Free
Basic Table
Free
List Group
Free