2021-12-24 08:02:49 -05:00
|
|
|
import {
|
|
|
|
ChevronLeft,
|
|
|
|
ChevronRight,
|
|
|
|
Menu,
|
|
|
|
} from "@styled-icons/boxicons-regular";
|
|
|
|
import { observer } from "mobx-react-lite";
|
2021-06-19 10:29:04 -04:00
|
|
|
import styled, { css } from "styled-components";
|
|
|
|
|
2021-08-09 10:51:22 -04:00
|
|
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
|
|
|
|
2021-12-24 08:02:49 -05:00
|
|
|
import { useApplicationState } from "../../mobx/State";
|
|
|
|
import { SIDEBAR_CHANNELS } from "../../mobx/stores/Layout";
|
|
|
|
|
|
|
|
import { Children } from "../../types/Preact";
|
|
|
|
|
2021-06-19 10:29:04 -04:00
|
|
|
interface Props {
|
2021-07-05 06:25:20 -04:00
|
|
|
borders?: boolean;
|
|
|
|
background?: boolean;
|
|
|
|
placement: "primary" | "secondary";
|
2021-06-19 10:29:04 -04:00
|
|
|
}
|
|
|
|
|
2021-12-24 08:02:49 -05:00
|
|
|
const Header = styled.div<Props>`
|
2021-12-20 08:37:21 -05:00
|
|
|
gap: 10px;
|
2021-07-05 06:25:20 -04:00
|
|
|
height: 48px;
|
|
|
|
flex: 0 auto;
|
|
|
|
display: flex;
|
|
|
|
flex-shrink: 0;
|
|
|
|
padding: 0 16px;
|
|
|
|
font-weight: 600;
|
|
|
|
user-select: none;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
background-size: cover !important;
|
|
|
|
background-position: center !important;
|
|
|
|
background-color: var(--primary-header);
|
|
|
|
|
|
|
|
svg {
|
|
|
|
flex-shrink: 0;
|
|
|
|
}
|
|
|
|
|
2021-07-08 12:39:03 -04:00
|
|
|
.menu {
|
|
|
|
margin-inline-end: 8px;
|
|
|
|
color: var(--secondary-foreground);
|
|
|
|
}
|
|
|
|
|
2021-08-30 13:01:32 -04:00
|
|
|
${() =>
|
|
|
|
isTouchscreenDevice &&
|
|
|
|
css`
|
|
|
|
height: 56px;
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
${(props) =>
|
|
|
|
props.background &&
|
|
|
|
css`
|
|
|
|
height: 120px !important;
|
|
|
|
align-items: flex-end;
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
text-shadow: 0px 0px 1px black;
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
${(props) =>
|
|
|
|
props.placement === "secondary" &&
|
|
|
|
css`
|
|
|
|
background-color: var(--secondary-header);
|
|
|
|
padding: 14px;
|
|
|
|
`}
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
${(props) =>
|
2021-07-05 06:25:20 -04:00
|
|
|
props.borders &&
|
|
|
|
css`
|
|
|
|
border-start-start-radius: 8px;
|
|
|
|
`}
|
2021-06-19 10:29:04 -04:00
|
|
|
`;
|
2021-08-09 10:51:22 -04:00
|
|
|
|
2021-12-24 08:02:49 -05:00
|
|
|
export default Header;
|
|
|
|
|
|
|
|
const IconContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
cursor: pointer;
|
|
|
|
color: var(--secondary-foreground);
|
|
|
|
margin-right: 5px;
|
|
|
|
|
|
|
|
> svg {
|
|
|
|
margin-right: -5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
${!isTouchscreenDevice &&
|
|
|
|
css`
|
|
|
|
&:hover {
|
|
|
|
color: var(--foreground);
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
`;
|
|
|
|
|
|
|
|
interface PageHeaderProps {
|
|
|
|
noBurger?: boolean;
|
|
|
|
children: Children;
|
|
|
|
icon: Children;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const PageHeader = observer(
|
|
|
|
({ children, icon, noBurger }: PageHeaderProps) => {
|
|
|
|
const layout = useApplicationState().layout;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Header placement="primary">
|
|
|
|
{!noBurger && <HamburgerAction />}
|
|
|
|
<IconContainer
|
|
|
|
onClick={() =>
|
|
|
|
layout.toggleSectionState(SIDEBAR_CHANNELS, true)
|
|
|
|
}>
|
|
|
|
{!isTouchscreenDevice &&
|
|
|
|
layout.getSectionState(SIDEBAR_CHANNELS, true) && (
|
|
|
|
<ChevronLeft size={18} />
|
|
|
|
)}
|
|
|
|
{icon}
|
|
|
|
{!isTouchscreenDevice &&
|
|
|
|
!layout.getSectionState(SIDEBAR_CHANNELS, true) && (
|
|
|
|
<ChevronRight size={18} />
|
|
|
|
)}
|
|
|
|
</IconContainer>
|
|
|
|
{children}
|
|
|
|
</Header>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-08-09 10:51:22 -04:00
|
|
|
export function HamburgerAction() {
|
|
|
|
if (!isTouchscreenDevice) return null;
|
|
|
|
|
|
|
|
function openSidebar() {
|
|
|
|
document
|
|
|
|
.querySelector("#app > div > div")
|
|
|
|
?.scrollTo({ behavior: "smooth", left: 0 });
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="menu" onClick={openSidebar}>
|
|
|
|
<Menu size={27} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|