Image Gallery

Photo gallery laid out as a masonry or uniform grid sized by its own container width, with hover zoom and caption reveal, category filters behind a gliding chip with spring layout reflow, and a lightbox that grows out of the clicked tile with prev/next, arrow keys, Escape, swipe, a counter and a focus trap; reduced motion turns every move into a fade.

Preview

Image Gallery preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/image-gallery
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

items
GalleryItem[]
—
layout?
"grid" | "masonry"

"masonry" keeps each item's aspect ratio; "grid" crops to uniform tiles.

masonry
gridAspectRatio?
number

Tile aspect ratio (width / height) for `layout="grid"`. Default 1.

1
columns?
number

Most columns the gallery will use. Default 3.

3
minColumnWidth?
number

Narrowest a column may get before one is dropped, in px. Default 170.

170
filterable?
boolean

Show category chips. Default true when items span 2+ categories.

—
categories?
string[]

Category order. Defaults to first-seen order in `items`.

—
allLabel?
string

Label of the chip that shows everything. Default "All".

All
category?
string

Controlled active category (`allLabel` or a category).

—
defaultCategory?
string
—
onCategoryChange?
((category: string) => void)
—
onOpenItem?
((item: GalleryItem) => void)

Called whenever the lightbox opens on, or navigates to, an item.

—
label?
string

Accessible name for the gallery region. Default "Gallery".

Gallery
className?
string
—

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.

Updated