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

react-image-lightbox

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-image-lightbox

A lightbox component for React.js

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
106K
decreased by-4.82%
Maintainers
1
Weekly downloads
 
Created
Source

React Image Lightbox

NPM

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

DEMO

Features

  • Few dependencies
  • Keyboard shortcuts (with rate limiting)
  • Image preloading for smoother viewing
  • Flexible rendering using src values assigned on the fly

Example

var React    = require('react');
var Lightbox = require('react-image-lightbox');

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

module.exports = React.createClass({
    getInitialState: function() {
        return {
            index: 0,
            isOpen: false
        };
    },
    openLightbox: function() {
        this.setState({ isOpen: true });
    },
    closeLightbox: function() {
        this.setState({ isOpen: false });
    },
    moveNext: function() {
        this.setState({ index: (this.state.index + 1) % images.length });
    },
    movePrev: function() {
        this.setState({ index: (this.state.index + images.length - 1) % images.length });
    },
    render: function() {
        var lightbox = '';
        if (this.state.isOpen) {
            lightbox = (
                <Lightbox
                    mainSrc={images[this.state.index]}
                    nextSrc={images[(this.state.index + 1) % images.length]}
                    prevSrc={images[(this.state.index + images.length - 1) % images.length]}

                    onCloseRequest={this.closeLightbox}
                    onMovePrevRequest={this.movePrev}
                    onMoveNextRequest={this.moveNext}
                />
            );
        }

        return (
            <div>
                <button type="button" onClick={this.openLightbox}>Open Lightbox</button>
                {lightbox}
            </div>
        );
    }
});

Options

PropertyTypeDefaultRequiredDescription
mainSrcstringyesMain display image url
prevSrcstringPrevious display image url (displayed to the left). If left undefined, movePrev actions will not be performed, and the button not displayed
nextSrcstringNext display image url (displayed to the right). If left undefined, moveNext actions will not be performed, and the button not displayed
mainSrcThumbnailstringThumbnail image url corresponding to props.mainSrc
prevSrcThumbnailstringThumbnail image url corresponding to props.prevSrc
nextSrcThumbnailstringThumbnail image url corresponding to props.nextSrc
onCloseRequestfuncyesClose window event. Should change the parent state such that the lightbox is not rendered
onMovePrevRequestfuncempty functionMove to previous image event. Should change the parent state such that props.prevSrc becomes props.mainSrc, props.mainSrc becomes props.nextSrc, etc.
onMoveNextRequestfuncempty functionMove to next image event. Should change the parent state such that props.nextSrc becomes props.mainSrc, props.mainSrc becomes props.prevSrc, etc.
discourageDownloadsboolfalseEnable download discouragement (prevents [right-click -> Save Image As...])
animationDisabledboolfalseDisable all animation
animationOnKeyInputboolfalseDisable animation on actions performed with keyboard shortcuts
animationDurationnumber300Animation duration (ms)
keyRepeatLimitnumber180Required interval of time (ms) between key actions (prevents excessively fast navigation of images)
keyRepeatKeyupBonusnumber40Amount of time (ms) restored after each keyup (makes rapid key presses slightly faster than holding down the key to navigate images)
imageTitlestringImage title
toolbarButtonsnode[]Array of custom toolbar buttons
imagePaddingnumber10Padding (px) between the edge of the window and the lightbox

Keywords

FAQs

Package last updated on 16 Feb 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