This component features a lightbox containing a slideshow, which allows users to cycle through the images in the gallery.
The following features are supported:
Zooming: Users can zoom through their mouse wheel on desktop devices, or through pinch-to-zoom on mobile devices.
Panning: Once an image is zoomed into, the image can be panned by dragging the image through the mouse, or if on a mobile device, with a swipe-to-drag motion.
Lots of customization options: There are lots of props available that you can edit to update the theme of the lightbox, as well as its functionality.
Demo
Import
Firstly, import the components required as well as the CSS file for this library:
Here's an example using functional components and Tailwind CSS to style the images, so that they appear in a grid format. However external CSS can be used for this, or styling with the style object on the image gallery container.
This will display the following image gallery, along with a lightbox that will appear after one of the images are clicked:
Check out the Image component to display a single image.
Alternative Method: Array of Images
An alternative method of rendering images in the lightbox is by passing an array of images to the SlideshowLightbox component. To get started, just create an array of images (as shown in the code sample below) and then pass this array to the imagesprop.
importReactfrom'react'import{SlideshowLightbox}from'lightbox.js-react'import'lightbox.js-react/dist/index.css'functionDemo(){const images =[{src:'https://source.unsplash.com/sQZ_A17cufs/549x711',alt:'Mechanical keyboard with white keycaps.',},{src:'https://source.unsplash.com/rsAeSMzOX9Y/768x512',alt:'Mechanical keyboard with white, pastel green and red keycaps.',},{src:'https://source.unsplash.com/Z6SXt1v5tP8/768x512',alt:'Mechanical keyboard with white, pastel pink, yellow and red keycaps.',},]let[isOpen, setIsOpen]=useState(false);return(<div><buttononClick={()=>{setIsOpen(true)}}> Open Lightbox
</button><SlideshowLightboximages={images}showThumbnails={true}open={isOpen}lightboxIdentifier="lbox1"onClose={()=>{setIsOpen(false)}}></SlideshowLightbox></div>)}
Available Themes
There are 3 themes available, which can be selected via setting the `theme` prop:
day: A light theme with a white background and gray icons
night: A dark theme with gray icons
lightbox: A theme with a semi-transparent gray background
If you'd like to change the theme of the lightbox, this can be done by passing a theme name to the theme prop, with the options including: "lightbox", "night", "day"
You could then select the `img` component within the lightbox with CSS, such as:
.lightboxImg img{...
}
Background Color
If you'd like to customize the background color of the lightbox, this can be done by passing a color to the color prop, as a RGB, RGBA, HEX or CSS color name value:
Each thumbnail contains a border which can be customized or removed entirely (by setting the border color to transparent). The border can be customized through specifying a color value for the `thumbnailBorder` prop, and the color can be a RGB, RGBA, HEX or CSS color name value.
If you'd like to show/hide particular icons in the controls at the top of the lightbox, this can be done by toggling the respective values to true/false.
If you'd like to open/close the lightbox (through a custom element, such as via a button), this can be done by toggling the value of the open prop. For a full tutorial, take a look at this guide here.
The starting slide index the lightbox should open to when the modal is opened/closed. The default is 0. For a full tutorial, take a look at this guide here.
By default, the thumbnails are animated in and out of the DOM using a fade-in effect. If you would prefer to switch this animation off, this can be done so by setting the `animateThumbnails` prop to `false`.
Custom component to be included as the next arrow. If you'd like to render a different arrow to the default, just pass a custom component to the `nextArrow` prop.
Custom component to be included for the previous arrow. If you'd like to render a different arrow to the default, just pass a custom component to the `prevArrow` prop.