zepio/app/components/sidebar.js

89 lines
2.6 KiB
JavaScript
Raw Normal View History

// @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';
import styled from 'styled-components';
import type { Location, RouterHistory } from 'react-router-dom';
import { MENU_OPTIONS } from '../constants/sidebar';
2018-11-26 18:52:47 -08:00
const Wrapper = styled.div`
display: flex;
flex-direction: column;
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};
2018-12-12 11:05:19 -08:00
padding-top: 15px;
2019-01-10 05:00:52 -08:00
position: relative;
`;
2019-02-04 20:41:45 -08:00
/* eslint-disable max-len */
type StyledLinkProps = PropsWithTheme<{ isActive: boolean }>;
const StyledLink = styled.a`
color: ${(props: StyledLinkProps) => (props.isActive ? props.theme.colors.sidebarItemActive : props.theme.colors.sidebarItem)};
font-size: ${(props: StyledLinkProps) => `${props.theme.fontSize.regular}em`};
2018-12-04 20:26:03 -08:00
text-decoration: none;
font-weight: ${(props: StyledLinkProps) => String(props.theme.fontWeight.bold)};
background-color: ${(props: StyledLinkProps) => (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;
border-right: ${(props: StyledLinkProps) => (props.isActive ? `3px solid ${props.theme.colors.sidebarItemActive}` : 'none')};
2019-01-10 04:38:00 -08:00
cursor: pointer;
transition: all 0.03s ${(props: StyledLinkProps) => props.theme.transitionEase};
2018-12-11 15:43:27 -08:00
&:hover {
color: ${(props: StyledLinkProps) => (props.isActive ? props.theme.colors.sidebarItemActive : '#ddd')}
background-color: ${(props: StyledLinkProps) => props.theme.colors.sidebarHoveredItem};
2018-12-11 15:43:27 -08:00
}
2018-11-26 18:52:47 -08:00
`;
2018-12-12 11:05:19 -08:00
const Icon = styled.img`
width: 17px;
height: 17px;
margin-right: 13px;
${StyledLink}:hover & {
filter: ${(props: StyledLinkProps) => (props.isActive ? 'none' : 'brightness(300%)')};
}
2018-12-12 11:05:19 -08:00
`;
type MenuItem = {
route: string,
label: string,
2018-12-12 11:05:19 -08:00
icon: (isActive: boolean) => string,
};
2018-11-26 18:52:47 -08:00
type Props = {
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
};
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;
2018-12-12 11:48:08 -08:00
return (
<StyledLink
isActive={isActive}
key={item.route}
onClick={() => (isActive ? {} : history.push(item.route))}
>
<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,
};