2020-10-20 12:25:46 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-11-11 04:44:21 +03:00
|
|
|
import * as Validations from "~/common/validations";
|
2020-11-20 01:14:34 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2020-10-20 12:25:46 +03:00
|
|
|
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css, keyframes } from "@emotion/react";
|
2020-10-20 12:25:46 +03:00
|
|
|
import { useState } from "react";
|
|
|
|
|
2020-10-21 01:25:50 +03:00
|
|
|
const fadeIn = keyframes`
|
2020-10-20 12:25:46 +03:00
|
|
|
0%{
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
100%{
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FILE_PREVIEW_BUBBLE = css`
|
|
|
|
z-index: ${Constants.zindex.tooltip};
|
|
|
|
border-radius: 4px;
|
|
|
|
background-color: ${Constants.system.black};
|
2020-10-21 01:25:50 +03:00
|
|
|
animation: ${fadeIn} 200ms ease-out 1;
|
2020-10-20 12:25:46 +03:00
|
|
|
width: 200px;
|
|
|
|
position: absolute;
|
2020-12-09 07:22:17 +03:00
|
|
|
border: 1px solid black;
|
|
|
|
overflow: hidden;
|
2020-10-20 12:25:46 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FILE_PREVIEW = css`
|
2020-10-21 01:25:50 +03:00
|
|
|
display: block;
|
2020-10-20 12:25:46 +03:00
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_BUBBLE_ANCHOR = css`
|
|
|
|
display: inline-flex;
|
|
|
|
align-item: center;
|
|
|
|
justify-content: center;
|
|
|
|
cursor: pointer;
|
|
|
|
`;
|
|
|
|
|
2020-10-21 01:25:50 +03:00
|
|
|
//Jim: the parent of this element needs to be position: relative or this bubble will fly off its position
|
2020-10-20 12:25:46 +03:00
|
|
|
export const FilePreviewBubble = (props) => {
|
|
|
|
const [onHover, setHover] = useState(false);
|
2020-11-11 04:44:21 +03:00
|
|
|
const showPreview = props.type && Validations.isPreviewableImage(props.type) && onHover;
|
2020-10-20 12:25:46 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<div
|
|
|
|
css={STYLES_BUBBLE_ANCHOR}
|
|
|
|
onMouseEnter={() => setHover(true)}
|
|
|
|
onMouseLeave={() => setHover(false)}
|
|
|
|
>
|
|
|
|
{props.children}
|
|
|
|
</div>
|
2020-10-21 01:25:50 +03:00
|
|
|
{showPreview && (
|
2020-10-20 12:25:46 +03:00
|
|
|
<div css={STYLES_FILE_PREVIEW_BUBBLE}>
|
2021-03-07 23:53:54 +03:00
|
|
|
<img css={STYLES_FILE_PREVIEW} src={Strings.getURLfromCID(props.cid)} />
|
2020-10-20 12:25:46 +03:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FilePreviewBubble;
|