0.0.10 • Published 2 years ago

eco-react-image-viewer v0.0.10

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

eco-react-image-viewer

npm GitHub

基于react的图片预览组件,兼容 PC、移动端

查看文档和示例

使用

npm 或 yarn 安装

npm install eco-react-image-viewer --save

or

yarn add eco-react-image-viewer

示例

import React, { useState } from 'react';
import ImageViewer from 'eco-react-image-viewer';

import aLg from '../../fixtures/images/a-lg.png';
import aMd from '../../fixtures/images/a-md.png';
import xLg from '../../fixtures/images/x-lg.png';
import xMd from '../../fixtures/images/x-md.png';
import yLg from '../../fixtures/images/y-lg.png';
import yMd from '../../fixtures/images/y-md.png';

export default () => {
  const [visible, setVisible] = useState<boolean>(false);
  const [index, setIndex] = useState<number>(0);

  const onClose = () => setVisible((val) => !val);

  return (
    <div>
      <div onClick={onClose}>预览</div>
      <ImageViewer
        visible={visible}
        urls={[aLg, aMd, xLg, xMd, yLg, yMd]}
        onClose={onClose}
        index={index}
        onIndexChange={setIndex}
      />
    </div>
  );
};

API

属性说明类型默认值
urls图片数组string[][]
visible控制显示/隐藏booleanfalse
onClose关闭预览回调() => void-
index当前展示图片的下标number0
onIndexChange图片切换回调(val: number) => void-
0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago