Yet Another React Lightbox

Modern React lightbox component

README

Yet Another React Lightbox


Modern React lightbox component. Performant, easy to use, customizable and extendable.

Overview


NPM Version
Bundle Size
License MIT

- Built for React: works with React 18, 17 and 16.8.0+
- UX: supports keyboard, mouse, touchpad and touchscreen navigation
- Preloading: never displays partially downloaded images
- Performance: preloads limited number of images without compromising performance or UX
- Responsive: responsive images with automatic resolution switching are supported out of the box
- Video: video slides are supported via an optional plugin
- Zoom: image zoom is supported via an optional plugin
- Customization: customize any UI element or add your own custom slides
- No bloat: never bundle rarely used features; add optional features via plugins
- TypeScript: type definitions come built-in in the package
- RTL: compatible with RTL layout

Yet Another React Lightbox | Example

Documentation



Examples



Installation


  1. ```shell
  2. npm install yet-another-react-lightbox
  3. ```

or

  1. ```shell
  2. yarn add yet-another-react-lightbox
  3. ```

Minimal Setup Example


  1. ```jsx
  2. import * as React from "react";
  3. import Lightbox from "yet-another-react-lightbox";
  4. import "yet-another-react-lightbox/styles.css";

  5. export default function App() {
  6.   const [open, setOpen] = React.useState(false);

  7.   return (
  8.     <>
  9.       <button type="button" onClick={() => setOpen(true)}>
  10.         Open Lightbox
  11.       </button>

  12.       <Lightbox
  13.         open={open}
  14.         close={() => setOpen(false)}
  15.         slides={[
  16.           { src: "/image1.jpg" },
  17.           { src: "/image2.jpg" },
  18.           { src: "/image3.jpg" },
  19.         ]}
  20.       />
  21.     </>
  22.   );
  23. }
  24. ```

Recommended Setup


Unlike many other lightbox libraries, Yet Another React Lightbox doesn't have a concept of "thumbnail" or "original"
(or "full size") images. We use responsive images instead and recommend you provide multiple files of different
resolutions for each image. Yet Another React Lightbox automatically populates srcset / sizes attributes and lets
the browser decide which image is more appropriate for its viewport size.

  1. ```jsx
  2. import * as React from "react";
  3. import Lightbox from "yet-another-react-lightbox";
  4. import "yet-another-react-lightbox/styles.css";

  5. export default function App() {
  6.   const [open, setOpen] = React.useState(false);

  7.   return (
  8.     <>
  9.       <button type="button" onClick={() => setOpen(true)}>
  10.         Open Lightbox
  11.       </button>

  12.       <Lightbox
  13.         open={open}
  14.         close={() => setOpen(false)}
  15.         slides={[
  16.           {
  17.             src: "/image1x3840.jpg",
  18.             alt: "image 1",
  19.             width: 3840,
  20.             height: 2560,
  21.             srcSet: [
  22.               { src: "/image1x320.jpg", width: 320, height: 213 },
  23.               { src: "/image1x640.jpg", width: 640, height: 427 },
  24.               { src: "/image1x1200.jpg", width: 1200, height: 800 },
  25.               { src: "/image1x2048.jpg", width: 2048, height: 1365 },
  26.               { src: "/image1x3840.jpg", width: 3840, height: 2560 },
  27.             ]
  28.           },
  29.           // ...
  30.         ]}
  31.       />
  32.     </>
  33.   );
  34. }
  35. ```

You can also integrate 3rd-party image components (e.g., Next.js Image or Gatsby Image) via a custom render function.
See examples on the documentation website.

Plugins


Yet Another React Lightbox allows you to add optional features based on your requirements via plugins.

The following plugins come bundled in the package:

- Captions - adds support for slide title and
  description
- Counter - adds slides counter
- Download - adds download button
- Fullscreen - adds support for fullscreen mode
- Inline - adds support for inline rendering mode
- Slideshow - adds slideshow autoplay feature
- Thumbnails - adds thumbnails track
- Video - adds support for video slides
- Zoom - adds image zoom feature

License


MIT © 2022 Igor Danchenko