Zoom Lightbox

Image Lightbox Gallery for React

A thumbnail that grows into a full-screen photo, pages sideways, and shrinks back into its tile when you drag it down, like Apple Photos.

  • Gallery
  • Gesture
  • Motion

Uses motion, clsx, tailwind-merge

Open in ChatGPTOpen in Claude
openDuration0.42s
openBounce0.12
closeDuration0.40s
closeBounce0.16
pageDuration0.38s
<ZoomLightbox />

The demo follows as you drag.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Zoom Lightbox: A thumbnail that grows into a full-screen photo, pages sideways, and shrinks back into its tile when you drag it down, like Apple Photos.
This demo, Gallery: A photo grid. Tap a photo, swipe or use the arrow keys to page, then drag it down and it lands back in its tile.

1. Install it:
   npx shadcn@latest add @keyframeui/zoom-lightbox-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/zoom-lightbox-demo.json instead.)
   It adds the demo, components/zoom-lightbox-demo.tsx, and the component, components/ui/zoom-lightbox.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <ZoomLightbox> on its own.

3. These props set its feel. Change them before you change the file:
   - openDuration (default 0.42): How long the photo takes to grow out of its tile to full screen, in seconds.
   - openBounce (default 0.12): Bounce of the zoom open, from 0 (none) to 1.
   - closeDuration (default 0.4): How long the photo takes to fly back into its tile, from a close or a drag down, in seconds.
   - closeBounce (default 0.16): Bounce of the flight home, from 0 (none) to 1.
   - pageDuration (default 0.38): How long paging to the next photo takes, by swipe, arrow key or trackpad, in seconds.

4. Don't change, in components/ui/zoom-lightbox.tsx:
   - The photo is laid out once in its full-screen box; looking like its tile comes only from `x`, `y`, `scale` and a rounded `clipPath` inset, all motion values, so nothing re-lays out as it moves.
   - The tile's image hides while its photo is open (`hideTile`), and `finish` shows it, closes the dialog and focuses the tile in one task, so no frame shows both or neither.
   - A lift's release goes by the projected throw, not where the finger stopped: it flies home carrying the release velocity, and grabbing it on the way back makes it the user's again.
   - Paging scrolls the next tile into view behind the viewer, so every photo has somewhere to land, and photos between `anchor` and `index` stay mounted, so a fast run never shows an empty slot.
   - Under reduced motion the photo fades instead of flying, its tile stays visible, and paging by key, button or trackpad jumps the track instead of sliding it.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/zoom-lightbox.md

Installation

Add the component on its own with the CLI, or copy the file in by hand.

The CLI writes components/ui/zoom-lightbox.tsx and installs motion, clsx and tailwind-merge. It needs the @keyframeui registry in components.json; add it once per project.

npx shadcn@latest add @keyframeui/zoom-lightbox

Examples

Finished sections built with Zoom Lightbox. Each one installs whole, with the component included.

Product Images

A storefront grid with portrait tiles and rounder corners. Captions carry the name, colorway and price.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Zoom Lightbox: A thumbnail that grows into a full-screen photo, pages sideways, and shrinks back into its tile when you drag it down, like Apple Photos.
This demo, Product Images: A storefront grid with portrait tiles and rounder corners. Captions carry the name, colorway and price.

1. Install it:
   npx shadcn@latest add @keyframeui/zoom-lightbox-products-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/zoom-lightbox-products-demo.json instead.)
   It adds the demo, components/zoom-lightbox-products-demo.tsx, and the component, components/ui/zoom-lightbox.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <ZoomLightbox> on its own.

3. These props set its feel. Change them before you change the file:
   - openDuration (default 0.42): How long the photo takes to grow out of its tile to full screen, in seconds.
   - openBounce (default 0.12): Bounce of the zoom open, from 0 (none) to 1.
   - closeDuration (default 0.4): How long the photo takes to fly back into its tile, from a close or a drag down, in seconds.
   - closeBounce (default 0.16): Bounce of the flight home, from 0 (none) to 1.
   - pageDuration (default 0.38): How long paging to the next photo takes, by swipe, arrow key or trackpad, in seconds.

