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';
|
2019-02-16 19:34:12 -08:00
|
|
|
import styled, { withTheme } from 'styled-components';
|
2019-01-28 07:05:03 -08:00
|
|
|
import type { Location, RouterHistory } from 'react-router-dom';
|
2019-02-16 19:34:12 -08:00
|
|
|
|
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-03-20 06:03:34 -07:00
|
|
|
justify-content: space-between;
|
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-03-20 06:03:34 -07:00
|
|
|
const InnerWrapperTop = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const InnerWrapperBottom = styled.div`
|
|
|
|
background-color: ${props => props.theme.colors.sidebarItemHoveredBg};
|
2019-03-20 21:02:46 -07:00
|
|
|
padding-bottom: 3px;
|
|
|
|
border-top: 1px solid ${props => props.theme.colors.sidebarBorderRight};
|
|
|
|
|
2019-03-20 06:03:34 -07:00
|
|
|
`;
|
|
|
|
|
|
|
|
const DetailsItemWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
padding: 10px 15px;
|
|
|
|
justify-content: space-between;
|
|
|
|
border-top: 2px solid ${props => props.theme.colors.sidebarBg};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DetailsItemLabel = styled.div`
|
|
|
|
color: ${props => props.theme.colors.sidebarItem};
|
|
|
|
font-size: 10px;
|
|
|
|
letter-spacing: 0.5px;
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
|
|
|
${DetailsItemWrapper}:hover & {
|
|
|
|
color: ${props => props.theme.colors.sidebarItemHovered};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const DetailsItemValue = styled.div`
|
|
|
|
color: ${props => props.theme.colors.sidebarItem};
|
|
|
|
font-size: 10px;
|
|
|
|
letter-spacing: 0.5px;
|
|
|
|
text-transform: uppercase;
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
|
|
${DetailsItemWrapper}:hover & {
|
|
|
|
color: ${props => props.theme.colors.sidebarItemHovered};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
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
|
|
|
|
)};
|
|
|
|
background-color: ${(props: StyledLinkProps) => (props.isActive
|
2019-02-16 19:34:12 -08:00
|
|
|
? props.theme.colors.sidebarItemHoveredBg
|
2019-02-10 12:25:09 -08:00
|
|
|
: 'transparent'
|
|
|
|
)};
|
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-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-01-10 04:38:00 -08:00
|
|
|
cursor: pointer;
|
2019-02-15 18:59:05 -08:00
|
|
|
outline: none;
|
2019-02-06 19:06:48 -08:00
|
|
|
transition: all 0.03s ${(props: StyledLinkProps) => props.theme.transitionEase};
|
2019-02-15 18:59:05 -08:00
|
|
|
border-right: ${(props: StyledLinkProps) => (props.isActive ? `3px solid ${props.theme.colors.sidebarActiveItemBorder}` : 'none')};
|
2019-02-16 19:34:12 -08:00
|
|
|
border-top: 1px solid ${(props: StyledLinkProps) => (props.isActive ? props.theme.colors.sidebarBorderRight : 'transparent')};
|
|
|
|
border-bottom: 1px solid ${(props: StyledLinkProps) => (props.isActive ? props.theme.colors.sidebarBorderRight : 'transparent')};
|
2018-12-11 15:43:27 -08:00
|
|
|
|
|
|
|
&:hover {
|
2019-02-16 19:34:12 -08:00
|
|
|
border-top: 1px solid ${props => props.theme.colors.sidebarBorderRight};
|
|
|
|
border-bottom: 1px solid ${props => props.theme.colors.sidebarBorderRight};
|
|
|
|
|
|
|
|
background-color: ${(props: StyledLinkProps) => props.theme.colors.sidebarItemHoveredBg};
|
|
|
|
color: ${(props: StyledLinkProps) => (props.isActive ? props.theme.colors.sidebarItemActive : props.theme.colors.sidebarItemHovered)}
|
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;
|
|
|
|
|
2019-02-16 19:34:12 -08:00
|
|
|
opacity: ${(props: any) => (props.isActive ? '1' : '0.3')};
|
|
|
|
|
2019-01-10 19:30:46 -08:00
|
|
|
${StyledLink}:hover & {
|
2019-02-16 19:34:12 -08:00
|
|
|
opacity: 1;
|
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,
|
2019-02-16 19:34:12 -08:00
|
|
|
icon: (isActive: boolean, themeMode: string) => 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,
|
2019-02-16 19:34:12 -08:00
|
|
|
theme: AppTheme,
|
2019-03-20 06:03:34 -07:00
|
|
|
zcashNetwork: string,
|
|
|
|
embeddedDaemon: boolean,
|
2018-11-26 18:52:47 -08:00
|
|
|
};
|
|
|
|
|
2019-02-16 19:34:12 -08:00
|
|
|
export const Component = ({
|
2019-03-20 06:03:34 -07:00
|
|
|
options, location, history, theme, zcashNetwork, embeddedDaemon,
|
2019-02-16 19:34:12 -08:00
|
|
|
}: Props) => (
|
2019-01-22 10:50:11 -08:00
|
|
|
<Wrapper id='sidebar'>
|
2019-03-20 06:03:34 -07:00
|
|
|
<InnerWrapperTop>
|
|
|
|
{(options || []).map((item) => {
|
|
|
|
const isActive = item.route === '/'
|
|
|
|
? location.pathname === item.route
|
|
|
|
: location.pathname.startsWith(item.route);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledLink
|
2019-02-15 18:59:05 -08:00
|
|
|
isActive={isActive}
|
2019-03-20 06:03:34 -07:00
|
|
|
key={item.route}
|
|
|
|
onClick={() => (isActive ? {} : history.push(item.route))}
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
isActive={isActive}
|
|
|
|
src={item.icon(isActive, theme.mode)}
|
|
|
|
alt={`${item.route}`}
|
|
|
|
/>
|
|
|
|
{item.label}
|
|
|
|
</StyledLink>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</InnerWrapperTop>
|
|
|
|
<InnerWrapperBottom>
|
|
|
|
<DetailsItemWrapper>
|
|
|
|
<DetailsItemLabel>
|
|
|
|
Daemon
|
|
|
|
</DetailsItemLabel>
|
|
|
|
<DetailsItemValue>
|
|
|
|
{embeddedDaemon ? 'Built-in' : 'Custom'}
|
|
|
|
</DetailsItemValue>
|
|
|
|
</DetailsItemWrapper>
|
|
|
|
<DetailsItemWrapper>
|
|
|
|
<DetailsItemLabel>
|
|
|
|
Network
|
|
|
|
</DetailsItemLabel>
|
|
|
|
<DetailsItemValue>
|
|
|
|
{zcashNetwork}
|
|
|
|
</DetailsItemValue>
|
|
|
|
</DetailsItemWrapper>
|
|
|
|
</InnerWrapperBottom>
|
2018-12-12 11:48:08 -08:00
|
|
|
</Wrapper>
|
|
|
|
);
|
2018-12-12 11:05:19 -08:00
|
|
|
|
2019-02-16 19:34:12 -08:00
|
|
|
Component.defaultProps = {
|
2018-12-12 11:48:08 -08:00
|
|
|
options: MENU_OPTIONS,
|
|
|
|
};
|
2019-02-16 19:34:12 -08:00
|
|
|
|
|
|
|
export const SidebarComponent = withTheme(Component);
|