react-image-lightbox vs react-images vs react-photo-gallery vs yet-another-react-lightbox
React Image and Lightbox Libraries
react-image-lightboxreact-imagesreact-photo-galleryyet-another-react-lightboxSimilar Packages:

React Image and Lightbox Libraries

These libraries provide various functionalities for displaying images and galleries in React applications, enhancing user experience through features like lightboxes, galleries, and responsive layouts. They cater to different needs, from simple image viewing to complex gallery management, allowing developers to choose based on project requirements and desired user interactions.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-image-lightbox01,280-05 years agoMIT
react-images02,342-505 years agoMIT
react-photo-gallery02,010-807 years agoMIT
yet-another-react-lightbox01,233237 kB34 days agoMIT

Feature Comparison: react-image-lightbox vs react-images vs react-photo-gallery vs yet-another-react-lightbox

Lightbox Functionality

  • react-image-lightbox:

    Provides a straightforward lightbox experience with basic features such as image navigation and close functionality, making it easy to implement and use.

  • react-images:

    Offers a more enhanced lightbox experience with additional features like zooming and full-screen mode, allowing users to interact with images more dynamically.

  • react-photo-gallery:

    Does not inherently provide lightbox functionality but can be easily integrated with other lightbox libraries for a comprehensive gallery experience.

  • yet-another-react-lightbox:

    Delivers a powerful lightbox experience with support for images, videos, and custom content, along with advanced navigation options.

Customization

  • react-image-lightbox:

    Customization options are limited, focusing on simplicity and ease of use, which may not suit all design needs.

  • react-images:

    Allows for some level of customization, enabling developers to style the gallery and lightbox to fit their application's design.

  • react-photo-gallery:

    Highly customizable, offering various layout options and the ability to control the rendering of images, making it suitable for unique design requirements.

  • yet-another-react-lightbox:

    Extensive customization capabilities, allowing developers to tailor the lightbox's appearance and behavior to match their application's needs.

Performance

  • react-image-lightbox:

    Lightweight and optimized for performance, making it suitable for projects where load time is critical.

  • react-images:

    Performance is generally good, but may vary based on the number of images and features used; lazy loading can help improve performance.

  • react-photo-gallery:

    Designed for performance with efficient rendering of images in a grid layout, ensuring a smooth user experience even with large galleries.

  • yet-another-react-lightbox:

    Optimized for performance with features like lazy loading and efficient image handling, ensuring quick loading times and smooth interactions.

Ease of Use

  • react-image-lightbox:

    Very easy to implement, making it ideal for developers looking for a quick solution without extensive configuration.

  • react-images:

    User-friendly with a straightforward API, though it may require more setup than react-image-lightbox.

  • react-photo-gallery:

    Requires more configuration and understanding of props, which may increase the learning curve for new developers.

  • yet-another-react-lightbox:

    Offers a rich set of features but may have a steeper learning curve due to its extensive options and configurations.

Community and Support

  • react-image-lightbox:

    Has a smaller community, which may result in limited support and resources available for troubleshooting.

  • react-images:

    Moderate community support with some documentation and examples available, making it easier to find help when needed.

  • react-photo-gallery:

    A larger community with good documentation, making it easier to find resources and support for implementation.

  • yet-another-react-lightbox:

    Growing community and active development, providing ample resources and support for users.

How to Choose: react-image-lightbox vs react-images vs react-photo-gallery vs yet-another-react-lightbox

  • react-image-lightbox:

    Choose react-image-lightbox if you need a simple and lightweight solution for displaying images in a lightbox format with basic navigation features. It is ideal for projects that require minimal setup and straightforward image viewing.

  • react-images:

    Select react-images if you want a more comprehensive gallery solution that includes features like image zooming, full-screen viewing, and responsive design. It is suitable for applications that require a robust gallery with a focus on user interaction.

  • react-photo-gallery:

    Opt for react-photo-gallery when you need a flexible and customizable grid layout for displaying images. This package is great for projects that require a responsive gallery with various layout options and the ability to handle different image sizes efficiently.

  • yet-another-react-lightbox:

    Go for yet-another-react-lightbox if you are looking for a feature-rich lightbox solution that supports image galleries, videos, and custom content. It is perfect for applications that require advanced functionalities like keyboard navigation, swipe gestures, and lazy loading.

README for react-image-lightbox

React Image Lightbox

NPM Build Status Coverage Status

RIL Snapshot

A flexible lightbox component for displaying images in a React project.

DEMO

Features

  • Keyboard shortcuts (with rate limiting)
  • Image Zoom
  • Flexible rendering using src values assigned on the fly
  • Image preloading for smoother viewing
  • Mobile friendly, with pinch to zoom and swipe (Thanks, @webcarrot!)

Example

import React, { Component } from 'react';
import Lightbox from 'react-image-lightbox';
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app

const images = [
  '//placekitten.com/1500/500',
  '//placekitten.com/4000/3000',
  '//placekitten.com/800/1200',
  '//placekitten.com/1500/1500',
];

export default class LightboxExample extends Component {
  constructor(props) {
    super(props);

    this.state = {
      photoIndex: 0,
      isOpen: false,
    };
  }