4. Don't change, in components/ui/zoom-lightbox.tsx:
   - The photo is laid out once in its full-screen box; looking like its tile comes only from `x`, `y`, `scale` and a rounded `clipPath` inset, all motion values, so nothing re-lays out as it moves.
   - The tile's image hides while its photo is open (`hideTile`), and `finish` shows it, closes the dialog and focuses the tile in one task, so no frame shows both or neither.
   - A lift's release goes by the projected throw, not where the finger stopped: it flies home carrying the release velocity, and grabbing it on the way back makes it the user's again.
   - Paging scrolls the next tile into view behind the viewer, so every photo has somewhere to land, and photos between `anchor` and `index` stay mounted, so a fast run never shows an empty slot.
   - Under reduced motion the photo fades instead of flying, its tile stays visible, and paging by key, button or trackpad jumps the track instead of sliding it.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/zoom-lightbox.md

Case Study

Shots spread through an article, in different grids. The viewer pages through them in reading order and scrolls each one into view so it has a tile to land in.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Zoom Lightbox: A thumbnail that grows into a full-screen photo, pages sideways, and shrinks back into its tile when you drag it down, like Apple Photos.
This demo, Case Study: Shots spread through an article, in different grids. The viewer pages through them in reading order and scrolls each one into view so it has a tile to land in.

1. Install it:
   npx shadcn@latest add @keyframeui/zoom-lightbox-case-study-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/zoom-lightbox-case-study-demo.json instead.)
   It adds the demo, components/zoom-lightbox-case-study-demo.tsx, and the component, components/ui/zoom-lightbox.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <ZoomLightbox> on its own.

3. These props set its feel. Change them before you change the file:
   - openDuration (default 0.42): How long the photo takes to grow out of its tile to full screen, in seconds.
   - openBounce (default 0.12): Bounce of the zoom open, from 0 (none) to 1.
   - closeDuration (default 0.4): How long the photo takes to fly back into its tile, from a close or a drag down, in seconds.
   - closeBounce (default 0.16): Bounce of the flight home, from 0 (none) to 1.
   - pageDuration (default 0.38): How long paging to the next photo takes, by swipe, arrow key or trackpad, in seconds.

4. Don't change, in components/ui/zoom-lightbox.tsx:
   - The photo is laid out once in its full-screen box; looking like its tile comes only from `x`, `y`, `scale` and a rounded `clipPath` inset, all motion values, so nothing re-lays out as it moves.
   - The tile's image hides while its photo is open (`hideTile`), and `finish` shows it, closes the dialog and focuses the tile in one task, so no frame shows both or neither.
   - A lift's release goes by the projected throw, not where the finger stopped: it flies home carrying the release velocity, and grabbing it on the way back makes it the user's again.
   - Paging scrolls the next tile into view behind the viewer, so every photo has somewhere to land, and photos between `anchor` and `index` stay mounted, so a fast run never shows an empty slot.
   - Under reduced motion the photo fades instead of flying, its tile stays visible, and paging by key, button or trackpad jumps the track instead of sliding it.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/zoom-lightbox.md

Props

src Required

Typestring

ZoomLightboxItem: the full-size image shown in the viewer.

alt Required

Typestring

ZoomLightboxItem: describes the image, for both the tile and the viewer.

thumbnail

Typestring

ZoomLightboxItem: a smaller image for the tile, with the same aspect ratio. Defaults to src. The full image is preloaded on hover or focus.

caption

TypeReact.ReactNode

ZoomLightboxItem: shown under the photo in the viewer.

width / height

Typenumber

ZoomLightboxItem: intrinsic size of src. Lets the viewer size the photo before it loads. Without them the tile image's own ratio is used.

className

Typestring

ZoomLightboxItem: classes for the tile. Give it a size or aspect ratio; its corner radius carries into the zoom. ZoomLightbox also takes className and other div props for its wrapper.

imageClassName

Typestring

ZoomLightboxItem: classes for the tile's <img>.

overlayClassName

TypestringDefault"bg-background"

ZoomLightbox: classes for the backdrop behind an open photo. Items can sit anywhere inside ZoomLightbox; the viewer pages through them in document order.

openDuration

TypenumberDefault0.42

ZoomLightbox: how long the photo takes to grow out of its tile to full screen, in seconds.

openBounce

TypenumberDefault0.12

ZoomLightbox: bounce of the zoom open, from 0 (none) to 1.

closeDuration

TypenumberDefault0.4

ZoomLightbox: how long the photo takes to fly back into its tile, from a close or a drag down, in seconds.

closeBounce

TypenumberDefault0.16

ZoomLightbox: bounce of the flight home, from 0 (none) to 1.

pageDuration

TypenumberDefault0.38

ZoomLightbox: how long paging to the next photo takes, by swipe, arrow key or trackpad, in seconds.