35
Componentregistry:componentModern collection

Contact Sheet

A grid of photo thumbnails that opens into a full-screen lightbox. It zooms out of the thumbnail you press, swipes, drags and pages with the arrow keys, has a thumbnail strip, and closes back into the photo you ended on. Built on ui-sdk's Dialog and Carousel, so the focus trap, scroll lock and ARIA are done.

Preview

Columns

Viewing–

Installation

$ npx shadcn@latest add @creative-ui/contact-sheet

On an older shadcn CLI, use the URL: npx shadcn@latest add https://ui.krutikraut.com/r/contact-sheet.json

Add `@layer ui-sdk;` at the top of your global stylesheet, above `@import "tailwindcss"`.

Usage

Example.tsx
import { ContactSheet } from "@/components/contact-sheet"

const photos = [
  { src: "/work/harbour.jpg", thumb: "/work/harbour-400.jpg", alt: "Fishing boats in a harbour at dawn", caption: "Harbour, 6 am" },
  { src: "/work/market.jpg", alt: "A spice stall at a night market" },
  // ...
]

export function Portfolio() {
  return <ContactSheet photos={photos} label="Harbour series" />
}

// Four fixed columns, wrapping round at the ends, reporting which photo is open.
<ContactSheet photos={photos} columns={4} loop onIndexChange={(i) => i !== null && track("photo_viewed", i)} />

Props

PropTypeDefaultDescription
photos*ContactSheetPhoto[]—Each photo is { src, alt, thumb?, caption? }. thumb is a smaller file for the grid and the strip; src is what the lightbox shows. src must be unique: it is the key.
labelstring"Photos"Names the grid for screen readers, and titles the lightbox and its carousel.
columnsnumber—A fixed column count. Without it the grid fits as many 9rem columns as there's room for.
loopbooleanfalseNext on the last photo goes to the first, and back from the first reaches the last.
frameNumbersbooleantrueSmall numbers under each thumbnail, like the frame numbers on a darkroom contact sheet.
onIndexChange(index: number | null) => void—Called with the photo's index, from 0, as the lightbox opens and pages, and with null when it closes.

Also accepts every div prop, which is spread onto the root element.

Also exported

type ContactSheetPhoto
The shape of one photo.

Notes

  • Built on @ui-sdk/react Dialog and Carousel, which handle the focus trap, Escape, scroll lock, swipe and drag, arrow keys and the ARIA. Add @layer ui-sdk; at the top of your global stylesheet, above @import "tailwindcss", so your styles win over the few rules ui-sdk adds.
  • The lightbox opens from the thumbnail you pressed and closes into the photo you ended on, and focus goes back to that thumbnail, not the one you started from.
  • Left and Right page from anywhere in the lightbox. The thumbnail strip is a tablist: one Tab stop, arrows to move, Home and End for the ends.
  • Photos next to the current one load eagerly and the rest lazily, so a long sheet costs the grid's thumbnails up front. Give thumb a small file for a fast grid.
  • The lightbox is always dark, whatever the page theme, so photos are judged against black. Reduced motion keeps the fade and drops the zoom.
  • @ui-sdk/react needs React 19 and, with TypeScript, @types/react 19.2.10 or newer. It's in beta: this item pins 0.1.0-beta.20.

Dependencies

@ui-sdk/react@0.1.0-beta.20@ui-sdk/core@0.1.0-beta.20lucide-reactshadcn/utils