slate/components/core/ApplicationUserControls.js

266 lines
6.5 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
import * as SVG from "~/common/svg";
2020-11-08 05:32:17 +03:00
import { PopoverNavigation } from "~/components/system";
import { css } from "@emotion/core";
2020-09-05 00:37:50 +03:00
import { Boundary } from "~/components/system/components/fragments/Boundary";
const STYLES_HEADER = css`
position: relative;
2020-11-14 02:43:59 +03:00
margin-left: 16px;
@media (max-width: ${Constants.sizes.mobile}px) {
2020-09-29 07:39:05 +03:00
padding: 0px;
2020-09-29 08:47:27 +03:00
width: auto;
}
`;
const STYLES_PROFILE = css`
2020-09-29 07:39:05 +03:00
position: relative;
display: flex;
2020-09-05 04:40:23 +03:00
align-items: center;
justify-content: flex-start;
min-width: 10%;
2020-09-05 22:27:41 +03:00
width: 204px;
color: ${Constants.system.pitchBlack};
background-color: ${Constants.system.white};
font-size: 12px;
text-decoration: none;
2020-09-05 04:40:23 +03:00
border-radius: 4px;
min-height: 48px;
cursor: pointer;
border: 1px solid rgba(229, 229, 229, 0.5);
2020-09-05 04:40:23 +03:00
box-shadow: 0 0 7px 0 rgba(0, 0, 0, 0.03);
@media (max-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
2020-09-05 22:27:41 +03:00
const STYLES_PROFILE_MOBILE = css`
display: flex;
align-items: center;
`;
const STYLES_PROFILE_IMAGE = css`
background-color: ${Constants.system.foreground};
background-size: cover;
background-position: 50% 50%;
flex-shrink: 0;
height: 32px;
width: 32px;
2020-11-14 02:43:59 +03:00
border-radius: 2px;
2020-09-05 22:27:41 +03:00
cursor: pointer;
@media (max-width: ${Constants.sizes.mobile}px) {
height: 24px;
width: 24px;
}
`;
const STYLES_PROFILE_USERNAME = css`
min-width: 10%;
width: 100%;
white-space: nowrap;
overflow: hidden;
2020-09-06 05:27:30 +03:00
text-overflow: ellipsis;
padding: 12px;
user-select: none;
2020-09-05 04:40:23 +03:00
font-family: ${Constants.font.medium};
2020-09-10 06:28:48 +03:00
font-size: ${Constants.typescale.lvl1};
2020-09-05 04:40:23 +03:00
`;
2020-09-05 22:27:41 +03:00
const STYLES_ITEM_BOX_MOBILE = css`
display: flex;
align-items: center;
justify-content: center;
padding: 4px;
background-color: ${Constants.system.white};
cursor: pointer;
border-radius: 4px;
border-left: 2px solid ${Constants.system.foreground};
2020-09-05 22:27:41 +03:00
`;
2020-09-05 04:40:23 +03:00
const STYLES_ITEM_BOX = css`
display: flex;
align-items: center;
justify-content: center;
height: 100%;
padding: 8px;
2020-10-17 23:21:35 +03:00
padding-right: 9px;
2020-09-05 04:40:23 +03:00
transition: 200ms ease all;
border-left: 2px solid ${Constants.system.foreground};
2020-09-05 04:40:23 +03:00
:hover {
color: ${Constants.system.brand};
}
`;
2020-09-29 07:39:05 +03:00
const STYLES_MENU = css`
position: absolute;
top: 48px;
2020-11-14 02:43:59 +03:00
right: 0px;
${"" /* @media (max-width: ${Constants.sizes.mobile}px) {
top: 48px;
left: 0px;
} */}
2020-09-29 07:39:05 +03:00
`;
const STYLES_MOBILE_HIDDEN = css`
@media (max-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
const STYLES_MOBILE_ONLY = css`
@media (min-width: ${Constants.sizes.mobile}px) {
display: none;
}
`;
export default class ApplicationUserControls extends React.Component {
state = { visible: false };
2020-09-17 22:15:34 +03:00
_handleClick = (e) => {
2020-09-05 04:40:23 +03:00
e.stopPropagation();
2020-10-05 00:30:28 +03:00
e.preventDefault();
2020-09-05 04:40:23 +03:00
if (this.state.visible) {
this._handleHide();
return;
}
this.setState({ visible: true });
};
_handleHide = () => {
this.setState({ visible: false });
};
2020-10-02 02:44:22 +03:00
_handleAction = (e, data) => {
e.preventDefault();
e.stopPropagation();
this._handleHide();
return this.props.onAction(data);
};
2020-09-17 22:15:34 +03:00
_handleSignOut = (data) => {
this._handleHide();
return this.props.onSignOut(data);
};
render() {
2020-09-29 07:39:05 +03:00
let tooltip = (
2020-11-14 02:43:59 +03:00
<Boundary
captureResize={true}
captureScroll={false}
enabled
onOutsideRectEvent={this._handleHide}
style={this.props.style}
>
<div>
<PopoverNavigation
style={{ top: 36, right: 0, padding: "0px 24px", width: 220 }}
itemStyle={{ margin: "24px 0", fontSize: 18, justifyContent: "flex-end" }}
navigation={[
{
text: "View profile",
onClick: (e) =>
this._handleAction(e, {
type: "NAVIGATE",
value: "V1_NAVIGATION_PROFILE",
data: this.props.viewer,
}),
},
{
text: "Account settings",
onClick: (e) =>
this._handleAction(e, {
type: "NAVIGATE",
value: "V1_NAVIGATION_PROFILE_EDIT",
}),
},
{
text: "Contact us",
onClick: (e) =>
this._handleAction(e, {
type: "SIDEBAR",
value: "SIDEBAR_HELP",
}),
},
{
text: "Sign out",
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
this._handleSignOut(e);
2020-09-29 07:39:05 +03:00
},
2020-11-14 02:43:59 +03:00
},
]}
/>
</div>
{/* <div css={STYLES_MOBILE_HIDDEN} style={{ marginBottom: "8px" }}>
2020-09-29 07:39:05 +03:00
<PopoverNavigation
navigation={[
{
text: "Account settings",
2020-10-02 02:44:22 +03:00
onClick: (e) =>
this._handleAction(e, {
2020-09-29 07:39:05 +03:00
type: "NAVIGATE",
value: "V1_NAVIGATION_PROFILE_EDIT",
}),
},
2020-10-05 00:30:28 +03:00
{
text: "Sign out",
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
this._handleSignOut(e);
},
},
2020-09-29 07:39:05 +03:00
]}
/>
2020-11-14 02:43:59 +03:00
</div> */}
</Boundary>
2020-09-29 07:39:05 +03:00
);
return (
<div css={STYLES_HEADER}>
2020-11-14 02:43:59 +03:00
{/* <div
2020-09-29 07:39:05 +03:00
css={STYLES_PROFILE}
onClick={() =>
this.props.onAction({
type: "NAVIGATE",
value: "V1_NAVIGATION_PROFILE",
data: this.props.viewer,
})
}
>
2020-09-29 07:39:05 +03:00
<span
css={STYLES_PROFILE_IMAGE}
style={{
backgroundImage: `url('${this.props.viewer.data.photo}')`,
}}
/>
<span css={STYLES_PROFILE_USERNAME}>{this.props.viewer.username}</span>
2020-09-29 07:39:05 +03:00
<div onClick={this._handleClick} css={STYLES_ITEM_BOX}>
<SVG.ChevronDown height="20px" />
</div>
2020-09-29 07:39:05 +03:00
{this.state.visible ? tooltip : null}
2020-11-14 02:43:59 +03:00
</div> */}
<div css={STYLES_PROFILE_MOBILE} style={{ position: "relative" }}>
2020-09-29 07:39:05 +03:00
<span
css={STYLES_PROFILE_IMAGE}
onClick={this._handleClick}
style={{
backgroundImage: `url('${this.props.viewer.data.photo}')`,
}}
/>
{this.state.visible ? tooltip : null}
</div>
</div>
);
}
}