slate/components/core/SlateMediaObjectPreview.js
2020-08-26 21:24:49 -07:00

58 lines
1.6 KiB
JavaScript

import * as React from "react";
import * as Constants from "~/common/constants";
import { css } from "@emotion/react";
const STYLES_IMAGE = css`
display: block;
max-width: 100%;
max-height: 100%;
pointer-events: none;
transition: 200ms ease all;
`;
const STYLES_ENTITY = css`
height: 100%;
width: 100%;
border: 1px solid ${Constants.system.border};
background-color: ${Constants.system.foreground};
font-size: 24px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
pointer-events: none;
`;
export default class SlateMediaObjectPreview extends React.Component {
render() {
// NOTE(jim):
// This is a hack to catch this undefined case I don't want to track down yet.
const url = this.props.url.replace("https://undefined", "https://");
let element = <article css={STYLES_ENTITY}>No Preview</article>;
if (this.props.type && this.props.type.startsWith("video/")) {
element = <article css={STYLES_ENTITY}>Video</article>;
}
if (this.props.type && this.props.type.startsWith("audio/")) {
element = <article css={STYLES_ENTITY}>Audio</article>;
}
if (this.props.type && this.props.type.startsWith("application/epub")) {
element = <article css={STYLES_ENTITY}>EPub</article>;
}
if (this.props.type && this.props.type.startsWith("application/pdf")) {
element = <article css={STYLES_ENTITY}>PDF</article>;
}
if (this.props.type && this.props.type.startsWith("image/")) {
element = <img css={STYLES_IMAGE} src={url} />;
}
return element;
}
}