Skip to content
ContentImage gridMenu

Image grid

One to four images in a fixed-shape grid, with a +N tile for the rest and a shared lightbox you can page through.

Seven research results in four tiles, with a +N count that opens the lightbox.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/image-grid.json

Usage

tsx
import { ImageGrid } from "@/components/ui/chatcn/image-grid"

<ImageGrid images={results.map((r) => ({ src: r.url, alt: r.title, placeholder: r.thumb }))} />

Examples

Layouts

One image keeps its own shape. Two sit side by side, three lead with a tall tile, four make a square. The grid keeps its shape while images load, so the message never jumps.

One, two, three and four image layouts.

Props

PropTypeNotes
imagesImageSource[]{ src, alt, width?, height?, placeholder?, caption?, filename? }
maxnumberTiles before the last one shows +N. Default and maximum 4
downloadbooleanDownload action in the lightbox. Default true

Keyboard

KeyAction
TabMove between tiles
Enter, SpaceOpen the lightbox at that image
Left, RightPage through every image, including the hidden ones
EscClose the lightbox

Accessibility

  • Each tile is a button named after its image. The +N tile says how many more images it opens.
  • The lightbox counter reads 3 of 7 in tabular figures.

Motion

  • Tiles fade in as their images decode, each on its own schedule. There is no stagger.
  • The +N wash lightens on hover over 150 ms, on fine pointers only.