2022-10-12 18:22:22 +00:00
|
|
|
import * as React from "react";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import Icon, { ActionType } from "./icon";
|
|
|
|
|
2023-01-27 14:08:30 +00:00
|
|
|
import MediaContextMenu from "PUBLIC_DIR/images/vertical-dots.react.svg";
|
2022-10-27 11:07:09 +00:00
|
|
|
|
2022-10-12 18:22:22 +00:00
|
|
|
const ToolbarItem = styled.li`
|
|
|
|
height: 48px;
|
|
|
|
width: 48px;
|
2022-12-30 08:25:44 +00:00
|
|
|
|
|
|
|
${(props) => (props.isSeparator ? "width: 33px;" : "width: 48px;")}
|
2022-10-12 18:22:22 +00:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2023-01-13 13:14:55 +00:00
|
|
|
.zoomPercent {
|
|
|
|
font-size: 10px;
|
2023-01-16 11:31:06 +00:00
|
|
|
font-weight: 700;
|
2023-01-17 08:23:17 +00:00
|
|
|
-webkit-user-select: none;
|
2023-01-13 13:14:55 +00:00
|
|
|
}
|
|
|
|
|
2023-01-17 09:19:17 +00:00
|
|
|
.zoomOut,
|
|
|
|
.zoomIn,
|
|
|
|
.rotateLeft,
|
|
|
|
.rotateRight {
|
|
|
|
margin-top: 3px;
|
|
|
|
}
|
|
|
|
|
2022-10-12 18:22:22 +00:00
|
|
|
svg {
|
2023-01-17 08:01:26 +00:00
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
2022-10-12 18:22:22 +00:00
|
|
|
path,
|
|
|
|
rect {
|
2022-10-27 15:04:16 +00:00
|
|
|
${(props) => (props.percent !== 25 ? "fill: #fff;" : "fill: #BEBEBE;")}
|
2022-10-12 18:22:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const defaultToolbars = [
|
|
|
|
{
|
|
|
|
key: "zoomIn",
|
|
|
|
actionType: ActionType.zoomIn,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "zoomOut",
|
|
|
|
actionType: ActionType.zoomOut,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "prev",
|
|
|
|
actionType: ActionType.prev,
|
|
|
|
noHover: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "reset",
|
|
|
|
actionType: ActionType.reset,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "next",
|
|
|
|
actionType: ActionType.next,
|
|
|
|
noHover: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "rotateLeft",
|
|
|
|
actionType: ActionType.rotateLeft,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "rotateRight",
|
|
|
|
actionType: ActionType.rotateRight,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "scaleX",
|
|
|
|
actionType: ActionType.scaleX,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "scaleY",
|
|
|
|
actionType: ActionType.scaleY,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "download",
|
|
|
|
actionType: ActionType.download,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
function deleteToolbarFromKey(toolbars, keys) {
|
|
|
|
const targetToolbar = toolbars.filter((item) => keys.indexOf(item.key) < 0);
|
|
|
|
|
|
|
|
return targetToolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function ViewerToolbar(props) {
|
|
|
|
function handleAction(config) {
|
2023-01-18 13:50:38 +00:00
|
|
|
clearTimeout(props.imageTimer);
|
2022-10-27 15:04:16 +00:00
|
|
|
if (config.key === "percent") return props.onPercentClick();
|
2022-10-12 18:22:22 +00:00
|
|
|
props.onAction(config);
|
|
|
|
}
|
|
|
|
|
2022-10-27 11:07:09 +00:00
|
|
|
const iconRef = React.useRef(null);
|
|
|
|
|
2022-10-12 18:22:22 +00:00
|
|
|
function renderAction(config) {
|
|
|
|
let content = null;
|
|
|
|
if (typeof ActionType[config.actionType] !== "undefined") {
|
|
|
|
content = <Icon type={config.actionType} />;
|
|
|
|
}
|
|
|
|
if (config.render) {
|
|
|
|
content = config.render;
|
|
|
|
}
|
|
|
|
|
2022-10-27 15:04:16 +00:00
|
|
|
if (config.key === "percent") {
|
|
|
|
content = (
|
|
|
|
<div
|
|
|
|
className="iconContainer zoomPercent"
|
|
|
|
style={{ width: "auto", color: "#fff", userSelect: "none" }}
|
|
|
|
>
|
|
|
|
{`${props.percent}%`}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-27 11:07:09 +00:00
|
|
|
if (config.key === "context-menu") {
|
2022-11-17 14:59:50 +00:00
|
|
|
const contextMenu = props.generateContextMenu(props.isOpen);
|
2022-10-27 11:07:09 +00:00
|
|
|
return (
|
|
|
|
<ToolbarItem
|
|
|
|
ref={iconRef}
|
|
|
|
style={{ position: "relative" }}
|
|
|
|
noHover={config.noHover}
|
|
|
|
key={config.key}
|
|
|
|
className={`${props.prefixCls}-btn`}
|
2023-01-17 10:55:10 +00:00
|
|
|
onClick={() => {
|
|
|
|
props.setIsOpenContextMenu((open) => !open);
|
|
|
|
props.setIsOpen((open) => !open);
|
|
|
|
}}
|
2022-10-27 11:07:09 +00:00
|
|
|
data-key={config.key}
|
|
|
|
>
|
|
|
|
<div className="context" style={{ height: "16px" }}>
|
|
|
|
<MediaContextMenu size="scale" />
|
|
|
|
</div>
|
|
|
|
{contextMenu}
|
|
|
|
</ToolbarItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-12 18:22:22 +00:00
|
|
|
return (
|
|
|
|
<ToolbarItem
|
2022-10-27 15:04:16 +00:00
|
|
|
percent={config.percent ? props.percent : 100}
|
2022-10-12 18:22:22 +00:00
|
|
|
noHover={config.noHover}
|
|
|
|
key={config.key}
|
2022-12-30 08:25:44 +00:00
|
|
|
isSeparator={config.actionType === -1}
|
2022-10-12 18:22:22 +00:00
|
|
|
className={`${props.prefixCls}-btn`}
|
|
|
|
onClick={() => {
|
|
|
|
handleAction(config);
|
|
|
|
}}
|
|
|
|
data-key={config.key}
|
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</ToolbarItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
let toolbars = props.toolbars;
|
2022-11-02 15:07:05 +00:00
|
|
|
|
|
|
|
if (!props.isMobileOnly) {
|
|
|
|
toolbars = deleteToolbarFromKey(toolbars, ["delete", "favorite"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.isMobileOnly) {
|
|
|
|
toolbars = deleteToolbarFromKey(toolbars, [
|
|
|
|
"zoomIn",
|
|
|
|
"zoomOut",
|
|
|
|
"percent",
|
|
|
|
"separator",
|
|
|
|
"context-menu",
|
|
|
|
]);
|
|
|
|
}
|
2022-10-12 18:22:22 +00:00
|
|
|
if (!props.zoomable) {
|
|
|
|
toolbars = deleteToolbarFromKey(toolbars, ["zoomIn", "zoomOut"]);
|
|
|
|
}
|
|
|
|
if (!props.changeable) {
|
|
|
|
toolbars = deleteToolbarFromKey(toolbars, ["prev", "next"]);
|
|
|
|
}
|
|
|
|
if (!props.rotatable) {
|
|
|
|
toolbars = deleteToolbarFromKey(toolbars, ["rotateLeft", "rotateRight"]);
|
|
|
|
}
|
|
|
|
if (!props.scalable) {
|
|
|
|
toolbars = deleteToolbarFromKey(toolbars, ["scaleX", "scaleY"]);
|
|
|
|
}
|
2023-01-12 16:31:40 +00:00
|
|
|
|
2023-01-30 15:44:15 +00:00
|
|
|
if (props.isPreviewFile || props.archiveRoom) {
|
2023-01-12 16:31:40 +00:00
|
|
|
toolbars = deleteToolbarFromKey(toolbars, [
|
|
|
|
"context-menu",
|
|
|
|
"context-separator",
|
|
|
|
]);
|
|
|
|
}
|
2022-12-01 14:03:35 +00:00
|
|
|
// if (!props.downloadable) {
|
|
|
|
// toolbars = deleteToolbarFromKey(toolbars, ["download"]);
|
|
|
|
// }
|
2022-10-12 18:22:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ul className={`${props.prefixCls}-toolbar`}>
|
|
|
|
{toolbars.map((item) => {
|
|
|
|
return renderAction(item);
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|