2.2.7 • Published 7 years ago

react-viewer-mda v2.2.7

Weekly downloads
26
License
MIT
Repository
github
Last release
7 years ago

react-viewer-mda

NPM version

react image viewer.

Introduction

Because i can`t comfortable use viewerjs in react, so i create react-viewer to replace it. This is a fork of react-viewer.

v2.2.5

  • Added downloadable option to image download.
  • Hide navigation arrows when shows only one image.

v2.2.6

  • Added afterChange property.
  • Disable apropriate keyboard shortcuts when zoomable and rotatable is set to false.

Installation

npm install react-viewer-mda --save

Usage

import * as React from 'react';
import Viewer from 'react-viewer-mda';
import 'react-viewer-mda/dist/index.css';

class App extends React.Component<any, any> {
  constructor() {
    super();

    this.state = {
      visible: false,
    };
  }

  render() {
    return (
      <div>
        <button onClick={() => { this.setState({ visible: !this.state.visible }); } }>show</button>
        <Viewer
        visible={this.state.visible}
        onClose={() => { this.setState({ visible: false }); } }
        images={[{src: '', alt: '', name: ''}]}
        />
      </div>
    );
  }
}

Props

propstypedefaultdescriptionrequired
visiblestringfalseViewer visibletrue
afterChangestringnoopSpecify a function that will be called when active index changesfalse
onClosestring-Specify a function that will be called when Visible closetrue
images{src: string, alt: string}[][]image source arraytrue
activeIndexnumber0active image indexfalse
zIndexnumber1000Viewer css z-indexfalse
containerHTMLElementnullset parent node(inline mode)false
dragbooleantruewhether to drag imagefalse
attributebooleantruewhether to show image attributefalse
zoomablebooleantruewhether to show 'zoom' buttomfalse
rotatablebooleantruewhether to show 'rotate' buttonfalse
scalablebooleantruewhether to show 'scale' buttonfalse
downloadablebooleantruewhether to show 'download' buttonfalse

Keyboard support

  • Esc: Close viewer.
  • : View the previous image.
  • : View the next image.
  • : Zoom in the image.
  • : Zoom out the image.
  • Ctrl + 1: Reset the image.
  • Ctrl + ←: Rotate left the image.
  • Ctrl + →: Rotate right the image.

License

MIT