"use client" import clsx from "clsx" import { useActiveOnScroll, useSidebar } from "docs-ui" import { useEffect, useRef } from "react" export type SectionProps = { checkActiveOnScroll?: boolean } & React.AllHTMLAttributes const Section = ({ children, className, checkActiveOnScroll = false, }: SectionProps) => { const sectionRef = useRef(null) const { activeItemId } = useActiveOnScroll({ rootElm: sectionRef.current || undefined, enable: checkActiveOnScroll, useDefaultIfNoActive: false, }) const { setActivePath } = useSidebar() useEffect(() => { if ("scrollRestoration" in history) { // disable scroll on refresh history.scrollRestoration = "manual" } }, []) useEffect(() => { if (activeItemId.length) { history.pushState({}, "", `#${activeItemId}`) setActivePath(activeItemId) } }, [activeItemId]) return (
{children}
) } export default Section