1.5.2 • Published 2 years ago

images-viewer-react v1.5.2

Weekly downloads
56
License
MIT
Repository
github
Last release
2 years ago

多图/pdf 预览组件

NPM version

react image viewers.

简介

因为需要支持图片和 pdf 的预览、放大、缩小、折叠、打印下载等功能,所以写了这个组件

安装

react >= 16.8.0 | react-dom >= 16.8.0

npm install images-viewer-react --save

使用方法

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

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>
  )
}

参数

propstypedefaultdescriptionrequired
visiblestringfalse是否显示true
onClosefunction-关闭预览窗口函数true
imagesImageDecorator[][]预览的图片数组true
activeIndexnumber0当前预览图片的 indexfalse
zIndexnumber1000预览图片的时候 zIndexfalse
containerHTMLElementnullinline 模式的容器false
dragbooleantrue拖拽图片的回调false
attributebooleantrue是否显示图片属性false
zoomablebooleantrue是否显示缩放按钮false
rotatablebooleantrue是否显示旋转按钮false
scalablebooleantrue是否显示缩放按钮false
onMaskClick(e) => void-当蒙版被点击时的回调函数false
downloadablebooleanfalse是否显示下载按钮false
noClosebooleanfalse是否隐藏关闭按钮false
noNavbarbooleanfalse是否隐藏导航条false
noToolbarbooleanfalse是否隐藏工具栏false
noImgDetailsbooleanfalse是否隐藏图片详情(width/height)false
noFooterbooleanfalse是否隐藏不呈现页脚false
changeablebooleantrue是否隐藏更改按钮false
customToolbar(defaultToolbarConfigs: ToolbarConfig[]) => ToolbarConfig[]-自定义工具栏false
zoomSpeednumber0.05变焦速度false
defaultSizeViewerImageSize-默认图片大小false
defaultImgviewerdefaultimg-如果图片加载失败显示的默认图片false
disableKeyboardSupportbooleanfalse禁用键盘支持false
noResetZoomAfterChangebooleanfalse没有复位变焦后的图像变化false
noLimitInitializationSizebooleanfalse没有限制图像初始化大小false
defaultScalenumber1默认的放大缩小倍数false
onChange(activeImage: ImageDecorator, index: number) => void-当图片改变时回调的回调false
onPreButton() => void-点击上一张(当 activeIndex<5>)false
onNextButton() => void-点击下一张(当 activeIndex>images.length-5false
loopbooleantrue导航条是否允许图片可循环false
disableMouseZoombooleanfalse是否禁用鼠标滚动缩放图片大小false
downloadInNewWindowbooleanfalse是否在新窗口中下载false
classNamestring-自定义样式名false
showTotalbooleantrue是否显示总数和范围false
maxScalenumber-最大缩放false
minScalenumber0.1最小缩放false

图片资源相关参数

propstypedefaultdescriptionrequired
srcstring-图片资源true
altstring-图片描述false
downloadUrlstring-图片下载的地址false
defaultSizeViewerImageSize-图片大小false

预览图片的大小

propstypedefaultdescriptionrequired
widthnumber-图片宽度true
heightnumber-图片高度true

默认图片相关属性

propstypedefaultdescriptionrequired
srcnumber-图片资源true
widthnumber-图片宽度false
heightnumber-图片高度false

工具栏配置

propstypedefaultdescriptionrequired
keystring-对应的 keytrue
renderReact.ReactNode-工具 render 的内容false
onClickfunction-点击时候的回调false

键盘按钮支持

  • Esc: 关闭预览的视图.
  • : 查看上一张.
  • : 查看下一张.
  • : 放大图片.
  • : 缩小图片.
  • Ctrl + 1: 重置图片或者 pdf 资源.
  • Ctrl + ←: 图片左旋转.
  • Ctrl + →: 图片又旋转.

License

MIT

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.9

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.9

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.8

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.1.2

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago