Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-modal-image

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-modal-image

Lightweight Lightbox React Component

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by47.38%
Maintainers
1
Weekly downloads
 
Created
Source

react-modal-image

Travis npm package Coveralls

A tiny an a simple React component providing modal image Lightbox.

DEMO

Usage

You'll provide 3 images, a small, medium size and a large one. The component will display the small one by default and open a Lightbox for the medium & large ones if clicked.

Features

  • Only 3 kB when gzipped.
  • Zero dependencies.
  • Includes builds for CommonJS and ES modules.
  • For React 15.x and 16.x.
  • Image alt text displayed as caption
  • Download button
  • Zoom and move the image

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}
  smallSrcSet={srcSetDefToTinyImageFile}
  medium={urlToLargeImageFile}
  large={urlToHugeImageFile}
  alt="Hello World!"
/>
PropTypeDescription
altStringalt text for the small img and the header in Lightbox.
smallURLsrc for the small small img.
smallSrcSetStringsrcSet for the small small imgs.
mediumURLImage shown in Lightbox.
largeURLImage shown when zoomed in Lightbox. Downloadable.

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

Keywords

FAQs

Package last updated on 25 Jan 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc