DocSpace-client/web/ASC.Web.Common/src/components/MediaViewer/sub-components/image-viewer.js

215 lines
5.3 KiB
JavaScript
Raw Normal View History

2020-04-19 20:06:17 +00:00
import React from "react";
import PropTypes from "prop-types";
import Viewer from 'react-viewer';
import { Icons } from "asc-web-components";
import styled from "styled-components";
import MediaScrollButton from "./scroll-button"
import ControlBtn from "./control-btn"
2020-04-19 20:06:17 +00:00
const StyledViewer = styled(Viewer)`
.react-viewer-footer{
bottom: 5px!important;
z-index: 4001!important;
overflow: visible;
}
.react-viewer-canvas{
z-index: 4000!important;
margin-top: 50px;
}
.react-viewer-navbar,
2020-05-28 06:06:18 +00:00
.react-viewer-mask,
.react-viewer-attribute,
.react-viewer-close{
display: none
}
2020-05-08 07:18:50 +00:00
.react-viewer-toolbar{
2020-05-28 06:06:18 +00:00
position: relative;
overflow: visible;
2020-05-08 07:18:50 +00:00
bottom: 4px;
}
2020-04-19 20:06:17 +00:00
.react-viewer-toolbar li{
width: 40px;
height:30px;
2020-05-28 06:06:18 +00:00
margin-top: 4px;
2020-04-19 20:06:17 +00:00
border-radius: 2px;
cursor: pointer;
line-height: 24px;
}
.react-viewer-btn{
background-color: transparent;
2020-04-19 20:06:17 +00:00
&:hover{
background-color: rgba(200, 200, 200, 0.2);
}
}
li[data-key='prev']{
left: 20px
}
li[data-key='next']{
right: 20px
}
li[data-key='prev'],
li[data-key='next']{
position: fixed;
top: calc(50% - 20px);
height: auto;
background: none;
&:hover{
background: none;
}
}
li[data-key='delete'],
li[data-key='customDownload']{
position: fixed;
bottom: 10px;
.controlBtn{
margin: 0
}
}
li[data-key='delete']{
right: 62px;
}
li[data-key='customDownload']{
right: 12px;
}
2020-05-05 09:22:58 +00:00
.iconContainer{
width: 20px;
2020-05-28 06:06:18 +00:00
line-height: 20px;
2020-05-05 09:22:58 +00:00
margin: 4px auto;
&.reset{
width: 18px;
}
2020-05-05 09:22:58 +00:00
}
.btnContainer{
display: block;
width: 20px;
margin: 3px 10px;
line-height: 19px;
}
.scrollBtn{
cursor: ${props => props.inactive ? 'default' : 'pointer'};
opacity: ${props => props.inactive ? '0.2' : '1'};
&:hover{
background-color: ${props => !props.inactive ? 'rgba(200, 200, 200, 0.2)' : 'rgba(11,11,11,0.7)'};
}
}
2020-04-19 20:06:17 +00:00
`
var customToolbar = [
{
key: 'zoomIn',
actionType: 1,
2020-05-05 09:22:58 +00:00
render: <div className="iconContainer"><Icons.MediaZoomInIcon size="scale" /></div>
2020-04-19 20:06:17 +00:00
},
{
key: 'zoomOut',
actionType: 2,
2020-05-05 09:22:58 +00:00
render: <div className="iconContainer"><Icons.MediaZoomOutIcon size="scale" /></div>
2020-04-19 20:06:17 +00:00
},
{
key: 'reset',
actionType: 7,
render: <div className="iconContainer reset"><Icons.MediaResetIcon size="scale" /></div>
2020-04-19 20:06:17 +00:00
},
{
key: 'rotateLeft',
actionType: 5,
2020-05-05 09:22:58 +00:00
render: <div className="iconContainer"><Icons.MediaRotateLeftIcon size="scale" /></div>
2020-04-19 20:06:17 +00:00
},
{
key: 'rotateRight',
actionType: 6,
2020-05-05 09:22:58 +00:00
render: <div className="iconContainer"><Icons.MediaRotateRightIcon size="scale" /></div>
},
{
key: 'prev',
actionType: 3,
render: <MediaScrollButton orientation="right" className="scrollBtn"/>
},
{
key: 'next',
actionType: 4,
render: <MediaScrollButton orientation="left" className="scrollBtn"/>
},
{
key: 'delete',
render: <ControlBtn className="controlBtn">
<div className="btnContainer">
<Icons.MediaDeleteIcon size="scale" />
</div>
</ControlBtn>
},
{
key: 'customDownload',
render: <ControlBtn className="controlBtn">
<div className="btnContainer">
<Icons.MediaDownloadIcon size="scale" />
</div>
</ControlBtn>
}
2020-04-19 20:06:17 +00:00
];
class ImageViewer extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: false,
};
2020-04-19 20:06:17 +00:00
}
render() {
2020-04-19 20:06:17 +00:00
const { className, visible, images, inactive } = this.props;
2020-04-19 20:06:17 +00:00
customToolbar.forEach((button) => {
switch (button.key) {
case "prev":
button.onClick = this.props.onPrevClick;
break;
case "next":
button.onClick = this.props.onNextClick;
break;
case "delete":
button.onClick = this.props.onDeleteClick;
break;
case "customDownload":
button.onClick = this.props.onDownloadClick;
break;
default:
break;
}
});
return (
<div className={className}>
2020-04-19 20:06:17 +00:00
<StyledViewer
inactive={inactive}
2020-04-19 20:06:17 +00:00
visible={visible}
customToolbar={(toolbars) => {
return customToolbar;
}}
2020-04-19 20:06:17 +00:00
images={images}
/>
</div>
)
};
}
ImageViewer.propTypes = {
className: PropTypes.string,
visible: PropTypes.bool,
inactive: PropTypes.bool,
images: PropTypes.arrayOf(PropTypes.object),
onNextClick: PropTypes.func,
onPrevClick: PropTypes.func,
onDeleteClick: PropTypes.func,
onDownloadClick: PropTypes.func
}
2020-04-19 20:06:17 +00:00
export default ImageViewer;