Product compare swipe — Storefront block

Free

storefront-product-compare-swipe · for product, catalog pages

Product compare swipe

Phone-first: columns scroll sideways and snap, the attribute names pinned; chosen automatically beyond four products

Documentation

Installation

One command copies the block into your project with the shadcn CLI (the registry is set once: Installation).

pnpm dlx shadcn-vue@latest add @trame/storefront-product-compare-swipe

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import StorefrontProductCompareSwipe from '@/components/trame/blocks/storefront/storefront-product-compare-swipe.vue'

const props = {
title: "Which bag should you choose?",
products: [
{
id: "p1",
name: "Line 20 bag",
price: 8900,
summary: "The everyday companion.",
image: "https://images.unsplash.com/photo-1680039211156-66c721b87625?w=1600&q=80",
alt: "A black flap backpack on a yellow background",
specs: {
weight: "1.4 lb",
capacity: "20 L",
material: "Recycled canvas",
warranty: "2 years",
origin: "Portugal"
}
},
{
id: "p2",
name: "Line 28 bag",
price: 10900,
summary: "For the whole day.",
image: "https://images.unsplash.com/photo-1641934725990-1326a660c184?w=1600&q=80",
alt: "A midnight blue mesh backpack with a cognac leather flap",
specs: {
weight: "1.7 lb",
capacity: "28 L",
material: "Recycled canvas",
warranty: "2 years",
origin: "Portugal"
}
}
],
rows: [
{
key: "weight",
label: "Weight",
group: "The product"
},
{
key: "capacity",
label: "Capacity",
group: "The product"
}
],
currentId: "p2",
action: {
label: "See this model",
action: "product"
}
}
</script>

<template>
<StorefrontProductCompareSwipe v-bind="props" />
</template>

Props

Each prop says who changes it: Words, Picture, Action, Design, Data.* required.

PropTypeDescription
title*stringWordswhat is compared ("Which model to choose?")
products*Product[]Data2 to 4 products of the same family (more switch to the swipe layout)
rows*Row[]the attributes compared, in order
currentIdstring | numberDatathe id of the product the visitor is looking at, marked in the grid
actionActionthe call to action: its words and the page action it runs
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Product products[] · 20 props
PropTypeDescription
id*string | numberDatathe record’s id in the tool that answers it
name*stringWordsthe product’s name
price*numberan amount in cents
compareAtnumberthe price before the merchant’s reduction
currencystringDesignISO 4217, EUR by default
imagestring | nullPicturethe main picture; null or absent: the product has none yet
imagesstring[]Picturea picture: a root-relative path (/media/…) or an absolute URL
altstringWordswhat the main picture shows
brandstringWordsthe brand or maker
categorystringWordsthe product’s category, e.g. "Knitwear"
summarystringWordsone short line on the product
badgestringWordsa short tag the merchant set ("New", "Handmade")
ratingnumberthe average of the shop’s own stored reviews
reviewCountnumberhow many stored reviews the rating averages
availablebooleanfalse: sold out; true or absent: can be bought
stocknumberthe real stock, when the merchant shows it
maxQuantitynumberthe most one order may hold of it, as the merchant set it (one per customer, a limited run)
optionsOption[]the product’s options and their values, e.g. sizes
highlightsHighlight[]a few key facts the merchant set, shown on the product’s card
specsRecord<string, string>the product’s attributes by row key, as the catalogue holds them
Option products[].options[] · 2 props
PropTypeDescription
name*stringWordsthe option’s name, e.g. "Size"
values*string[]Wordsits values, e.g. "S", "M", "L"
Highlight products[].highlights[] · 2 props
PropTypeDescription
label*stringWordsthe property ("Material", "Capacity")
value*stringWordsits value, as the merchant states it ("Washed linen", "50 cl")
Row rows[] · 3 props
PropTypeDescription
key*stringDesignthe key of the attribute in each product’s specs
label*stringWordsthe attribute ("Battery life")
groupstringWordsthe group it belongs to ("Comfort"), when rows are grouped
Action action · 2 props
PropTypeDescription
label*stringWordsthe button on each column ("See this model")
action*stringActiona named action of the page
Options options · 2 props
PropTypeDescription
captionstringWordsa sentence under the title, as the merchant writes it
mood'inverse' | 'brand' | 'warm' | 'tint' | stringa band of the page that redefines the theme surfaces inside it
What it asks your app for

The block never knows your app: it asks it, through one context provided once, where its links lead, what its actions do, how a price reads and which words to say (The host context).

MemberWhat it is for
hrefthe address an action leads to, or null to hide what leads there
actruns a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error }
canwhether the page has this action
moneyformats a price, given in cents
asseta picture’s address as your app serves it
Linkyour router’s link component
cartCountthe cart badge’s number
cartDrawerwhether your app has a cart drawer
cartOpenwhether the cart drawer is open
labelyour word for an interface key, or undefined to keep the block’s own

The words it says itself, in English and French; label(key) replaces any of them:

KeyEnglishFrench
newsletter.alreadyYou are already subscribed.Vous êtes déjà inscrit.
newsletter.doneDone: you are subscribed.C’est noté : vous êtes inscrit.
newsletter.invalidCheck the email address.Vérifiez l’adresse e-mail.
newsletter.tooManyToo many attempts, try again in a moment.Trop de tentatives, réessayez dans un moment.

Features

  • Every word in the server HTML
  • Same markup in Vue and React
  • Theme tokens only: every theme, light and dark
  • Shows what you give it, invents nothing
  • No motion; still under reduced motion
  • Real buttons and links, a visible focus
  • Asks your app through actions: action
  • Reads products from your app

A storefront section, for product, catalog pages; it uses @lucide/vue, @vueuse/core, class-variance-authority, clsx, reka-ui, tailwind-merge.

Built with

The components this block is made of; each one installs on its own too.

More storefront blocks

  • Price story figures: a short account, three or four key figures and a closing sentence, no ledger: reasons that are not only cost.
  • Product close ups film: tall close-ups in a row that scrolls sideways, each name over its foot, the piece leading the row as its first card: a product page band that shows the making quality without a long read.
  • Product close ups index: a numbered list of the details beside one large close-up that changes as a detail is chosen, the piece’s card under the list: a few details with real explanations, read one at a time.
  • Product close ups loupes: each detail in a round close-up like a magnifying glass, set in staggered balanced rows with its name and note under it, the piece itself in a card at the head: three to twelve details of a crafted piece (leather, knitwear, ceramics).
  • Product configurator compact: a product page’s buy box with one or two options: a thumbnail, the choices in a row, the total and the button, no second column.
  • Product configurator side by side: a made-to-order page of its own: the picture stays in view on one side while every option runs down the other, the recap at the end.
  • Product dimensions diagram: A dimension drawing with exact measurements, enlarged in a dialog with an all-media tab; the merchant’s own only.
  • Product facets radial: one product with 3 to 6 named facets around its picture: a single object seen from several sides.

All 409 storefront blocks