1 | import React, { Component } from 'react';
|
2 | import ReactDOM from 'react-dom';
|
3 | import PropTypes from 'prop-types';
|
4 | import ViewerJs from 'viewerjs';
|
5 |
|
6 | const 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 | };
|
17 | const defaultProps = {
|
18 | ready:()=>{},
|
19 | show:()=>{},
|
20 | shown:()=>{},
|
21 | hide:()=>{},
|
22 | hidden:()=>{},
|
23 | view:()=>{},
|
24 | viewed:()=>{},
|
25 | zoom:()=>{},
|
26 | zoomed:()=>{}
|
27 | };
|
28 |
|
29 | class 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 |
|
56 | Viewer.propTypes = propTypes;
|
57 | Viewer.defaultProps = defaultProps;
|
58 |
|
59 | export default Viewer; |
\ | No newline at end of file |