1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-15 07:40:07 +02:00
copilot/packages/ui-toolkit/src/anchor/index.js
Sérgio Ramos f3e531dbd8 feat(cp-frontend,ui-toolkit): style inheritance using .extend (#458)
styled-components@2 exposes a new `.extend`[1] API. It is less problematic than
styled(Parent).

[1]: https://www.styled-components.com/docs/basics#extending-styles
2017-05-25 09:59:58 -05:00

55 lines
1.0 KiB
JavaScript

import React from 'react';
import styled, { css } from 'styled-components';
import { A } from 'normalized-styled-components';
import is from 'styled-is';
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};
${is('secondary')`
color: ${props => props.theme.white};
text-decoration: none;
`}
`;
const StyledAnchor = A.extend`
${style}
`;
const StyledLink = styled(BaseLink)`
${style}
`;
/**
* @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);
return (
<View {...rest}>
{children}
</View>
);
};
Anchor.propTypes = {
/**
* The `<a>` text
*/
children: PropTypes.node,
secondary: PropTypes.bool
};
Anchor.defaultProps = {
secondary: false
};
export default Baseline(Anchor);