Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

image-tab-lightbox

sevenLee3MIT0.6.0

A simple, responsive lightbox component for displaying an array of images with React.js

react, react-component, react-images, react-lightbox, react-carousel, react-gallery, react images, react lightbox, react carousel, react gallery, lightbox, carousel, gallery

readme

React Images

react-images on npm Join the chat at https://gitter.im/react-images/Lobby

A simple, responsive lightbox component for displaying an array of images.

Quick start

npm install --save react-images

or

yarn add react-images
import React from 'react';
import Lightbox from 'react-images';

export default class Sample extends React.Component {
  ...
  render() {
    return (
      <Lightbox
        images={[{ src: 'http://example.com/img1.jpg' }, { src: 'http://example.com/img2.jpg' }]}
        isOpen={this.state.lightboxIsOpen}
        onClickPrev={this.gotoPrevious}
        onClickNext={this.gotoNext}
        onClose={this.closeLightbox}
      />
    );
  }
}

Demo & Examples

Live demo: jossmac.github.io/react-images

To build the examples locally, run:

yarn install
yarn start

Then open localhost:8000 in a browser.

Using srcSet

Example using srcSet:

<Lightbox
  images={LIGHTBOX_IMAGE_SET}
  ...
/>

const LIGHTBOX_IMAGE_SET = [
  {
    src: 'http://example.com/example/img1.jpg',
    caption: 'A forest'
    // As an array
    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',
    ],
  },
  {
    src: 'http://example.com/example/img2.jpg',
    // As a string
    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',
  }
];

Options

Property Type Default Description
backdropClosesModal bool false Allow users to exit the lightbox by clicking the backdrop
closeButtonTitle string ' Close (Esc) ' Customize close esc title
enableKeyboardInput bool true Supports keyboard input - esc, arrow left, and arrow right
currentImage number 0 The index of the image to display initially
customControls array undefined An array of elements to display as custom controls on the top of lightbox
images array undefined Required. Array of image objects See image options table below
imageCountSeparator String ' of ' Customize separator in the image count
isOpen bool false Whether or not the lightbox is displayed
leftArrowTitle string ' Previous (Left arrow key) ' Customize of left arrow title
onClickPrev func undefined Fired on request of the previous image
onClickNext func undefined Fired on request of the next image
onClose func undefined Required. Handle closing of the lightbox
onClickImage func undefined Handle click on image
onClickThumbnail func undefined Handle click on thumbnail
preloadNextImage bool true Based on the direction the user is navigating, preload the next available image
rightArrowTitle string ' Next (Right arrow key) ' Customize right arrow title
showCloseButton bool true Optionally display a close "X" button in top right corner
showImageCount bool true Optionally display image index, e.g., "3 of 20"
width number 1024 Maximum width of the carousel; defaults to 1024px
spinner func DefaultSpinner Spinner component class
spinnerColor string 'white' Color of spinner
spinnerSize number 100 Size of spinner
preventScroll bool true Determines whether scrolling is prevented via react-scrolllock

Images object

Property Type Default Description
src string undefined Required
srcSet array of strings or string undefined Optional
caption string undefined Optional
alt string undefined Optional

changelog

React-Images

v0.5.19 / 2018-07-19

  • Fix babel lib output not transpiling

v0.5.18 / 2018-07-19

  • LightBox srcSet support for string and array #236 thanks to lordoffreaks
  • Upgrade react-transition-group to v2 #238 thanks to filipecosta01
  • Add zindex to close button to bring it in front of spinner #225 thanks to seanpascoe
  • Fix #240: Spinner consumes pointer events #241 thanks to thepatrik
  • Fix #216 Cannot read property 'complete' of undefined #217 thanks to lkazberova
  • Fix Lightbox srcSet prop type validation #209 thanks to kripod

v0.5.17 / 2018-02-07

  • fix for "srcSet" inconsistency #204 thanks to kripod and wmertens
  • fix for preload bug when mounted with isOpen set to true thanks to mkalygin
  • removed react-spinners dependency which was bloating the bundle, and implemented a simple loading component, thanks kripod
  • support for conditional ScrollLock via new property preventScroll thanks to Josh-a-e

v0.5.16 / 2018-01-30

  • add preloadImage call to componentDidMount PR #200 thanks to ilker0
  • Changes some docs to clarify that yarn is the preferred package manager for this project. Removes package-lock.json. PR #191 Thanks to jorrit
  • Unmount the component tree before removing the portal node from DOM PR #180 thanks to pleunv
  • Fix react warnings by updating react-scrolllock version jorrit)

