Voltar ao ranking

benhowell/react-grid-gallery

TypeScriptbenhowell.github.io/react-grid-gallery/

Justified image gallery component for React

reactlightboximagesphotosgalleryselectablejustifiedtagstaggingthumbnailsphoto-galleryjavascript
Crescimento de estrelas
Estrelas
1.1k
Forks
214
Crescimento semanal
Issues
14
1.1k
18 de jul.19 de jul.20 de jul.20 de jul.
Artefatosnpmnpm install react-grid-gallery
README

React Grid Gallery

Justified image gallery component for React inspired by Google Photos.


After more than 10 years I've decided it's time to officially end support of the library, today, the 28th of August 2025. As I haven't used it in any project since 2015, the development and maintainence was solely for the benefit of FOSS and my goodwill towards those using this library in their own projects.

See https://github.com/benhowell/react-grid-gallery/issues/375#issuecomment-3231131756 for further details.

Feel free to continue to use, fork, fork and maintain, submit PR's, whatever. Thanks and goodbye!


:tada: v1.0.0 is out!

There are breaking changes with v0.5.x, check out the migration guide to learn more. Documentation for v0.5.x is here.

Live Demo & Examples

https://benhowell.github.io/react-grid-gallery/

Installation

Using npm:

npm install --save react-grid-gallery

Quick Start

import { Gallery } from "react-grid-gallery";

const images = [
   {
      src: "https://c2.staticflickr.com/9/8817/28973449265_07e3aa5d2e_b.jpg",
      width: 320,
      height: 174,
      isSelected: true,
      caption: "After Rain (Jeshu John - designerspics.com)",
   },
   {
      src: "https://c2.staticflickr.com/9/8356/28897120681_3b2c0f43e0_b.jpg",
      width: 320,
      height: 212,
      tags: [
         { value: "Ocean", title: "Ocean" },
         { value: "People", title: "People" },
      ],
      alt: "Boats (Jeshu John - designerspics.com)",
   },
   {
      src: "https://c4.staticflickr.com/9/8887/28897124891_98c4fdd82b_b.jpg",
      width: 320,
      height: 212,
   },
];

<Gallery images={images} />

Image Options

Property Type Description
src string Required. A string referring to any valid image resource (file, url, etc).
width number Required. Width of the image.
height number Required. Height of the image.
nano string:base64 Optional. Thumbnail Base64 image will be injected to background under the main image. This provides a base64, 4x4 generated image whilst the image is being loaded.
alt string Optional. Image alt attribute.
tags array Optional. An array of objects containing tag attributes (value, title and key if value is element). e.g. {value: "foo", title: "bar"} or {value: <a href={tag.url}>{tag.name}</a>, title: tag.title, key: tag.key}
isSelected bool Optional. The selected state of the image.
caption string | ReactNode Optional. Image caption.
customOverlay element Optional. A custom element to be rendered as a thumbnail overlay on hover.
thumbnailCaption string | ReactNode Optional. A thumbnail caption shown below thumbnail.
orientation number Optional. Orientation of the image. Many newer digital cameras (both dSLR and Point & Shoot digicams) have a built-in orientation sensor. The output of this sensor is used to set the EXIF orientation flag in the image file's metatdata to reflect the positioning of the camera with respect to the ground (See EXIF Orientation Page for more info).
Property Type Description
images array Required. An array of objects containing image properties (see Image Options above).
id string Optional, default ReactGridGallery. id attribute for <Gallery> tag. This prop may be useful for those who wish to discriminate between multiple galleries.
enableImageSelection bool Optional, default true. Allow images to be selectable. Setting this option to false whilst supplying images with isSelected: true will result in those images being permanently selected.
onSelect func Optional. Function to execute when an image is selected. Optional args: index (index of selected image in images array), image (the selected image), event. This function is only executable when enableImageSelection: true.
rowHeight number Optional, default 180. The height of each row in the gallery.
maxRows number Optional. The maximum number of rows to show in the gallery.
margin number Optional, default 2. The margin around each image in the gallery.
onClick func Optional. Function to execute when gallery image clicked. Optional args: index (index of selected image in images array), image (the clicked image), event (the click event).
tagStyle func | CSSProperties Optional. Style or function that returns style to pass to tag elements. Optional args: item (the image item in images). Overrides internal tag style.
tileViewportStyle func | CSSProperties Optional. Style or function to style the image tile viewport. Optional args: item (the image item in images). Overrides internal tileViewportStyle function.
thumbnailStyle func | CSSProperties Optional. Style or function to style the image thumbnail. Optional args: item (the image item in images). Overrides internal thumbnailStyle function.
thumbnailImageComponent React component Optional. Substitute in a React component that would get passed imageProps (the props that would have been passed to the <img> tag) and item (the original item in images) to be used to render thumbnails; useful for lazy loading.
defaultContainerWidth number Optional. Set default width for the container. This option is useful during server-side rendering when we want to generate an initial markup before we can detect the actual container width.

