zepio/app/components/sidebar.js

81 lines
2.1 KiB
JavaScript
Raw Normal View History

// @flow
2018-12-12 11:48:08 -08:00
import React from 'react';
import styled from 'styled-components';
2018-12-11 16:15:38 -08:00
import { Link, type Location } 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;
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}
2018-12-12 11:05:19 -08:00
background-color: ${props => props.theme.colors.sidebarBg};
padding-top: 15px;
`;
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;
2018-12-15 07:10:39 -08:00
font-weight: ${props => (props.isActive
? props.theme.fontWeight.bold
: props.theme.fontWeight.default)};
2018-12-12 11:48:08 -08:00
padding: 0 20px;
height: 35px;
width: 100%;
margin: 12.5px 0;
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
? `1px solid ${props.theme.colors.sidebarItemActive}`
: 'none')};
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-12-12 11:05:19 -08:00
const Icon = styled.img`
width: 20px;
height: 20px;
margin-right: 15px;
`;
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 = {
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;
return (
<StyledLink isActive={isActive} key={item.route} to={item.route}>
<Icon src={item.icon(isActive)} alt={`Sidebar Icon ${item.route}`} />
{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,
};