2.1.7 • Published 6 years ago

@astrocoders/react-modal-image v2.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

react-modal-image

CircleCI npm package

A lightweight React component providing modal image Lightbox.

DEMO

Features

  • Only 3 kB when gzipped.
  • Zero dependencies.
  • Includes builds for CommonJS and ES modules.
  • For React 15.x and 16.x.
  • Esc, Enter & click outside the image close the lightbox
  • User can zoom & move the image or download the highest quality one
  • Image alt shown as title of lightbox

You need to bring your own Set polyfill if you use old Internet Explorers.

Simple API

import ModalImage from 'react-modal-image'

<ModalImage
  small={urlToTinyImageFile}
  large={urlToHugeImageFile}
  alt="Hello World!"
/>
PropTypeDescription
classNameStringOptional. class for the small preview image.
altStringOptional. alt for the small image and the heading text in Lightbox.
smallURLsrc for the small preview image.
smallSrcSetStringOptional. srcSet for the small preview image.
mediumURLOptional if large is defined. Image shown when zoomed out in Lightbox.
largeURLOptional if medium is defined. Image shown when zoomed in Lightbox. Downloadable.
hasDownloadButtonBooleanOptional. Show download button in LightBox if set true

Lightbox-only API

You can also choose to import only the Lightbox.

To use the Lightbox only, you'll need to handle the open state by yourself:

import { Lightbox } from 'react-modal-image'

// ...

const closeLightbox = () => {
  this.state.open = true
}

// ...

{
  this.state.open && (
    <Lightbox medium={urlToLargeImageFile} large={urlToHugeImageFile} alt="Hello World!" onClose={this.closeLightbox} />
  )
}
PropTypeDescription
onClosefunctionWill be invoked when the Lightbox requests to be closed