Composition

Lightbox

Images large, one at a time, over the page: a product's photos, a portfolio piece

Markdown version for agents · 5 stories in Storybook(opens in a new tab)

Import
import { Lightbox } from '@amezquita/design-system/components/composition/Lightbox'

Live render

    Props

    PropTypeDescription
    images{ src: string; alt: string; caption?: string; width?: number; height?: number; thumbnail?: string }[]
    openboolean
    onOpenChange(open: boolean) => void
    indexnumberWhich image shows, from 0.
    onIndexChange(index: number) => void
    title?stringNames the dialog. Default "Images".
    labels?{ previous?: string; next?: string; close?: string; of?: string }Words for other languages.

    Best practices

    Do

    • Write alt for what the image shows, and put credits or places in caption.
    • Pass a smaller thumbnail for galleries.
    • Give width and height, so nothing jumps while images load.

    Don't

    • Don't use a Lightbox for content people need to act on; use a Dialog.
    • Don't autoplay through images; people move at their own pace.

    Accessibility

    • A modal dialog named by its title and position; focus starts on Close and stays inside
    • Previous and Next buttons, Left and Right, Home and End, and a sideways swipe move through the images, wrapping at the ends so no button is ever disabled
    • Each change is announced: "3 of 4: Skanderborg Lake at night"
    • Escape or Close shuts it and focus returns to what opened it, such as the thumbnail
    • Each thumbnail is a button named "Open <alt>"; the thumbnail image itself is decorative
    • Images are fitted, never cropped, and keep their space while loading when width and height are given

    Sub-components

    Imported from the same path as Lightbox.