-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeaderMenu.tsx
204 lines (194 loc) · 5.91 KB
/
HeaderMenu.tsx
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import React, { useEffect } from "react";
import {
Group,
Burger,
Container,
Drawer,
Box,
rem,
Anchor,
} from "@mantine/core";
import { useDisclosure, useWindowScroll } from "@mantine/hooks";
import { useState } from "react";
import { IconChevronDown } from "@tabler/icons-react";
import classes from "./HeaderMenu.module.css";
import Image from "next/image";
import Link from "next/link";
import { IconBrandFacebook, IconBrandLinkedin } from "@tabler/icons-react";
import { Fade } from "react-awesome-reveal";
const links = [
{ link: "/#about", label: "About" },
{ link: "/#services", label: "Our Services" },
{ link: "/#projects", label: "Our Work" },
{ link: "/#contact", label: "Contact" },
// strucutre of the links for the DROPDOWN menu
// {
// link: "#1",
// label: "Learn",
// links: [
// { link: "/docs", label: "Documentation" },
// { link: "/resources", label: "Resources" },
// { link: "/community", label: "Community" },
// { link: "/blog", label: "Blog" },
// ],
// },
];
export function HeaderMenu() {
const [opened, { toggle }] = useDisclosure(false);
const [active, setActive] = useState(-1);
const [scroll] = useWindowScroll(); // Get the current scroll position
const [showHeader, setShowHeader] = useState(false);
useEffect(() => {
// Check if the user has scrolled down 200px and update showHeader accordingly
const handleScroll = () => setShowHeader(scroll.y > 300);
handleScroll(); // Call it on component mount
// Since useWindowScroll hook provides scroll position reactively,
// there's no need to add a separate event listener for scroll events.
}, [scroll.y]);
const items = links.map((link, index) => {
// This is the code for the DROPDOWN menu
// const menuItems = link.links?.map((item: any) => (
// <Menu.Item key={item.link}>{item.label}</Menu.Item>
// ));
// if (menuItems) {
// return (
// <Menu
// key={link.label}
// trigger="hover"
// transitionProps={{ exitDuration: 0 }}
// withinPortal
// >
// <Menu.Target>
// <a
// href={link.link}
// className={classes.link}
// onClick={(event) => event.preventDefault()}
// >
// <Center>
// <span className={classes.linkLabel}>{link.label}</span>
// <IconChevronDown size="0.9rem" stroke={1.5} />
// </Center>
// </a>
// </Menu.Target>
// <Menu.Dropdown>{menuItems}</Menu.Dropdown>
// </Menu>
// );
// }
return (
<Link
key={link.label}
href={link.link}
data-active={index === active || undefined}
className={classes.link}
onClick={() => {
setActive(index);
}}
>
{link.label}
</Link>
);
});
if (!showHeader) return null; // Do not render the header if the user hasn't scrolled down 200px yet
return (
<>
<header
className={`${classes.header} ${
showHeader ? classes.headerVisible : ""
}`}
>
<Container size="lg">
<div className={classes.inner}>
<Link
href="/"
onClick={() => {
setActive(-1);
}}
>
<Image
src={`${process.env.NEXT_PUBLIC_BASE_PATH}/cc-main-logo-green.svg`}
alt="Colchuck Consulting Logo"
width={120}
height={30}
priority={true} // Load this image before others
className={classes.logo}
style={{ marginTop: "7px" }}
/>
</Link>
<Group gap={0} justify="flex-end" visibleFrom="sm">
{items}
</Group>
<Burger
opened={opened}
onClick={toggle}
size="sm"
hiddenFrom="sm"
/>
</div>
</Container>
</header>
<Drawer
opened={opened}
onClose={toggle}
position="top"
padding="md"
size="100%"
title={
<Image
src={`${process.env.NEXT_PUBLIC_BASE_PATH}/cc-main-logo-green.svg`}
alt="Colchuck Consulting Logo"
width={120}
height={30}
priority={true} // Load this image before others
className={classes.logo}
/>
}
onClick={toggle}
>
<Box>
<Group gap={0} className={classes.drawerContent}>
{items}
</Group>
{opened && (
<>
<Box
ta="center"
mt={"md"}
pb={"sm"}
className={classes.cascadeFadeInSocialIcons}
>
{/* Facebook */}
<Anchor
href="https://www.facebook.com/people/Colchuck-Consulting/100092182747710/"
target="_blank"
rel="noopener noreferrer"
className={classes.socialIcon}
>
<IconBrandFacebook
style={{ width: rem(32), height: rem(32) }}
stroke={1.5}
/>
</Anchor>
{/* LinkedIn */}
<Anchor
href="https://www.linkedin.com/company/colchuck-consulting"
target="_blank"
rel="noopener noreferrer"
className={classes.socialIcon}
>
<IconBrandLinkedin
style={{
width: rem(32),
height: rem(32),
marginLeft: "5px",
}}
stroke={1.5}
/>
</Anchor>
</Box>
</>
)}
</Box>
</Drawer>
</>
);
}