2021-02-09 05:51:32 +01:00
|
|
|
import React, { ReactNode, useContext } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
2021-02-05 03:52:59 +01:00
|
|
|
import { UI } from '../../constants';
|
2021-02-09 05:51:32 +01:00
|
|
|
import { ScreenContext } from '../../contexts/screen';
|
|
|
|
import { PageType } from '../../state/navigation';
|
|
|
|
import { IState } from '../../state/reducers';
|
2021-02-01 07:02:12 +01:00
|
|
|
import { Header } from '../navigation/Header';
|
2021-02-05 03:52:59 +01:00
|
|
|
import { SideMenu } from '../navigation/SideMenu';
|
2021-01-22 03:43:42 +01:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Layout({ children }: Props) {
|
2021-02-11 06:26:56 +01:00
|
|
|
const { isMobile, isTablet, isDesktop } = useContext(ScreenContext);
|
|
|
|
const { pageType, headerMobileMenuExpanded } = useSelector(
|
2021-02-09 05:51:32 +01:00
|
|
|
(state: IState) => state.navigation,
|
|
|
|
);
|
|
|
|
|
2021-02-12 04:14:34 +01:00
|
|
|
const marginLeft = `${
|
2021-02-09 05:51:32 +01:00
|
|
|
pageType === PageType.NORMAL && isTablet
|
|
|
|
? UI.SIDE_MENU_SIDE_BAR_WIDTH_PX
|
2021-02-12 04:14:34 +01:00
|
|
|
: 0
|
|
|
|
}px`;
|
2021-02-09 05:51:32 +01:00
|
|
|
|
2021-02-11 06:26:56 +01:00
|
|
|
const mobileMenuOpen =
|
|
|
|
(pageType === PageType.BLOG || pageType === PageType.POST) &&
|
|
|
|
headerMobileMenuExpanded;
|
|
|
|
|
2021-01-22 03:43:42 +01:00
|
|
|
return (
|
2021-01-28 07:07:25 +01:00
|
|
|
<div
|
|
|
|
style={{ height: '100vh', width: '100%' }}
|
2021-02-08 01:20:21 +01:00
|
|
|
className="relative flex flex-col justify-between bg-alt"
|
2021-01-28 07:07:25 +01:00
|
|
|
>
|
2021-02-05 03:52:59 +01:00
|
|
|
<Header />
|
|
|
|
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
height: `calc(100vh - ${UI.HEADER_HEIGHT_PX}px`,
|
|
|
|
}}
|
|
|
|
className="flex w-full h-full"
|
|
|
|
>
|
|
|
|
<SideMenu />
|
2021-02-12 04:14:34 +01:00
|
|
|
|
2021-02-09 05:51:32 +01:00
|
|
|
<div
|
|
|
|
style={{
|
2021-02-12 04:14:34 +01:00
|
|
|
marginLeft,
|
2021-02-11 06:26:56 +01:00
|
|
|
filter: `brightness(${mobileMenuOpen ? 0.85 : 1})`,
|
2021-02-09 05:51:32 +01:00
|
|
|
}}
|
2021-02-18 04:07:53 +01:00
|
|
|
className="relative z-50 w-full h-full overflow-y-auto duration-300"
|
2021-02-09 05:51:32 +01:00
|
|
|
>
|
2021-02-08 00:25:27 +01:00
|
|
|
{children}
|
2021-02-05 03:52:59 +01:00
|
|
|
</div>
|
2021-01-22 03:43:42 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|