slate/components/core/SlatePicker.js

194 lines
5.1 KiB
JavaScript
Raw Normal View History

2020-09-27 07:43:25 +03:00
import * as React from "react";
import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
import * as SVG from "~/common/svg";
import * as UserBehaviors from "~/common/user-behaviors";
2020-09-27 07:43:25 +03:00
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
2020-09-27 07:43:25 +03:00
import { LoaderSpinner } from "~/components/system/components/Loaders";
const STYLES_SLATE_NAME = css`
overflow: hidden;
text-overflow: ellipsis;
2020-12-18 05:59:41 +03:00
white-space: nowrap;
2020-09-27 07:43:25 +03:00
font-family: ${Constants.font.medium};
color: ${Constants.system.black};
`;
const STYLES_SLATE_NAME_DARK = css`
2020-12-18 05:59:41 +03:00
${STYLES_SLATE_NAME}
color: ${Constants.system.white};
2020-09-27 07:43:25 +03:00
`;
2020-10-22 08:24:43 +03:00
const STYLES_NO_VISIBLE_SCROLL = css`
2020-09-27 07:43:25 +03:00
overflow-y: scroll;
2020-10-22 08:24:43 +03:00
scrollbar-width: none;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: -ms-autohiding-scrollbar;
::-webkit-scrollbar {
width: 0px;
display: none;
}
2020-11-08 05:32:17 +03:00
2020-10-22 08:24:43 +03:00
::-webkit-scrollbar-track {
background: ${Constants.system.foreground};
}
2020-11-08 05:32:17 +03:00
2020-10-22 08:24:43 +03:00
::-webkit-scrollbar-thumb {
background: ${Constants.system.darkGray};
}
2020-09-27 07:43:25 +03:00
`;
2020-10-22 08:24:43 +03:00
const STYLES_SLATE_LIST = css`
${STYLES_NO_VISIBLE_SCROLL}
max-height: 316px;
2020-12-11 05:59:17 +03:00
border-radius: 4px;
`;
2020-09-27 07:43:25 +03:00
const STYLES_SLATE_LINE = css`
display: flex;
align-items: center;
2020-12-18 05:59:41 +03:00
justify-content: space-between;
2020-09-27 07:43:25 +03:00
width: 100%;
padding: 12px 16px;
background-color: ${Constants.system.white};
2020-12-11 05:59:17 +03:00
border-bottom: 1px solid ${Constants.system.foreground};
2020-09-27 07:43:25 +03:00
cursor: pointer;
color: ${Constants.system.darkGray};
2020-12-11 05:59:17 +03:00
height: 48px;
2020-09-27 07:43:25 +03:00
:hover {
2020-09-27 23:11:04 +03:00
color: ${Constants.system.grayBlack};
2020-09-27 07:43:25 +03:00
}
`;
const STYLES_SLATE_LINE_DARK = css`
2020-10-22 08:24:43 +03:00
${STYLES_SLATE_LINE}
background-color: transparent;
2020-10-22 08:24:43 +03:00
border-bottom: 1px solid #3c3c3c;
:hover {
color: ${Constants.system.brand};
}
:last-child {
border: none;
}
`;
2020-10-22 08:24:43 +03:00
const STYLES_SLATE_CREATE = css`
display: flex;
align-items: center;
width: 100%;
padding: 12px 16px;
2020-10-22 08:24:43 +03:00
background-color: ${Constants.system.white};
cursor: pointer;
color: ${Constants.system.darkGray};
2020-12-11 05:59:17 +03:00
border-radius: 4px;
:hover {
2020-10-22 08:24:43 +03:00
color: ${Constants.system.grayBlack};
}
`;
2020-10-22 08:24:43 +03:00
const STYLES_SLATE_CREATE_DARK = css`
${STYLES_SLATE_CREATE}
background-color: transparent;
border: 1px solid #3c3c3c;
:hover {
2020-10-22 08:24:43 +03:00
color: ${Constants.system.brand};
}
`;
2020-09-27 07:43:25 +03:00
const STYLES_ICON_BOX = css`
display: flex;
align-items: center;
`;
export class SlatePicker extends React.Component {
render() {
2020-11-24 09:31:52 +03:00
const selected = this.props.selected;
2020-09-27 07:43:25 +03:00
return (
<React.Fragment>
<div
css={this.props.dark ? STYLES_SLATE_CREATE_DARK : STYLES_SLATE_CREATE}
2020-09-27 07:43:25 +03:00
onClick={this.props.onCreateSlate}
>
<SVG.Plus
height="24px"
style={{
marginRight: 8,
pointerEvents: "none",
}}
/>
<div>Create new collection</div>
2020-09-27 07:43:25 +03:00
</div>
2020-11-28 02:02:16 +03:00
{this.props.slates.length ? (
<React.Fragment>
<br />
2020-09-27 07:43:25 +03:00
<div
2020-11-28 02:02:16 +03:00
css={STYLES_SLATE_LIST}
style={{ border: this.props.dark ? "1px solid #3c3c3c" : "none" }}
2020-09-27 07:43:25 +03:00
>
2020-11-28 02:02:16 +03:00
{this.props.slates.map((slate) => (
<div
key={slate.id}
css={this.props.dark ? STYLES_SLATE_LINE_DARK : STYLES_SLATE_LINE}
onClick={() => this.props.onAdd(slate)}
>
<div
2020-12-18 05:59:41 +03:00
style={{ minWidth: "10%", width: "100%", display: "flex", flexWrap: "nowrap" }}
2020-11-28 02:02:16 +03:00
>
2020-12-18 05:59:41 +03:00
<div css={STYLES_ICON_BOX}>
{selected[slate.id] ? (
<SVG.Slate
height="24px"
style={{
marginRight: 8,
pointerEvents: "none",
color: this.props.dark
? Constants.system.white
: Constants.system.black,
}}
/>
) : (
<SVG.PlusCircle
height="24px"
style={{
marginRight: 8,
pointerEvents: "none",
}}
/>
)}
</div>
<div
css={this.props.dark ? STYLES_SLATE_NAME_DARK : STYLES_SLATE_NAME}
style={{
color: selected[slate.id] ? this.props.selectedColor : "inherit",
}}
>
{Strings.getPresentationSlateName(slate)}
</div>
2020-11-28 02:02:16 +03:00
</div>
{slate.isPublic ? (
2020-12-18 05:59:41 +03:00
<div style={{ flexShrink: 0, marginLeft: 16 }}>
<SVG.Globe height="24px" />
</div>
) : (
<div style={{ flexShrink: 0, marginLeft: 16 }}>
<SVG.SecurityLock height="24px" />
</div>
)}
2020-11-28 02:02:16 +03:00
</div>
))}
2020-09-27 07:43:25 +03:00
</div>
2020-11-28 02:02:16 +03:00
</React.Fragment>
) : null}
2020-09-27 07:43:25 +03:00
</React.Fragment>
);
}
}