forked from QuantStack/quantstack.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMenuSideBar.tsx
More file actions
49 lines (44 loc) · 1.56 KB
/
MenuSideBar.tsx
File metadata and controls
49 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// src/components/ScrollSidebar.js
import React, { useEffect, useState } from 'react';
import styles from "./styles.module.css";
const sections = [
{ id: 'jupyter-ecosystem', label: 'Jupyter ecosystem' },
{ id: 'package-management', label: 'Package management' },
{ id: 'scientific-computing', label: 'Scientific computing' }
];
export default function MenuSideBar() {
const [activeSectionId, setActiveSectionId] = useState('jupyter-ecosystem');
useEffect(() => {
const handleScroll = () => {
const scrollPosition = window.scrollY + 300;
for (const section of sections) {
const element = document.getElementById(section.id);
if (element && element.offsetTop <= scrollPosition) {
setActiveSectionId(section.id);
}
}
};
window.addEventListener('scroll', handleScroll);
handleScroll();
return () => window.removeEventListener('scroll', handleScroll);
}, []);
return (
<div className={styles.menu_sidebar_container}>
<aside className={styles.menu_sidebar}>
<ul style={{ listStyle: 'none', padding: "0px" }}>
{sections.map((section) => (
<li key={section.id}>
<a
href={`#${section.id}`}
className={`${activeSectionId === section.id ? styles.active_section : ''}`}
>
<span className={styles.menu_sidebar_indicator} />
<span className={styles.menu_sidebar_item}>{section.label}</span>
</a>
</li>
))}
</ul>
</aside>
</div>
);
}