({
toc,
className,
}: {
toc: {
title?: React.ReactNode;
url: string;
depth: number;
}[];
className?: string;
})
| 44 | } |
| 45 | |
| 46 | export function DocsTableOfContents({ |
| 47 | toc, |
| 48 | className, |
| 49 | }: { |
| 50 | toc: { |
| 51 | title?: React.ReactNode; |
| 52 | url: string; |
| 53 | depth: number; |
| 54 | }[]; |
| 55 | className?: string; |
| 56 | }) { |
| 57 | const itemIds = React.useMemo( |
| 58 | () => toc.map((item) => item.url.replace("#", "")), |
| 59 | [toc], |
| 60 | ); |
| 61 | const activeHeading = useActiveItem(itemIds); |
| 62 | |
| 63 | if (!toc?.length) { |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | return ( |
| 68 | <div |
| 69 | className={cn( |
| 70 | "z-10 flex flex-col gap-1 py-2 ps-6 pe-4 text-sm", |
| 71 | className, |
| 72 | )} |
| 73 | > |
| 74 | <p className="flex h-7 items-center font-medium text-xs">On This Page</p> |
| 75 | <div className="relative ms-3.5 flex flex-col gap-0.5 before:absolute before:inset-y-0 before:-left-3.25 before:w-px before:bg-border"> |
| 76 | {toc.map((item) => ( |
| 77 | <a |
| 78 | className="relative py-1 text-[.8125rem] text-sidebar-foreground leading-4.5 no-underline transition-colors before:absolute before:inset-y-px before:-left-3.25 before:w-px before:rounded-full hover:bg-transparent hover:text-foreground data-[active=true]:bg-transparent data-[depth=3]:ps-3.5 data-[depth=4]:ps-5.5 data-[active=true]:text-foreground data-[active=true]:before:w-0.5 data-[active=true]:before:bg-primary" |
| 79 | data-active={item.url === `#${activeHeading}`} |
| 80 | data-depth={item.depth} |
| 81 | href={item.url} |
| 82 | key={item.url} |
| 83 | > |
| 84 | {item.title} |
| 85 | </a> |
| 86 | ))} |
| 87 | </div> |
| 88 | </div> |
| 89 | ); |
| 90 | } |
nothing calls this directly
no test coverage detected