vaiperui

components / gallery

Gallery

Responsive grid of thumbnails that opens a full-screen viewer.

How to use

Pass `items` (`src`, `alt`, optional `thumbnail` and `caption`). Each thumbnail is a button that opens the `Lightbox` on that image; focus returns to the thumbnail on close. Control the grid with `columns`, `gap` and `aspectRatio`, or turn the viewer off with `lightbox={false}` and use `onItemClick`.

preview
Gallery.tsx
import { Gallery } from "vaiperui";
<Gallery
aria-label="Trip photos"
columns={3}
items={[
{ src: "/photos/road.jpg", alt: "Mountain road", caption: "Road" },
{ src: "/photos/sky.jpg", alt: "Starry sky", thumbnail: "/photos/sky-sm.jpg" },
]}
/>

Columns

preview
2
4 · 1 / 1
columns.tsx
<Gallery columns={2} items={items} />
<Gallery columns={4} aspectRatio="1 / 1" items={items} />

Radius and gap

preview
none · 2
lg · 16
radius.tsx
<Gallery radius="none" gap={2} items={items} />
<Gallery radius="lg" gap={16} items={items} />

Without viewer

preview
lightbox={false}
no-viewer.tsx
<Gallery lightbox={false} onItemClick={(item, i) => select(i)} items={items} />

Props

PropValuesDefaultDescription
items{ src, alt, thumbnail?, caption? }[]—Images. `thumbnail` is used in the grid, `src` in the viewer
columnsnumber3Grid columns
gapnumber8Space between thumbnails, in px
aspectRatiostring4 / 3CSS aspect ratio of each thumbnail
lightboxbooleantrueOpen the viewer on click
onItemClick(item, index) => voidnoneCalled on every thumbnail click
openLabel(item, index) => stringOpen image N: altAccessible name of each thumbnail button
lightboxProps{ label, closeLabel, previousLabel, nextLabel, counterLabel }noneTexts of the viewer
radiusnone | sm | md | lg | fullmdThumbnail rounding
animationnone | smooth | fast | bouncesmoothHover zoom transition
aria-labelstringnoneDescribes the list of images

Accessibility

  • Items are a list (`<ul aria-label>`), and each thumbnail is a real `<button>`, reachable with Tab and activated with Enter or Space.
  • Each button is named by `openLabel(item, index)`, which by default is `Open image N: <alt>`.
  • `alt` is required on every item and is used on the thumbnail and in the viewer.
  • The hover caption is also shown when the button has keyboard focus.
  • With `lightbox`, the click opens the `Lightbox` (a modal dialog); without it, the buttons only call `onItemClick`.

Keyboard

KeyAction
TabMoves between thumbnails
Enter / SpaceOpens the image in the viewer

Keep in mind

  • Write a real `alt` for each image (describe it, or use an empty string only for purely decorative ones, which should not be in a gallery); the component does not check it.
  • Pass `aria-label` for the list and translate `openLabel` for the page language.