-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathHeader.js
More file actions
96 lines (89 loc) · 3.11 KB
/
Copy pathHeader.js
File metadata and controls
96 lines (89 loc) · 3.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use client";
import Navbar from "react-bootstrap/Navbar";
import { useRouter } from "@@/src/hooks/useRouter";
import { Link } from "../utils/Link";
import { useEffect, useState } from "react";
import SolanaLogo from "../../public/src/img/logos-solana/logotype.inline.svg";
import Moon from "../../public/src/img/icons/Moon.inline.svg";
import Sun from "../../public/src/img/icons/Sun.inline.svg";
import HeaderList from "./header/HeaderList";
import { InkeepSearchBar } from "@@/src/app/components/inkeep/inkeep-searchbar";
import { useTheme } from "@/themecontext";
import { useTranslations } from "next-intl";
import DevelopersNav from "./developers/DevelopersNav/DevelopersNav";
import styles from "./Header.module.scss";
const Header = ({ className = "", containerClassName = "" }) => {
const router = useRouter();
const { theme, toggleTheme, isThemePage } = useTheme();
const t = useTranslations();
const [expanded, setExpanded] = useState(false);
useEffect(() => {
const navbar = document.getElementById("navbar");
if (navbar) {
if (isThemePage) {
navbar.classList.remove("navbar-light", "navbar-dark");
navbar.classList.add("navbar-" + theme);
} else {
navbar.classList.add("navbar-dark");
}
}
}, [t, theme, isThemePage]);
useEffect(() => {
// Close mobile navigation on route change
setExpanded(false);
}, [router.asPath]);
return (
<>
<header className={`position-sticky sticky-top ${className}`}>
<Navbar
id="navbar"
expand="lg"
variant=""
expanded={expanded}
onToggle={setExpanded}
>
<div className={`container-xl ${containerClassName}`}>
<Link to="/" className="d-flex" aria-label="Solana">
<SolanaLogo
style={{ color: "var(--body-text)" }}
width={149}
height={22}
/>
</Link>
<div className="d-flex align-items-center">
<Navbar.Toggle
aria-controls="navbarCollapse"
as="button"
type="button"
>
<span className="bar"></span>
<span className="bar"></span>
<span className="bar"></span>
</Navbar.Toggle>
<Navbar.Collapse id="navbarCollapse">
<HeaderList />
</Navbar.Collapse>
<InkeepSearchBar />
{isThemePage && (
<button
className={styles.header__toggle}
onClick={toggleTheme}
aria-label={t("commands.toggle")}
>
{theme === "light" && <Moon />}
{theme === "dark" && <Sun />}
</button>
)}
</div>
</div>
</Navbar>
</header>
{/* Secondary nav for /developers/* and /docs/* */}
{(router.asPath.includes("/developers") ||
router.asPath.includes("/docs")) && (
<DevelopersNav containerClassName={containerClassName} />
)}
</>
);
};
export default Header;