v0.5.15 / 2018-01-25

  • spinner functionality pull request #187 thanks to mkalygin

v0.5.13 / 2017-11-29

  • change srcset to srcSet to fix intermittent warning: Invalid DOM property srcset. Did you mean srcSet?

v0.5.12 / 2017-11-29

  • Fix React warning issue #171 thanks to kachkaev

v0.5.10 / 2017-10-18

  • New build

v0.5.8 / 2017-10-06

  • Incorrect peer dependency in package.json file

v0.5.7 / 2017-10-04

  • Fix warnings for React 16.0.0 and update dependencies

v0.5.6 / 2017-09-20

  • Update: Let user pass in srcSet as prop in addition to srcset thanks to smeijer
  • Fix: default arrow bg color is none
  • Fix: make content div, figure, image respond to theme props #127
  • Fix: caption extending and disabling backdropClosesModal click issue #156
  • Fix: alignment in safari issue #105

v0.5.5 / 2017-07-28

  • Fix: let user override all possible properties with theme object thanks to clintharris
  • Fix: clicking on image closes lightbox when backdropClosesModal is set to true #152
  • Fix: clicking close lightbox button fired onClose handler twice #155

v0.5.4 / 2017-05-31

  • Update: separate out prop-types for React 16 thanks to hiyamamo
  • Update: update react-addons-css-transition-group to react-transition-group thanks to neptunian
  • Fix: React warnings in React v15.5.0

v0.5.2 / 2016-11-17

  • Fix: keydown listeners thanks to aknuds1 archr
  • Fix: thumbnail click propagation thanks to GregoryPotdevin
  • Update: use abstracted ScrollLock component

v0.5.1 / 2016-08-21

  • Feature: Support theming with aphrodite classes
  • Examples: Update options with new new prop details

v0.5.0 / 2016-08-20

  • Feature: Added a thumbnail preview beneath the lightbox thanks to GregoryPotdevin
  • Feature: Re-implemented the layout using flexbox
  • Examples: Replaced local images with hot-linked Unsplash photographs

v0.4.11 / 2016-08-15

  • Feature: Pre-load the next image based on user intention, uses new prop preloadNextImage
  • Fix: bug with enableKeyboardInput where images fail to render thanks to benhowell
  • Bump dev dependencies for react and react-dom to 15.3.0
  • Increase the default max-width of the Lightbox to 1024px

v0.4.10 / 2016-08-11

  • Fix react PropTypes warning. See fixing-the-false-positive
  • Simplify fade transition using react-css-addons-transition-group

v0.4.9 / 2016-07-28

  • Resolve react "no-unused-prop" warnings benhowell

v0.4.7 / 2016-07-14

  • Custom controls thanks to robintail
  • dependency fix for react-addons-transition-group thanks to fend25

v0.4.6 / 2016-05-17

  • General cleanup

v0.4.5 / 2016-05-16

  • Added imageCountSeparator prop to replace " of " in the image count

v0.4.4 / 2016-05-16

  • Account for scrollbar width when opening/closing the lightbox
  • Remove required flag on onClickNext and onClickPrev - may only render a single image
  • Increase dialog z-index to 2001 thanks to newsiberian

v0.4.3 / 2016-05-16

  • Resolve peer-dependency issues thanks to jedwatson

v0.4.2 / 2016-05-14

  • Update dependencies

v0.4.1 / 2016-05-12

  • Update peer dependencies

v0.4.0 / 2016-05-12

  • Bump all applicable dependencies
  • Remove peer dependencies

v0.3.3 / 2016-05-12

  • Updated website with more info + new design
  • Introduction of onClickImage prop thanks to pradel
  • Documentation for showImageCount thanks to neptunian

v0.3.2 / 2016-01-20

  • Fix backdropClosesModal behaviour
  • Update defaults: backdropClosesModal false, showCloseButton true

v0.3.1 / 2016-01-15

  • Updated react dependencies
  • Better handling of lightbox positioning

v0.3.0 / 2016-01-06

  • Update to use ES6
  • Update to use JSS
  • Layout refactor:
    • Moved away from CSS transforms for centering
    • Improved responsiveness, performance
  • Update example images to Gratisography
  • Optional captions below images thanks to @ko
  • Optional count below images e.g. "3 of 12"
  • Move close button top right of frame, and replace with × icon

v0.2.1 / 2015-11-29

  • Fix bug in examples with goto functions

v0.2.0 / 2015-11-29

  • Make the component stateless, now uses functions onClickPrev/onClickNext

v0.1.0 / 2015-11-20