Photo Stack
A pile of photos. Drag the top one aside to send it to the back, or press any photo to open it as a carousel.
Drag the top photo aside, or use the arrow keys, to send it to the back. Click any photo to open it.
Six photos sit in a loose pile. Drag the top one off either side and it carries on out, then tucks in at the back while the next comes forward. Press any photo, the top one or a sliver of one behind it, and it opens at full size with its neighbours beside it as a carousel. Swipe the carousel, use its arrows, or press Escape to put the pile back.
With the keyboard, Tab to the top photo, press ← or → to send it to the back, or Enter to open it. Once a photo is open, ← and → walk the carousel and Escape closes it.
How it works
- Every card is always mounted, and only moves. The pile and the carousel are two sets of poses for the same elements, so opening a photo is that card travelling from where it was, never a copy growing out of it.
- The poses are pure.
stack.tsturns the stage's size and one question, shut or open, into a target for every card. The component measures the stage and asks. - A drag and a spring write the same values. Each card's position, rotation, box and opacity are motion values written imperatively, so nothing renders per frame.
- A thrown card gets clear before it goes behind. It leaves on a quick ease-out, and only once just its edge still overlaps the pile does it give up its place in front, so the change of stacking order is hidden.
- Hover leans the pile out. On a mouse or pen, the cards behind fan a little wider, which is the only thing at rest that says the top photo can be moved.
- Reduced motion replaces the springs with a short ease, and a card dragged to the back goes straight there without the throw.
Cards two places from the open photo are transparent and inert. A polite live region inside the stage, which screen readers hear but sighted users do not see, announces the open photo.
Installation
Usage
import PhotoStack from "@/components/ui/photo-stack";
<PhotoStack />;The component draws its own stage and fits the photos to it. Pass your own pile with photos, and set aspect to the photos' width over height (the default pile is 4:5). Pass className to change the wrapper, and hint to change the line under the stage, or false to remove it. A new set of photos starts a new pile; a new array with the same ids does not.
<PhotoStack
aspect={3 / 4}
photos={[
{ id: "a", title: "Harbour at six", src: "/photos/harbour.jpg" },
{ id: "b", title: "Market stall", src: "/photos/market.jpg" },
{ id: "c", title: "Night train", src: "/photos/train.jpg" },
]}
/>API
| Prop | Type | Default | Description |
|---|---|---|---|
photos | readonly Photo[] | six pictures | The pile, top first. A photo is { id, title, src }. |
aspect | number | 0.8 | Width over height of every photo. |
hint | string | false | a short line | The line under the stage. false hides it. |
className | string | - | Classes for the outer wrapper. |
Photos
The default pile is six public-domain works from the Metropolitan Museum of Art's Open Access collection, released under CC0. Each is cropped to a 4:5 portrait, softened, saturated and grained so they read as one set, and they are hosted on this site, so the component adds no image weight to your bundle. Pass your own photos for anything you ship.
- Hawkmoth: Nicolaas Struyk, A Moth
- Iris: Goodwin & Company, Iris (Iris Germanica), 1890
- Turquoise wave: Christopher Dresser, Wave bowl, ca. 1880
- Peacock feather: Peacock feather brooch, late 19th century
- Mountain mist: Soga Shōhaku, Mountain Landscape, ca. 1761-63
- Phoenix: Rank Badge with Peacock, 18th century