Skip to content

Commit 0d022f8

Browse files
committed
add sidebar navigation component for introduction page
1 parent 56ddd57 commit 0d022f8

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use client";
2+
3+
import React from "react";
4+
import { getIntroductionDictionary } from "@/features/localization/services/language-dictionary.service";
5+
import styles from "./sidebar-nav.module.scss";
6+
import { useRouter } from "next/navigation";
7+
8+
interface SidebarNavComponentProps {
9+
languageCode: string;
10+
}
11+
12+
const scrollToElementWithOffset = (id: string, offset = 0) => {
13+
const element = document.getElementById(id);
14+
if (element) {
15+
const y = element.getBoundingClientRect().top + window.pageYOffset + offset;
16+
window.scrollTo({ top: y, behavior: "smooth" });
17+
}
18+
};
19+
20+
export const SidebarNavComponent: React.FC<SidebarNavComponentProps> = ({
21+
languageCode,
22+
}) => {
23+
const introductionDictionary = getIntroductionDictionary(languageCode);
24+
const router = useRouter();
25+
const handleClick = (id: string) => {
26+
scrollToElementWithOffset(id, -120);
27+
history.replaceState(null, "", `#${id}`);
28+
};
29+
30+
return (
31+
<div className={styles.container}>
32+
<ul className={styles.list}>
33+
{introductionDictionary.content.headings.map((heading, index) => (
34+
<li
35+
key={index}
36+
className={styles.title}
37+
onClick={() => handleClick(heading.id)}
38+
>
39+
{heading.title}
40+
</li>
41+
))}
42+
</ul>
43+
</div>
44+
);
45+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.container {
2+
position: sticky;
3+
color: white;
4+
height: 100vh;
5+
flex-shrink: 0;
6+
top: 0;
7+
padding: 100px 30px 0px;
8+
border-right: 1px solid white;
9+
max-width: 250px;
10+
overflow-y: auto
11+
}
12+
13+
.title {
14+
margin-bottom: 36px;
15+
padding-right: 8px;
16+
cursor: pointer;
17+
}
18+
19+
.list {
20+
list-style-type: none;
21+
}
22+
23+
@media (max-width: 768px) {
24+
.container {
25+
width: 100%;
26+
height: auto;
27+
position: relative;
28+
}
29+
}

0 commit comments

Comments
 (0)