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

react-grid-gallery

Package Overview
Dependencies
Maintainers
1
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.

  • 0.1.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.5K
increased by21.64%
Maintainers
1
Weekly downloads
 
Created
Source

Justified gallery component for React.js.

No curation and no tricks, just beautifully justified images.

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,
        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,
        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
        //look ma, no caption!
}]

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.
captionstringundefinedOptional. Image caption.
srcsetarrayundefinedOptional. Array of srcsets for lightbox.
PropertyTypeDefaultDescription
imagesarrayundefinedRequired. An array of objects containing image properties (see Image Options above).
enableImageSelectionbooltrueOptional. Allow images to be selectable. Setting this option to false whilst supplying a non empty selectedImages array will result in those images being permanently selected.
selectedImagesarrayemptyOptional. An array of image indicies to set as selected upon gallery creation (Note: this selection is permanent if enableImageSelection: false).
onSelectedImagesChangefuncundefinedOptional. Function to execute when selectedImages array changes (i.e. image selection has been updated). Optional arg: selectedImages array. This function is only executable when enableImageSelection: true.
rowHeightnumber180Optional. The height of each row 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. Overrides openLightbox.

Lightbox Options

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".

Using srcset:

images={[{
  src: 'http://example.com/example/img1.jpg',
  srcset: [
    'http://example.com/example/img1_1024.jpg 1024w',
    'http://example.com/example/img1_800.jpg 800w',
    'http://example.com/example/img1_500.jpg 500w',
    'http://example.com/example/img1_320.jpg 320w',
  ],
  thumbnail: 'http://example.com/example/thumbnailImg1.jpg',
  caption: "Image 1",
  thumbnailWidth: 180,
  thumbnailHeight: 320
},
{
  src: 'http://example.com/example/img2.jpg',
  srcset: [
    'http://example.com/example/img2_1024.jpg 1024w',
    'http://example.com/example/img2_800.jpg 800w',
    'http://example.com/example/img2_500.jpg 500w',
    'http://example.com/example/img2_320.jpg 320w',
  ],
  thumbnail: 'http://example.com/example/thumbnailImg2.jpg',
  caption: "Image 2",
  thumbnailWidth: 240,
  thumbnailHeight: 165
}

Read more about the srcset and sizes attributes here: https://ericportis.com/posts/2014/srcset-sizes/.

General Notes

  • 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.

  • 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.

  • 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.

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 22 Aug 2016

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