2018-11-23 15:46:06 -08:00
|
|
|
// @flow
|
|
|
|
|
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';
|
2018-12-11 16:15:38 -08:00
|
|
|
import { Link, type Location } 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;
|
2018-12-12 11:05:19 -08:00
|
|
|
width: ${props => props.theme.sidebarWidth};
|
|
|
|
height: ${props => `calc(100vh - ${props.theme.headerHeight})`};
|
2018-12-04 20:26:03 -08:00
|
|
|
font-family: ${props => props.theme.fontFamily}
|
2019-01-10 19:30:46 -08:00
|
|
|
background-color: ${props => props.theme.colors.sidebarBg};
|
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
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledLink = styled(Link)`
|
2018-12-15 07:10:39 -08:00
|
|
|
color: ${props => (props.isActive
|
|
|
|
? props.theme.colors.sidebarItemActive
|
|
|
|
: props.theme.colors.sidebarItem)};
|
2018-12-21 04:13:01 -08:00
|
|
|
font-size: ${props => `${props.theme.fontSize.regular}em`};
|
2018-12-04 20:26:03 -08:00
|
|
|
text-decoration: none;
|
2019-01-10 19:30:46 -08:00
|
|
|
font-weight: ${props => props.theme.fontWeight.bold};
|
|
|
|
background-color: ${props => (props.isActive
|
|
|
|
? `${props.theme.colors.sidebarHoveredItem}`
|
|
|
|
: 'transparent')};
|
|
|
|
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;
|
2018-12-15 07:10:39 -08:00
|
|
|
border-right: ${props => (props.isActive
|
2019-01-10 19:30:46 -08:00
|
|
|
? `3px solid ${props.theme.colors.sidebarItemActive}`
|
2018-12-15 07:10:39 -08:00
|
|
|
: 'none')};
|
2019-01-10 04:38:00 -08:00
|
|
|
cursor: pointer;
|
2019-01-10 19:30:46 -08:00
|
|
|
transition: all 0.03s ${props => props.theme.colors.transitionEase};
|
2018-12-11 15:43:27 -08:00
|
|
|
|
|
|
|
&:hover {
|
2018-12-12 11:48:08 -08:00
|
|
|
color: ${/* eslint-disable-next-line max-len */
|
2018-12-15 07:10:39 -08:00
|
|
|
props => (props.isActive
|
|
|
|
? props.theme.colors.sidebarItemActive
|
|
|
|
: props.theme.colors.sidebarHoveredItemLabel)};
|
2018-12-12 11:48:08 -08:00
|
|
|
background-color: ${props => props.theme.colors.sidebarHoveredItem};
|
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 & {
|
|
|
|
filter: ${props => (props.isActive ? 'none' : 'brightness(200%)')};
|
|
|
|
}
|
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 = {
|
|
|
|
options?: MenuItem[],
|
2018-12-11 16:15:38 -08:00
|
|
|
location: Location,
|
2018-11-26 18:52:47 -08:00
|
|
|
};
|
|
|
|
|
2018-12-12 11:48:08 -08:00
|
|
|
export const SidebarComponent = ({ options, location }: Props) => (
|
|
|
|
<Wrapper>
|
|
|
|
{(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-10 19:30:46 -08:00
|
|
|
<StyledLink
|
|
|
|
isActive={isActive}
|
|
|
|
key={item.route}
|
|
|
|
to={item.route}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
isActive={isActive}
|
|
|
|
src={item.icon(isActive)}
|
|
|
|
alt={`Sidebar Icon ${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,
|
|
|
|
};
|