Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Photo Gallery

ProNew

A photo gallery as a grid, masonry, justified rows, carousel, slider or thumbnail strip, with hover captions, load more and a full lightbox.

Installation

pnpm dlx shadcn@latest add @viewport/photo-gallery

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

<PhotoGallery>

PropTypeDefault
photos*GalleryPhoto[]—
layoutPhotoGalleryLayout

Grid of squares, vertical masonry, justified rows, a multi-photo carousel, a one-photo slider, or a slider with a thumbnail strip.

"grid"
titlestring

Heading shown above the photos.

—
columnsnumber

Most columns to use when there is room. Defaults to 4 for the grid and 3 for masonry and the carousel.

—
gapnumber

Space between photos, in pixels.

8
radiusnumber

Corner radius of each photo, in pixels.

16
rowHeightnumber

Target row height of the justified layout on wide screens, in pixels.

220
caption"hover" | "always" | "hide-on-hover" | "none"

When the title and description sit on the photo: on hover or focus, always, until hover, or never.

"hover"
action"lightbox" | "link" | "none"

What a click does: open the lightbox, follow the photo's `href`, or nothing.

"lightbox"
pageSizenumber

Photos shown before a “Load more” button appears. 0 shows everything. Ignored by the sliding layouts.

0
loadingboolean

Shows placeholder tiles while your photos are being fetched.

false
emptyTextstring

Message for an empty gallery.

"No photos yet"
slideshowIntervalnumber

Seconds each photo stays up while the lightbox slideshow plays.

3
onPhotoClick(photo: GalleryPhoto, index: number) => void

Called with the photo and its index whenever a tile is activated.

—
classNamestring—

<Tile>

PropTypeDefault
photo*GalleryPhoto—
index*number—
total*number—
rationumber

Width over height; leave out to fill the parent.

—
radius*number16
caption*NonNullable<PhotoGalleryProps["caption"]>"hover"
action*NonNullable<PhotoGalleryProps["action"]>"lightbox"
delay*number—
onActivate*(index: number) => void—
onRatio*(src: string, ratio: number) => void—
register*(node: HTMLElement | null) => void—

<Slides>

PropTypeDefault
photos*GalleryPhoto[]—
layout*PhotoGalleryLayout"grid"
columns*number—
gap*number8
radius*number16
renderTile*(photo: GalleryPhoto, index: number) => React.ReactNode—

<Lightbox>

PropTypeDefault
photos*GalleryPhoto[]—
index*number | null—
interval*number—
onIndex*(index: number | null) => void—

Accessibility

  • Every photo is a button named with its position and title; Load more moves focus to the first new photo.
  • The lightbox is a dialog that traps focus and returns it to the photo you opened. Left, Right, Home and End change photo, Escape closes.
  • Swipe or drag to change photo on touch screens; position and title are announced politely as they change.
  • Sliding layouts scroll natively and answer to arrow keys. No slides, zooms or fades under reduced motion.