New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-photo-view

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-photo-view

一款精致的 React 的图片预览组件

  • 0.3.10
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-photo-view

一款精致的 React 的图片预览组件

npm react-photo-view react-photo-view

Demo: https://minjieliu.github.io/react-photo-view

特性

  1. 支持左右切换导航、上/下滑关闭、双击放大/缩小、双指放大/缩小/平移、键盘导航/关闭、点击切换控件等
  2. 打开/关闭缩放动画
  3. 自适应图像适应
  4. 支持桌面端(兼容 IE10+)/移动端
  5. 轻量的体积
  6. 高度的扩展性
  7. 支持服务端渲染
  8. 基于 typescript 友好的语法提示

开始使用

yarn add react-photo-view

基本:

import { PhotoProvider, PhotoConsumer } from 'react-photo-view';
import 'react-photo-view/dist/index.css';

function ImageView() {
  return (
    <PhotoProvider>
      {photoImages.map((item, index) => (
        <PhotoConsumer key={index} src={item} intro={item}>
          <img src={item} alt="" />
        </PhotoConsumer>
      ))}
    </PhotoProvider>
  );
}

受控 PhotoSlider

function ImageView() {
  const [visible, setVisible] = React.useState(false);
  const [photoIndex, setPhotoIndex] = React.useState(0);

  return (
    <div>
      <Button onClick={() => setVisible(true)}>打开</Button>
      <PhotoSlider
        images={photoImages.map(item => ({ src: item }))}
        visible={visible}
        onClose={() => setVisible(false)}
        index={photoIndex}
        onIndexChange={setPhotoIndex}
      />
    </div>
  );
}

API

PhotoProvider
名称类型必选描述
childrenReact.ReactNode
maskClosableboolean背景可点击关闭,默认 true
photoClosableboolean图片点击可关闭,默认 false
bannerVisibleboolean导航条 visible,默认 true
introVisibleboolean简介 visible,默认 true
overlayRender(overlayProps) => React.ReactNode自定义渲染
classNamestringclassName
maskClassNamestring遮罩 className
viewClassNamestring图片容器 className
imageClassNamestring图片 className
loadingElementJSX.Element自定义 loading
brokenElementJSX.Element加载失败 Element
PhotoConsumer
名称类型必选描述
srcstring图片地址
introReact.ReactNode图片介绍
childrenReact.ReactElement

注意:若 PhotoConsumerchildren 为自定义组件

  1. 需要向外部参数暴露 React.HTMLAttributes
  2. 展开/关闭动画精准位置则需要用 React.forwardRef 暴露内部 React.ReactHTMLElement 节点的 Ref
PhotoSlider

继承自 PhotoProvider。手动控制 react-photo-view 的展现与隐藏

名称类型必选描述
imagesdataType[]图片列表
indexnumber图片当前索引
visibleboolean可见
onClose(evt) => void关闭事件
onIndexChangeFunction索引改变回调

谁在使用

Keywords

FAQs

Package last updated on 08 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc