import type { MarkdownHeading } from 'astro'; import { useEffect, useMemo, useState } from 'react'; import { Scrollbars } from 'react-custom-scrollbars-2'; import { VscListSelection } from 'react-icons/vsc'; import { useLocation } from 'react-use'; const LINK_HEIGHT = 30; const INDICATOR_SIZE = 10; const INDICATOR_OFFSET = (LINK_HEIGHT - INDICATOR_SIZE) / 2; export function Outline({ headings }: { headings: MarkdownHeading[] }) { const state = useLocation(); const [active, setActive] = useState(0); const headingItems = useMemo( () => headings.map((heading, idx) => ( {heading.text} )), [headings, active], ); useEffect(() => { const idx = headings.findIndex((heading) => heading.slug === state.hash?.slice(1)); if (idx >= 0) { setActive(idx); } }, [state, headings]); return (
} renderTrackVertical={(props) => (
)} universal >
Contents
{headingItems}
); }