🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@caldwell619/react-image-lightbox

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@caldwell619/react-image-lightbox

A lightbox component for React

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

React Image Lightbox

Forked from react-image-lightbox.

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

Demo

Why Fork?

The main reason is that the original seems to not be maintained anymore. The last commit was July 2021, and many of the issues are stale.

Some other issues:

  • Didn't have TypeScript types.
  • Class based, which isn't an issue itself, but more about the enhancement. It was all in one file, 1500 lines.
  • Dragging an image caused a console error about preventing the default on the event.
  • Demo was class based.
  • Using React Modal incorrectly. They recommend to keep it mounted, the og library has you conditionally render it.
    • This is slightly opinionated, but react-modal should be a peer dependency to avoid version conflicts if you also use it.

Features

  • Keyboard shortcuts (with rate limiting)
  • Image Zoom
  • Flexible rendering using src values assigned on the fly
  • Image preloading for smoother viewing
  • Mobile friendly, with pinch to zoom and swipe (Thanks, @webcarrot!)

Example

Pseudo code to get your started. See the demo for a full example.

import { Lightbox } from '@caldwell619/react-image-lightbox'
// This only needs to be imported once in your app
import '@caldwell619/react-image-lightbox/dist/style.css'

const images: string[] = [...]

const App = () => {
  // Define logic handlers and state

  return (
    <Lightbox
      isOpen={isOpen}
      mainSrc={images[0]}
      // ...rest props
    />
  )
}

Logic Helpers

For convenience, there is a set of logical helpers you can use for next and previous functionality.

import { Lightbox, useControlHelper } from '@caldwell619/react-image-lightbox'
const App = () => {
  const { activeIndex, isOpen, toggleOpen, moveNext, movePrev, nextImage, prevImage, mainImage } =
    useControlHelper(images)

  return (
    <Lightbox
      isOpen={isOpen}
      mainSrc={mainImage}
      nextSrc={nextImage}
      prevSrc={prevImage}
      onMovePrevRequest={movePrev}
      onMoveNextRequest={moveNext}
      onCloseRequest={toggleOpen}
    />
  )
}

Props

Full, yet WIP list of props

Contributing

WIP guide here

Contributor List

License

MIT

Keywords

react

FAQs

Package last updated on 07 Oct 2022

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