|
|
import * as React from 'react'; |
|
|
import { Interactive, InteractiveExtendableProps } from 'react-interactive'; |
|
|
import { Link } from 'react-router-dom'; |
|
|
import { styled } from '../stitches.config'; |
|
|
|
|
|
type LinkUnionProps = |
|
|
| (InteractiveExtendableProps<typeof Link> & { href?: never }) |
|
|
| (InteractiveExtendableProps<'a'> & { to?: never; replace?: never }); |
|
|
|
|
|
|
|
|
|
|
|
const LinkUnion = React.forwardRef<HTMLAnchorElement, LinkUnionProps>( |
|
|
(props, ref) => { |
|
|
|
|
|
|
|
|
const As = props.to && !props.disabled ? Link : 'a'; |
|
|
let passThroughProps = props; |
|
|
if (props.disabled) { |
|
|
const { to, replace, ...propsWithoutRouterProps } = props; |
|
|
passThroughProps = propsWithoutRouterProps; |
|
|
} |
|
|
|
|
|
return <Interactive {...passThroughProps} as={As} ref={ref} />; |
|
|
}, |
|
|
); |
|
|
|
|
|
export const InteractiveLink = styled(LinkUnion, { |
|
|
color: '$highContrast', |
|
|
|
|
|
|
|
|
|
|
|
textDecorationLine: 'underline', |
|
|
textDecorationStyle: 'dotted', |
|
|
textDecorationColor: '$green', |
|
|
textDecorationThickness: 'from-font', |
|
|
|
|
|
|
|
|
|
|
|
padding: '2px 3px', |
|
|
margin: '-2px -3px', |
|
|
|
|
|
|
|
|
|
|
|
borderRadius: '3px', |
|
|
|
|
|
'&.hover, &.mouseActive': { |
|
|
textDecorationColor: '$green', |
|
|
textDecorationStyle: 'solid', |
|
|
}, |
|
|
'&.touchActive, &.keyActive': { |
|
|
color: '$green', |
|
|
textDecorationColor: '$green', |
|
|
textDecorationStyle: 'solid', |
|
|
}, |
|
|
'&.focusFromKey': { |
|
|
boxShadow: '0 0 0 2px $colors$purple', |
|
|
}, |
|
|
}); |
|
|
|