2019-11-05 05:09:50 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
import styled from "styled-components";
|
2020-01-28 06:27:46 +00:00
|
|
|
import { Menu, Button } from "@blueprintjs/core";
|
2019-12-09 11:31:09 +00:00
|
|
|
import SideNavItem, { SideNavItemProps } from "./SideNavItem";
|
2020-01-28 06:27:46 +00:00
|
|
|
import LetterIcon from "components/editorComponents/LetterIcon";
|
2019-11-05 05:09:50 +00:00
|
|
|
type SideNavProps = {
|
2019-12-09 11:31:09 +00:00
|
|
|
items?: SideNavItemProps[];
|
2019-11-22 14:02:55 +00:00
|
|
|
active?: string;
|
2019-11-05 05:09:50 +00:00
|
|
|
headeroffset?: number;
|
2020-07-23 12:28:02 +00:00
|
|
|
open: boolean;
|
|
|
|
|
toggleCollapse: (open: boolean) => void;
|
2019-11-05 05:09:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* eslint-disable no-unexpected-multiline */
|
|
|
|
|
|
|
|
|
|
const SideNavWrapper = styled.div<{
|
|
|
|
|
open: boolean;
|
|
|
|
|
headeroffset?: number;
|
|
|
|
|
}>`
|
|
|
|
|
&&& {
|
|
|
|
|
width: ${props =>
|
|
|
|
|
props.open
|
|
|
|
|
? props.theme.sideNav.maxWidth
|
|
|
|
|
: props.theme.sideNav.minWidth}px;
|
2020-04-14 05:41:18 +00:00
|
|
|
transition: width 0.2s ease-in;
|
2019-11-05 05:09:50 +00:00
|
|
|
height: 100%;
|
|
|
|
|
& ul {
|
|
|
|
|
min-width: ${props => props.theme.sideNav.minWidth}px;
|
|
|
|
|
overflow-y: auto;
|
2020-01-28 06:27:46 +00:00
|
|
|
& a {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
color: ${props => props.theme.colors.textOnDarkBG};
|
|
|
|
|
}
|
2019-11-05 05:09:50 +00:00
|
|
|
& li > div {
|
|
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
2020-01-28 06:27:46 +00:00
|
|
|
padding: 0 ${props => (props.open ? props.theme.spaces[6] : 0)}px;
|
2019-11-05 05:09:50 +00:00
|
|
|
height: ${props => props.theme.sideNav.navItemHeight}px;
|
|
|
|
|
text-transform: capitalize;
|
|
|
|
|
& > span {
|
|
|
|
|
margin-right: ${props => (props.open ? props.theme.spaces[3] : 0)}px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ToggleButton = styled(Button)<{
|
|
|
|
|
open: boolean;
|
|
|
|
|
headeroffset?: number;
|
|
|
|
|
}>`
|
2019-12-09 11:31:09 +00:00
|
|
|
&& {
|
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
width: ${props =>
|
|
|
|
|
props.open
|
|
|
|
|
? props.theme.sideNav.maxWidth
|
|
|
|
|
: props.theme.sideNav.minWidth}px;
|
|
|
|
|
height: ${props => props.headeroffset || 50}px;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
padding-right: ${props => props.theme.sideNav.minWidth / 2}px;
|
2020-01-28 06:27:46 +00:00
|
|
|
transition: width 0.1s ease-in;
|
2019-12-09 11:31:09 +00:00
|
|
|
}
|
2019-11-05 05:09:50 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const SideNav = (props: SideNavProps) => {
|
2020-07-23 12:28:02 +00:00
|
|
|
const { open, toggleCollapse } = props;
|
2019-12-09 11:31:09 +00:00
|
|
|
const renderItems = (sideNavItems?: SideNavItemProps[]) => {
|
2019-11-22 14:02:55 +00:00
|
|
|
let items = sideNavItems;
|
|
|
|
|
if (!items) {
|
|
|
|
|
items = [
|
2020-01-28 06:27:46 +00:00
|
|
|
{ id: "0", text: "", path: "", loading: true, showText: true },
|
|
|
|
|
{ id: "1", text: "", path: "", loading: true, showText: true },
|
|
|
|
|
{ id: "2", text: "", path: "", loading: true, showText: true },
|
2019-11-22 14:02:55 +00:00
|
|
|
];
|
|
|
|
|
}
|
2019-11-05 05:09:50 +00:00
|
|
|
return items.map(item => {
|
2020-01-28 06:27:46 +00:00
|
|
|
const icon =
|
|
|
|
|
item.text.length > 0 ? (
|
2020-03-27 09:02:11 +00:00
|
|
|
<LetterIcon
|
|
|
|
|
text={String.fromCodePoint(item.text.codePointAt(0) || 0)}
|
|
|
|
|
/>
|
2020-01-28 06:27:46 +00:00
|
|
|
) : null;
|
|
|
|
|
return (
|
|
|
|
|
<SideNavItem key={item.id} showText={open} {...item} icon={icon} />
|
2019-11-05 05:09:50 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SideNavWrapper open={open} headeroffset={props.headeroffset}>
|
|
|
|
|
<ToggleButton
|
|
|
|
|
headeroffset={props.headeroffset}
|
2020-07-23 12:28:02 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
toggleCollapse(!open);
|
|
|
|
|
}}
|
2019-12-09 11:31:09 +00:00
|
|
|
icon={open ? "double-chevron-left" : "menu"}
|
2019-11-05 05:09:50 +00:00
|
|
|
minimal
|
|
|
|
|
open={open}
|
|
|
|
|
className="sidenav-toggle"
|
|
|
|
|
></ToggleButton>
|
|
|
|
|
<Menu large>{renderItems(props.items)}</Menu>
|
|
|
|
|
</SideNavWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SideNav;
|