import React, { useEffect, useState } from "react";
import clsx from "clsx";
import TOCItems from "@theme/TOCItems";
import styles from "./styles.module.css";
import contentStyles from "../DocItem/Content/styles.module.css"
const LINK_CLASS_NAME = "table-of-contents__link toc-highlight";
const LINK_ACTIVE_CLASS_NAME = "table-of-contents__link--active";
export default function TOC({ className, ...props }) {
const [tocHeight, setTocHeight] = useState(0);
useEffect(() => {
const element = document.querySelector(`.${contentStyles.topLevelDoc} > :nth-child(3)`);
if (element) {
const yCoordinate = element.getBoundingClientRect().y + window.scrollY;
setTocHeight(`${yCoordinate-112}px`); }
}, []);
return (
<div
className={clsx(styles.tableOfContents, "thin-scrollbar", className)}
style={{ marginTop: tocHeight }} >
<TOCItems
{...props}
linkClassName={LINK_CLASS_NAME}
linkActiveClassName={LINK_ACTIVE_CLASS_NAME}
/>
</div>
);
}