2021-02-04 04:34:23 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-02-05 02:06:00 +01:00
|
|
|
import TriangleSVG from '../../assets/svgs/triangle.svg';
|
|
|
|
import { NAVIGATION, UI } from '../../constants';
|
2021-02-04 04:34:23 +01:00
|
|
|
import { ScreenContext } from '../../contexts/screen';
|
|
|
|
import { collapseSideMenu, expandSideMenu } from '../../state/navigation';
|
|
|
|
import { IState } from '../../state/reducers';
|
|
|
|
|
2021-02-05 02:06:00 +01:00
|
|
|
export enum SideBarMode {
|
|
|
|
MENU = 'MENU',
|
|
|
|
LABEL = 'LABEL',
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
mode: SideBarMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function SideMenuSideBar({ mode }: Props) {
|
|
|
|
const { isMobile, isTablet, isDesktop, isHuge } = useContext(ScreenContext);
|
|
|
|
const isCollapsible = isTablet || isMobile;
|
2021-02-04 04:34:23 +01:00
|
|
|
const { sideMenuExpanded: expanded, sideMenuActive: active } = useSelector(
|
|
|
|
(state: IState) => state.navigation,
|
|
|
|
);
|
2021-02-05 02:06:00 +01:00
|
|
|
|
2021-02-04 04:34:23 +01:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
2021-02-05 02:06:00 +01:00
|
|
|
const toggleSideMenu = () =>
|
|
|
|
dispatch(expanded ? collapseSideMenu() : expandSideMenu());
|
|
|
|
|
2021-02-04 04:34:23 +01:00
|
|
|
return (
|
|
|
|
<div
|
2021-02-05 02:06:00 +01:00
|
|
|
style={{
|
|
|
|
width: `${UI.SIDE_MENU_SIDE_BAR_WIDTH_PX}px`,
|
|
|
|
}}
|
2021-02-04 04:34:23 +01:00
|
|
|
className={classNames(
|
2021-02-05 02:06:00 +01:00
|
|
|
'flex flex-col justify-between items-center h-full bg-blue-300 px-4 py-6 border-l border-black',
|
|
|
|
isHuge ? 'text-3xl' : 'w-12 text-2xl',
|
|
|
|
mode === SideBarMode.LABEL && 'border-r border-b',
|
|
|
|
mode === SideBarMode.MENU && !expanded && 'border-r',
|
2021-02-04 04:34:23 +01:00
|
|
|
)}
|
2021-02-05 02:06:00 +01:00
|
|
|
onClick={() => mode === SideBarMode.MENU && toggleSideMenu()}
|
2021-02-04 04:34:23 +01:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
{isCollapsible && (
|
|
|
|
<>
|
2021-02-05 02:06:00 +01:00
|
|
|
<TriangleSVG
|
|
|
|
className={classNames(
|
|
|
|
'h-4 transform outline-none duration-300 cursor-pointer',
|
|
|
|
expanded ? 'rotate-180' : '-rotate-60',
|
|
|
|
)}
|
|
|
|
/>
|
2021-02-04 04:34:23 +01:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
2021-02-04 06:42:15 +01:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'flex items-center justify-start w-0 h-0 duration-300 transform -rotate-90',
|
|
|
|
)}
|
|
|
|
>
|
2021-02-04 04:34:23 +01:00
|
|
|
<span className="whitespace-no-wrap">
|
2021-02-05 02:06:00 +01:00
|
|
|
{mode === SideBarMode.LABEL
|
|
|
|
? NAVIGATION.SIDE_MENU_ITEMS[active].label
|
|
|
|
: 'Menu'}
|
2021-02-04 04:34:23 +01:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|