  render() {
    const { photoIndex, isOpen } = this.state;

    return (
      <div>
        <button type="button" onClick={() => this.setState({ isOpen: true })}>
          Open Lightbox
        </button>

        {isOpen && (
          <Lightbox
            mainSrc={images[photoIndex]}
            nextSrc={images[(photoIndex + 1) % images.length]}
            prevSrc={images[(photoIndex + images.length - 1) % images.length]}
            onCloseRequest={() => this.setState({ isOpen: false })}
            onMovePrevRequest={() =>
              this.setState({
                photoIndex: (photoIndex + images.length - 1) % images.length,
              })
            }
            onMoveNextRequest={() =>
              this.setState({
                photoIndex: (photoIndex + 1) % images.length,
              })
            }
          />
        )}
      </div>
    );
  }
}

Play with the code on the example on CodeSandbox

Options

PropertyTypeDescription
mainSrc
(required)
stringMain display image url
prevSrcstringPrevious display image url (displayed to the left). If left undefined, onMovePrevRequest will not be called, and the button not displayed
nextSrcstringNext display image url (displayed to the right). If left undefined, onMoveNextRequest will not be called, and the button not displayed
mainSrcThumbnailstringThumbnail image url corresponding to props.mainSrc. Displayed as a placeholder while the full-sized image loads.
prevSrcThumbnailstringThumbnail image url corresponding to props.prevSrc. Displayed as a placeholder while the full-sized image loads.
nextSrcThumbnailstringThumbnail image url corresponding to props.nextSrc. Displayed as a placeholder while the full-sized image loads.
onCloseRequest
(required)
funcClose window event. Should change the parent state such that the lightbox is not rendered
onMovePrevRequestfuncMove to previous image event. Should change the parent state such that props.prevSrc becomes props.mainSrc, props.mainSrc becomes props.nextSrc, etc.
onMoveNextRequestfuncMove to next image event. Should change the parent state such that props.nextSrc becomes props.mainSrc, props.mainSrc becomes props.prevSrc, etc.
onImageLoadfuncCalled when an image loads.
(imageSrc: string, srcType: string, image: object): void
onImageLoadErrorfuncCalled when an image fails to load.
(imageSrc: string, srcType: string, errorEvent: object): void
imageLoadErrorMessagenodeWhat is rendered in place of an image if it fails to load. Centered in the lightbox viewport. Defaults to the string "This image failed to load".
onAfterOpenfuncCalled after the modal has rendered.
discourageDownloadsboolWhen true, enables download discouragement (preventing [right-click -> Save Image As...]). Defaults to false.
animationDisabledboolWhen true, image sliding animations are disabled. Defaults to false.
animationOnKeyInputboolWhen true, sliding animations are enabled on actions performed with keyboard shortcuts. Defaults to false.
animationDurationnumberAnimation duration (ms). Defaults to 300.
keyRepeatLimitnumberRequired interval of time (ms) between key actions (prevents excessively fast navigation of images). Defaults to 180.
keyRepeatKeyupBonusnumberAmount of time (ms) restored after each keyup (makes rapid key presses slightly faster than holding down the key to navigate images). Defaults to 40.
imageTitlenodeImage title (Descriptive element above image)
imageCaptionnodeImage caption (Descriptive element below image)
imageCrossOriginstringcrossorigin attribute to append to img elements (MDN documentation)
toolbarButtonsnode[]Array of custom toolbar buttons
reactModalStyleObjectSet z-index style, etc., for the parent react-modal (react-modal style format)
reactModalPropsObjectOverride props set on react-modal (https://github.com/reactjs/react-modal)
imagePaddingnumberPadding (px) between the edge of the window and the lightbox. Defaults to 10.
clickOutsideToCloseboolWhen true, clicks outside of the image close the lightbox. Defaults to true.
enableZoomboolSet to false to disable zoom functionality and hide zoom buttons. Defaults to true.
wrapperClassNamestringClass name which will be applied to root element after React Modal
nextLabelstringaria-label and title set on the 'Next' button. Defaults to 'Next image'.
prevLabelstringaria-label and title set on the 'Previous' button. Defaults to 'Previous image'.
zoomInLabelstringaria-label and title set on the 'Zoom In' button. Defaults to 'Zoom in'.
zoomOutLabelstringaria-label and title set on the 'Zoom Out' button. Defaults to 'Zoom out'.
closeLabelstringaria-label and title set on the 'Close Lightbox' button. Defaults to 'Close lightbox'.
loadernodeCustom Loading indicator for loading

Browser Compatibility

BrowserWorks?
ChromeYes
FirefoxYes
SafariYes
IE 11Yes

Contributing

After cloning the repository and running npm install inside, you can use the following commands to develop and build the project.

# Starts a webpack dev server that hosts a demo page with the lightbox.
# It uses react-hot-loader so changes are reflected on save.
npm start

# Lints the code with eslint and my custom rules.
yarn run lint

# Lints and builds the code, placing the result in the dist directory.
# This build is necessary to reflect changes if you're
#  `npm link`-ed to this repository from another local project.
yarn run build

Pull requests are welcome!

License

MIT