Skip to Content

Product Tile

Product card components for ecommerce: a portrait media frame, label, title whose link covers the tile, description and price, plus a tile grid with grid and swipe-rail variants for shop and catalog pages.

Installation

pnpm dlx shadcn@latest add @01orbital/product-tile

Usage

import {
  ProductTile,
  ProductTileDescription,
  ProductTileGrid,
  ProductTileLabel,
  ProductTileMedia,
  ProductTilePrice,
  ProductTileTitle,
} from "@/components/store/product-tile"

// Every print in the row. Change them here, not in the markup.
const PRODUCTS = [
  {
    name: "Navy Field",
    label: "New",
    description: "Navy and bone",
    price: "$38",
    href: "#",
    imageUrl: "https://01orbital.dev/art/kit/newman-blue.png",
    imageAlt: "Print of a deep navy field split by two pale vertical lines.",
  },
  {
    name: "Ink Rings",
    label: "Bestseller",
    description: "Black on white",
    price: "$72",
    href: "#",
    imageUrl: "https://01orbital.dev/art/kit/thomas-v2-596378.png",
    imageAlt: "Print of concentric rings of heavy black dashes on white.",
  },
  {
    name: "Fern",
    label: "Line work",
    description: "Sage on black",
    price: "$135",
    href: "#",
    imageUrl: "https://01orbital.dev/art/kit/fern.png",
    imageAlt: "Print of branching sage lines spreading across a black ground.",
  },
  {
    name: "Dawn Rings",
    label: "Limited",
    description: "Pink into pale yellow",
    price: "$88",
    href: "#",
    imageUrl: "https://01orbital.dev/art/kit/thomas-v2-86369.png",
    imageAlt:
      "Print of concentric rings of dashes fading from pink to pale yellow.",
  },
] as const

// The rail: a swipe row with an edge fade until 64rem, then four across. The
// frame widens at each step so a tile stays about 250px wide throughout.
export default function ProductTileDemo() {
  return (
    <div className="w-full max-w-md min-w-0 p-6 md:max-w-3xl lg:max-w-5xl">
      <ProductTileGrid variant="rail">
        {PRODUCTS.map((product) => (
          <ProductTile key={product.name}>
            <ProductTileMedia>
              <img src={product.imageUrl} alt={product.imageAlt} />
            </ProductTileMedia>
            <ProductTileLabel>{product.label}</ProductTileLabel>
            <ProductTileTitle>
              <a href={product.href}>{product.name}</a>
            </ProductTileTitle>
            <ProductTileDescription>
              {product.description}
            </ProductTileDescription>
            <ProductTilePrice>{product.price}</ProductTilePrice>
          </ProductTile>
        ))}
      </ProductTileGrid>
    </div>
  )
}

This example installs with everything it uses:

pnpm dlx shadcn@latest add @01orbital/product-tile-demo

Anatomy

Product Tile is built from 7 parts. In the example they nest like this:

ProductTileGrid
└─ ProductTile
   ├─ ProductTileMedia
   ├─ ProductTileLabel
   ├─ ProductTileTitle
   ├─ ProductTileDescription
   └─ ProductTilePrice
  • ProductTileGrid: grid: two columns on a phone, three from 48rem, cols from 64rem. rail: a swipe row of 70% tiles (40% from 48rem) that becomes the grid at 64rem.
  • ProductTile: The whole tile is the link: the anchor in ProductTileTitle covers it, and the tile draws the focus ring while that anchor has keyboard focus.
  • ProductTileMedia: The 4:5 frame: a direct img fills it, any other art sits centered on it.
  • ProductTileLabel: A small uppercase line above the title, such as a category or "New".
  • ProductTileTitle: Put your own <a> or framework Link inside; it stretches over the tile.
  • ProductTileDescription: A muted line under the title, such as a color or a short note.
  • ProductTilePrice: The price, in figures of even width so prices line up.

API reference

ProductTileGrid

grid: two columns on a phone, three from 48rem, cols from 64rem. rail: a swipe row of 70% tiles (40% from 48rem) that becomes the grid at 64rem.

Prop

Type

It also accepts the HTML attributes of the element it renders.

ProductTile

The whole tile is the link: the anchor in ProductTileTitle covers it, and the tile draws the focus ring while that anchor has keyboard focus.

It accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.

ProductTileMedia

The 4:5 frame: a direct img fills it, any other art sits centered on it.

It accepts the HTML attributes of the element it renders.

ProductTileLabel

A small uppercase line above the title, such as a category or "New".

It accepts the HTML attributes of the element it renders.

ProductTileTitle

Put your own <a> or framework Link inside; it stretches over the tile.

It accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.

ProductTileDescription

A muted line under the title, such as a color or a short note.

It accepts the HTML attributes of the element it renders.

ProductTilePrice

The price, in figures of even width so prices line up.

It accepts the HTML attributes of the element it renders.

Dependencies

npm: @base-ui/react, class-variance-authority, cn. The CLI installs them for you.

Used in blocks

5 blocks are built with Product Tile:

Last updated on