3.2.2 • Published 4 years ago

react-viewer v3.2.2

Weekly downloads
7,892
License
MIT
Repository
github
Last release
4 years ago

react-viewer

NPM version npm.io codecov

react image viewer.

Introduction

Because I can`t be comfortable using viewerjs in react, so I created react-viewer to replace it.

Installation

react >= 16.8.0 | react-dom >= 16.8.0

npm install react-viewer --save

Usage

import * as React from 'react';
import Viewer from 'react-viewer';

function App() {
  const [ visible, setVisible ] = React.useState(false);

  return (
    <div>
      <button onClick={() => { setVisible(true); } }>show</button>
      <Viewer
      visible={visible}
      onClose={() => { setVisible(false); } }
      images={[{src: '', alt: ''}]}
      />
    </div>
  );
}

Server Side Rendering

I'm sorry, ssr is not currently supported in 3.x, it will be fixed in 4.0.

Props

propstypedefaultdescriptionrequired
visiblestringfalseViewer visibletrue
onClosefunction-Specify a function that will be called when Visible closetrue
imagesImageDecorator[][]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' buttonfalse
rotatablebooleantruewhether to show 'rotate' buttonfalse
scalablebooleantruewhether to show 'scale' buttonfalse
onMaskClick(e) => void-callback function when mask is clickedfalse
downloadablebooleanfalsewhether to show 'download'false
noClosebooleanfalseto not render close buttonfalse
noNavbarbooleanfalseto not render the navbarfalse
noToolbarbooleanfalseto not render the toolbarfalse
noImgDetailsbooleanfalseto not render image detail (WxH)false
noFooterbooleanfalseto not render the entire footerfalse
changeablebooleantruewheather to show change buttonfalse
customToolbar(defaultToolbarConfigs: ToolbarConfig[]) => ToolbarConfig[]-customer toolbarfalse
zoomSpeednumber0.05zoom speedfalse
defaultSizeViewerImageSize-default image sizefalse
defaultImgviewerdefaultimg-if load img failed, show default imgfalse
disableKeyboardSupportbooleanfalsedisable keyboard supportfalse
noResetZoomAfterChangebooleanfalsepreserve zoom after image changefalse
noLimitInitializationSizebooleanfalseno limit image initialization sizefalse
defaultScalenumber1set default scalefalse
onChange(activeImage: ImageDecorator, index: number) => void-callback when iamge changefalse
loopbooleantruewhether enable image loopfalse
disableMouseZoombooleanfalsewhether disable mouse zoomfalse
downloadInNewWindowbooleanfalsewhether to download in a new windowfalse
classNamestring-customized CSS classfalse
showTotalbooleantruewhether to display the total number and rangefalse
maxScalenumber-maximum scalingfalse
minScalenumber0.1minimum scalingfalse

ImageDecorator

propstypedefaultdescriptionrequired
srcstring-image sourcetrue
altstring-image descriptionfalse
downloadUrlstring-image downlaod urlfalse
defaultSizeViewerImageSize-image sizefalse

ViewerImageSize

propstypedefaultdescriptionrequired
widthnumber-image widthtrue
heightnumber-image heighttrue

ViewerDefaultImg

propstypedefaultdescriptionrequired
srcnumber-image sourcetrue
widthnumber-image widthfalse
heightnumber-image heightfalse

ToolbarConfig

propstypedefaultdescriptionrequired
keystring-tool keytrue
renderReact.ReactNode-tool renderfalse
onClickfunction-callback function when action is clickedfalse

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

cmhit-front-componentshzero-boothzero-boot-purehzero-front-runtime@infinitebrahmanuniverse/nolb-react-vhelper-centersnbc-paas-bootcpaas-bootwiseboxxgui-for-reactxiaomai-m-componentsstarfish-libistrong-react-componentmhc-adminmhc-antd-adminmitter-web-reactknew-uiimages-galleryifunuikitmed-im-chatmed-im-componentsluck-reactopen-yqcloud-front-bootomnichat_web_componentsonchain-sdkproduction-webreact-amplify-wrappernew-yqcloud-front-bootsiemens-op-yqcloud-front-bootsixue-photo-previewtlf-componentttk-app-corettk-componenttuya-alioth@aistarfish/lib@beisen-elearning/manage-courses-edit@beisen-elearning/ux-p-man-courseware-lib@bayer/ol-kit@chaoswise/uiyes-frameworkzcxvzxcvxzvyangtze-uiyqcloud-front-bootyqcloud-front-boot-testyrantdzeal-cubeupload-file-toolsxtra-web-components@greatz/feedback@greatz/feedback-plugin@hipop/rich-markdown-editor@iicoding/ui@isle-project/components@epig/admin-tools@everything-registry/sub-chunk-2622@might-dev/work-table@crawless/ui@cver-design/pro-preview@cver-design/pro-web@cver-design/web@detorrevc/widget@detorrevc/react-echat-widgetcrpcg-yqcloud-front-bootdadada111dynamicform-for-xguicifccommercial-scaffold-mddcomponents_amincontenful-graph-webdlt-for-reactdfxk-admin-toolsdokb-wisebot@moon-design/pro-preview@moon-design/pro-web@qiejs/rui@ttk/component@titaui/rich-editor@xyfe/uikitbelajar-uikitarachne-uiasuna-adminav-libraryantduipackageantd-form-matefr-testfamcfamc-cmbfamc-i18nfaw-yqcloud-front-bootfeup-designfk-componentfaw-op-yqcloud-front-bootfaw-op-yqcloud-front-boot-another
3.2.2

4 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.11.1

5 years ago

2.11.0

5 years ago

2.10.2

5 years ago

2.10.1

5 years ago

2.10.0

5 years ago

2.9.1

5 years ago

2.9.0

5 years ago

2.8.1

6 years ago

2.8.0

6 years ago

2.7.0

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.4

6 years ago

2.5.3

6 years ago

2.5.2

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.0

7 years ago

2.3.9

7 years ago

2.3.8

7 years ago

2.3.7

7 years ago

2.3.6

7 years ago

2.3.5

7 years ago

2.3.4

7 years ago

2.3.3

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.6

7 years ago

2.2.5

7 years ago

2.2.4

8 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.6

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago