import { useInView } from 'react-intersection-observer' import { FC, PropsWithChildren } from 'react' import { highlightSelectedNavItem } from '~/components/CustomHTMLElements/CustomHTMLElements.utils' import { useRouter } from 'next/router' import { useNavigationMenuContext } from '~/components/Navigation/NavigationMenu/NavigationMenu.Context' import { menuState } from '~/hooks/useMenuState' interface ISectionContainer { id: string title?: string monoFont?: boolean slug: string scrollSpyHeader?: boolean singleColumn?: boolean } type RefSubLayoutNonFuncSubComponents = { Section: FC Details: FC Examples: FC } type StickyHeader = { id: string slug?: string title?: string monoFont?: boolean scrollSpyHeader?: boolean // whether or not the header updates the url on scroll } type RefSubLayoutNonFuncType = {} const RefSubLayoutNonFunc: FC> & RefSubLayoutNonFuncSubComponents = (props) => { return
{props.children}
} const Section: FC> = (props) => { return (
{props.children}
) } const StickyHeader: FC = (props) => { const router = useRouter() const { setActiveRefItem } = useNavigationMenuContext() const { ref } = useInView({ threshold: 1, rootMargin: '30% 0% -35% 0px', onChange: (inView, entry) => { if (inView && window) highlightSelectedNavItem(entry.target.attributes['data-ref-id'].value) if (inView && props.scrollSpyHeader) { window.history.replaceState(null, '', entry.target.id) // if (setActiveRefItem) setActiveRefItem(entry.target.attributes['data-ref-id'].value) menuState.setMenuActiveRefId(entry.target.attributes['data-ref-id'].value) // router.push(`/reference/javascript/${entry.target.attributes['data-ref-id'].value}`, null, { // shallow: true, // }) } }, }) return (

{props.title && {props.title}}

) } interface ISectionDetails {} const Details: FC> = (props) => { return
{props.children}
} interface ISectionExamples {} const Examples: FC> = (props) => { return (
{props.children}
) } RefSubLayoutNonFunc.Section = Section RefSubLayoutNonFunc.Details = Details RefSubLayoutNonFunc.Examples = Examples export default RefSubLayoutNonFunc