'use client' import Link from 'next/link' import React, { FC, type ReactNode } from 'react' import { Badge, cn } from 'ui' import { TopNavMenu, TopNavMenuGroup, TopNavMenuGroupLink, TopNavMenuItem, TopNavMenuLink, TopNavMenuPanel, } from 'ui-patterns/TopNav/TopNavMenu' import type { DropdownMenuItem, GlobalMenuItems } from '../Navigation.types' import MenuIconPicker from './MenuIconPicker' import { getMenuGroupLabelByPath } from './NavigationMenu.utils' import { IA_NAV_PENDING_CLASS, useDocsPathname, useIaNavReady, useNavItems } from '@/features/IaNav' interface MenuItemLabelProps { title: ReactNode icon?: ReactNode community?: boolean isNew?: boolean experimental?: boolean } const GlobalNavigationMenu: FC = () => { const { GLOBAL_MENU_ITEMS } = useNavItems() const isNavReady = useIaNavReady() const pathname = useDocsPathname() const activeLabel = getMenuGroupLabelByPath({ menu: GLOBAL_MENU_ITEMS, pathname }) const itemClassName = cn(!isNavReady && IA_NAV_PENDING_CLASS) return ( <> {GLOBAL_MENU_ITEMS.filter(([section]) => section.enabled !== false).map(([section]) => { const label = section.label === 'Home' ? : section.label const ariaCurrent = activeLabel === section.label ? 'true' : undefined return section.menuItems ? ( {section.menuItems.map((group, index) => ( ))} ) : ( {label} ) })} ) } // the menu panels mount on the client, so their links are also rendered for readers without JavaScript const GlobalMenuPanelsFallback = ({ menuItems }: { menuItems: GlobalMenuItems }) => ( ) // an item without a link is the heading of its group. the first group falls back to the menu name const GlobalMenuGroup = ({ items, fallbackLabel, }: { items: DropdownMenuItem[] fallbackLabel?: string }) => { const enabledItems = items.filter((item) => item.enabled !== false) return ( !item.href)?.label ?? fallbackLabel}> {enabledItems .filter((item) => item.href) .map((item) => ( {item.label} {item.community ? Community : null} {item.new ? New : null} {item.experimental ? Experimental : null} ))} ) } export const MenuItemLabel = ({ title, icon, community, isNew, experimental, }: MenuItemLabelProps) => ( <> {icon ? ( {icon} ) : null} {title} {community ? Community : null} {isNew ? New : null} {experimental ? Experimental : null} ) export const MenuItem = React.forwardRef< React.ElementRef<'a'>, React.ComponentPropsWithoutRef<'a'> & { icon?: string community?: boolean new?: boolean experimental?: boolean } >( ( { className, title, href = '', icon, community, new: isNew, experimental, children, ...props }, ref ) => { return ( {children ?? ( : null} community={community} isNew={isNew} experimental={experimental} /> )} ) } ) GlobalNavigationMenu.displayName = 'GlobalNavigationMenu' MenuItem.displayName = 'MenuItem' export default GlobalNavigationMenu