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

org.webjars.npm:react-grid-gallery

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

org.webjars.npm:react-grid-gallery

WebJar for react-grid-gallery

  • 0.5.5
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Justified image gallery component for React inspired by Google Photos and based upon React Images.

Note:

As of the release of v0.5.4 (2019-03-10) I will no longer be actively adding features and aggressively maintaining react-grid-gallery. My online behavioral experiment platform Psychstudio consumes all of my time and I am no longer capable of giving react-grid-gallery the attention it needs. A big thanks to everyone who has contributed over the last 4 years and thanks to everyone who has downloaded react-grid-gallery (hopefully it has been useful to you).

Live Demo & Examples

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

Installation

Using npm:

npm install --save react-grid-gallery

Quick (and dirty) Start

import React from 'react';
import { render } from 'react-dom';
import Gallery from 'react-grid-gallery';

const IMAGES =
[{
        src: "https://c2.staticflickr.com/9/8817/28973449265_07e3aa5d2e_b.jpg",
        thumbnail: "https://c2.staticflickr.com/9/8817/28973449265_07e3aa5d2e_n.jpg",
        thumbnailWidth: 320,
        thumbnailHeight: 174,
        isSelected: true,
        caption: "After Rain (Jeshu John - designerspics.com)"
},
{
        src: "https://c2.staticflickr.com/9/8356/28897120681_3b2c0f43e0_b.jpg",
        thumbnail: "https://c2.staticflickr.com/9/8356/28897120681_3b2c0f43e0_n.jpg",
        thumbnailWidth: 320,
        thumbnailHeight: 212,
        tags: [{value: "Ocean", title: "Ocean"}, {value: "People", title: "People"}],
        caption: "Boats (Jeshu John - designerspics.com)"
},

{
        src: "https://c4.staticflickr.com/9/8887/28897124891_98c4fdd82b_b.jpg",
        thumbnail: "https://c4.staticflickr.com/9/8887/28897124891_98c4fdd82b_n.jpg",
        thumbnailWidth: 320,
        thumbnailHeight: 212
}]

render(
        <Gallery images={IMAGES}/>,
        document.getElementById('example-0')
);

Image Options

PropertyTypeDefaultDescription
srcstringundefinedRequired. A string referring to any valid image resource (file, url, etc).
thumbnailstringundefinedRequired. A string referring to any valid image resource (file, url, etc).
thumbnailWidthnumberundefinedRequired. Width of the thumbnail image.
thumbnailHeightnumberundefinedRequired. Height of the thumbnail image.
nanostring:base64undefinedOptional. Thumbnail Base64 image will be injected to background under the main image. This provides a base64, 4x4 generated image whilst the image is beong loaded.
altstring""Optional. Image alt attribute.
tagsarrayundefinedOptional. An array of objects containing tag attributes (value and title). e.g. {value: "foo", title: "bar"}
isSelectedboolundefinedOptional. The selected state of the image.
captionstringundefinedOptional. Image caption.
srcSetarrayundefinedOptional. Array of srcSets for lightbox.
customOverlayelementundefinedOptional. A custom element to be rendered as a thumbnail overlay on hover.
thumbnailCaptionstring|elementundefinedOptional. A thumbnail caption shown below thumbnail.
orientationnumberundefinedOptional. 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).
PropertyTypeDefaultDescription
imagesarrayundefinedRequired. An array of objects containing image properties (see Image Options above).
idstring"ReactGridGallery"Optional. id attribute for <Gallery> tag. This prop may be useful for those who wish to discriminate between multiple galleries.
enableImageSelectionbooltrueOptional. Allow images to be selectable. Setting this option to false whilst supplying images with isSelected: true will result in those images being permanently selected.
onSelectImagefuncundefinedOptional. Function to execute when an image is selected. Allows access to image object using this (See Programmers notes for more info about implicit this). Optional args: index (index of selected image in images array), image (the selected image). This function is only executable when enableImageSelection: true.
rowHeightnumber180Optional. The height of each row in the gallery.
maxRowsnumberundefinedOptional. The maximum number of rows to show in the gallery.
marginnumber2Optional. The margin around each image in the gallery.
enableLightboxbooltrueOptional. Enable lightbox display of full size image when thumbnail clicked.
onClickThumbnailfuncopenLightboxOptional. Function to execute when gallery thumbnail clicked. Allows access to image object using this (See Programmers notes for more info about implicit this). Optional args: index (index of selected image in images array), event (the click event). Overrides openLightbox.
lightboxWillOpenfuncundefinedOptional. Function to be called before opening lightbox. Allows access to gallery object using this (See Programmers notes for more info about implicit this). Optional arg: index (index of selected image in images array).
lightboxWillClosefuncundefinedOptional. Function to be called before closing lightbox. Allows access to gallery object using this (See Programmers notes for more info about implicit this).
tagStyleobjecttagStyleOptional. Style to pass to tag elements. Overrides internal tag style.
tileViewportStylefunctileViewportStyleOptional. Function to style the image tile viewport. Allows access to image object using this (See Programmers notes for more info about implicit this). Overrides internal tileViewportStyle function.
thumbnailStylefuncthumbnailStyleOptional. Function to style the image thumbnail. Allows access to image object using this (See Programmers notes for more info about implicit this). Overrides internal thumbnailStyle function.
thumbnailImageComponentReact componentundefinedOptional. 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.

