2017-05-18 21:21:33 +03:00
|
|
|
import React from 'react';
|
|
|
|
import styled, { css } from 'styled-components';
|
|
|
|
import { A } from 'normalized-styled-components';
|
2017-09-26 19:07:45 +03:00
|
|
|
import is, { isOr } from 'styled-is';
|
2017-05-18 21:21:33 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Link as BaseLink } from 'react-router-dom';
|
|
|
|
import Baseline from '../baseline';
|
|
|
|
|
|
|
|
const style = css`
|
|
|
|
color: ${props => props.theme.primary};
|
|
|
|
|
2017-09-26 19:07:45 +03:00
|
|
|
&:hover {
|
2017-05-18 21:21:33 +03:00
|
|
|
text-decoration: none;
|
2017-09-26 19:07:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
${isOr('secondary', 'reversed')`
|
|
|
|
color: ${props => props.theme.white};
|
2017-07-27 20:44:29 +03:00
|
|
|
`};
|
|
|
|
|
|
|
|
${is('disabled')`
|
|
|
|
color: ${props => props.theme.grey};
|
2017-09-26 19:07:45 +03:00
|
|
|
pointer-events: none;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
2017-07-27 20:44:29 +03:00
|
|
|
`};
|
2017-05-18 21:21:33 +03:00
|
|
|
`;
|
|
|
|
|
2017-10-11 19:59:59 +03:00
|
|
|
const StyledAnchor = A.extend`
|
|
|
|
${style};
|
|
|
|
`;
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-10-11 19:59:59 +03:00
|
|
|
const StyledLink = styled(BaseLink)`
|
|
|
|
${style};
|
|
|
|
`;
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @example ./usage.md
|
|
|
|
*/
|
|
|
|
const Anchor = ({ children, ...rest }) => {
|
|
|
|
const { to = '' } = rest;
|
|
|
|
|
|
|
|
const Views = [() => (to ? StyledLink : null), () => StyledAnchor];
|
|
|
|
const View = Views.reduce((sel, view) => (sel ? sel : view()), null);
|
|
|
|
|
2017-08-28 22:21:08 +03:00
|
|
|
return <View {...rest}>{children}</View>;
|
2017-05-18 21:21:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Anchor.propTypes = {
|
|
|
|
/**
|
|
|
|
* The `<a>` text
|
|
|
|
*/
|
|
|
|
children: PropTypes.node,
|
|
|
|
secondary: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
|
|
|
Anchor.defaultProps = {
|
|
|
|
secondary: false
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Baseline(Anchor);
|