stream/src/components/Link/index.js

21 lines
677 B
JavaScript
Raw Normal View History

2021-10-15 13:37:54 +00:00
import { h } from 'preact'
2021-03-24 15:24:34 +00:00
2021-10-15 13:37:54 +00:00
import { useRouteMatch } from 'react-router-dom'
import { A } from '../Text'
import { RRLink } from './styles'
const Link = ({ children, to, activeOnlyWhenExact = true, href, textProps: { colour, size } = {}, navLink, ...rest }) => {
const match = useRouteMatch({
path: to,
exact: activeOnlyWhenExact
})
return href ? <A href={href} colour={colour} size={size} fontFamily={navLink ? 'Lunchtype24' : null} {...rest}>{children}</A> : (
<A as="span" colour={colour} size={size} {...rest}>
<RRLink to={to} $navLink={navLink} $colour={colour} $selected={match && navLink}>{children}</RRLink>
</A>
)
}
export default Link