# Lightbox

A modal image and video viewer with gallery navigation.

A modal image and video viewer with gallery navigation.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/dialog">Base UI Dialog</a> for upstream
  behavior and configuration. Zenos owns the public API, styling, and composition shown on this
  page.
</p>

```tsx
import { Button, Lightbox } from "@zentara-co/zenos-ui";
import { useState } from "react";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function LightboxExample() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button variant="primary" onClick={() => setOpen(true)}>
        View image
      </Button>
      <Lightbox
        open={open}
        onOpenChange={setOpen}
        media={{
          src: thumbnailPhotos.moraineLake.src,
          alt: thumbnailPhotos.moraineLake.alt,
          caption: "Moraine Lake, Banff",
        }}
      />
    </>
  );
}
```

The examples use photographs from Unsplash by [ConfinedRiley](https://unsplash.com/photos/a-lake-surrounded-by-mountains-mIj8Cn3oNDg), [Tim G](https://unsplash.com/photos/snow-capped-mountains-reflected-in-a-calm-lake-BrFSOHMGuak), and [Sebastian Schuster](https://unsplash.com/photos/modern-building-exterior-with-strong-geometric-shadows-A-13PmQkP1o).

## Import

```tsx
import { Lightbox } from "@zentara-co/zenos-ui";
```

Lightbox is a controlled or uncontrolled fullscreen viewer. The application owns the trigger so the same viewer can open from a button, thumbnail, or other product-specific surface.

## Gallery

Pass an ordered media array to enable previous, next, counter, and arrow-key navigation. Control `index` when external triggers must open a specific item.

```tsx
import { Button, Lightbox, Stack } from "@zentara-co/zenos-ui";
import { useState } from "react";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

const lightboxGallery = [
  { ...thumbnailPhotos.moraineLake, caption: "Moraine Lake, Banff" },
  { ...thumbnailPhotos.lakeMatheson, caption: "Lake Matheson, New Zealand" },
  { ...thumbnailPhotos.architecture, caption: "Geometric architecture" },
];

function LightboxGalleryExample() {
  const [open, setOpen] = useState(false);
  const [index, setIndex] = useState(0);
  return (
    <>
      <Stack direction="row" gap="3" wrap="wrap" justify="center">
        {lightboxGallery.map((item, itemIndex) => (
          <Button
            key={item.alt}
            variant="primary"
            onClick={() => {
              setIndex(itemIndex);
              setOpen(true);
            }}
          >
            {item.caption}
          </Button>
        ))}
      </Stack>
      <Lightbox
        open={open}
        onOpenChange={setOpen}
        media={lightboxGallery}
        index={index}
        onIndexChange={setIndex}
      />
    </>
  );
}
```

## Zoom and pan

Set `hasZoom` for images that benefit from close inspection. Users can double-click, press Enter or Space, or use `+` and `−` to change zoom. Arrow keys pan while zoomed, and pointer dragging is also supported.

```tsx
import { Button, Lightbox } from "@zentara-co/zenos-ui";
import { useState } from "react";

const thumbnailPhotos = {
  moraineLake: {
    src: "https://images.unsplash.com/photo-1669604120699-eeba651ac235?auto=format&fit=crop&w=1600&q=80",
    alt: "Turquoise Moraine Lake surrounded by evergreen forest and mountains",
    label: "moraine-lake.jpg",
  },
  lakeMatheson: {
    src: "https://images.unsplash.com/photo-1768160864911-90f7837453a2?auto=format&fit=crop&w=1600&q=80",
    alt: "Snow-capped Southern Alps reflected in Lake Matheson",
    label: "lake-matheson.jpg",
  },
  architecture: {
    src: "https://images.unsplash.com/photo-1761600577035-c9cb717c7059?auto=format&fit=crop&w=1600&q=80",
    alt: "Minimal modern building with strong geometric shadows",
    label: "architecture.jpg",
  },
} as const;

function LightboxZoomExample() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button variant="primary" onClick={() => setOpen(true)}>
        Open zoomable image
      </Button>
      <Lightbox
        open={open}
        onOpenChange={setOpen}
        media={{
          src: thumbnailPhotos.architecture.src,
          alt: thumbnailPhotos.architecture.alt,
          caption: "Double-click, press Enter, or use + and − to zoom.",
        }}
        hasZoom
      />
    </>
  );
}
```

## Video

Set a media item's `type` to `"video"` to render native video controls. `hasAutoPlay` requests playback when the viewer opens; browser autoplay policy still applies.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| media | LightboxMedia \| LightboxMedia[] | — | A single image or video, or an ordered gallery. |
| open | boolean | — | Controlled open state. |
| defaultOpen | boolean | false | Initial uncontrolled state. |
| onOpenChange | (open: boolean, eventDetails) => void | — | Runs when visibility changes. |
| index / defaultIndex | number | 0 | Controlled or initial gallery index. |
| onIndexChange | (index: number) => void | — | Runs when gallery navigation requests another item. |
| hasZoom | boolean | false | Enables image zoom and pan. |
| hasAutoPlay | boolean | false | Starts video playback automatically. |
| className / style | string / CSSProperties | — | Customizes the fullscreen viewer popup. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Lightbox uses Base UI Dialog for modal focus management, Escape handling, outside interaction, and focus restoration. Every media item requires meaningful `alt` text, which also names the dialog and video. Captions describe the active item. Left and Right Arrow navigate a gallery when focus is on the viewer, and the counter announces index changes politely. Reduced-motion preferences disable viewer animations.

Source: https://zenos-ui.pages.dev/components/lightbox/