Web · Components
Gallery
Image and video gallery: a grid, Pinterest-style masonry or Google Photos-style rows; grouping by date or your own criterion, iOS-like long-press multi-selection and a full-screen viewer.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Google Photos style: rows grouped by day, sticky headers, selection
Pinterest style masonry: loads as you scroll (with skeleton boxes)
Reels feed: vertical videos, swipe up to move on like Instagram
Upload to a server: progress ring, processing, error (tap to retry), an image that fails to load and renderItem
Paged grid: 240 items, 24 per page
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Image and video gallery: a grid, Pinterest-style masonry or Google Photos-style rows; grouping by date or your own criterion, iOS-like long-press multi-selection and a full-screen viewer.
- Speed: Only boxes visible on screen (and a little beyond) are rendered; positions are computed in a single number array. 100,000 items scroll smoothly. Thumbnails load lazily. With
width/height, masonry and rows render correctly before the images load. - Groups:
groupBy="day"gives "Today", "Yesterday", "Tuesday, October 28" titles; titles stick on top while scrolling, and in selection mode the circle in the title selects the whole group. - Selection: With
selectable. On touch, long press (light haptic), slide without lifting to select the ones in between; it auto-scrolls at the screen edge. On desktop click the circle, use Ctrl/⌘ and Shift, or drag to select an area. The selection bar has the count, select all and your own actions. The selection look is chosen withselectionStyle, the appearance withappear, hover withhoverEffect. - Videos: Duration in the corner; a muted preview on hover (
videoPreview). Plays withVideoPlayerin full screen. - Full screen:
Lightboxopens on click: swipe, previous/next, preloading neighbors, zoom; Instagram Reels style withlightbox={{ mode: "vertical" }}. The image grows from its thumbnail. - Many records: Infinite scroll with
onLoadMore+hasMoreor a "Show more" button; pages withpageSize. - Keyboard: Arrow keys navigate by layout (up/down to the on-screen neighbor), Enter opens, Space selects, Shift + arrow selects a range, Home/End, PageUp/PageDown.
It is a client component.
Examples
Viewer showing images and videos full screen. Used automatically inside Gallery; it can also be used on its own for your own grid or a single button.
- Navigation: Swipe sideways (the browser's own scrolling; smooth as butter), side buttons, ←/→ keys, Home/End. With
mode="vertical"you swipe up like Instagram Reels / TikTok; a video plays from the start with the last volume when it comes on screen. - Preloading: Items on both sides of the visible one (
preload) are kept ready; the next image downloads in the background and the first seconds of a video load. The thumbnail holds the place until the large one loads; there is no feeling of waiting. - Zoom: With two fingers, by double tapping/clicking and with the wheel; drag to pan while zoomed in.
- Closing: × button, Esc, the phone's back button and pulling the image down. On open the image grows from its thumbnail and returns to it on close.
- Videos: Play with
VideoPlayer; full screen, speed and PiP included. - Full screen: The button in the top bar (or F) switches to the browser's full screen; with
fullscreenit opens directly in full screen. - Selection: With
selectable, a circle in the top bar selects the current item; whileGalleryis in selection mode, selection continues on the enlarged item. - Wheel in vertical mode: Each wheel gesture advances one item.
- A single tap hides/shows the top and bottom tools. A slideshow, download, share (copies the link in unsupported browsers) and your own action buttons can be added.
- Even with a 100,000-item list only the visible one and its neighbors render.
It is a client component.
Examples
mediaType
functionType of the item: inferred from the URL extension when type is omitted.
formatDuration
functionFormats a duration as 1:05 or 1:02:05.
Examples
GalleryAction
interfaceAn action in the selection bar (e.g. Share, Delete).
| Name | Type | Description |
|---|---|---|
label | string | Button text. |
icon? | IconProp | Icon: a name or an element. |
tone? | "neutral" | "danger" | If "danger", it appears red. |
onClick | (items: GalleryItem[], clear: () => void) => unknown | Called with the selected items. If it returns a Promise, the button shows loading until it settles. Call clear() to end the selection. |
How a selected item is shown.
GalleryClassNames
interfaceClasses added to the parts of Gallery.
| Name | Type | Description |
|---|---|---|
item? | string | Each item box (e.g. rounded-none). |
header? | string | Group title. |
selectionBar? | string | Selection bar. |
Gallery pagination options: the look of pagination.
Extends: Pick<PaginationProps, "variant" | "siblings" | "boundaries" | "firstLast" | "jumper" | "summary" | "responsive" | "size" | "activeVariant" | "align" | "label" | "className" | "classNames">
| Name | Type | Default | Description |
|---|---|---|---|
sticky? | boolean | false | Page buttons stick to the bottom of the visible area: on a long page you * can change pages without scrolling to the end. The selection bar sits * above the buttons. * |
GalleryProps
interfaceProps of the Gallery component.
Extends: Omit<ComponentProps<"div">, "children" | "onSelect" | "onLoad">
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly GalleryItem[] | Items. If they are grouped, give them sorted in group order (e.g. by date). | |
layout? | GalleryLayout | "grid" | Layout: "grid" equal squares, "masonry" Pinterest-style columns (ratios kept, added to the shortest column), "rows" Google Photos / Flickr-style rows (each row fills the full width). |
columns? | number | Fixed column count. If omitted, it fits the width by itemWidth. | |
itemWidth? | number | 200 | Target item width in grid and masonry (px); determines the column count. |
minColumns? | number | 3` for grid, `2` for masonry | Minimum column count when columns is not given; the grid look is kept on phones too. |
rowHeight? | number | 200 | Target row height in the rows layout (px). On narrow screens it shrinks to as little as a third of the width. |
aspectRatio? | number | 1 | Cell ratio in the grid (width / height). |
gap? | number | 4 | Gap between items (px). |
groupBy? | GalleryGroupBy | ((item: GalleryItem, index: number) => string) | Grouping: "day" | "month" | "year" by the item's date field ("Today", "Yesterday", "Tuesday, October 28"…), or a function returning a group name from the item. Consecutive items with the same name form a group. Define the function outside the component; a new function on every render recomputes all groups. | |
groupLabel? | (key: string, info: { count: number; start: number; }) => ReactNode | Group title. If omitted, the date or group name is written. | |
stickyHeaders? | boolean | true | Group titles stay stuck on top while scrolling. If there is a fixed bar at the top of the page, give its height with stickyOffset. |
stickyOffset? | number | string | 0 | Distance of the sticky title from the top (px or a CSS value). |
selectable? | boolean | false | Multi-selection. On touch, a long press starts selection (like iOS Photos); sliding without lifting the finger selects the ones in between. In selection mode a tap selects/deselects and a sideways swipe selects by dragging. On desktop click the circle in the corner, select one by one with Ctrl/⌘, a range with Shift, or drag with the mouse to select an area. Ctrl/⌘ + A selects all, Esc clears. To see an item large while selecting, press the zoom button in the corner (or Enter); the full-screen view opens and selection continues there with the circle in the top bar. Selection made in full screen is reflected in the gallery. |
selected? | readonly string[] | Ids of the selected items when controlled. | |
defaultSelected? | readonly string[] | Initially selected ones when uncontrolled. | |
onSelectedChange? | (selected: string[]) => void | With the ids when the selection changes. | |
selectionStyle? | GallerySelectionStyle | "shrink" | Look of a selected item: "shrink" shrinks with rounded corners (iOS, Google Photos), "ring" a frame, "dim" darkens. |
selectionActions? | readonly GalleryAction[] | Actions in the selection bar. See GalleryAction. | |
selectionBar? | boolean | true | A sticky selection bar at the bottom while there is a selection. |
hoverEffect? | "zoom" | "lift" | "none" | "zoom" | On mouse hover: "zoom" the image grows, "lift" it lifts. |
effect? | EffectProp | Effect or effects of the tiles (e.g. "shine", ["tilt", "glow"]); works together with hoverEffect. If omitted, UIProvider appearance.defaults.gallery.effect. See BuiltinEffect. | |
appear? | "fade" | "scale" | "none" | "fade" | Appearance when the image loads: "fade", "scale" (growing) or "none". |
rounded? | boolean | true | Rounded corners. |
videoPreview? | "hover" | "visible" | "none" | "hover" | Preview for videos: "hover" plays muted on mouse hover, "visible" plays when visible on screen (for phone feeds), "none". A light preview video can be given for the preview. |
videoFrames? | boolean | true | For videos without a cover image (thumbnail, poster), the first frame is extracted in the browser and used as the cover: only the start of the video is downloaded, the frame is turned into a small image and cached; videos coming on screen are processed in turn (at most 3 at a time). When disabled, only a play icon is shown. Having the server generate a poster once is always cheaper. |
titles? | "hover" | "always" | Show item titles below the box: "hover" or "always". | |
overlay? | (item: GalleryItem, index: number) => ReactNode | Extra content drawn on top of the box (e.g. a like count badge). | |
renderItem? | (item: GalleryItem, context: GalleryRenderContext) => ReactNode | Render the inside of the box yourself (e.g. a document card, an audio file, custom badges). Selection, drag selection, keyboard, status indicator and full screen work as before; the built-in rendering comes via context.children. Don't do heavy work so it stays fast with many items; define the function outside the component. | |
onRetry? | (item: GalleryItem, index: number) => void | When an item with status="error" is tapped (e.g. restart the upload). If given, "Try again" appears on the tile. | |
lightbox? | boolean | LightboxOptions | true | Full-screen view opened on click. false disables it; an object gives LightboxOptions ({ mode: "vertical", download: true }). |
onItemClick? | (item: GalleryItem, index: number, event: MouseEvent<HTMLElement>) => void | When an item is clicked (outside selection mode). If you call event.preventDefault(), the full-screen view does not open. | |
onLoadMore? | () => unknown | Fetches the next items. If it returns a Promise, skeleton boxes appear at the bottom until it settles. Called while hasMore is true. | |
hasMore? | boolean | false | There are more items to fetch. |
loadMore? | "scroll" | "button" | "scroll" | When the next items arrive: "scroll" automatically near the end (infinite scroll), "button" with a "Show more" button. |
loading? | boolean | Loading: a skeleton grid if there are no items, skeleton boxes at the bottom if there are. | |
pageSize? | number | Pagination: this many items per page with page buttons at the bottom. If total is given, items is only the current page (server pagination). | |
page? | number | Page when controlled (starts at 1). | |
defaultPage? | number | 1 | Initial page when uncontrolled. |
onPageChange? | (page: number) => void | When the page changes. | |
total? | number | Total item count for server pagination. | |
pagination? | GalleryPaginationOptions | Look of the page buttons (with pageSize): e.g. { variant: "compact", firstLast: true, summary: true, jumper: true }. See PaginationProps. | |
height? | number | string | Height of the gallery's own scroll area (px or a CSS value). If omitted, it scrolls with the page (or the nearest scrolling container). | |
overscan? | number | 800 | Distance pre-rendered above and below the visible area (px). |
empty? | ReactNode | Content shown when there are no items. | |
label? | string | "Galeri" | Screen reader name. |
classNames? | GalleryClassNames | Classes added to the parts. See GalleryClassNames. |
GalleryLayout
typeGallery layout.
LightboxAction
interfaceAn action button in the full-screen view (e.g. Like, Delete, Share).
| Name | Type | Description |
|---|---|---|
label | string | Name of the button; for screen readers and the tooltip. |
icon | IconProp | Icon: a name or an element. |
tone? | "neutral" | "danger" | If "danger", it appears red. |
onClick | (item: GalleryItem, index: number) => unknown | Called with the current item on click. If it returns a Promise, the button shows loading until it settles. |
LightboxOptions
interfaceLightbox view options; Gallery's lightbox prop takes them too.
| Name | Type | Default | Description |
|---|---|---|---|
mode? | "horizontal" | "vertical" | "horizontal" | Transition direction: "horizontal" swipes sideways (like photo apps), "vertical" swipes up like Instagram Reels / TikTok; videos play when they come on screen. |
loop? | boolean | false | Go from end to start (and start to end) with the buttons and keys. |
thumbnails? | boolean | true | Thumbnail strip at the bottom (horizontal only, wide screens). |
zoom? | boolean | true | Zoom for images: with two fingers, by double tapping/clicking and with Ctrl + wheel; in horizontal and vertical mode. When zoomed in, pan with a finger. |
preload? | number | 1 | Number of items prepared in advance on each side of the visible one. Images download in the background and the first seconds of videos load; transitions don't wait. |
download? | boolean | false | Download button. |
share? | boolean | ((item: GalleryItem, index: number) => ShareContent) | false` (when enabled, the item's URL and title) | Share button. On phones the system share sheet opens; in browsers that don't support it (most desktops) the link is copied to the clipboard and the button says "Link copied". If a function is given, it returns the content to share (e.g. the page URL instead of the image itself): share={(item) => ({ url: \/photo/${item.id}\, title: item.alt })}. |
fullscreen? | boolean | false | Goes straight to the browser's full screen when opened: the address bar and tabs are hidden too. Leaving full screen (Esc or the phone's back gesture) also closes the viewer; the full screen button is not shown. If the browser doesn't allow it (e.g. iPhone Safari), it opens inside the window. |
fullscreenButton? | boolean | true | Full screen button in the top bar (the F key toggles too). Visible in supporting browsers while fullscreen is off. |
slideshow? | boolean | number | false` (4000 ms when enabled) | Slideshow button. If a number is given, the duration of each item (ms); videos advance when they end. |
captions? | boolean | true | Show the title and description at the bottom. |
videoFrames? | boolean | true | For videos without a cover image, the first frame is extracted in the browser and used as the cover in the thumbnail strip and the player. See VideoFrameImage. |
actions? | readonly LightboxAction[] | Extra action buttons. See LightboxAction. |
LightboxProps
interfaceProps of the Lightbox component.
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly GalleryItem[] | Items to show. | |
open? | boolean | Is it open when controlled? | |
defaultOpen? | boolean | false | Is it initially open when uncontrolled? |
onOpenChange? | (open: boolean) => void | When it opens or closes. | |
index? | number | Index of the shown item when controlled. | |
defaultIndex? | number | 0 | Initial index when uncontrolled. |
onIndexChange? | (index: number) => void | With the new index when the item changes. | |
onReachEnd? | () => void | Called when nearing the last items; to fetch the next page in infinite lists. When new items are added to items, it continues where it left off. | |
originRect? | (index: number) => DOMRect | null | undefined | On-screen position of the thumbnail the image grows out of / returns to on open and close. Gallery gives it itself; in your own grid return (index) => element.getBoundingClientRect(). | |
onRatio? | (item: GalleryItem, ratio: number) => void | Reports the measured aspect ratio (e.g. for the gallery layout). | |
label? | string | "Galeri" | Screen reader name of the window. |
selectable? | boolean | false | Selection: a circle in the top bar that selects the current item, the selected count and a mark on thumbnails. Gallery gives it itself while selectable; while selecting in the gallery you can see the item large and continue selecting here. |
selected? | readonly string[] | Ids of the selected items (id, or src if missing). | |
onSelectedChange? | (selected: string[]) => void | With the ids when the selection changes. | |
mode? | "horizontal" | "vertical" | "horizontal" | Transition direction: "horizontal" swipes sideways (like photo apps), "vertical" swipes up like Instagram Reels / TikTok; videos play when they come on screen. |
loop? | boolean | false | Go from end to start (and start to end) with the buttons and keys. |
thumbnails? | boolean | true | Thumbnail strip at the bottom (horizontal only, wide screens). |
zoom? | boolean | true | Zoom for images: with two fingers, by double tapping/clicking and with Ctrl + wheel; in horizontal and vertical mode. When zoomed in, pan with a finger. |
preload? | number | 1 | Number of items prepared in advance on each side of the visible one. Images download in the background and the first seconds of videos load; transitions don't wait. |
download? | boolean | false | Download button. |
share? | boolean | ((item: GalleryItem, index: number) => ShareContent) | false` (when enabled, the item's URL and title) | Share button. On phones the system share sheet opens; in browsers that don't support it (most desktops) the link is copied to the clipboard and the button says "Link copied". If a function is given, it returns the content to share (e.g. the page URL instead of the image itself): share={(item) => ({ url: \/photo/${item.id}\, title: item.alt })}. |
fullscreen? | boolean | false | Goes straight to the browser's full screen when opened: the address bar and tabs are hidden too. Leaving full screen (Esc or the phone's back gesture) also closes the viewer; the full screen button is not shown. If the browser doesn't allow it (e.g. iPhone Safari), it opens inside the window. |
fullscreenButton? | boolean | true | Full screen button in the top bar (the F key toggles too). Visible in supporting browsers while fullscreen is off. |
slideshow? | boolean | number | false` (4000 ms when enabled) | Slideshow button. If a number is given, the duration of each item (ms); videos advance when they end. |
captions? | boolean | true | Show the title and description at the bottom. |
videoFrames? | boolean | true | For videos without a cover image, the first frame is extracted in the browser and used as the cover in the thumbnail strip and the player. See VideoFrameImage. |
actions? | readonly LightboxAction[] | Extra action buttons. See LightboxAction. |
GalleryMediaType
typeType of a gallery item.
Status on the server: "uploading" (percentage via progress), "processing" (e.g. the video is being transcoded), "error" failed. Not given for a ready item.
GalleryItem
interfaceAn item of Gallery and Lightbox.
| Name | Type | Description |
|---|---|---|
id? | string | Unique id; used for selection. If omitted, src is used. |
src | string | Full-size image or video URL (opens in the full-screen view). |
thumbnail? | string | Thumbnail shown in the grid. Give it to avoid downloading large files in the grid; if omitted, src is used for images and poster for videos. |
type? | GalleryMediaType | Type. If omitted, inferred from the URL extension (.mp4, .webm, .mov → video). |
width? | number | Original width and height (px). Only their ratio is used; if given, masonry and rows render correctly before the images load and the page doesn't shift. If omitted, the ratio is measured when the image loads. |
height? | number | Original height (px). See width. |
alt? | string | Alternative text of the image; for screen readers and search engines. |
title? | ReactNode | Title; shown on top and in the caption in full screen. |
description? | ReactNode | Description; shown at the bottom in full screen. |
poster? | string | Cover image of the video. |
preview? | string | Short, light preview video played on mouse hover. If omitted, src is played muted. |
duration? | number | Duration of the video (seconds); shown in the corner like 1:24. |
date? | Date | string | number | Date; used for grouping with groupBy="day" | "month" | "year". |
placeholder? | string | Color shown until the image loads (e.g. the image's dominant color #8a9bb0) or a small blurred image (data:image/...). |
srcSet? | string | Different sizes of the image (<img srcset>); used in full screen. |
disabled? | boolean | Cannot be selected. |
status? | GalleryItemStatus | Status on the server. If given, a progress ring, "Processing" or an error is shown on the tile and the item doesn't open in full screen (it can be selected; e.g. to delete failed ones). While uploading, a local preview of the file (URL.createObjectURL) can be given as src. |
progress? | number | Progress while status="uploading", 0–1. If omitted, it spins indeterminately. |
statusText? | ReactNode | Your own text shown next to the status (e.g. "Compressing…", the error reason). |
GalleryGroupBy
typeBuilt-in grouping: by day, month or year of the item's date field.