Gathering detailed insights and metrics for react-image-lightbox
Gathering detailed insights and metrics for react-image-lightbox
Gathering detailed insights and metrics for react-image-lightbox
Gathering detailed insights and metrics for react-image-lightbox
yet-another-react-lightbox
Modern React lightbox component
@seafile/react-image-lightbox
A lightbox component for React.js
react-native-lightbox
Images etc in Full Screen Lightbox Popovers for React Native
react-image-video-lightbox
A React lightbox that supports videos, images and pinch zooming on images. Optimized for mobile UI with swiping, but can be used on desktop as well.
npm install react-image-lightbox
Typescript
Module System
Node Version
NPM Version
95.5
Supply Chain
95.7
Quality
77.2
Maintenance
100
Vulnerability
100
License
JavaScript (65.24%)
CSS (34.45%)
Shell (0.31%)
Total Downloads
32,113,485
Last Day
4,171
Last Week
111,385
Last Month
491,940
Last Year
5,706,291
MIT License
1,287 Stars
370 Commits
358 Forks
11 Watchers
28 Branches
27 Contributors
Updated on Jun 20, 2025
Minified
Minified + Gzipped
Latest Version
5.1.4
Package Id
react-image-lightbox@5.1.4
Size
1.28 MB
NPM Version
7.0.14
Node Version
15.3.0
Published on
Jul 13, 2021
Cumulative downloads
Total Downloads
Last Day
-8.8%
4,171
Compared to previous day
Last Week
-3.5%
111,385
Compared to previous week
Last Month
7.4%
491,940
Compared to previous month
Last Year
-3.1%
5,706,291
Compared to previous year
2
35
A flexible lightbox component for displaying images in a React project.
Features
1import React, { Component } from 'react'; 2import Lightbox from 'react-image-lightbox'; 3import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app 4 5const images = [ 6 '//placekitten.com/1500/500', 7 '//placekitten.com/4000/3000', 8 '//placekitten.com/800/1200', 9 '//placekitten.com/1500/1500', 10]; 11 12export default class LightboxExample extends Component { 13 constructor(props) { 14 super(props); 15 16 this.state = { 17 photoIndex: 0, 18 isOpen: false, 19 }; 20 } 21 22 render() { 23 const { photoIndex, isOpen } = this.state; 24 25 return ( 26 <div> 27 <button type="button" onClick={() => this.setState({ isOpen: true })}> 28 Open Lightbox 29 </button> 30 31 {isOpen && ( 32 <Lightbox 33 mainSrc={images[photoIndex]} 34 nextSrc={images[(photoIndex + 1) % images.length]} 35 prevSrc={images[(photoIndex + images.length - 1) % images.length]} 36 onCloseRequest={() => this.setState({ isOpen: false })} 37 onMovePrevRequest={() => 38 this.setState({ 39 photoIndex: (photoIndex + images.length - 1) % images.length, 40 }) 41 } 42 onMoveNextRequest={() => 43 this.setState({ 44 photoIndex: (photoIndex + 1) % images.length, 45 }) 46 } 47 /> 48 )} 49 </div> 50 ); 51 } 52}
Play with the code on the example on CodeSandbox
Property | Type | Description |
---|---|---|
mainSrc (required) | string | Main display image url |
prevSrc | string | Previous display image url (displayed to the left). If left undefined, onMovePrevRequest will not be called, and the button not displayed |
nextSrc | string | Next display image url (displayed to the right). If left undefined, onMoveNextRequest will not be called, and the button not displayed |
mainSrcThumbnail | string | Thumbnail image url corresponding to props.mainSrc . Displayed as a placeholder while the full-sized image loads. |
prevSrcThumbnail | string | Thumbnail image url corresponding to props.prevSrc . Displayed as a placeholder while the full-sized image loads. |
nextSrcThumbnail | string | Thumbnail image url corresponding to props.nextSrc . Displayed as a placeholder while the full-sized image loads. |
onCloseRequest (required) | func | Close window event. Should change the parent state such that the lightbox is not rendered |
onMovePrevRequest | func | Move to previous image event. Should change the parent state such that props.prevSrc becomes props.mainSrc , props.mainSrc becomes props.nextSrc , etc. |
onMoveNextRequest | func | Move to next image event. Should change the parent state such that props.nextSrc becomes props.mainSrc , props.mainSrc becomes props.prevSrc , etc. |
onImageLoad | func | Called when an image loads.(imageSrc: string, srcType: string, image: object): void |
onImageLoadError | func | Called when an image fails to load.(imageSrc: string, srcType: string, errorEvent: object): void |
imageLoadErrorMessage | node | What 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" . |
onAfterOpen | func | Called after the modal has rendered. |
discourageDownloads | bool | When true , enables download discouragement (preventing [right-click -> Save Image As...]). Defaults to false . |
animationDisabled | bool | When true , image sliding animations are disabled. Defaults to false . |
animationOnKeyInput | bool | When true , sliding animations are enabled on actions performed with keyboard shortcuts. Defaults to false . |
animationDuration | number | Animation duration (ms). Defaults to 300 . |
keyRepeatLimit | number | Required interval of time (ms) between key actions (prevents excessively fast navigation of images). Defaults to 180 . |
keyRepeatKeyupBonus | number | Amount of time (ms) restored after each keyup (makes rapid key presses slightly faster than holding down the key to navigate images). Defaults to 40 . |
imageTitle | node | Image title (Descriptive element above image) |
imageCaption | node | Image caption (Descriptive element below image) |
imageCrossOrigin | string | crossorigin attribute to append to img elements (MDN documentation) |
toolbarButtons | node[] | Array of custom toolbar buttons |
reactModalStyle | Object | Set z-index style, etc., for the parent react-modal (react-modal style format) |
reactModalProps | Object | Override props set on react-modal (https://github.com/reactjs/react-modal) |
imagePadding | number | Padding (px) between the edge of the window and the lightbox. Defaults to 10 . |
clickOutsideToClose | bool | When true , clicks outside of the image close the lightbox. Defaults to true . |
enableZoom | bool | Set to false to disable zoom functionality and hide zoom buttons. Defaults to true . |
wrapperClassName | string | Class name which will be applied to root element after React Modal |
nextLabel | string | aria-label and title set on the 'Next' button. Defaults to 'Next image' . |
prevLabel | string | aria-label and title set on the 'Previous' button. Defaults to 'Previous image' . |
zoomInLabel | string | aria-label and title set on the 'Zoom In' button. Defaults to 'Zoom in' . |
zoomOutLabel | string | aria-label and title set on the 'Zoom Out' button. Defaults to 'Zoom out' . |
closeLabel | string | aria-label and title set on the 'Close Lightbox' button. Defaults to 'Close lightbox' . |
loader | node | Custom Loading indicator for loading |
Browser | Works? |
---|---|
Chrome | Yes |
Firefox | Yes |
Safari | Yes |
IE 11 | Yes |
After cloning the repository and running npm install
inside, you can use the following commands to develop and build the project.
1# Starts a webpack dev server that hosts a demo page with the lightbox. 2# It uses react-hot-loader so changes are reflected on save. 3npm start 4 5# Lints the code with eslint and my custom rules. 6yarn run lint 7 8# Lints and builds the code, placing the result in the dist directory. 9# This build is necessary to reflect changes if you're 10# `npm link`-ed to this repository from another local project. 11yarn run build
Pull requests are welcome!
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 5/20 approved changesets -- score normalized to 2
Reason
project is archived
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
48 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More