New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-images-zoom-loop

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-images-zoom-loop

Fork of react-images-zoom repository

latest
Source
npmnpm
Version
1.0.9-alpha
Version published
Maintainers
1
Created
Source

React Images Extended

downloads

A simple, responsive lightbox React JS component for displaying an array of images with zooming and rotating capabilities. This is a fork of jossmac/react-images and simokhalil/react-images-extended

Why this fork?

Fork is based on xiaoman885 react-images-zoom repository. I needed it to add additional stuff and make some small fixes for zoom and rotate features. There is also "loop" prop added. If enabled, it prevents arrow images from being hidden on last/first image.

Quick start

npm install --save react-images-zoom

or

yarn add react-images-zoom
import React from 'react';
import Lightbox from 'react-images-zoom';

export default class Sample extends React.Component {
  ...
  render() {
    return (
      <Lightbox
        images={[{ src: 'http://example.com/img1.jpg' }, { src: 'http://example.com/img2.jpg' }]}
        isOpen={this.state.lightboxIsOpen}
        loop
        onClickPrev={this.gotoPrevious}
        onClickNext={this.gotoNext}
        onClose={this.closeLightbox}
        rotatable={true}
        zoomable={true}
        onSave={(currentImageIndex, params) => console.log('currentImageIndex, currentImageSrc, params : ', currentImageIndex, this.props.images[currentImageIndex].src, params)}
      />
    );
  }
}

Loop example

To add a loop to your lightbox gallery you need to add a loop prop to your component and tell lightbox what to do when condition is met. Like:

gotoPrevious() {
    this.setState({
      currentImage: this.state.currentImage - 1,
    });
    if (this.state.currentImage === 0) {
      this.setState({
        currentImage: this.props.images.length - 1,
      });
    }
  }
  gotoNext() {
    this.setState({
      currentImage: this.state.currentImage + 1,
    });
    if (this.state.currentImage === this.props.images.length - 1) {
      this.setState({
        currentImage: 0,
      });
    }
  }

Examples

To build the examples locally, run:

yarn install
yarn start

Then open localhost:8000 in a browser.

Using srcSet

Example using srcSet:

<Lightbox
  images={LIGHTBOX_IMAGE_SET}
  ...
/>

const LIGHTBOX_IMAGE_SET = [
  {
    src: 'http://example.com/example/img1.jpg',
    caption: 'A forest'
    srcSet: [
      'http://example.com/example/img1_1024.jpg 1024w',
      'http://example.com/example/img1_800.jpg 800w',
      'http://example.com/example/img1_500.jpg 500w',
      'http://example.com/example/img1_320.jpg 320w',
    ],
  },
  {
    src: 'http://example.com/example/img2.jpg',
    srcSet: [
      'http://example.com/example/img2_1024.jpg 1024w',
      'http://example.com/example/img2_800.jpg 800w',
      'http://example.com/example/img2_500.jpg 500w',
      'http://example.com/example/img2_320.jpg 320w',
    ],
  }
];

Options

PropertyTypeDefaultDescription
backdropClosesModalboolfalseAllow users to exit the lightbox by clicking the backdrop
closeButtonTitlestring' Close (Esc) 'Customize close esc title
enableKeyboardInputbooltrueSupports keyboard input - esc, arrow left, and arrow right
currentImagenumber0The index of the image to display initially
customControlsarrayundefinedAn array of elements to display as custom controls on the top of lightbox
imagesarrayundefinedRequired. Array of image objects See image options table below
imageCountSeparatorString' of 'Customize separator in the image count
isOpenboolfalseWhether or not the lightbox is displayed
leftArrowTitlestring' Previous (Left arrow key) 'Customize of left arrow title
loopboolfalseEnables loop for lightbox gallery
onClickPrevfuncundefinedFired on request of the previous image
onClickNextfuncundefinedFired on request of the next image
onClosefuncundefinedRequired. Handle closing of the lightbox
onClickImagefuncundefinedHandle click on image
onClickThumbnailfuncundefinedHandle click on thumbnail
onSavefuncundefinedShow save button and handle click / params : currentImageIndex, {rotation, zoom}
preloadNextImagebooltrueBased on the direction the user is navigating, preload the next available image
rightArrowTitlestring' Next (Right arrow key) 'Customize right arrow title
rotatableboolfalseShow rotate buttons
showCloseButtonbooltrueOptionally display a close "X" button in top right corner
showImageCountbooltrueOptionally display image index, e.g., "3 of 20"
widthnumber1024Maximum width of the carousel; defaults to 1024px
spinnerfuncDefaultSpinnerSpinner component class
spinnerColorstring'white'Color of spinner
spinnerSizenumber100Size of spinner
preventScrollbooltrueDetermines whether scrolling is prevented via react-scrolllock
zoomableboolfalseShow zoom buttons

Images object

PropertyTypeDefaultDescription
srcstringundefinedRequired
srcSetarray of stringsundefinedOptional
captionstringundefinedOptional
altstringundefinedOptional
initialZoomnumber1Optional
initialRotationnumber0Optional

Keywords

react

FAQs

Package last updated on 13 Nov 2019

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