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-10-20 12:25:46 +03:00
|
|
|
|
2020-11-04 20:55:48 +03:00
|
|
|
import { css, keyframes } from "@emotion/core";
|
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};
|
|
|
|
padding: 8px;
|
|
|
|
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;
|
|
|
|
`;
|
|
|
|
|
|
|
|
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}>
|
|
|
|
<img css={STYLES_FILE_PREVIEW} src={`${Constants.gateways.ipfs}/${props.url}`} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FilePreviewBubble;
|