feat(header): add chevron / unified sidebar collapse

This commit is contained in:
Paul
2021-12-24 13:02:49 +00:00
parent e263b627aa
commit d8d002cc4a
7 changed files with 91 additions and 79 deletions

View File

@@ -1,3 +1,4 @@
import { observer } from "mobx-react-lite";
import { Route, Switch } from "react-router";
import { useApplicationState } from "../../mobx/State";
@@ -8,7 +9,7 @@ import HomeSidebar from "./left/HomeSidebar";
import ServerListSidebar from "./left/ServerListSidebar";
import ServerSidebar from "./left/ServerSidebar";
export default function LeftSidebar() {
export default observer(() => {
const layout = useApplicationState().layout;
const isOpen = layout.getSectionState(SIDEBAR_CHANNELS, true);
@@ -35,4 +36,4 @@ export default function LeftSidebar() {
</Switch>
</SidebarBase>
);
}
});

View File

@@ -1,15 +1,25 @@
import { Menu } from "@styled-icons/boxicons-regular";
import {
ChevronLeft,
ChevronRight,
Menu,
} from "@styled-icons/boxicons-regular";
import { observer } from "mobx-react-lite";
import styled, { css } from "styled-components";
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
import { useApplicationState } from "../../mobx/State";
import { SIDEBAR_CHANNELS } from "../../mobx/stores/Layout";
import { Children } from "../../types/Preact";
interface Props {
borders?: boolean;
background?: boolean;
placement: "primary" | "secondary";
}
export default styled.div<Props>`
const Header = styled.div<Props>`
gap: 10px;
height: 48px;
flex: 0 auto;
@@ -33,10 +43,6 @@ export default styled.div<Props>`
color: var(--secondary-foreground);
}
/*@media only screen and (max-width: 768px) {
padding: 0 12px;
}*/
${() =>
isTouchscreenDevice &&
css`
@@ -66,6 +72,60 @@ export default styled.div<Props>`
`}
`;
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>
);
},
);
export function HamburgerAction() {
if (!isTouchscreenDevice) return null;