Image Gallery
Use the ImageGallery component to display a responsive collection of image cards in either a standard grid or a masonry-style layout.
Import Image Gallery
Import ImageGallery from Tavix:
import { ImageGallery } from "tavix";Component API
<ImageGallery
images={[]}
columns={3}
gap="md"
layout="grid"
className
/>Props
images: Array of image objects to render. Each item should includecontentand may include anidfor stable keys.columns: Number of columns in grid layouts. Defaults to3.gap: Gap size token for the gallery spacing. Defaults tomd.layout: Layout mode. Supported values includegridandmasonry.className: Additional class names for the gallery root.
Behavior
- Renders each image through
ImagePreviewso every item can open in a full-screen dialog. - Supports both
gridandmasonrylayouts. - Uses the image
idwhen present, otherwise falls back to its array index. - Produces a varying masonry tile size by hashing the image key.
- Returns
nullwhen theimagesarray is empty.
Examples
Standard grid
const images = [
{ id: "img-1", content: <img src="/images/one.jpg" alt="One" /> },
{ id: "img-2", content: <img src="/images/two.jpg" alt="Two" /> },
{ id: "img-3", content: <img src="/images/three.jpg" alt="Three" /> },
{ id: "img-4", content: <img src="/images/four.jpg" alt="Four" /> },
];
<ImageGallery images={images} columns={3} gap="md" layout="grid" />;Masonry layout
<ImageGallery
images={images}
columns={2}
gap="lg"
layout="masonry"
/>Empty state
<ImageGallery images={[]} />;Notes
- The gallery expects each item to render its own content, which makes it flexible for images, cards, or custom media blocks.
- The component prefers composition over a fixed data model, so the caller can provide any valid image-like content.