1
1
import React from 'react'
2
2
import { Link as PrimerLink } from '@primer/react'
3
- import { Link as GatsbyLink } from 'gatsby'
4
3
import omit from '../util/omit'
5
4
6
5
const FALLBACK = `http://_${ Math . random ( ) . toString ( ) . slice ( 2 ) } ._${ Math . random ( ) . toString ( ) . slice ( 2 ) } `
@@ -22,15 +21,26 @@ const getLocalPath = href => {
22
21
return null
23
22
}
24
23
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
+ )
27
37
} )
28
38
29
39
const Link = React . forwardRef ( function Link ( { to, href, ...props } , ref ) {
30
40
const localPath = getLocalPath ( href )
31
41
32
42
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 } />
34
44
}
35
45
36
46
return < PrimerLink ref = { ref } href = { href } { ...props } />
0 commit comments