Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-grid-gallery

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-grid-gallery

Justified gallery component for React.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by18.45%
Maintainers
2
Weekly downloads
 
Created
Source

Justified image gallery component for React inspired by Google Photos.

: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

PropertyTypeDescription
srcstringRequired. A string referring to any valid image resource (file, url, etc).
widthnumberRequired. Width of the image.
heightnumberRequired. Height of the image.
nanostring:base64Optional. 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.
altstringOptional. Image alt attribute.
tagsarrayOptional. 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}
isSelectedboolOptional. The selected state of the image.
captionstring | ReactNodeOptional. Image caption.
customOverlayelementOptional. A custom element to be rendered as a thumbnail overlay on hover.
thumbnailCaptionstring | ReactNodeOptional. A thumbnail caption shown below thumbnail.
orientationnumberOptional. 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).
PropertyTypeDescription
imagesarrayRequired. An array of objects containing image properties (see Image Options above).
idstringOptional, default ReactGridGallery. id attribute for <Gallery> tag. This prop may be useful for those who wish to discriminate between multiple galleries.
enableImageSelectionboolOptional, 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.
onSelectfuncOptional. 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.
rowHeightnumberOptional, default 180. The height of each row in the gallery.
maxRowsnumberOptional. The maximum number of rows to show in the gallery.
marginnumberOptional, default 2. The margin around each image in the gallery.
onClickfuncOptional. 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).
tagStylefunc | CSSPropertiesOptional. Style or function that returns style to pass to tag elements. Optional args: item (the image item in images). Overrides internal tag style.
tileViewportStylefunc | CSSPropertiesOptional. Style or function to style the image tile viewport. Optional args: item (the image item in images). Overrides internal tileViewportStyle function.
thumbnailStylefunc | CSSPropertiesOptional. Style or function to style the image thumbnail. Optional args: item (the image item in images). Overrides internal thumbnailStyle function.
thumbnailImageComponentReact componentOptional. 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.
defaultContainerWidthnumberOptional. 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

Keywords

FAQs

Package last updated on 29 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc