Skip to content
synccn

Lightbox

New

Image grid with a full-screen viewer, swipe and keyboard.

Click an image. Use ← → to browse and Esc to close.

Installation

$ pnpm dlx shadcn@latest add @synccn/lightbox

First time in this project? Connect synccn with one command.

Usage

import { Lightbox } from "@/components/ui/lightbox";<Lightbox items={photos} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

Lightbox

Thumbnail grid that opens a full-screen viewer with arrows, swipe, keyboard (←, →, Esc) and a thumbnail strip. items: [{ id, thumb: ReactNode, full: ReactNode, caption? }]

  • itemsrequired
    LightboxItem[]

    Images.

  • columns
    2 | 3 | 4

    Default 3

    Thumbnail columns.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseFocusTrap (keeps focus inside while open), useIsClient (renders portals only in the browser), useLockScroll (locks page scroll while open)

npm packages

Keyboard

  • ←or→Previous or next image
  • EscClose
  • TabMove focus; it stays inside while open

Accessibility

  • Swipe left or right on touch screens. Thumbnails mark the current image with aria-current.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: dialog
  • ARIA attributes: aria-current, aria-label, aria-modal
  • Keys handled: ArrowLeft, ArrowRight, Escape
  • Keeps keyboard focus inside while open, and returns it when closed
  • Stops the page behind from scrolling while open
  • Shows a visible focus ring for keyboard users