1- // src/components/Navbar/MegaMenuNavbarItem.tsx
2-
31import React , { useEffect , useMemo , useRef , useState } from "react" ;
42import clsx from "clsx" ;
53import Link from "@docusaurus/Link" ;
64import { useLocation } from "@docusaurus/router" ;
75import useBaseUrl from "@docusaurus/useBaseUrl" ;
8-
96import ChevronDown from "/svg/icon-chevron-down.svg" ;
107import { sidebarIconMap , SidebarIconName } from "../../../icons" ;
118import styles from "./styles.module.css" ;
@@ -14,6 +11,7 @@ export type MegaMenuItem = {
1411 title : string ;
1512 description ?: string ;
1613 href : string ;
14+ external ?: boolean ;
1715 icon ?: SidebarIconName ;
1816 activeBaseRegex ?: string ;
1917} ;
@@ -27,6 +25,7 @@ export type MegaMenuNavbarItemProps = {
2725 primaryItems : MegaMenuItem [ ] ;
2826 otherItems ?: MegaMenuItem [ ] ;
2927 otherLabel ?: string ;
28+ otherCol ?: 1 | 2 ;
3029} ;
3130
3231const EVENT_NAME = "nervos:megamenu-open" ;
@@ -39,6 +38,7 @@ const MegaMenuNavbarItem: React.FC<MegaMenuNavbarItemProps> = ({
3938 primaryItems,
4039 otherItems = [ ] ,
4140 otherLabel = "OTHER" ,
41+ otherCol = 1 ,
4242} ) => {
4343 const location = useLocation ( ) ;
4444 const [ open , setOpen ] = useState ( false ) ;
@@ -183,15 +183,25 @@ const MegaMenuNavbarItem: React.FC<MegaMenuNavbarItemProps> = ({
183183 { otherItems . length > 0 && (
184184 < div className = { styles . otherCol } >
185185 < div className = { styles . otherLabel } > { otherLabel } </ div >
186- < div className = { styles . otherList } >
186+ < div
187+ className = { clsx (
188+ styles . otherList ,
189+ otherCol === 2 && styles . otherListTwoCols
190+ ) }
191+ >
187192 { otherItems . map ( ( item ) => {
188193 const Icon = item . icon ? sidebarIconMap [ item . icon ] : null ;
194+ const External = sidebarIconMap [ "external" ] ;
189195 const active = isItemActive ( item ) ;
190196
191197 return (
192198 < Link
193199 key = { item . href }
194- to = { useBaseUrl ( item . href ) }
200+ to = { item . external ? item . href : useBaseUrl ( item . href ) }
201+ { ...( item . external && {
202+ target : "_blank" ,
203+ rel : "noopener noreferrer" ,
204+ } ) }
195205 className = { clsx (
196206 styles . otherItem ,
197207 active && styles . cardActive
@@ -205,6 +215,12 @@ const MegaMenuNavbarItem: React.FC<MegaMenuNavbarItemProps> = ({
205215 />
206216 ) }
207217 < span className = { styles . otherTitle } > { item . title } </ span >
218+ { item . external && (
219+ < External
220+ className = { styles . externalIcon }
221+ aria-hidden = "true"
222+ />
223+ ) }
208224 </ Link >
209225 ) ;
210226 } ) }
0 commit comments