mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-06 11:25:02 +00:00
* crawl files and create directory tree for sidebar * dropdown * Working on dropdown links and styling * setup header nav * Styles * DocumentNav sidebar done * wrap up header sidebar * setup top level nav * update root level data and fix link bug * doc links yaml * nav links for docs * remove character * prettier * fix build error * MDX style * Update src/components/UI/docs/DocsLinks.tsx Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com> * Abstract LinksList component into its own file * change requests * AccordionButton styles * AccordionButton styled * fix broken links * prettier * prettier * fix broken default code snippet * fix accordion spacing * fix gap at top of DocsNav lg * fix but of persistent header link * remove test content * setup Notes and prettier * rehype * Note component * Note font styling * convert old notes to use component * Breadcrumb cleanup and prettier * MDXComponents -> MDComponent and documentation Co-authored-by: Paul Wackerow <54227730+wackerow@users.noreply.github.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
|
|
/**
|
|
* A hook to determine which section of the page is currently in the viewport.
|
|
* @param {*} itemIds Array of document ids to observe
|
|
* @param {*} rootMargin
|
|
* @returns id of the element currently in viewport
|
|
*/
|
|
export const useActiveHash = (itemIds: Array<string>, rootMargin = `0% 0% -80% 0%`): string => {
|
|
const [activeHash, setActiveHash] = useState(``);
|
|
|
|
useEffect(() => {
|
|
const observer = new IntersectionObserver(
|
|
entries => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
setActiveHash(`${entry.target.id}`);
|
|
}
|
|
});
|
|
},
|
|
{ rootMargin }
|
|
);
|
|
|
|
itemIds?.forEach(id => {
|
|
const element = document.getElementById(id);
|
|
if (element !== null) {
|
|
observer.observe(element);
|
|
}
|
|
});
|
|
|
|
return () => {
|
|
itemIds?.forEach(id => {
|
|
const element = document.getElementById(id);
|
|
if (element !== null) {
|
|
observer.unobserve(element);
|
|
}
|
|
});
|
|
};
|
|
}, [itemIds, rootMargin]);
|
|
|
|
return activeHash;
|
|
};
|