@@ -3,14 +3,17 @@ import classNames from 'classnames';
33import Link from 'next/link' ;
44import PlusIcon from 'static/images/icons/plus.svg' ;
55import MinusIcon from 'static/images/icons/minus.svg' ;
6+ import OutboundLink from 'components/OutboundLink/OutboundLink' ;
7+ import { twMerge } from 'tailwind-merge' ;
68import styles from './NavListItem.module.css' ;
79
8- type SublinkType = {
10+ interface SublinkType {
911 name : string ;
1012 href : string ;
11- } ;
13+ isExternal ?: boolean ;
14+ }
1215
13- export type NavListItemPropsType = {
16+ export interface NavListItemPropsType {
1417 /**
1518 * Text used for the label.
1619 */
@@ -27,7 +30,7 @@ export type NavListItemPropsType = {
2730 * Includes an optional icon.
2831 */
2932 icon ?: React . ReactElement | null ;
30- } ;
33+ }
3134
3235function NavListItem ( { sublinks, href, name, icon = null } : NavListItemPropsType ) {
3336 const [ areSublinksVisible , setSublinksVisible ] = useState ( false ) ;
@@ -58,7 +61,10 @@ function NavListItem({ sublinks, href, name, icon = null }: NavListItemPropsType
5861 < li className = { styles . NavListItem } >
5962 < Link href = { href } >
6063 < a
61- className = { classNames ( styles . link , styles . navItemLink ) }
64+ className = { classNames (
65+ twMerge ( styles . link , '[&>svg]:-bottom-2 [&>svg]:right-3' ) ,
66+ styles . navItemLink ,
67+ ) }
6268 onMouseEnter = { exposeSublinks }
6369 onMouseLeave = { hideSublinks }
6470 role = "link"
@@ -99,18 +105,29 @@ function NavListItem({ sublinks, href, name, icon = null }: NavListItemPropsType
99105 { sublinks . map ( ( sublink , index ) => (
100106 < li className = { styles . sublinkListItem } key = { sublink . name } >
101107 { /* 😞 next/link fought being mocked, so `prefetch` has test-specific code */ }
102- < Link href = { sublink . href } prefetch = { process . env . NODE_ENV === 'production' } >
103- < a
104- className = { styles . link }
105- key = { sublink . name }
106- role = "link"
107- tabIndex = { 0 }
108+ { ! sublink . isExternal ? (
109+ < Link href = { sublink . href } prefetch = { process . env . NODE_ENV === 'production' } >
110+ < a
111+ className = { twMerge ( styles . link , '[&>svg]:-bottom-2 [&>svg]:right-3' ) }
112+ role = "link"
113+ tabIndex = { 0 }
114+ data-testid = { `Nav Item ${ sublink . name } ` }
115+ onKeyDown = { event => handleKeyDown ( event , index ) }
116+ >
117+ < span className = { styles . linkContent } > { sublink . name } </ span >
118+ </ a >
119+ </ Link >
120+ ) : (
121+ < OutboundLink
122+ analyticsEventLabel = { `Clicked on ${ sublink . name } -> ${ sublink . href } ` }
123+ className = { twMerge ( styles . link , '[&>svg]:-bottom-2 [&>svg]:right-3' ) }
108124 data-testid = { `Nav Item ${ sublink . name } ` }
109- onKeyDown = { event => handleKeyDown ( event , index ) }
125+ href = { sublink . href }
126+ hasIcon
110127 >
111- < span className = { styles . linkContent } > { sublink . name } </ span >
112- </ a >
113- </ Link >
128+ < span className = { twMerge ( styles . link , '[&>svg]:-bottom-2 [&>svg]:right-3' ) } > { sublink . name } </ span >
129+ </ OutboundLink >
130+ ) }
114131 </ li >
115132 ) ) }
116133 </ ul >
0 commit comments