1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-13 01:20:59 +00:00

Added navlink to link component

This commit is contained in:
Vladimir Volek 2018-10-10 13:48:45 +02:00 committed by Szymon Lesisz
parent 5e6968757e
commit 453cda908f

View File

@ -1,8 +1,9 @@
import React from 'react'; import React, { Component } from 'react';
import styled, { css } from 'styled-components'; import styled, { css } from 'styled-components';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FONT_SIZE, TRANSITION } from 'config/variables'; import { FONT_SIZE, TRANSITION } from 'config/variables';
import colors from 'config/colors'; import colors from 'config/colors';
import { NavLink } from 'react-router-dom';
const A = styled.a` const A = styled.a`
text-decoration: none; text-decoration: none;
@ -34,20 +35,44 @@ const A = styled.a`
} }
`; `;
const Link = ({ const StyledNavLink = styled(NavLink)`
children, className, href, target, rel, onClick, isGreen = false, isGray = false, ${props => props.isGreen && css`
}) => ( color: ${colors.GREEN_PRIMARY};
`}
${props => props.isGray && css`
color: ${colors.TEXT_SECONDARY};
`}
`;
class Link extends Component {
render() {
const shouldRenderRouterLink = !!this.this.to;
let LinkComponent;
if (shouldRenderRouterLink) {
LinkComponent = (
<StyledNavLink
isGreen={this.props.isGreen}
isGray={this.props.isGray}
to={this.props.to}
/>);
} else {
LinkComponent = (
<A <A
className={className} className={this.props.className}
href={href} href={this.props.href}
target={target} target="_blank"
rel={rel} rel="noreferrer noopener"
onClick={onClick} onClick={this.props.onClick}
isGreen={isGreen} isGreen={this.props.isGreen}
isGray={isGray} isGray={this.props.isGray}
>{children} >{this.props.children}
</A> </A>
); );
}
return (<LinkComponent />);
}
}
Link.propTypes = { Link.propTypes = {
children: PropTypes.oneOfType([ children: PropTypes.oneOfType([
@ -57,11 +82,15 @@ Link.propTypes = {
]).isRequired, ]).isRequired,
className: PropTypes.string, className: PropTypes.string,
href: PropTypes.string, href: PropTypes.string,
target: PropTypes.string, to: PropTypes.string,
rel: PropTypes.string,
onClick: PropTypes.func, onClick: PropTypes.func,
isGreen: PropTypes.bool, isGreen: PropTypes.bool,
isGray: PropTypes.bool, isGray: PropTypes.bool,
}; };
Link.defaultProps = {
isGreen: false,
isGray: false,
};
export default Link; export default Link;