-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNavBar.jsx
More file actions
117 lines (107 loc) · 3.67 KB
/
NavBar.jsx
File metadata and controls
117 lines (107 loc) · 3.67 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React, { useState, useRef, useEffect } from 'react';
import Button from './Button';
import { TiLocationArrow } from 'react-icons/ti';
import { ArrowUpRight, ZentryLogo } from './icons';
import { useWindowScroll } from 'react-use';
import gsap from 'gsap';
const navItems = ['Nexus', 'About', 'Contact'];
const NavBar = () => {
const [isAudioPlaying, setIsAudioPlaying] = useState(false);
const [isIndicatorActive, setIsIndicatorActive] = useState(false);
const [lastScrollY, setLastScrollY] = useState(0);
const [isNavVisible, setIsNavVisible] = useState(true);
const navContainerRef = useRef(null);
const audioElementRef = useRef(null);
const { y: currentScrollY } = useWindowScroll();
useEffect(() => {
if (currentScrollY === 0) {
setIsNavVisible(true);
navContainerRef.current.classList.remove('floating-nav');
} else if (currentScrollY > lastScrollY) {
setIsNavVisible(false);
navContainerRef.current.classList.add('floating-nav');
} else if (currentScrollY < lastScrollY) {
setIsNavVisible(true);
navContainerRef.current.classList.add('floating-nav');
}
setLastScrollY(currentScrollY);
}, [currentScrollY, lastScrollY]);
useEffect(() => {
if (isNavVisible) {
navContainerRef.current.classList.add('floating-nav');
} else {
navContainerRef.current.classList.remove('floating-nav');
}
gsap.to(navContainerRef.current, {
y: isNavVisible ? 0 : -100,
opacity: isNavVisible ? 1 : 0,
duration: 0.2,
});
}, [isNavVisible]);
const toggleAudioIndicator = () => {
setIsAudioPlaying((prev) => !prev);
setIsIndicatorActive((prev) => !prev);
};
useEffect(() => {
if (isAudioPlaying) {
audioElementRef.current.play();
} else {
audioElementRef.current.pause();
}
}, [isAudioPlaying]);
return (
<div
ref={navContainerRef}
className="fixed inset-x-0 top-4 z-50 h-16 border-none transition-all duration-700 sm:inset-x-6 "
>
<header className="absolute top-1/2 w-full -translate-y-1/2">
<nav className="flex size-full items-center justify-between p-4">
<div className="flex items-center gap-7">
<ZentryLogo className="w-24 text-white" />
<Button
id="product-button"
title="Products"
rightIcon={<ArrowUpRight />}
containerClass={
'bg-blue-50 md:flex hidden font-bold items-center justify-center gap-1 !px-4 !py-1.5 !text-[10px]'
}
/>
</div>
<div className="flex h-full items-center">
<div className="hidden md:flex items-center">
{navItems.map((item) => (
<a
key={item}
href={`#${item.toLowerCase()}`}
className="nav-hover-btn flex items-center gap-1"
>
{item}
<ArrowUpRight className="w-2.5 h-2.5" />
</a>
))}
</div>
<button
className="ml-10 flex items-center space-x-0.5"
onClick={toggleAudioIndicator}
>
<audio
ref={audioElementRef}
className="hidden"
src="/audio/loop.mp3"
loop
/>
{[1, 2, 3, 4].map((bar) => (
<div
key={bar}
className={`indicator-line ${isIndicatorActive ? 'active' : ''}`}
style={{ animationDelay: `${bar * 0.1}s` }}
/>
))}
</button>
</div>
</nav>
</header>
</div>
);
};
export default NavBar;