General Notes

  • react-grid-gallery is built for modern browsers and therefore IE support is limited to IE 11 and newer.

  • As the inspiration for this component comes from Google Photos, very small thumbnails may not be the most aesthetically pleasing due to the border size applied when selected. A sensible rowHeight default of 180px has been chosen, but rowHeights down to 100px are still reasonable.

  • Gallery width is determined by the containing element. Therefore your containing element must have a width (%, em, px, whatever) before the gallery is loaded!

  • If you don't know your width and height values, you can find these out using any number of javascript hacks, bearing in mind the load penalty associated with these methods.

Contributing

All contributions to react-grid-gallery are very welcome. Feature requests, issue reports and pull requests are greatly appreciated. Please follow the contribution guidelines

License

React Grid Gallery is free to use for personal and commercial projects under the MIT License. Attribution is not required, but appreciated.

Acknowledgements

Repositórios relacionados
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

TypeScriptnpmBSD 3-Clause "New" or "Revised" Licenselearn-to-codenonprofits
contribute.freecodecamp.org
452.2k45.6k
react/react

The library for web and native user interfaces.

JavaScriptnpmMIT Licensejavascriptreact
react.dev
246.6k51.3k
facebook/react

The library for web and native user interfaces.

JavaScriptnpmMIT Licensejavascriptreact
react.dev
233k47.8k
vercel/next.js

The React Framework

JavaScriptnpmMIT Licensereactserver-rendering
nextjs.org
141k31.5k
react/react-native

A framework for building native applications using React

C++MIT Licenseandroidapp-framework
reactnative.dev
126.2k25.2k
facebook/react-native

A framework for building native applications using React

C++MIT Licenseandroidapp-framework
reactnative.dev
120.9k24.5k
shadcn-ui/ui

A set of beautifully-designed, accessible components and a code distribution platform. Works with your favorite frameworks. Open Source. Open Code.

TypeScriptnpmMIT Licensecomponentsnextjs
ui.shadcn.com
119.4k9.5k
justjavac/free-programming-books-zh_CN

:books: 免费的计算机编程类中文书籍,欢迎投稿

GNU General Public License v3.0pythonjavascript
weibo.com/justjavac
117.7k28.2k
nextlevelbuilder/ui-ux-pro-max-skill

An AI SKILL that provide design intelligence for building professional UI/UX multiple platforms

PythonPyPIMIT Licenseai-skillsantigravity
uupm.cc
108.2k11.5k
react/create-react-app

Set up a modern web app by running one command.

JavaScriptnpmMIT Licensereactzero-configuration
create-react-app.dev
103.3k26.9k
facebook/create-react-app

Set up a modern web app by running one command.

JavaScriptnpmMIT Licensereactzero-configuration
create-react-app.dev
103.1k27k
ant-design/ant-design

An enterprise-class UI design language and React UI library

TypeScriptnpmMIT Licensereactui-kit
ant.design
98.8k54.7k