Skip to content
New

Gallery, grid

beta

Three to twelve photos in a grid, the first one large; a photo opens in a dialog with its caption and arrows.

npx rasengan-ui add gallery-grid
Use it
Showing the place, the dishes or the work, when photos sell better than words.
Avoid it
Fewer than three good photos; product photos to buy from.
Built with
DialogButton

Installation

Terminal
npx rasengan-ui add gallery-grid

It installs into components/blocks/gallery-grid/, with what it uses (Dialog, Button) and lib/blocks.ts.

Usage

Without content, the block shows its example. Pass your own, typed by the block's schema, from a content file (here, the example with one field changed):

app/_routes/index.page.tsx
import { GalleryGrid } from "@/components/blocks/gallery-grid";
import { home } from "@/content/home";
 
export default function Home() {
  return <GalleryGrid content={home.gallery} />;
}
content/home.ts
import { example, type GalleryGridContent } from "@/components/blocks/gallery-grid";
 
export const home = {
  gallery: {
    ...example,
    title: "The place",
  } satisfies GalleryGridContent,
};

The first photo is shown two by two. A photo opens in a Dialog, large, with its caption; the arrows and the arrow keys move to the others. Captions also show over the photo on hover and focus.

Content

FieldTypeLimitsGuidance
titlestring2–48 chars'The place', 'From our kitchen'.
sublineoptionalstring≤ 160 chars
photosobject[]3–12 itemsThe first is shown large. Real photos of the place, the dishes, the team.
photos[].srcstringA local path ('/images/terrace.jpg') or the project's asset URL.
photos[].altstring≤ 140 charsWhat the image shows, for people who cannot see it. Empty only if purely decorative.
photos[].widthinteger
photos[].heightinteger
photos[].captionoptionalstring≤ 80 charsShown under the photo when it is open.
labelsobjectThe names of the buttons in the open photo, for screen readers.
labels.previousstring1–24 chars'Previous photo'
labels.nextstring1–24 chars'Next photo'

Props

PropNotes
contentGalleryGridContent; the example when left out
idthe section's id, for anchor links; "gallery" by default
headingLevel1, 2 or 3: the heading's tag; 2 by default
classNameon the <section>, for spacing

Accessibility

  • Each photo is a button named by its alt; the Dialog traps focus and closes with Escape.
  • The previous and next buttons are named by labels.