Command Palette

Search for a command to run...

0GitHub stars
Components

Perspective stack gallery

An interactive 3D perspective card stack gallery with receding depth geometry, tactile hover-peek previews, forward-tilting exit transitions, wheel and swipe navigation, and a vertical dot indicator rail.

Loading…
Dependencies (1)

Overview and background

The perspective stack gallery is inspired by tangible desk card catalogs and physical paper decks arranged in spatial depth. Rather than a flat, linear carousel, it positions cards along a receding 3D Z-plane with non-linear exponential vertical offset decay, modeled by the geometric series:

y_n = sum(k = 1 to n) [-27 * 0.915^(k-1)]

As cards recede further into the stack, each subsequent card undergoes compounding scale compression (S_n = 0.946^n), mimicking real-world optical perspective with a virtual focal distance of 1150px and perspective origin at (50%, 42%). Cards hovering in the background stack lift upward by -24px with a subtle forward tilt to reveal their contents before selection. When advancing forward, departing cards release into an independent flight layer with a -76° forward X-axis pitch and downward acceleration, powered by critically-damped spring mechanics (k = 290, d = 30, m = 0.88).

Features

  • Non-linear 3D depth stack with exponential scale compression and realistic perspective shadow grounding.
  • Tactile hover-peek interactions that elevate background cards without disrupting the active focal card.
  • Natural multi-modal navigation supporting mouse wheel scrolling, vertical swipe gestures, dot indicators, and keyboard arrows.
  • Independent forward exit flight layer executing non-blocking exit animations during rapid transitions.
  • Automatic theme adaptation for dark, light, and system color schemes with matched radial shadow intensities.
  • Comprehensive accessibility with ARIA carousel landmarks, roving focus, and graceful prefers-reduced-motion fallbacks.

Use cases

  • Creative agency portfolios highlighting selected client projects and visual identity case studies.
  • Product feature exploration decks presenting architectural diagrams, mockups, and high-impact screenshots.
  • Editorial photography collections, album artwork showcases, and curated digital asset galleries.
  • Landing page hero focal pieces replacing static hero images with interactive spatial previews.

Installation

pnpm dlx shadcn@latest add @abushaidislam/perspective-stack-gallery

Usage

import PerspectiveStackGallery, {
  type GalleryCardItem,
} from "@/components/perspective-stack-gallery"
const CARDS: GalleryCardItem[] = [
  { id: "1", title: "Velvet", category: "Chromatic", artwork: "velvet" },
  { id: "2", title: "Warmth", category: "Soleil", artwork: "warmth" },
  {
    id: "3",
    title: "Summit",
    category: "Alpine Collective",
    artwork: "summit",
  },
  { id: "4", title: "Dusk", category: "Violet Hour", artwork: "dusk" },
]
 
export function GalleryExample() {
  return (
    <PerspectiveStackGallery
      items={CARDS}
      visibleCards={8}
      enableWheel={true}
      showIndicators={true}
      onSelectCard={(item, index) => console.log("Selected:", item.title)}
    />
  )
}

Composition

PerspectiveStackGallery (region, role="carousel", tabIndex=0)
├── Header (metadata bar)
│   └── AnimatePresence (category eyebrow + card title crossfade)
├── Stage (perspective: 1150px)
│   ├── Perspective Floor Shadow (radial-gradient blur grounding)
│   ├── Visible Stack (receding cards, z-index ordered)
│   │   └── motion.button (card container, artwork/image, hover lift)
│   └── Exiting Cards Layer (non-blocking forward tilt exit)
└── Dot Rail (nav indicators)
    └── Dot Buttons (spring scale animation)

API reference

PerspectiveStackGalleryProps

PropTypeDefaultDescription
itemsGalleryCardItem[]DEFAULT_GALLERY_ITEMSArray of card data objects containing id, title, category, and image/artwork.
initialIndexnumber0Zero-based index of the card initially placed at the front of the stack.
activeIndexnumberundefinedOptional controlled active card index.
onActiveIndexChange(index: number) => voidundefinedCallback invoked when the active card changes through user interaction.
onSelectCard(item: GalleryCardItem, index: number) => voidundefinedCallback fired when a card is clicked or selected.
visibleCardsnumber10Maximum number of cards rendered simultaneously in the visual depth buffer (clamped between 3 and 12).
enableWheelbooleantrueWhether vertical trackpad/mouse-wheel scrolling steps through the card deck.
showIndicatorsbooleantrueWhether the vertical dot rail indicator is rendered along the right edge.
theme"auto" | "light" | "dark""auto"Visual theme override for background contrast, typography, and shadow depth.

GalleryCardItem

PropertyTypeDescription
idstringUnique identifier for key tracking and transition caching.
titlestringPrimary headline displayed in the header and card accessibility label.
categorystringUppercase category eyebrow label displayed above the title.
imagestringOptional URL to an image asset covering the card surface.
artworkstringBuilt-in procedural vector artwork theme ("velvet", "warmth", "summit", "dusk", "stripes", "tidal", "sands", "midnight", "horizon", "abyss", "glow", "teal").

Accessibility

  • Roles & landmarks: The root container declares role="region" with aria-roledescription="carousel" and aria-label="3D perspective stack gallery".
  • Keyboard navigation: When focused, the component responds to keyboard shortcuts:
    • ArrowRight / ArrowDown: Advances to the next card in the stack.
    • ArrowLeft / ArrowUp: Returns to the previous card.
    • Home: Immediately jumps to the first card.
    • End: Immediately jumps to the last card.
  • Card announcements: Individual cards are accessible <button> elements with descriptive labels combining title and category (aria-label="${title} — ${category}"), with the front card marked aria-current="true".
  • Reduced motion: When prefers-reduced-motion: reduce is detected, 3D rotations, tilting forward exits, and perspective spring lifts are deactivated in favor of instantaneous opacity transitions.

Frequently asked questions

How does the component handle performance with many cards?

The component limits rendered DOM nodes to visibleCards (defaults to 10, clamped between 3 and 12), regardless of total items. Cards beyond the visible threshold are excluded from the render tree until stepped into range. All spatial movement operates exclusively on GPU-accelerated CSS properties (transform: translateY, scale, rotateX and opacity), preventing browser layout thrashing and repaint spikes.

Can custom image URLs or arbitrary React components be used on cards?

Yes. Provide an image prop in the GalleryCardItem object to render high-resolution photos or render custom cover artwork. When neither image nor artwork is specified, the card defaults to a modern abstract procedural teal gradient.

How does wheel navigation prevent accidental double-skips?

Wheel delta accumulation is throttled using a time-lock window of 135ms and an absolute threshold of 28px. This debounce filter ensures that momentum scrolling from Apple magic mice and trackpads registers cleanly as discrete single-card advancements.

License and usage

  • Free to use and modify in both personal and commercial projects.
  • Attribution is appreciated but not required.
  • Released under the MIT License.

Was this helpful?

Command Palette

Search for a command to run...