2020-09-01 07:44:56 +03:00
|
|
|
import React, { Component } from "react";
|
2020-08-31 21:19:46 +03:00
|
|
|
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-09-01 07:44:56 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
2020-08-31 21:19:46 +03:00
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
import SlateMediaObjectPreview from "~/components/core/SlateMediaObjectPreview";
|
|
|
|
|
|
|
|
const STYLES_IMAGE_ROW = css`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-wrap: wrap;
|
2020-09-04 01:42:08 +03:00
|
|
|
height: 186px;
|
2020-08-31 21:19:46 +03:00
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
@media (max-width: ${Constants.sizes.mobile}px) {
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ITEM_BOX = css`
|
|
|
|
width: 186px;
|
|
|
|
height: 186px;
|
|
|
|
padding: 16px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export function SlatePreviewRow(props) {
|
|
|
|
let numItems = props.numItems || 5;
|
|
|
|
let objects =
|
|
|
|
props.slate.data.objects.length > numItems
|
|
|
|
? props.slate.data.objects.slice(0, numItems)
|
|
|
|
: props.slate.data.objects;
|
|
|
|
return (
|
|
|
|
<div css={STYLES_IMAGE_ROW} style={props.containerStyle}>
|
|
|
|
{objects.map((each) => (
|
|
|
|
<div key={each.url} css={STYLES_ITEM_BOX} style={props.style}>
|
|
|
|
<SlateMediaObjectPreview
|
|
|
|
type={each.type}
|
|
|
|
url={each.url}
|
|
|
|
style={props.previewStyle}
|
2020-09-01 02:09:57 +03:00
|
|
|
title={each.title || each.name}
|
|
|
|
small={props.small}
|
2020-08-31 21:19:46 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const STYLES_BLOCK = css`
|
|
|
|
border: 1px solid ${Constants.system.border};
|
2020-09-04 01:42:08 +03:00
|
|
|
border-radius: 20px;
|
|
|
|
padding: 40px;
|
2020-08-31 21:19:46 +03:00
|
|
|
font-size: 12px;
|
|
|
|
text-align: left;
|
2020-09-04 01:42:08 +03:00
|
|
|
margin: 24px auto 48px auto;
|
|
|
|
max-width: 1012px;
|
2020-08-31 21:19:46 +03:00
|
|
|
cursor: pointer;
|
|
|
|
`;
|
|
|
|
|
2020-09-01 07:44:56 +03:00
|
|
|
const STYLES_TITLE_LINE = css`
|
|
|
|
display: grid;
|
2020-09-03 02:17:31 +03:00
|
|
|
grid-template-columns: auto auto 1fr;
|
2020-09-01 07:44:56 +03:00
|
|
|
align-items: center;
|
2020-08-31 21:19:46 +03:00
|
|
|
font-size: ${Constants.typescale.lvl1};
|
2020-09-01 07:44:56 +03:00
|
|
|
margin-bottom: 16px;
|
2020-08-31 21:19:46 +03:00
|
|
|
`;
|
|
|
|
|
2020-09-01 07:44:56 +03:00
|
|
|
const STYLES_BUTTON = css`
|
|
|
|
display: inline-block;
|
|
|
|
margin-left: 12px;
|
|
|
|
padding: 4px 8px;
|
|
|
|
cursor: pointer;
|
|
|
|
color: ${Constants.system.brand};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_COPY_INPUT = css`
|
|
|
|
pointer-events: none;
|
|
|
|
position: absolute;
|
|
|
|
tabindex: -1;
|
|
|
|
opacity: 0;
|
|
|
|
`;
|
|
|
|
|
2020-09-03 02:17:31 +03:00
|
|
|
const STYLES_TAG = css`
|
|
|
|
margin-left: 24px;
|
|
|
|
padding: 4px 8px;
|
2020-09-04 01:42:08 +03:00
|
|
|
border-radius: 2px;
|
2020-09-03 02:17:31 +03:00
|
|
|
background-color: ${Constants.system.gray};
|
|
|
|
color: ${Constants.system.white};
|
|
|
|
`;
|
|
|
|
|
2020-09-01 07:44:56 +03:00
|
|
|
export default class SlatePreviewBlock extends Component {
|
|
|
|
_ref;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
copyable: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleCopy = (e, value) => {
|
|
|
|
console.log("copy");
|
|
|
|
this.setState({ copyable: value }, () => {
|
|
|
|
this._ref.select();
|
|
|
|
document.execCommand("copy");
|
|
|
|
});
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div css={STYLES_BLOCK}>
|
|
|
|
<div css={STYLES_TITLE_LINE}>
|
|
|
|
<strong style={{ fontSize: Constants.typescale.lvl2 }}>
|
|
|
|
{this.props.slate.data.name}
|
|
|
|
</strong>
|
2020-09-03 02:17:31 +03:00
|
|
|
{this.props.editing ? (
|
|
|
|
this.props.slate.data.public ? (
|
2020-09-04 01:42:08 +03:00
|
|
|
<div
|
|
|
|
css={STYLES_TAG}
|
|
|
|
style={{ backgroundColor: Constants.system.brand }}
|
|
|
|
>
|
|
|
|
Public
|
|
|
|
</div>
|
2020-09-03 02:17:31 +03:00
|
|
|
) : (
|
|
|
|
<div css={STYLES_TAG}>Private</div>
|
|
|
|
)
|
2020-09-01 07:44:56 +03:00
|
|
|
) : null}
|
|
|
|
{this.props.editing ? (
|
|
|
|
<div style={{ justifySelf: "end" }}>
|
|
|
|
<div
|
|
|
|
css={STYLES_BUTTON}
|
|
|
|
onClick={(e) => this._handleCopy(e, this.props.slate.id)}
|
|
|
|
>
|
|
|
|
Copy ID
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
<SlatePreviewRow
|
|
|
|
{...this.props}
|
|
|
|
previewStyle={this.props.previewStyle}
|
|
|
|
/>
|
|
|
|
<input
|
2020-09-04 01:42:08 +03:00
|
|
|
readOnly
|
2020-09-01 07:44:56 +03:00
|
|
|
ref={(c) => {
|
|
|
|
this._ref = c;
|
|
|
|
}}
|
|
|
|
value={this.state.copyable}
|
|
|
|
css={STYLES_COPY_INPUT}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-08-31 21:19:46 +03:00
|
|
|
}
|