UNPKG

1.26 kBJavaScriptView Raw
1import React, { Component } from 'react';
2import ReactDOM from 'react-dom';
3import PropTypes from 'prop-types';
4import ViewerJs from 'viewerjs';
5
6const propTypes = {
7 ready:PropTypes.func,
8 show:PropTypes.func,
9 shown:PropTypes.func,
10 hide:PropTypes.func,
11 hidden:PropTypes.func,
12 view:PropTypes.func,
13 viewed:PropTypes.func,
14 zoom:PropTypes.func,
15 zoomed:PropTypes.func,
16};
17const defaultProps = {
18 ready:()=>{},
19 show:()=>{},
20 shown:()=>{},
21 hide:()=>{},
22 hidden:()=>{},
23 view:()=>{},
24 viewed:()=>{},
25 zoom:()=>{},
26 zoomed:()=>{}
27};
28
29class Viewer extends Component {
30 constructor(props){
31 super(props)
32 }
33
34 componentDidMount(){
35 this.viewerCase = new ViewerJs(ReactDOM.findDOMNode(this.refs.views),{
36 url: 'data-original',
37 ...this.props
38 })
39 }
40 componentWillUnmount(){
41 this.viewerCase.destroy()
42 }
43 render () {
44 return (
45 <div>
46 {
47 React.cloneElement(this.props.children,{
48 ref:'views'
49 })
50 }
51 </div>
52 )
53 }
54};
55
56Viewer.propTypes = propTypes;
57Viewer.defaultProps = defaultProps;
58
59export default Viewer;
\No newline at end of file