Photo Gallery
ProNewA photo gallery as a grid, masonry, justified rows, carousel, slider or thumbnail strip, with hover captions, load more and a full lightbox.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
<PhotoGallery>
| Prop | Type | Default |
|---|---|---|
| photos* | GalleryPhoto[] | — |
| layout | PhotoGalleryLayoutGrid of squares, vertical masonry, justified rows, a multi-photo carousel, a one-photo slider, or a slider with a thumbnail strip. | "grid" |
| title | stringHeading shown above the photos. | — |
| columns | numberMost columns to use when there is room. Defaults to 4 for the grid and 3 for masonry and the carousel. | — |
| gap | numberSpace between photos, in pixels. | 8 |
| radius | numberCorner radius of each photo, in pixels. | 16 |
| rowHeight | numberTarget row height of the justified layout on wide screens, in pixels. | 220 |
| caption | "hover" | "always" | "hide-on-hover" | "none"When the title and description sit on the photo: on hover or focus, always, until hover, or never. | "hover" |
| action | "lightbox" | "link" | "none"What a click does: open the lightbox, follow the photo's `href`, or nothing. | "lightbox" |
| pageSize | numberPhotos shown before a “Load more” button appears. 0 shows everything. Ignored by the sliding layouts. | 0 |
| loading | booleanShows placeholder tiles while your photos are being fetched. | false |
| emptyText | stringMessage for an empty gallery. | "No photos yet" |
| slideshowInterval | numberSeconds each photo stays up while the lightbox slideshow plays. | 3 |
| onPhotoClick | (photo: GalleryPhoto, index: number) => voidCalled with the photo and its index whenever a tile is activated. | — |
| className | string | — |
<Tile>
| Prop | Type | Default |
|---|---|---|
| photo* | GalleryPhoto | — |
| index* | number | — |
| total* | number | — |
| ratio | numberWidth over height; leave out to fill the parent. | — |
| radius* | number | 16 |
| caption* | NonNullable<PhotoGalleryProps["caption"]> | "hover" |
| action* | NonNullable<PhotoGalleryProps["action"]> | "lightbox" |
| delay* | number | — |
| onActivate* | (index: number) => void | — |
| onRatio* | (src: string, ratio: number) => void | — |
| register* | (node: HTMLElement | null) => void | — |
<Slides>
| Prop | Type | Default |
|---|---|---|
| photos* | GalleryPhoto[] | — |
| layout* | PhotoGalleryLayout | "grid" |
| columns* | number | — |
| gap* | number | 8 |
| radius* | number | 16 |
| renderTile* | (photo: GalleryPhoto, index: number) => React.ReactNode | — |
<Lightbox>
| Prop | Type | Default |
|---|---|---|
| photos* | GalleryPhoto[] | — |
| index* | number | null | — |
| interval* | number | — |
| onIndex* | (index: number | null) => void | — |
Accessibility
- Every photo is a button named with its position and title; Load more moves focus to the first new photo.
- The lightbox is a dialog that traps focus and returns it to the photo you opened. Left, Right, Home and End change photo, Escape closes.
- Swipe or drag to change photo on touch screens; position and title are announced politely as they change.
- Sliding layouts scroll natively and answer to arrow keys. No slides, zooms or fades under reduced motion.