slate/components/core/ApplicationLayout.js

246 lines
5.9 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
import * as SVG from "~/common/svg";
2021-07-07 23:50:57 +03:00
import * as Styles from "~/common/styles";
2020-11-30 08:24:22 +03:00
import { css } from "@emotion/react";
2020-08-12 22:41:56 +03:00
import { GlobalTooltip } from "~/components/system/components/fragments/GlobalTooltip";
2020-08-26 07:13:02 +03:00
import { Boundary } from "~/components/system/components/fragments/Boundary";
2020-09-11 06:57:17 +03:00
import { Alert } from "~/components/core/Alert";
2020-08-14 11:29:29 +03:00
const STYLES_NO_VISIBLE_SCROLL = css`
overflow-y: scroll;
scrollbar-width: none;
-webkit-overflow-scrolling: touch;
2020-08-14 11:29:29 +03:00
-ms-overflow-style: -ms-autohiding-scrollbar;
2020-08-14 11:29:29 +03:00
::-webkit-scrollbar {
width: 0px;
display: none;
}
::-webkit-scrollbar-track {
2021-07-07 22:58:14 +03:00
background: ${Constants.semantic.bgLight};
2020-08-14 11:29:29 +03:00
}
::-webkit-scrollbar-thumb {
2021-07-07 22:58:14 +03:00
background: ${Constants.system.grayLight2};
2020-08-14 11:29:29 +03:00
}
`;
const STYLES_CONTENT = css`
2021-05-27 11:20:34 +03:00
background: ${Constants.system.white};
width: 100%;
min-width: 10%;
min-height: 100vh;
position: relative;
@media (max-width: ${Constants.sizes.mobile}px) {
2020-09-29 07:39:05 +03:00
padding-left: 0px;
padding: 0 0 88px 0;
}
`;
const STYLES_SIDEBAR_ELEMENTS = css`
height: 100vh;
width: ${Constants.sizes.sidebar}px;
padding: 0;
flex-shrink: 0;
background-color: ${Constants.semantic.bgGrayLight};
2020-08-26 07:13:02 +03:00
top: 0;
right: 0;
${STYLES_NO_VISIBLE_SCROLL}
2020-09-10 06:39:56 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
width: 100%;
}
/*
2020-10-22 08:38:37 +03:00
@supports ((-webkit-backdrop-filter: blur(25px)) or (backdrop-filter: blur(25px))) {
-webkit-backdrop-filter: blur(25px);
2020-09-10 06:39:56 +03:00
backdrop-filter: blur(25px);
2020-12-11 05:59:17 +03:00
background-color: rgba(195, 195, 196, 0.6);
2020-09-10 06:39:56 +03:00
}
*/
`;
const STYLES_SIDEBAR = css`
position: fixed;
2021-05-25 01:19:48 +03:00
top: 0;
right: 0;
margin: auto;
z-index: ${Constants.zindex.sidebar};
`;
2021-07-07 23:50:57 +03:00
const STYLES_MODAL = css`
z-index: ${Constants.zindex.modal};
top: ${Constants.sizes.header}px;
right: 0;
bottom: 0;
position: fixed;
left: 0;
padding: 24px 24px 32px;
height: calc(100vh - ${Constants.sizes.header}px);
2021-07-07 23:50:57 +03:00
background-color: ${Constants.semantic.bgBlurWhiteOP};
2021-07-07 23:50:57 +03:00
@supports ((-webkit-backdrop-filter: blur(75px)) or (backdrop-filter: blur(75px))) {
-webkit-backdrop-filter: blur(75px);
backdrop-filter: blur(75px);
2021-07-07 23:50:57 +03:00
}
`;
const STYLES_MODAL_ELEMENTS = css`
width: 100%;
height: 100%;
2021-07-07 23:50:57 +03:00
`;
const STYLES_SIDEBAR_HEADER = css`
display: flex;
justify-content: flex-end;
margin-bottom: 8px;
`;
2020-08-09 06:52:22 +03:00
const STYLES_SIDEBAR_CONTENT = css`
2020-09-29 01:38:35 +03:00
padding: 56px 24px 24px 24px;
2020-12-11 05:59:17 +03:00
padding-top: calc(32px + ${Constants.sizes.topOffset}px);
2020-09-29 08:47:27 +03:00
@media (max-width: ${Constants.sizes.mobile}px) {
padding-top: 8px;
2020-10-01 21:57:37 +03:00
margin-bottom: 48px;
2020-09-29 08:47:27 +03:00
}
2020-08-09 06:52:22 +03:00
`;
const STYLES_BLOCK = css`
2020-09-10 06:28:48 +03:00
margin-top: 8px;
height: 56px;
width: 56px;
display: inline-flex;
align-items: center;
justify-content: center;
transition: 200ms ease all;
cursor: pointer;
2021-07-08 00:44:13 +03:00
color: ${Constants.semantic.textGray};
2021-07-07 23:50:57 +03:00
`;
const STYLES_DISMISS = css`
${Styles.ICON_CONTAINER}
2021-07-08 00:44:13 +03:00
color: ${Constants.semantic.textGray};
2021-07-07 23:50:57 +03:00
:focus {
outline: none;
}
:hover {
2021-07-08 00:44:13 +03:00
color: ${Constants.system.blue};
2021-07-07 23:50:57 +03:00
}
`;
export default class ApplicationLayout extends React.Component {
2020-08-12 22:41:56 +03:00
_sidebar;
_navigation;
_body;
2020-10-01 03:41:53 +03:00
state = {
2020-10-02 02:44:22 +03:00
headerTop: 0,
2020-10-01 03:41:53 +03:00
};
componentDidMount = () => {
this.prevScrollPos = window.pageYOffset;
if (this.props.isMobile) {
2020-10-01 03:41:53 +03:00
window.addEventListener("scroll", this._handleScroll);
}
};
componentWillUnmount = () => {
if (this.props.isMobile) {
2020-10-01 03:41:53 +03:00
window.removeEventListener("scroll", this._handleScroll);
}
};
_handleScroll = () => {
let currentScrollPos = window.pageYOffset;
if (this.prevScrollPos > currentScrollPos) {
2020-10-01 03:49:38 +03:00
this.setState({ headerTop: 0 });
2020-10-01 03:41:53 +03:00
} else {
if (currentScrollPos > 56) {
2020-10-01 03:49:38 +03:00
this.setState({ headerTop: -56 });
2020-10-01 03:41:53 +03:00
}
}
this.prevScrollPos = currentScrollPos;
};
2020-09-29 08:47:27 +03:00
_handleDismiss = (e) => {
e.stopPropagation();
e.preventDefault();
this.props.onDismissSidebar();
};
render() {
let sidebarElements = null;
if (this.props.sidebar) {
sidebarElements = (
<Boundary
onMouseDown
captureResize={false}
captureScroll={false}
enabled
onOutsideRectEvent={this._handleDismiss}
>
<div css={STYLES_SIDEBAR}>
<div
css={STYLES_SIDEBAR_ELEMENTS}
ref={(c) => {
this._sidebar = c;
}}
2021-07-07 23:50:57 +03:00
>
<div css={STYLES_SIDEBAR_HEADER}>
<div css={STYLES_BLOCK} onClick={this._handleDismiss}>
<SVG.Dismiss height="24px" />
2021-07-07 23:50:57 +03:00
</div>
</div>
<div css={STYLES_SIDEBAR_CONTENT}>{this.props.sidebar}</div>
2021-07-07 23:50:57 +03:00
</div>
</div>
</Boundary>
);
}
return (
<React.Fragment>
2021-07-07 23:50:57 +03:00
<div css={STYLES_CONTENT}>
2020-10-05 00:30:28 +03:00
<GlobalTooltip />
2021-05-06 03:08:14 +03:00
{this.props.header && (
<>
<div style={{ height: Constants.sizes.header }} />
<div>{this.props.header}</div>
</>
2021-05-06 03:08:14 +03:00
)}
<Alert
2021-05-25 01:19:48 +03:00
noWarning={
this.props.page?.id === "NAV_SIGN_IN"
? true
: this.props.viewer
? this.props.viewer?.onboarding?.hidePrivacyAlert
2021-05-25 01:19:48 +03:00
: false
}
onAction={this.props.onAction}
id={this.props.isMobile ? "slate-mobile-alert" : null}
2020-12-09 07:22:17 +03:00
viewer={this.props.viewer}
style={
this.props.isMobile
? { top: this.props.page?.id === "NAV_SIGN_IN" ? 0 : this.state.headerTop + 56 }
: {
2021-06-01 02:41:00 +03:00
top: this.props.page?.id === "NAV_SIGN_IN" ? 0 : 56,
paddingRight: this.props.sidebar
? `calc(${Constants.sizes.sidebar}px + 48px`
: "auto",
}
}
/>
{this.props.children}
</div>
2021-07-07 23:50:57 +03:00
{sidebarElements ? sidebarElements : null}
</React.Fragment>
);
}
}