Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
react-grid-gallery
Advanced tools
Justified gallery component for React.
https://benhowell.github.io/react-grid-gallery/
Using npm:
npm install --save react-grid-gallery
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: false,
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,
isSelected: false,
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')
);
Property | Type | Default | Description |
---|---|---|---|
src | string | undefined | Required. A string referring to any valid image resource (file, url, etc). |
thumbnail | string | undefined | Required. A string referring to any valid image resource (file, url, etc). |
thumbnailWidth | number | undefined | Required. Width of the thumbnail image. |
thumbnailHeight | number | undefined | Required. Height of the thumbnail image. |
isSelected | bool | undefined | Optional. The selected state of the image. |
caption | string | undefined | Optional. Image caption. |
srcset | array | undefined | Optional. Array of srcsets for lightbox. |
Property | Type | Default | Description |
---|---|---|---|
images | array | undefined | Required. An array of objects containing image properties (see Image Options above). |
enableImageSelection | bool | true | Optional. Allow images to be selectable. Setting this option to false whilst supplying images with isSelected: true will result in those images being permanently selected. |
onImageSelected | func | undefined | Optional. Function to execute when an image is selected. Optional arg: image (the selected image). This function is only executable when enableImageSelection: true . |
rowHeight | number | 180 | Optional. The height of each row in the gallery. |
margin | number | 2 | Optional. The margin around each image in the gallery. |
enableLightbox | bool | true | Optional. Enable lightbox display of full size image when thumbnail clicked. |
onClickThumbnail | func | openLightbox | Optional. Function to execute when gallery thumbnail clicked. Overrides openLightbox. |
Property | Type | Default | Description |
---|---|---|---|
backdropClosesModal | bool | false | Optional. Allow users to exit the lightbox by clicking the backdrop. |
currentImage | number | 0 | Optional. The index of the image to display initially (only relevant when used in conjunction with isOpen: true property). |
preloadNextImage | bool | true | Optional. Based on the direction the user is navigating, preload the next available image. |
customControls | array | undefined | Optional. An array of elements to display as custom controls on the top of lightbox. |
enableKeyboardInput | bool | true | Optional. Supports keyboard input - esc , arrow left , and arrow right . |
imageCountSeparator | string | ' of ' | Optional. Customize separator in the image count. |
isOpen | bool | false | Optional. 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). |
showCloseButton | bool | true | Optional. Display a close "X" button in top right corner. |
showImageCount | bool | true | Optional. Display image index, e.g., "3 of 20". |
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/.
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.
React Grid Gallery is free to use for personal and commercial projects under the MIT License. Attribution is not required, but appreciated.
Visual design inspired by Google Photos.
Thumbnail viewport implementation inspired by GPlusGallery by Florian Maul.
Backend lightbox functionality via React Images by jossmac.
Demo stock photos:
v0.2.3 / 2016-09-16
Image selection state now handled within image object by optional boolean prop isSelected
. This greatly reduces complexity both within and outside the component as the image itself carries it's selected state. Therefore selectedImages
prop has been removed.
onSelectedImagesChange
prop removed due to the changes outlined above.
Optional onImageSelected
prop added. This prop takes a function and an optional image object as a parameter.
isSelected
removed as first class prop on Image (now a prop on the image item passed in)
Image onToggleSelected
renamed to onImageSelected
.
FAQs
Justified gallery component for React.
The npm package react-grid-gallery receives a total of 11,234 weekly downloads. As such, react-grid-gallery popularity was classified as popular.
We found that react-grid-gallery demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.