All Projects → specter256 → react-simple-image-viewer

specter256 / react-simple-image-viewer

Licence: MIT license
Simple image viewer component for React

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-simple-image-viewer

Silentbox
A lightbox inspired Vue.js component.
Stars: ✭ 196 (+345.45%)
Mutual labels:  gallery, images, lightbox, image-viewer
Nanogallery2
a modern photo / video gallery and lightbox [JS library]
Stars: ✭ 488 (+1009.09%)
Mutual labels:  gallery, images, lightbox
Spotlight
Web's most easy to integrate lightbox gallery library. Super-lightweight, outstanding performance, no dependencies.
Stars: ✭ 799 (+1715.91%)
Mutual labels:  gallery, lightbox, image-viewer
hes-gallery
Light, dependency free, responsive gallery script
Stars: ✭ 27 (-38.64%)
Mutual labels:  gallery, images, lightbox
React Grid Gallery
Justified image gallery component for React
Stars: ✭ 571 (+1197.73%)
Mutual labels:  gallery, images, lightbox
Simple React Lightbox
A simple but functional light-box for React.
Stars: ✭ 265 (+502.27%)
Mutual labels:  gallery, images, lightbox
Lightgallery.js
Full featured JavaScript image & video gallery. No dependencies
Stars: ✭ 5,168 (+11645.45%)
Mutual labels:  gallery, lightbox
React Native Image Gallery
Pure JavaScript image gallery component for iOS and Android with high-performance and native feeling in mind
Stars: ✭ 601 (+1265.91%)
Mutual labels:  gallery, images
Glightbox
Pure Javascript lightbox with mobile support. It can handle images, videos with autoplay, inline content and iframes
Stars: ✭ 702 (+1495.45%)
Mutual labels:  gallery, lightbox
Photo view
📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.
Stars: ✭ 1,280 (+2809.09%)
Mutual labels:  gallery, images
V Img
Stars: ✭ 400 (+809.09%)
Mutual labels:  gallery, images
Photobox
A lightweight CSS3 image viewer that is pretty to look and and easy to use
Stars: ✭ 735 (+1570.45%)
Mutual labels:  gallery, image-viewer
Natural Gallery Js
A lazy load, infinite scroll and natural layout list gallery
Stars: ✭ 93 (+111.36%)
Mutual labels:  gallery, lightbox
Ngx Gallery
Angular Gallery, Carousel and Lightbox
Stars: ✭ 417 (+847.73%)
Mutual labels:  gallery, lightbox
Vue Gallery
📷 Responsive and customizable image and video gallery, carousel and lightbox, optimized for both mobile and desktop web browsers.
Stars: ✭ 405 (+820.45%)
Mutual labels:  gallery, images
Baguettebox.js
⚡ Simple and easy to use lightbox script written in pure JavaScript
Stars: ✭ 2,252 (+5018.18%)
Mutual labels:  gallery, lightbox
React Slideshow
A react component for slideshow supporting slide, fade and zoom
Stars: ✭ 201 (+356.82%)
Mutual labels:  gallery, images
MediaSliderView
Pure java based, highly customizable media slider gallery supporting both images and videos for android.
Stars: ✭ 85 (+93.18%)
Mutual labels:  gallery, images
Perfect Layout
Image layout generator based on linear partitioning
Stars: ✭ 312 (+609.09%)
Mutual labels:  gallery, images
React Native Gallery Toolkit
Reanimated 2 powered gallery implementation
Stars: ✭ 379 (+761.36%)
Mutual labels:  gallery, lightbox

React Simple Image Viewer

npm version Build Status

Simple image viewer component for React.

Installation

$ npm install react-simple-image-viewer

or

$ yarn add react-simple-image-viewer

Example

import React, { useState, useCallback } from 'react';
import { render } from 'react-dom';
import ImageViewer from 'react-simple-image-viewer';

function App() {
  const [currentImage, setCurrentImage] = useState(0);
  const [isViewerOpen, setIsViewerOpen] = useState(false);
  const images = [
    'http://placeimg.com/1200/800/nature',
    'http://placeimg.com/800/1200/nature',
    'http://placeimg.com/1920/1080/nature',
    'http://placeimg.com/1500/500/nature',
  ];

  const openImageViewer = useCallback((index) => {
    setCurrentImage(index);
    setIsViewerOpen(true);
  }, []);

  const closeImageViewer = () => {
    setCurrentImage(0);
    setIsViewerOpen(false);
  };

  return (
    <div>
      {images.map((src, index) => (
        <img
          src={ src }
          onClick={ () => openImageViewer(index) }
          width="300"
          key={ index }
          style={{ margin: '2px' }}
          alt=""
        />
      ))}

      {isViewerOpen && (
        <ImageViewer
          src={ images }
          currentIndex={ currentImage }
          disableScroll={ false }
          closeOnClickOutside={ true }
          onClose={ closeImageViewer }
        />
      )}
    </div>
  );
}

render(<App />, document.getElementById('app'));

Demo

Try out demo on CodeSandbox

API

Property Type Description
src string[] Array of image URLs
currentIndex number Index of image in src property which will be shown first when viewer is opened
onClose function Callback which will be called when viewer will closed
backgroundStyle object Custom styles for background of modal window
disableScroll boolean Disable scrolling images by mouse wheel
closeOnClickOutside boolean Whether viewer should be closed when clicking outside of image
closeComponent JSX.Element Custom component for the close button
leftArrowComponent JSX.Element Custom component for the left arrow
rightArrowComponent JSX.Element Custom component for the right arrow

Shortcuts

Shortcut Description
Escape Close the viewer
Right Arrow / l Next image
Left Arrow / h Previous image
Mouse wheel Scrolling previous / next image
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].