Gathering detailed insights and metrics for react-the1-lightbox
Gathering detailed insights and metrics for react-the1-lightbox
Gathering detailed insights and metrics for react-the1-lightbox
Gathering detailed insights and metrics for react-the1-lightbox
npm install react-the1-lightbox
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
3
44
React-spring-lightbox is a flexible image gallery lightbox with native-feeling touch gestures and buttery smooth animations.
Mousewheel
, swipe or click+drag to page photosMousewheel
or Trackpad Pinch
to zoom<img />
attribute including loading
(lazy loading), srcset
and aria-*
1yarn add react-spring-lightbox
The images
prop now accepts a list of objects whose properties can be almost any valid React <img />
prop including srcset
, loading
(lazy loading) and aria-*
attributes.
If you use typescript, the exact type can be imported from import { ImagesListType } from 'react-spring-lightbox';
1import React, { useState } from 'react'; 2import Lightbox, { ImagesListType } from 'react-spring-lightbox'; 3 4const images: ImagesListType = [ 5 { 6 src: 'https://timellenberger.com/static/blog-content/dark-mode/win10-dark-mode.jpg', 7 loading: 'lazy', 8 alt: 'Windows 10 Dark Mode Setting', 9 }, 10 { 11 src: 'https://timellenberger.com/static/blog-content/dark-mode/macos-dark-mode.png', 12 loading: 'lazy', 13 alt: 'macOS Mojave Dark Mode Setting', 14 }, 15 { 16 src: 'https://timellenberger.com/static/blog-content/dark-mode/android-9-dark-mode.jpg', 17 loading: 'lazy', 18 alt: 'Android 9.0 Dark Mode Setting', 19 }, 20]; 21 22const CoolLightbox = () => { 23 const [currentImageIndex, setCurrentIndex] = useState(0); 24 25 const gotoPrevious = () => 26 currentImageIndex > 0 && setCurrentIndex(currentImageIndex - 1); 27 28 const gotoNext = () => 29 currentImageIndex + 1 < images.length && 30 setCurrentIndex(currentImageIndex + 1); 31 32 return ( 33 <Lightbox 34 isOpen={true} 35 onPrev={gotoPrevious} 36 onNext={gotoNext} 37 images={images} 38 currentIndex={currentImageIndex} 39 /* Add your own UI */ 40 // renderHeader={() => (<CustomHeader />)} 41 // renderFooter={() => (<CustomFooter />)} 42 // renderPrevButton={() => (<CustomLeftArrowButton />)} 43 // renderNextButton={() => (<CustomRightArrowButton />)} 44 // renderImageOverlay={() => (<ImageOverlayComponent >)} 45 46 /* Add styling */ 47 // className="cool-class" 48 // style={{ background: "grey" }} 49 50 /* Handle closing */ 51 // onClose={handleClose} 52 53 /* Use single or double click to zoom */ 54 // singleClickToZoom 55 56 /* react-spring config for open/close animation */ 57 // pageTransitionConfig={{ 58 // from: { transform: "scale(0.75)", opacity: 0 }, 59 // enter: { transform: "scale(1)", opacity: 1 }, 60 // leave: { transform: "scale(0.75)", opacity: 0 }, 61 // config: { mass: 1, tension: 320, friction: 32 } 62 // }} 63 /> 64 ); 65}; 66 67export default CoolLightbox;
Prop | Description |
---|---|
isOpen | Flag that dictates if the lightbox is open or closed |
onClose | Function that closes the Lightbox |
onPrev | Function that changes currentIndex to previous image in images |
onNext | Function that changes currentIndex to next image in images |
currentIndex | Index of image in images array that is currently shown |
renderHeader | A React component that renders above the image pager |
renderFooter | A React component that renders below the image pager |
renderPrevButton | A React component that is used for previous button in image pager |
renderNextButton | A React component that is used for next button in image pager |
renderImageOverlay | A React component that renders within the image stage, useful for creating UI overlays on top of the current image |
singleClickToZoom | Overrides the default behavior of double clicking causing an image zoom to a single click |
images | Array of image objects to be shown in Lightbox |
className | Classes are applied to the root lightbox component |
style | Inline styles are applied to the root lightbox component |
pageTransitionConfig | React-Spring useTransition config for page open/close animation |
Clone the repo
1git clone https://github.com/tim-soft/react-spring-lightbox.git react-spring-lightbox 2cd react-spring-lightbox
Setup symlinks
1yarn link 2cd example 3yarn link react-spring-lightbox
Run the library in development mode
1yarn start
Run the example app in development mode
1cd example 2yarn dev
Changes to the library code should hot reload in the demo app
MIT © Tim Ellenberger
No vulnerabilities found.
No security vulnerabilities found.