import type { FunctionalComponent } from 'preact'; import { h } from 'preact'; import { useState, useEffect, useRef } from 'preact/hooks'; import EditOnGithub from './EditOnGithub'; const DocSidebar: FunctionalComponent<{ headers: any[]; editHref: string }> = ({ headers = [], editHref }) => { const itemOffsets = useRef([]); const [activeId, setActiveId] = useState(undefined); useEffect(() => { const getItemOffsets = () => { const titles = document.querySelectorAll('article :is(h2, h3, h4)'); itemOffsets.current = Array.from(titles).map((title) => ({ id: title.id, topOffset: title.getBoundingClientRect().top + window.scrollY, })); }; const onScroll = () => { const itemIndex = itemOffsets.current.findIndex((item) => item.topOffset > window.scrollY + window.innerHeight / 3); if (itemIndex === 0) { setActiveId(undefined); } else if (itemIndex === -1) { setActiveId(itemOffsets.current[itemOffsets.current.length - 1].id); } else { setActiveId(itemOffsets.current[itemIndex - 1].id); } }; getItemOffsets(); window.addEventListener('resize', getItemOffsets); window.addEventListener('scroll', onScroll); return () => { window.removeEventListener('resize', getItemOffsets); window.removeEventListener('scroll', onScroll); }; }, []); return ( ); }; export default DocSidebar; ver-destroy Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/examples/with-tailwindcss/.stackblitzrc (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-06-28Fix Tailwind integration Typescript warning (#3732)Gravatar Victor 2-1/+6
2022-06-27[ci] formatGravatar bholmesdev 2-3/+3
2022-06-27Refactor: remove Deno shim to esbuild "banner" (#3734)Gravatar Ben Holmes 7-15/+22
2022-06-27[ci] formatGravatar FredKSchott 9-23/+25
2022-06-27update telemetry to support more anonymized project id (#3713)Gravatar Fred K. Schott 20-351/+311
2022-06-27SImplify "astro add" by removing confusing multi-select (#3715)Gravatar Fred K. Schott 13-258/+157