2017-06-16 03:39:08 +00:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2017-07-02 00:02:17 +00:00
|
|
|
import { NavLink } from 'react-router-dom';
|
2017-09-25 03:03:03 +00:00
|
|
|
import { color, fontWeight } from 'styles/constants';
|
2017-06-16 03:39:08 +00:00
|
|
|
import styled from 'styled-components';
|
|
|
|
|
2017-09-27 07:21:40 +00:00
|
|
|
import Flex from 'components/Flex';
|
|
|
|
import ChevronIcon from 'components/Icon/ChevronIcon';
|
|
|
|
|
2017-06-16 03:39:08 +00:00
|
|
|
const activeStyle = {
|
2017-09-09 05:06:47 +00:00
|
|
|
color: color.black,
|
|
|
|
fontWeight: fontWeight.semiBold,
|
2017-06-16 03:39:08 +00:00
|
|
|
};
|
|
|
|
|
2017-09-24 21:25:14 +00:00
|
|
|
// This is a hack for `styleComponent()` as NavLink fails to render without `to` prop
|
|
|
|
const StyleableDiv = props => <div {...props} />;
|
|
|
|
|
2017-09-18 06:45:40 +00:00
|
|
|
const styleComponent = component => styled(component)`
|
2017-10-16 01:43:26 +00:00
|
|
|
display: flex;
|
2017-09-27 07:21:40 +00:00
|
|
|
width: 100%;
|
2017-09-09 05:06:47 +00:00
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
2017-10-15 18:42:03 +00:00
|
|
|
padding: 5px 0;
|
2017-09-27 07:21:40 +00:00
|
|
|
margin-left: ${({ hasChildren }) => (hasChildren ? '-20px;' : '0')};
|
2017-07-09 05:12:14 +00:00
|
|
|
color: ${color.slateDark};
|
2017-09-04 15:32:31 +00:00
|
|
|
font-size: 15px;
|
2017-09-18 06:45:40 +00:00
|
|
|
cursor: pointer;
|
2017-07-02 00:02:17 +00:00
|
|
|
|
2017-07-09 05:12:14 +00:00
|
|
|
&:hover {
|
2017-09-09 05:06:47 +00:00
|
|
|
color: ${color.text};
|
2017-06-16 03:39:08 +00:00
|
|
|
}
|
2017-09-27 07:21:40 +00:00
|
|
|
|
2017-09-27 07:32:55 +00:00
|
|
|
&.active ${StyledChevron} svg {
|
2017-09-27 07:21:40 +00:00
|
|
|
fill: ${activeStyle.color};
|
|
|
|
}
|
2017-06-16 03:39:08 +00:00
|
|
|
`;
|
|
|
|
|
2017-09-18 06:45:40 +00:00
|
|
|
function SidebarLink(props: Object) {
|
2017-09-24 21:25:14 +00:00
|
|
|
const Component = styleComponent(props.to ? NavLink : StyleableDiv);
|
2017-09-27 07:21:40 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Flex>
|
|
|
|
<Component exact activeStyle={activeStyle} {...props}>
|
|
|
|
{props.hasChildren && <StyledChevron expanded={props.expanded} />}
|
2017-10-16 01:43:26 +00:00
|
|
|
<div>{props.children}</div>
|
2017-09-27 07:21:40 +00:00
|
|
|
</Component>
|
|
|
|
</Flex>
|
|
|
|
);
|
2017-09-18 06:45:40 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 07:21:40 +00:00
|
|
|
const StyledChevron = styled(ChevronIcon)`
|
|
|
|
margin-right: -10px;
|
|
|
|
|
|
|
|
svg {
|
|
|
|
height: 18px;
|
|
|
|
margin-bottom: -4px;
|
|
|
|
margin-right: 6px;
|
|
|
|
|
|
|
|
fill: ${color.slateDark};
|
|
|
|
|
|
|
|
${({ expanded }) => expanded && 'transform: rotate(90deg);'}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2017-07-02 00:02:17 +00:00
|
|
|
export default SidebarLink;
|