Fit matrix — Comparison block

Pro

comparison-fit-matrix · for product, catalog, home pages

Fit matrix

Options as columns and situations as rows with a mark per cell: compatibility, "this bag goes with…"

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/comparison-fit-matrix

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import ComparisonFitMatrix from '@/components/trame/blocks/comparison/comparison-fit-matrix.vue'

const props = {
title: "Which bag should you choose?",
intro: "Three questions we hear often, and what we answer at the workshop.",
rules: [
{
when: "You’re heading off for a weekend",
pick: "The 20-liter bag",
because: "It fits under an airplane seat and is comfortable to carry all day.",
fits: [
"yes",
"partial"
],
action: "product",
record: {
id: "sac-20"
}
},
{
when: "You’re traveling for a week or more",
pick: "The 35-liter bag",
because: "A dedicated shoe pocket and a ventilated back for long days.",
fits: [
"partial",
"yes"
],
action: "product",
record: {
id: "sac-35"
}
}
],
columns: [
"20 L bag",
"35 L bag"
],
help: {
text: "Still unsure? Tell us what you carry and we’ll get back to you within two business days.",
link: {
label: "Write to the workshop",
action: "page",
record: {
id: "contact"
}
}
}
}
</script>

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

Props

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

PropTypeDescription
title*stringWordsthe section’s title, an h2
introstringWordsone or two sentences under the title
rules*Rule[]the rules that point to a choice
columns*string[]Wordsan option compared in the matrix ("20 L bag")
helpHelpa line and a link for the undecided
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Rule rules[] · 6 props
PropTypeDescription
when*stringWordsthe situation, in the visitor’s words ("You are going away for a weekend")
pick*stringWordsthe recommended option ("The 20-litre bag")
becausestringWordsone line on why
fits('yes' | 'partial' | 'no')[]one mark per column, in the order of `columns`
actionstringActiona named action of the page
recordRecord<string, unknown>Datathe record the action opens (the product), if any
Help help · 2 props
PropTypeDescription
text*stringWordsthe line for the undecided ("Still not sure?")
linkLinkthe link: its words and the page action it runs
Link help.link · 3 props
PropTypeDescription
label*stringWordswhat happens ("Write to us")
action*stringActiona named action of the page
recordRecord<string, unknown>Datathe record the action opens, if any
Options options · 1 props
PropTypeDescription
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
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
  • Subtle motion: one short reveal; still under reduced motion
  • Real buttons and links, a visible focus
  • Asks your app through actions: rules[], help.link

A comparison section, for product, catalog, home pages; it uses @lucide/vue, clsx, motion, tailwind-merge.

More comparison blocks

  • Compare side by side: the two pictures whole, next to each other with "or" on the seam: two options or states to choose between, where a slider would hide half of each.
  • Compare split: the title and text beside the pictures, the legend under the words: the words explain what changed.
  • Compare wide: the title and text above, the two pictures across the page: a detail worth seeing large.
  • Cost bars: the merchant’s cost against another cost the merchant sourced, as two bars and a sentence: when a saving is real.
  • Head to head choice cards: 2 to 4 cards, each with its price, what it adds over the previous and its points: tiers, sizes and variants.
  • Head to head dimension rows: each criterion a row with the answers side by side in sentences: 3 to 6 dimensions that need words, not marks.
  • Head to head versus split: two panels, ours and the other, each a list of points grouped by theme: 4 to 8 points without a table feel.
  • Table figures: each option’s value set large in a column, rows parted by thin rules, the chosen option carried by its tag: comparisons whose cells are numbers (weight, time, price, cost per use) where the contrast must be seen — the merchant’s own figures only.

All 15 comparison blocks