import { NavSectionCaret, NavSectionContent, NavSectionList, } from '~/components/Navigation/NavSection' import { useDocsPathname } from '~/features/IaNav' import { listsPage } from '~/features/IaNav/navTree' import { useTheme } from 'next-themes' import Image from 'next/legacy/image' import Link from 'next/link' import { Accordion } from 'radix-ui' import React, { useState, type PropsWithChildren } from 'react' import MenuIconPicker from './MenuIconPicker' import { SidebarGroupLabel } from './SidebarGroupLabel' type NavAccordionItem = { name?: string url?: string enabled?: boolean items?: NavAccordionItem[] } interface LinkContainerProps extends PropsWithChildren { url: string isCurrent: boolean className: string } function isRenderable(item: NavAccordionItem): boolean { if (item.enabled === false) return false if (item.url) return true return item.items?.some(isRenderable) ?? false } function groupLinks(item: NavAccordionItem): Array<{ name: string; url: string }> { return (item.items ?? []) .filter((child) => isRenderable(child)) .flatMap((child) => [ ...(child.url && child.name ? [{ name: child.name, url: child.url }] : []), ...groupLinks(child), ]) } const scrollIntoViewRef = (node: HTMLElement | null) => { node?.scrollIntoView({ block: 'nearest', behavior: 'instant' }) } const HeaderLink = React.memo(function HeaderLink(props: { title: string id: string url: string }) { const pathname = useDocsPathname() return ( {props.title ?? props.id} ) }) const LinkContainer = ({ url, isCurrent, className, children }: LinkContainerProps) => { const isExternal = url.startsWith('https://') return ( {children} ) } const ContentAccordionLink = React.memo(function ContentAccordionLink(props: any) { const pathname = useDocsPathname() const { resolvedTheme } = useTheme() const childItems = props.subItem.items ?? [] const activeItem = props.subItem.url === pathname && !childItems.some((child: NavAccordionItem) => child.url === pathname) const enabledChildren = childItems.filter(isRenderable) const hasChildren = enabledChildren.length > 0 const isChildActive = enabledChildren.some((child: NavAccordionItem) => listsPage(child, pathname) ) const [isOpen, setIsOpen] = useState(isChildActive) const [openedPathname, setOpenedPathname] = useState(pathname) // a route change to a page in the group opens it, and the user can still close it after that if (pathname !== openedPathname) { setOpenedPathname(pathname) if (isChildActive) setIsOpen(true) } const accordionValue = props.subItem.url || props.subItem.name const handleValueChange = (value: string) => setIsOpen(value === accordionValue) if (!hasChildren && !props.subItem.url) return null return (
  • {hasChildren ? (
    {props.subItem.icon && ( )} {props.subItem.name}
    {enabledChildren.map((child) => { if (child.items && child.items.length > 0) { return } return (
  • {child.url === pathname && ( )} {child.name}
  • ) })} ) : (
    {props.subItem.icon && ( )} {props.subItem.name}
    )} ) }) const ContentLink = React.memo(function ContentLink(props: any) { const pathname = useDocsPathname() return (
  • {props.icon && ( {props.icon} )} {props.name}
  • ) }) const Content = (props) => { const { menu, id } = props if (menu.enabled === false) { return null } return (
    ) } export default React.memo(Content)