1.3.0 • Published 7 years ago

react-photoswipe v1.3.0

Weekly downloads
7,720
License
-
Repository
-
Last release
7 years ago

React PhotoSwipe

PhotoSwipe, PhotoSwipeGallery component for ReactJS base on PhotoSwipe.

Installation

NPM

npm install --save react-photoswipe

Bower

bower install --save react-photoswipe

Usage

Styles

With webpack:

import 'react-photoswipe/lib/photoswipe.css';

Without webpack:

<link rel="stylesheet" type="text/css" href="path/to/react-photoswipe/lib/photoswipe.css">

JS

PhotoSwipe

import {PhotoSwipe} from 'react-photoswipe';

let isOpen = true;

let items = [
  {
    src: 'http://lorempixel.com/1200/900/sports/1',
    w: 1200,
    h: 900,
    title: 'Image 1'
  },
  {
    src: 'http://lorempixel.com/1200/900/sports/2',
    w: 1200,
    h: 900,
    title: 'Image 2'
  }
];

let options = {
  //http://photoswipe.com/documentation/options.html
};

handleClose = () => {
  isOpen: false
};

<PhotoSwipe isOpen={isOpen} items={items} options={options} onClose={handleClose}/>

PhotoSwipeGallery

import {PhotoSwipeGallery} from 'react-photoswipe';

let items = [
  {
    src: 'http://lorempixel.com/1200/900/sports/1',
    thumbnail: 'http://lorempixel.com/120/90/sports/1',
    w: 1200,
    h: 900,
    title: 'Image 1'
  },
  {
    src: 'http://lorempixel.com/1200/900/sports/2',
    thumbnail: 'http://lorempixel.com/120/90/sports/2',
    w: 1200,
    h: 900,
    title: 'Image 2'
  }
];

let options = {
  //http://photoswipe.com/documentation/options.html
};

getThumbnailContent = (item) => {
  return (
    <img src={item.thumbnail} width={120} height={90}/>
  );
}

<PhotoSwipeGallery items={items} options={options} thumbnailContent={getThumbnailContent}/>

UMD

<link rel="stylesheet" type="text/css" href="path/to/react-photoswipe/dist/photoswipe.css">
<script src="path/to/react-photoswipe/dist/react-photoswipe.js"></script>
var PhotoSwipe = window.ReactPhotoswipe.PhotoSwipe;
var PhotoSwipeGallery = window.ReactPhotoswipe.PhotoSwipeGallery;

Example here

Props

Note: The first argument of every listener is a Photoswipe instance.

EX:

beforeChange(instance, change);
imageLoadComplete(instance, index, item);

PhotoSwipe

NameTypeDefaultRequiredDescription
isOpenboolfalsetrue
itemsarray[]truehttp://photoswipe.com/documentation/getting-started.html
optionsobject{}falsehttp://photoswipe.com/documentation/options.html
onClosefunctionfalseCallback after PhotoSwipe close
idstringfalse
classNamestringpswp
beforeChangefunctionfalsePhotoswipe event listener
afterChangefunctionfalsePhotoswipe event listener
imageLoadCompletefunctionfalsePhotoswipe event listener
resizefunctionfalsePhotoswipe event listener
gettingDatafunctionfalsePhotoswipe event listener
mouseUsedfunctionfalsePhotoswipe event listener
initialZoomInfunctionfalsePhotoswipe event listener
initialZoomInEndfunctionfalsePhotoswipe event listener
initialZoomOutfunctionfalsePhotoswipe event listener
initialZoomOutEndfunctionfalsePhotoswipe event listener
parseVerticalMarginfunctionfalsePhotoswipe event listener
closefunctionfalsePhotoswipe event listener
unbindEventsfunctionfalsePhotoswipe event listener
destroyfunctionfalsePhotoswipe event listener
updateScrollOffsetfunctionfalsePhotoswipe event listener
preventDragEventfunctionfalsePhotoswipe event listener
shareLinkClickfunctionfalsePhotoswipe event listener

PhotoSwipeGallery

NameTypeDefaultRequiredDescription
itemsarray[]truehttp://photoswipe.com/documentation/getting-started.html
optionsobject{}falsehttp://photoswipe.com/documentation/options.html
thumbnailContentfunction<img src={item.src} width='100' height='100'/>falseThumbnail content
isOpenboolfalsefalseUse it with onClose prop
onClosefunctionfalseCallback after close
idstringfalse
classNamestringpswp-gallery
beforeChangefunctionfalsePhotoswipe event listener
afterChangefunctionfalsePhotoswipe event listener
imageLoadCompletefunctionfalsePhotoswipe event listener
resizefunctionfalsePhotoswipe event listener
gettingDatafunctionfalsePhotoswipe event listener
mouseUsedfunctionfalsePhotoswipe event listener
initialZoomInfunctionfalsePhotoswipe event listener
initialZoomInEndfunctionfalsePhotoswipe event listener
initialZoomOutfunctionfalsePhotoswipe event listener
initialZoomOutEndfunctionfalsePhotoswipe event listener
parseVerticalMarginfunctionfalsePhotoswipe event listener
closefunctionfalsePhotoswipe event listener
unbindEventsfunctionfalsePhotoswipe event listener
destroyfunctionfalsePhotoswipe event listener
updateScrollOffsetfunctionfalsePhotoswipe event listener
preventDragEventfunctionfalsePhotoswipe event listener
shareLinkClickfunctionfalsePhotoswipe event listener

Demo

View demo or example folder.