Zoomable Justified Gallery
Justified rows of frames with varying aspect ratios filling each row. Clicking a frame opens a viewer whose picture doubles as the zoom control: clicking the image toggles between "fit to screen" and a larger "fill" crop, with caption and prev/next controls below.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its media-slot dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/zoomable-justified-gallery.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/gallery/gallery16.tsx instead.
Usage
The file also exports gallery16Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.
import { Gallery16, gallery16Demo } from "@/components/blocks/gallery/gallery16"; export default function Page() { return <Gallery16 {...gallery16Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Selected frames" | Section heading. |
| description | string | "Click any frame to open it, then click the picture itself to switch between fit and fill." | Short subheading under the heading. |
| photos | JustifiedPhoto[] | none | Photos to lay out in justified rows, each with its own aspect ratio. |
| className | string | none | Extra classes for the outer section element. |
Types
interface JustifiedPhoto { id: string; caption?: string; /** Width divided by height, used to size the frame within its justified row. */ aspectRatio: number; image?: MediaSlotImage; }
Behavior notes
- The row layout is a flex-wrap approximation of a true justified gallery: each frame's flex-grow is sized by its own aspectRatio value rather than a full justified-layout algorithm.
- Clicking the open picture toggles real useState between a letterboxed "fit" size (object-contain, capped height) and a larger "fill" size (object-cover, bigger box); this is the block's zoom control, there's no separate zoom button.
- Prev/next cycle through the photos array and intentionally leave the fit/fill toggle as-is, so browsing several photos in "fill" mode doesn't reset on every step; opening a fresh photo from the grid or closing the viewer resets it back to "fit".
More Gallery Blocks
View all →Plan Chest Sheet Stack
Ruled plan-chest drawer index that opens into a real stack viewer with a lift-and-rotate top sheet.
Wall Scale Viewer
Print grid with a wall-mockup viewer that scales the piece as you switch between size options.
Archive Record Cards
Text-first archive index that opens into a real 3D flip card of front image and back registrar notes.
Loupe Surface Studies
Square material/texture studies that open into a viewer with a real draggable magnifying loupe.
Paired Hang Compare
Two-to-a-bay staggered hang whose viewer can split into two real panes to compare a second work.
Dark Room Fade Viewer
Inverted low-light hang that opens into a chromeless viewer, the work fading up like a dimmer lamp.