hotfix: sidebar icons
This commit is contained in:
parent
c0ace32d0b
commit
9228e053be
|
@ -1,50 +1,50 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import React, { type Element } from 'react';
|
import React, { Component } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Link, type Location } from 'react-router-dom';
|
import { Link, type Location } from 'react-router-dom';
|
||||||
import { MENU_OPTIONS } from '../constants/sidebar';
|
import { MENU_OPTIONS } from '../constants/sidebar';
|
||||||
import { ZCashLogo } from './zcash-logo';
|
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 200px;
|
width: ${props => props.theme.sidebarWidth};
|
||||||
height: 100vh;
|
height: ${props => `calc(100vh - ${props.theme.headerHeight})`};
|
||||||
font-family: ${props => props.theme.fontFamily}
|
font-family: ${props => props.theme.fontFamily}
|
||||||
background-color: ${props => props.theme.colors.sidebarBg};
|
background-color: ${props => props.theme.colors.sidebarBg};
|
||||||
`;
|
padding-top: 15px;
|
||||||
|
|
||||||
const LogoWrapper = styled.div`
|
|
||||||
height: 60px;
|
|
||||||
width: 200px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
background-image: linear-gradient(
|
|
||||||
to right,
|
|
||||||
${props => props.theme.colors.sidebarLogoGradientBegin},
|
|
||||||
${props => props.theme.colors.sidebarLogoGradientEnd}
|
|
||||||
);
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledLink = styled(Link)`
|
const StyledLink = styled(Link)`
|
||||||
color: ${props => (props.isActive ? props.theme.colors.sidebarItemActive : props.theme.colors.sidebarItem)};
|
color: ${props => (props.isActive ? props.theme.colors.sidebarItemActive : props.theme.colors.sidebarItem)};
|
||||||
font-size: 0.9em;
|
font-size: ${props => `${props.theme.fontSize.text}em`};
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: ${props => (props.isActive ? 700 : 400)};
|
font-weight: ${props => (props.isActive ? props.theme.fontWeight.bold : props.theme.fontWeight.default)};
|
||||||
padding: 15px 20px;
|
padding: 15px 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
border-right: ${props => (props.isActive ? `1px solid ${props.theme.colors.sidebarItemActive}` : 'none')};
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: ${props => props.theme.colors.sidebarItemActive};
|
color: ${props => props.theme.colors.sidebarItemActive};
|
||||||
|
|
||||||
|
svg {
|
||||||
|
color: ${props => props.theme.colors.sidebarItemActive};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Icon = styled.img`
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin-right: 15px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
type MenuItem = {
|
type MenuItem = {
|
||||||
route: string,
|
route: string,
|
||||||
label: string,
|
label: string,
|
||||||
icon: Element<*>,
|
icon: (isActive: boolean) => string,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
@ -52,23 +52,41 @@ type Props = {
|
||||||
location: Location,
|
location: Location,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SidebarComponent = ({ options, location }: Props) => (
|
type State = {
|
||||||
|
currentHovered: string | null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export class SidebarComponent extends Component<Props, State> {
|
||||||
|
static defaultProps = {
|
||||||
|
options: MENU_OPTIONS,
|
||||||
|
};
|
||||||
|
|
||||||
|
state = {
|
||||||
|
currentHovered: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { options, location } = this.props;
|
||||||
|
const { currentHovered } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<LogoWrapper>
|
{(options || []).map((item) => {
|
||||||
<ZCashLogo />
|
const isActive = location.pathname === item.route;
|
||||||
</LogoWrapper>
|
return (
|
||||||
{(options || []).map(item => (
|
<StyledLink
|
||||||
<StyledLink isActive={location.pathname === item.route} key={item.route} to={item.route}>
|
onMouseEnter={() => this.setState(() => ({ currentHovered: item.route }))}
|
||||||
{React.cloneElement(item.icon, {
|
onMouseLeave={() => this.setState(() => ({ currentHovered: null }))}
|
||||||
style: { marginRight: '15px' },
|
isActive={isActive}
|
||||||
size: 20,
|
key={item.route}
|
||||||
})}
|
to={item.route}
|
||||||
|
>
|
||||||
|
<Icon src={item.icon(currentHovered === item.route || isActive)} alt={`Sidebar Icon ${item.route}`} />
|
||||||
{item.label}
|
{item.label}
|
||||||
</StyledLink>
|
</StyledLink>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
SidebarComponent.defaultProps = {
|
}
|
||||||
options: MENU_OPTIONS,
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue