Product Gallery
ComponentsProduct Gallery
CardsNew

Product Gallery

Show the product from every useful angle. Thumbnail navigation and an expanded image viewer, built for detail pages and collections.

USE IT FORProduct detail pagesDesign object collectionsMaterial and finish previews
React + CSS
Live component. Go ahead, interact.
01

Installation

Run this in your shadcn-configured React project. The component and stylesheet are added together.

TERMINAL
npx shadcn@latest add http://localhost:5173/r/product-gallery.json

This command uses the current site address. For localhost, keep this preview running on the same computer. Files follow your configured components alias.

02

Usage

Import the component and make the details your own.

TypeScript
import { ProductGallery } from '@/components/anticraft/ProductGallery';

export function Example() {
  return (
    <ProductGallery
      title="The Everyday Tote"
      defaultValue="front"
      items={[
        { id: 'front', src: '/images/tote-front.jpg', alt: 'Natural canvas tote exterior', caption: 'The Everyday Tote in natural canvas.' },
        { id: 'inside', src: '/images/tote-interior.jpg', alt: 'Tote interior with two pockets', caption: 'Two inside pockets keep small essentials close.' },
        { id: 'detail', src: '/images/tote-detail.jpg', alt: 'Close view of the reinforced canvas stitching', caption: 'Reinforced stitching at the handles.' },
        { id: 'side', src: '/images/tote-side.jpg', alt: 'Side profile showing the tote depth and shoulder strap' },
      ]}
    />
  );
}
03

Props

PropTypeDefaultDescription
itemsProductGalleryItem[]RequiredImages with unique id, src, and meaningful alt text. Optional caption adds visible context; optional thumbnail supplies a smaller thumbnail source. Supply your own files for the example image paths. An empty array displays a placeholder without controls.
items[].src / altstringRequiredThe original image URL and its accessible description. The same original appears in the main stage and the expanded viewer. Images use object-fit: contain so details are not cropped.
items[].captionstringundefinedOptional visible caption beneath both views. Keep essential visual information in alt text, too.
items[].thumbnailstringitems[].srcOptional smaller image for the thumbnail rail. Thumbnail artwork is decorative because each button already describes the image it selects.
titlestring'A closer look'A visible heading that also labels the expanded image viewer. An empty string hides the gallery heading; both views retain accessible fallback labels.
defaultValuestringFirst itemThe selected image id on the initial render. An unknown or removed id falls back to the first available image.
onValueChange(id: string) => voidundefinedCalled when a visitor selects a different image, including selection inside the expanded viewer. Supply callbacks from a Client Component in Next.js.
classNamestring''Additional classes. Theme with --ac-product-surface, --ac-product-stage, --ac-product-ink, --ac-product-muted, --ac-product-line, and --ac-product-accent on the root.
04

Motion & accessibility

Considered by default.

Choose a thumbnail, or use the previous and next buttons to wrap through the images. Left/Right, Home, and End also select images when a thumbnail has keyboard focus; page-wide shortcuts are not captured. A polite count announces the current position. Expand image opens a native modal with a larger contained image, caption, and its own previous and next controls. The viewer traps focus, closes with Escape or its visible Close button, restores the opener, and temporarily locks background scrolling. Selection in the viewer updates the main gallery. Removing the selected image safely falls back to the first image; removing every image closes an open viewer. A short image entrance is removed for reduced motion. There is no automatic cycling or required swipe gesture. The KIN product artwork in the live demo is original example artwork.

Use semantic content and meaningful labels in your composition. Check contrast and keyboard behavior with your own styles and content.