2018-11-23 15:46:06 -08:00
|
|
|
// @flow
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2019-01-28 16:34:07 -08:00
|
|
|
/* eslint-disable max-len */
|
2018-12-12 11:48:08 -08:00
|
|
|
import React from 'react';
|
2018-11-23 15:46:06 -08:00
|
|
|
import styled from 'styled-components';
|
2019-01-28 07:05:03 -08:00
|
|
|
import type { Location, RouterHistory } from 'react-router-dom';
|
2018-11-28 14:00:25 -08:00
|
|
|
import { MENU_OPTIONS } from '../constants/sidebar';
|
2018-11-23 15:46:06 -08:00
|
|
|
|
2018-11-26 18:52:47 -08:00
|
|
|
const Wrapper = styled.div`
|
2018-11-28 14:00:25 -08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2019-02-07 08:31:59 -08:00
|
|
|
width: ${props => props.theme.sidebarWidth};
|
|
|
|
height: ${props => `calc(100vh - ${props.theme.headerHeight})`};
|
|
|
|
font-family: ${props => props.theme.fontFamily};
|
|
|
|
background-color: ${props => props.theme.colors.sidebarBg};
|
2019-02-10 12:25:09 -08:00
|
|
|
border-right: 1px solid ${props => props.theme.colors.sidebarBorderRight};
|
2018-12-12 11:05:19 -08:00
|
|
|
padding-top: 15px;
|
2019-01-10 05:00:52 -08:00
|
|
|
position: relative;
|
2018-11-28 14:00:25 -08:00
|
|
|
`;
|
2019-02-04 20:41:45 -08:00
|
|
|
|
2019-01-28 07:05:03 -08:00
|
|
|
/* eslint-disable max-len */
|
2019-02-06 19:06:48 -08:00
|
|
|
type StyledLinkProps = PropsWithTheme<{ isActive: boolean }>;
|
2019-01-28 07:05:03 -08:00
|
|
|
const StyledLink = styled.a`
|
2019-02-10 12:25:09 -08:00
|
|
|
color: ${(props: StyledLinkProps) => (props.isActive
|
|
|
|
? props.theme.colors.sidebarItemActive
|
|
|
|
: props.theme.colors.sidebarItem
|
|
|
|
)};
|
2019-02-06 19:06:48 -08:00
|
|
|
font-size: ${(props: StyledLinkProps) => `${props.theme.fontSize.regular}em`};
|
2018-12-04 20:26:03 -08:00
|
|
|
text-decoration: none;
|
2019-02-06 19:06:48 -08:00
|
|
|
font-weight: ${(props: StyledLinkProps) => String(props.theme.fontWeight.bold)};
|
2019-02-10 12:25:09 -08:00
|
|
|
background-color: ${(props: StyledLinkProps) => (props.isActive
|
|
|
|
? `${props.theme.colors.sidebarHoveredItem}`
|
|
|
|
: 'transparent'
|
|
|
|
)};
|
2019-01-10 19:30:46 -08:00
|
|
|
letter-spacing: 0.25px;
|
|
|
|
padding: 25px 20px;
|
2018-12-12 11:48:08 -08:00
|
|
|
height: 35px;
|
|
|
|
width: 100%;
|
2018-12-11 15:43:27 -08:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2018-12-11 16:45:52 -08:00
|
|
|
outline: none;
|
2019-02-06 19:06:48 -08:00
|
|
|
border-right: ${(props: StyledLinkProps) => (props.isActive ? `3px solid ${props.theme.colors.sidebarItemActive}` : 'none')};
|
2019-01-10 04:38:00 -08:00
|
|
|
cursor: pointer;
|
2019-02-06 19:06:48 -08:00
|
|
|
transition: all 0.03s ${(props: StyledLinkProps) => props.theme.transitionEase};
|
2018-12-11 15:43:27 -08:00
|
|
|
|
|
|
|
&:hover {
|
2019-02-06 19:06:48 -08:00
|
|
|
background-color: ${(props: StyledLinkProps) => props.theme.colors.sidebarHoveredItem};
|
2019-02-10 12:25:09 -08:00
|
|
|
color: ${(props: StyledLinkProps) => (props.isActive
|
|
|
|
? props.theme.colors.sidebarItemActive
|
|
|
|
: '#ddd'
|
|
|
|
)}
|
2018-12-11 15:43:27 -08:00
|
|
|
}
|
2018-11-26 18:52:47 -08:00
|
|
|
`;
|
2018-11-23 15:46:06 -08:00
|
|
|
|
2018-12-12 11:05:19 -08:00
|
|
|
const Icon = styled.img`
|
2019-01-10 19:30:46 -08:00
|
|
|
width: 17px;
|
|
|
|
height: 17px;
|
|
|
|
margin-right: 13px;
|
|
|
|
|
|
|
|
${StyledLink}:hover & {
|
2019-02-06 19:06:48 -08:00
|
|
|
filter: ${(props: StyledLinkProps) => (props.isActive ? 'none' : 'brightness(300%)')};
|
2019-01-10 19:30:46 -08:00
|
|
|
}
|
2018-12-12 11:05:19 -08:00
|
|
|
`;
|
|
|
|
|
2018-11-28 20:14:44 -08:00
|
|
|
type MenuItem = {
|
|
|
|
route: string,
|
|
|
|
label: string,
|
2018-12-12 11:05:19 -08:00
|
|
|
icon: (isActive: boolean) => string,
|
2018-11-28 20:14:44 -08:00
|
|
|
};
|
2018-11-26 18:52:47 -08:00
|
|
|
|
|
|
|
type Props = {
|
2019-01-28 07:05:03 -08:00
|
|
|
history: RouterHistory,
|
2018-11-26 18:52:47 -08:00
|
|
|
options?: MenuItem[],
|
2018-12-11 16:15:38 -08:00
|
|
|
location: Location,
|
2018-11-26 18:52:47 -08:00
|
|
|
};
|
|
|
|
|
2019-01-28 07:05:03 -08:00
|
|
|
export const SidebarComponent = ({ options, location, history }: Props) => (
|
2019-01-22 10:50:11 -08:00
|
|
|
<Wrapper id='sidebar'>
|
2018-12-12 11:48:08 -08:00
|
|
|
{(options || []).map((item) => {
|
|
|
|
const isActive = location.pathname === item.route;
|
2019-01-10 19:30:46 -08:00
|
|
|
|
2018-12-12 11:48:08 -08:00
|
|
|
return (
|
2019-01-28 07:05:03 -08:00
|
|
|
<StyledLink
|
|
|
|
isActive={isActive}
|
|
|
|
key={item.route}
|
|
|
|
onClick={() => (isActive ? {} : history.push(item.route))}
|
|
|
|
>
|
2019-02-06 19:06:48 -08:00
|
|
|
<Icon isActive={isActive} src={item.icon(isActive)} Alt={`${item.route}`} />
|
2018-12-12 11:48:08 -08:00
|
|
|
{item.label}
|
|
|
|
</StyledLink>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Wrapper>
|
|
|
|
);
|
2018-12-12 11:05:19 -08:00
|
|
|
|
2018-12-12 11:48:08 -08:00
|
|
|
SidebarComponent.defaultProps = {
|
|
|
|
options: MENU_OPTIONS,
|
|
|
|
};
|