Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Product lists

5 examples. Resize any preview to see it at phone and tablet widths.

Product Grid

Free

A filterable product list with animated reflow, a save toggle and an add-to-bag button that announces the bag count.

Product Rail

Free

A horizontal rail of products on native scroll snapping, with arrows that disable at each end.

Hide code
components/blocks/product-rail.tsx
"use client";

import { useEffect, useRef, useState } from "react";
import { ArrowLeft, ArrowRight } from "lucide-react";

const products = [
  { name: "Linen apron", price: 48, tint: "bg-[#e9e3d6] dark:bg-[#2c2923]", ink: "#a8997c" },
  { name: "Oak board", price: 64, tint: "bg-[#ead9c6] dark:bg-[#30271e]", ink: "#b98a5a" },
  { name: "Copper kettle", price: 120, tint: "bg-[#efd9cf] dark:bg-[#32241f]", ink: "#c1714f" },
  { name: "Stone mortar", price: 58, tint: "bg-[#e3e4e2] dark:bg-[#272827]", ink: "#8c908c" },
  { name: "Glass carafe", price: 36, tint: "bg-[#dfe8e8] dark:bg-[#222a2a]", ink: "#7ba0a1" },
  { name: "Wool runner", price: 92, tint: "bg-[#e6dfe6] dark:bg-[#2a262b]", ink: "#9a829c" },
];
const money = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

export default function ProductRail() {
  const rail = useRef<HTMLUListElement>(null);
  const [edge, setEdge] = useState({ start: true, end: false });

  useEffect(() => {
    const node = rail.current;
    if (!node) return;
    const update = () => setEdge({ start: node.scrollLeft < 4, end: node.scrollLeft + node.clientWidth > node.scrollWidth - 4 });
    update();
    node.addEventListener("scroll", update, { passive: true });
    const observer = new ResizeObserver(update);
    observer.observe(node);
    return () => {
      node.removeEventListener("scroll", update);
      observer.disconnect();
    };
  }, []);

  const move = (direction: 1 | -1) => {
    const node = rail.current;
    if (!node) return;
    const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    node.scrollBy({ left: direction * node.clientWidth * 0.8, behavior: reduce ? "instant" : "smooth" });
  };
  const arrow = "grid size-10 place-items-center rounded-full border border-border outline-none transition-[background-color,opacity,scale] duration-150 hover:bg-accent enabled:active:scale-[0.96] focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-35 motion-reduce:transition-none";

  return (
    <section aria-labelledby="rail-title" className="w-full py-12 sm:py-16">
      <div className="mx-auto flex max-w-6xl items-end justify-between gap-4 px-5 sm:px-8">
        <div>
          <h2 id="rail-title" className="text-3xl font-semibold tracking-[-0.035em]">New this week</h2>
          <p className="mt-1.5 text-sm text-muted-foreground">Six things for the kitchen, made to be used daily.</p>
        </div>
        <div className="hidden gap-2 sm:flex">
          <button type="button" aria-label="Previous products" disabled={edge.start} onClick={() => move(-1)} className={arrow}><ArrowLeft className="size-4" aria-hidden /></button>
          <button type="button" aria-label="Next products" disabled={edge.end} onClick={() => move(1)} className={arrow}><ArrowRight className="size-4" aria-hidden /></button>
        </div>
      </div>
      {/* Native scrolling with snap points: touch, trackpad and keyboard all work without a carousel library. */}
      <ul ref={rail} tabIndex={0} aria-label="New products" className="mt-7 flex snap-x snap-mandatory gap-4 overflow-x-auto scroll-px-5 px-5 pb-2 outline-none [scrollbar-width:none] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring sm:scroll-px-8 sm:px-8 xl:scroll-px-[max(2rem,calc((100vw-72rem)/2+2rem))] xl:px-[max(2rem,calc((100vw-72rem)/2+2rem))]">
        {products.map((product) => (
          <li key={product.name} className="w-[62%] shrink-0 snap-start sm:w-[38%] lg:w-[23.5%]">
            <a href="#product" className="group block rounded-xl outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background">
              <div className={`grid aspect-[4/5] place-items-center overflow-hidden rounded-xl ${product.tint}`}>
                <span aria-hidden className="size-[42%] rounded-full transition-transform duration-500 ease-[cubic-bezier(0.215,0.61,0.355,1)] group-hover:scale-[1.06] motion-reduce:transition-none" style={{ background: product.ink }} />
              </div>
              <div className="mt-3 flex items-baseline justify-between gap-3">
                <h3 className="truncate font-medium">{product.name}</h3>
                <p className="tabular-nums text-muted-foreground">{money.format(product.price)}</p>
              </div>
            </a>
          </li>
        ))}
      </ul>
    </section>
  );
}

Catalog with Filters

Pro

A product grid with a filter column for category, color, size and price. Each option shows how many products it would give, chosen filters appear as removable chips, and on phones the filters open in a bottom sheet.

The source for this block is part of Truffle Pro.

Saved Items

Pro

A wishlist grid with price-drop and stock notes, a move-to-bag button, a back-in-stock alert for sold-out sizes, removal with undo, and a share link.

The source for this block is part of Truffle Pro.