Lightbox Options

NOTE: these options are passed inside the Gallery tag.

e.g.

<Gallery images={IMAGES} backdropClosesModal={true}/>
PropertyTypeDefaultDescription
backdropClosesModalboolfalseOptional. Allow users to exit the lightbox by clicking the backdrop.
currentImagenumber0Optional. The index of the image to display initially (only relevant when used in conjunction with isOpen: true property).
preloadNextImagebooltrueOptional. Based on the direction the user is navigating, preload the next available image.
customControlsarrayundefinedOptional. An array of elements to display as custom controls on the top of lightbox.
enableKeyboardInputbooltrueOptional. Supports keyboard input - esc, arrow left, and arrow right.
imageCountSeparatorstring' of 'Optional. Customize separator in the image count.
isOpenboolfalseOptional. Whether or not the lightbox is displayed when gallery first rendered (can be used in conjunction with currentImage property, otherwise the first image will be diplayed).
showCloseButtonbooltrueOptional. Display a close "X" button in top right corner.
showImageCountbooltrueOptional. Display image index, e.g., "3 of 20".
onClickImagefunconClickImageOptional. Function to execute when lightbox image clicked. Overrides internal implementation of onClickImage.
onClickPrevfunconClickPrevOptional. Function to execute when lightbox left arrow clicked. Overrides internal implementation of onClickPrev.
onClickNextfunconClickNextOptional. Function to execute when lightbox right arrow clicked. Overrides internal implementation of onClickNext.
currentImageWillChangefuncundefinedOptional. Function to execute before lightbox image change. Useful for tracking current image shown in lightbox. Allows access to gallery object using this (See Programmers notes for more info about implicit this).
showLightboxThumbnailsboolfalseOptional. Display thumbnails beneath the Lightbox image.
onClickLightboxThumbnailfuncgotoImageOptional. Function to execute when lightbox thumbnail clicked. Overrides internal function: gotoImage.
lightboxWidthnumber1024Optional. Maximum width of the lightbox carousel; defaults to 1024px.
lightBoxPropsobjectundefinedOptional. Object to pass props directly to LightBox.

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!

  • Image Options: thumbnail can point to the same resource as src, bearing in mind the resultant data size of the gallery and page load cost. Thumbnails of whatever size will be scaled to match rowHeight.

Programmers Notes

  • User defined functions that allow access to this via Function.prototype.call() do not require you to declare or pass this as a parameter. this will be defined at the time the function is called.

e.g.

// somewhere in your code...
function myTileViewportStyleFn() {
  if (this.props.item.isSelected)
    return {
           // something stylish...
            };
}

<Gallery images={IMAGES} tileViewportStyle={myTileViewportStyleFn}/>


// internally, within the react-grid-gallery component it will be called like so:
myTileViewportStyleFn.call(this); // this now refers to the image to be styled

  • If you don't know your thumbnailWidth and thumbnailHeight 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

FAQs

Package last updated on 10 Aug 2019

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