Dashral Pro is hereSee pricing

Dashral

LightboxNew

A grid of pictures that opens each one large, with arrows, swipes and captions.

$ pnpm dlx shadcn@latest add @dashral/lightbox

Installation

$ pnpm dlx shadcn@latest add @dashral/lightbox

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/lightbox.json

Usage

example.tsx
import { Lightbox } from "@/components/dashral/lightbox"

<Lightbox images={photos.map((photo) => ({ src: photo.url, alt: photo.alt, caption: photo.caption }))} columns={3} />

Using the npm package? Import from @dashral/ui/components/lightbox instead, here and in the examples; the rest is the same.

Examples

Product photos

thumbnails={false}: your own cover opens the viewer at its picture, controlled with open and index.

API reference

Lightbox

PropTypeDefault
images{ src, alt, thumbnail?, caption?, width?, height? }[]

The pictures. Required.

—
columns2 | 3 | 4 | 5

The thumbnails' columns from the sm breakpoint (two on phones).

3
rationumber

The thumbnails' shape.

4 / 3
thumbnailsboolean

false: no grid, open it yourself with open and index.

true
open / onOpenChange

Control the viewer.

—
index / onIndexChangenumber

The picture shown, from 0.

—
imageAsElementType

Your image component, e.g. Next.js Image.

"img"
classNames{ grid, thumbnail, viewer, image, caption }

Classes for each part.

—
classNamestring

The grid's classes.

—

Keyboard

KeysAction
EnterorSpaceOpen the picture (on a thumbnail)
←or→The previous or next picture (in reading order: reversed in Arabic)
HomeorEndThe first or last picture
EscapeClose, back to the thumbnail it came from

Accessibility

  • Each thumbnail is a button named "View" and its alt text. The viewer is a dialog named by the picture's alt; focus stays inside.
  • The position ("2 of 6") is announced as it changes.
  • Its words come from the kit's messages, so a LocaleProvider translates them.

Motion

  • The viewer fades and grows in on the spring. Moving between pictures, the one on screen stays until the next has loaded, then the two cross: the old one fades out toward the side it's left on, the new one fades in from the side it comes from (reversed in Arabic). A sideways swipe moves between them on a touch screen.