terra vidhal

Product Comparator

Component

About

A product comparison board with a selectable shortlist, a specification table that highlights the best value per row, a differences-only switch, price and rating insights, animated column changes and full keyboard support.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Product Comparator to your project and fits it to your theme.

Code

How Product Comparator is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

/**
 * PrequelUI Animate — MIT — https://prequeluianimate.terravidhal.me
 */

import {
  ProductComparator,
  type CompareProduct,
  type CompareSpec,
} from "@/components/ui/product-comparator";

const PRODUCTS: CompareProduct[] = [
  {
    id: "aerobook",
    name: "AeroBook 14",
    tagline: "Balanced everyday laptop with a bright panel.",
    price: 1249,
    rating: 4.6,
    reviews: 812,
    values: {
      display: 14,
      panel: "LCD 60 Hz",
      battery: 13,
      weight: 1.35,
      memory: 16,
      storage: 512,
      ports: 3,
      warranty: 2,
    },
  },
  {
    id: "aerobook-pro",
    name: "AeroBook Pro 14",
    tagline: "Faster chip, sharper screen, same footprint.",
    price: 1799,
    rating: 4.8,
    reviews: 534,
    values: {
      display: 14,
      panel: "OLED 120 Hz",
      battery: 12,
      weight: 1.42,
      memory: 24,
      storage: 1024,
      ports: 4,
      warranty: 3,
    },
  },
  {
    id: "studio-slate",
    name: "Studio Slate",
    tagline: "Colour-accurate display for creative work.",
    price: 1999,
    rating: 4.7,
    reviews: 291,
    values: {
      display: 15,
      panel: "OLED 120 Hz",
      battery: 11,
      weight: 1.6,
      memory: 32,
      storage: 1024,
      ports: 5,
      warranty: 3,
    },
  },
  {
    id: "field-note",
    name: "Field Note 13",
    tagline: "Light travel machine with all-day battery.",
    price: 949,
    rating: 4.3,
    reviews: 1104,
    values: {
      display: 13,
      panel: "LCD 60 Hz",
      battery: 16,
      weight: 1.09,
      memory: 8,
      storage: 256,
      ports: 2,
      warranty: 1,
    },
  },
];

const SPECS: CompareSpec[] = [
  { id: "display", label: "Screen size", suffix: " in", higherIsBetter: true },
  { id: "panel", label: "Panel" },
  { id: "battery", label: "Battery life", suffix: " h", higherIsBetter: true, hint: "Mixed office work" },
  { id: "weight", label: "Weight", suffix: " kg", higherIsBetter: false, hint: "Lower is better" },
  { id: "memory", label: "Memory", suffix: " GB", higherIsBetter: true },
  { id: "storage", label: "Storage", suffix: " GB", higherIsBetter: true },
  { id: "ports", label: "Ports", higherIsBetter: true },
  { id: "warranty", label: "Warranty", suffix: " yr", higherIsBetter: true },
];

export default function ProductComparatorDemo() {
  return (
    <main className="flex min-h-screen w-full items-center justify-center bg-gradient-to-b from-muted/40 via-background to-background px-4 py-8 sm:px-6">
      <ProductComparator
        products={PRODUCTS}
        specs={SPECS}
        defaultSelected={["aerobook-pro", "studio-slate", "field-note"]}
        title="Which laptop fits the team?"
        description="Three shortlisted machines. Turn on the difference filter to cut the noise."
      />
    </main>
  );
}

Dependencies

More by terra vidhal

View all
  • Project Timeline

    Project Timeline

    30
  • Kanban Board

    Kanban Board

    20
  • Gravity Stars Background

    Gravity Stars Background

    20
  • Booking Calendar

    Booking Calendar

    18
  • Notification Center

    Notification Center

    16
  • Audio Waveform

    Audio Waveform

    16
  • Kpi Counter

    Kpi Counter

    16
  • Topographic Lines

    Topographic Lines

    16

Explore more

Part of PrequelUI Animate — browse the full library on 21st.dev.