'use client' import RefVersionDropdown from '~/components/RefVersionDropdown' import { getCrumbName, resolveBreadcrumbs, type BreadcrumbItem as Crumb } from '~/lib/breadcrumbs' import Link from 'next/link' import { useDocsPathname } from '~/features/IaNav/IaNavRouteProvider' import { useNavItems } from '~/features/IaNav/useNavItems' import { Fragment, type Ref } from 'react' import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, cn, } from 'ui' import MenuIconPicker from './MenuIconPicker' interface HeaderBreadcrumbsProps { headingSlotRef?: Ref className?: string } interface BreadcrumbCrumbProps { crumb: Crumb isCurrent: boolean hasIcon: boolean } export const HeaderBreadcrumbs = ({ headingSlotRef, className }: HeaderBreadcrumbsProps) => { const pathname = useDocsPathname() // a group with an overview page links to it, so on that page the group is the current crumb const linkedCrumbs = resolveBreadcrumbs(pathname, useNavItems()).reduce( (chain, crumb) => { const firstItem = crumb.items?.[0] const url = crumb.url ?? (firstItem && getCrumbName(firstItem) === 'Overview' ? firstItem.url : undefined) if (url && url === chain.at(-1)?.url) return chain return [...chain, url === crumb.url ? crumb : { ...crumb, url }] }, [] ) // the sidebar top row names the section, so the header keeps only the parent and the page const crumbs = (linkedCrumbs.length > 1 ? linkedCrumbs.slice(1) : linkedCrumbs).slice(-2) if (crumbs.length === 0) return null return ( {crumbs.map((crumb, index) => ( {index > 0 ? ( ) : null} {crumb.version ? ( ) : null} ))}
  • ) } const BreadcrumbCrumb = ({ crumb, isCurrent, hasIcon }: BreadcrumbCrumbProps) => { const label = ( <> {hasIcon && crumb.icon ? ( ) : null} {getCrumbName(crumb)} ) return ( {isCurrent ? ( {label} ) : crumb.url ? ( {label} ) : ( {label} )} ) }