Files
onspring-api-docs/src/app/components/Page.tsx
T

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-04-20 23:36:52 -05:00
'use client';
2023-04-27 07:54:36 -05:00
import { useEffect, useRef, useState } from 'react';
2023-04-20 23:36:52 -05:00
import { themes, useThemeContext } from '../theme';
import { DocSection, DocsStructure } from '../types/types';
import Main from './Main';
import NavBar from './NavBar';
import styles from './Page.module.css';
import SideBar from './SideBar';
export default function Page({
version,
versionSections,
}: {
version: DocsStructure;
versionSections: DocSection[];
}) {
const { theme } = useThemeContext();
const themeStyles = themes[theme];
2023-04-27 07:54:36 -05:00
const docRef = useRef<HTMLDivElement>(null);
const [currentSection, setCurrentSection] = useState('');
useEffect(() => {
const titles =
document.querySelectorAll<HTMLHeadingElement>(
'.section-title'
);
const observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
setCurrentSection(entry.target.id);
}
});
},
{
root: null,
rootMargin: '-10% 0% -80% 0%',
threshold: 1,
}
);
titles.forEach(title => observer.observe(title));
return () => {
titles.forEach(title => observer.unobserve(title));
};
}, []);
2023-04-20 23:36:52 -05:00
return (
<div className={styles.wrapper} style={themeStyles}>
<SideBar version={version} />
2023-04-27 07:54:36 -05:00
<div ref={docRef} className={styles.container}>
2023-04-20 23:36:52 -05:00
<NavBar version={version} />
<Main versionSections={versionSections} />
</div>
</div>
);
}