import React from 'react'; import styled, { css } from 'styled-components'; import { colors, typography } from '../../../constants'; import { useThemeContext } from '../../styles/Theme'; export interface LinkProps extends React.AnchorHTMLAttributes, React.RefAttributes { target?: '_blank'; negative?: boolean; as?: 'a' | 'button'; showTargetIcon?: boolean; } export const linkStyle = css` background-color: transparent; font-size: inherit; font-family: ${typography.primary}; font-weight: ${typography.weights.semiBold}; line-height: inherit; color: ${({ negative }) => (negative ? colors.greyDarkest : colors.actionPlain)}; cursor: pointer; text-decoration: underline; user-select: auto; appearance: none; padding: 0; border: none; &:hover, &:active { color: ${({ negative }) => (negative ? 'black' : colors.actionDark)}; svg path { fill: ${({ negative }) => (negative ? 'black' : colors.actionDark)}; } } `; const StyledLink = styled.a` ${linkStyle}; font-family: ${({ theme }) => theme.typography.primary}; font-weight: ${({ theme }) => theme.link.weight}; color: ${({ theme }) => theme.link.color}; &:hover { color: ${({ theme }) => theme.link.hover.color}; svg path { fill: ${({ negative, theme }) => (negative ? 'black' : theme.link.hover.color)}; } } &:active { color: ${({ theme }) => theme.link.active.color}; svg path { fill: ${({ negative, theme }) => (negative ? 'black' : theme.link.active.color)}; } } `; const TargetIconWrapper = styled.svg` margin-left: 6px; top: 2px; position: relative; `; const TargetIcon = (props: React.SVGProps) => { return ( ); }; const Link = React.forwardRef( ({ children, color = colors.actionPlain, target, showTargetIcon = true, ...rest }, ref) => { const theme = useThemeContext(); return ( {children} {target === '_blank' && showTargetIcon && !theme.link.disableTargetIcon && } ); }, ); Link.defaultProps = { color: colors.actionPlain, }; export default Link;