Skip to content

Commit 00f890c

Browse files
committed
chore: make link use a basic anchor tag instead of Gatsby
1 parent 6db1e23 commit 00f890c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/components/link.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react'
22
import {Link as PrimerLink} from '@primer/react'
3-
import {Link as GatsbyLink} from 'gatsby'
43
import omit from '../util/omit'
54

65
const FALLBACK = `http://_${Math.random().toString().slice(2)}._${Math.random().toString().slice(2)}`
@@ -22,15 +21,26 @@ const getLocalPath = href => {
2221
return null
2322
}
2423

25-
const GatsbyLinkWithoutSxProps = React.forwardRef(function GatsbyLinkWithoutSxProps(props, ref) {
26-
return <GatsbyLink ref={ref} {...omit(props, 'sx', 'underline', 'hoverColor', 'muted')} />
24+
const BasicLinkAdapter = React.forwardRef(function BasicLinkAdapter(props, ref) {
25+
const { to, ...otherProps } = props
26+
// Convert 'to' prop to 'href' for regular anchor tags
27+
return (
28+
<a
29+
ref={ref}
30+
href={to}
31+
{...omit(otherProps, 'sx', 'underline', 'hoverColor', 'muted')}
32+
aria-label={otherProps['aria-label'] || 'Link'}
33+
>
34+
{props.children || 'Link'}
35+
</a>
36+
)
2737
})
2838

2939
const Link = React.forwardRef(function Link({to, href, ...props}, ref) {
3040
const localPath = getLocalPath(href)
3141

3242
if (to || localPath !== null) {
33-
return <PrimerLink ref={ref} as={GatsbyLinkWithoutSxProps} to={to || localPath} {...props} />
43+
return <PrimerLink ref={ref} as={BasicLinkAdapter} to={to || localPath} {...props} />
3444
}
3545

3646
return <PrimerLink ref={ref} href={href} {...props} />

0 commit comments

Comments
 (0)