"use client" import { scrollIntoView } from "@/app/docs/scroll-into-view" import { Box, Stack, Text, chakra } from "@chakra-ui/react" import Link from "next/link" import { useEffect } from "react" import { useScrollSpy } from "../lib/use-scroll-spy" interface TocItem { title: React.ReactNode url: string depth: number } interface Props { items: TocItem[] } const TocLink = chakra(Link, { base: { fontSize: "sm", color: "fg.muted", _currentPage: { color: "fg", fontWeight: "medium" }, _hover: { color: "fg" }, ms: "calc(1rem * var(--toc-depth))", }, }) export const Toc = (props: Props) => { const { items } = props const activeItem = useScrollSpy(items.map((entry) => entry.url)) useEffect(() => { const activeLink = document.querySelector("[data-toc][aria-current='page']") const toc = document.getElementById("toc") if (toc && activeLink) { scrollIntoView(toc, activeLink as HTMLElement, 120) } }, [activeItem]) if (!items.length) { return
} return ( On this page {items.map((item, index) => ( {item.title} ))} ) }