-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathnavbar.tsx
More file actions
169 lines (160 loc) · 5.98 KB
/
navbar.tsx
File metadata and controls
169 lines (160 loc) · 5.98 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
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
"use client";
import React, { useState } from "react";
import PrimaryButton from "../ui/custom-button";
import { motion, useScroll, useMotionValueEvent } from "framer-motion";
import Image from "next/image";
import { Terminal, Github, Menu, X } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
import { useAnalytics } from "@/hooks/useAnalytics";
const Navbar = () => {
const { scrollYProgress } = useScroll();
const pathname = usePathname();
const isPricingPage = pathname === "/pricing";
const [showNavbar, setShowNavbar] = useState(isPricingPage ? true : false);
const [isOpen, setIsOpen] = useState(false);
const { trackButtonClick, trackLinkClick } = useAnalytics();
const handleGetStartedClick = (location: "navbar" | "mobile_menu") => {
trackButtonClick("Get Started", location);
};
const handleContributeClick = (location: "navbar" | "mobile_menu") => {
trackLinkClick(
"https://github.com/apsinghdev/opensox",
"Contribute",
location,
true
);
};
React.useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape" && isOpen) {
setIsOpen(false);
(document.activeElement as HTMLElement)?.blur();
}
};
document.addEventListener("keydown", handleEscape);
return () => document.removeEventListener("keydown", handleEscape);
}, [isOpen]);
useMotionValueEvent(scrollYProgress, "change", (latest) => {
if (!isPricingPage) {
setShowNavbar(latest > 0);
}
});
const links = [
{ name: "Pricing", href: "/pricing" },
{ name: "Testimonials", href: "/testimonials" },
{ name: "Features", href: "/#features" },
{ name: "Demo", href: "/#demo" },
{ name: "How it works", href: "/#HIW" },
{ name: "Stats", href: "/#Stats" },
];
return (
<motion.nav
initial={{ opacity: 0 }}
animate={showNavbar ? { opacity: 1 } : { opacity: 0, display: "none" }}
transition={{ duration: 0.3 }}
className={cn(
" z-40 flex items-center justify-between px-4 py-3 bg-neutral-900/5 backdrop-blur-xl border-white/10",
isPricingPage
? "relative h-max md:w-full top-0 border-b"
: "fixed rounded-3xl top-4 border w-[94%] md:w-[80%] mx-auto left-1/2 -translate-x-1/2"
)}
>
<div className="flex items-center gap-3">
<button
className="min-[1115px]:hidden text-white"
onClick={() => setIsOpen(!isOpen)}
aria-label="Toggle navigation menu"
aria-expanded={isOpen}
>
{isOpen ? <X size={28} /> : <Menu size={28} />}
</button>
<Link href="/" className="text-xl md:text-2xl font-medium tracking-tighter flex items-center gap-2">
<div className="w-8 md:w-10 aspect-square overflow-hidden relative">
<Image
src="/assets/logo.svg"
alt="Opensox logo"
fill
className="object-cover w-full h-full"
aria-label="Go to homepage"
/>
</div>
<span>Opensox AI</span>
</Link>
</div>
<div className="hidden min-[1115px]:flex items-center gap-5 max-[1270px]:gap-4 max-[1173px]:gap-3 tracking-tight text-lg max-[1270px]:text-base max-[1173px]:text-sm font-light max-[1173px]:font-normal text-[#d1d1d1]">
{links.map((link, index) => {
const isActive = pathname === link.href;
return (
<Link
key={index}
href={link.href}
className={cn(
"cursor-pointer hover:text-white",
isActive && "text-white"
)}
>
{link.name}
</Link>
);
})}
</div>
<div className="flex items-center gap-3">
<Link
href="https://github.com/apsinghdev/opensox"
target="_blank"
rel="noopener noreferrer"
onClick={() => handleContributeClick("navbar")}
className="hidden min-[1115px]:flex items-center gap-2 px-4 py-2.5 bg-github-bg hover:bg-github-hover transition-colors rounded-lg border border-github-border text-white"
>
<Github className="w-5 h-5" />
<span className="text-sm font-medium">Contribute</span>
</Link>
<Link
href="/dashboard/home"
className="cursor-pointer z-30"
onClick={() => handleGetStartedClick("navbar")}
>
<PrimaryButton classname="px-3 py-2 text-sm whitespace-nowrap md:px-5 md:py-3 md:text-base">
<Terminal className="w-4 h-4 md:w-5 md:h-5" />
<span>Get Started</span>
</PrimaryButton>
</Link>
</div>
{isOpen && (
<motion.div
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.25 }}
className="absolute top-full mt-2 left-0 w-full bg-neutral-900/90 backdrop-blur-xl border border-white/10 min-[1115px]:hidden flex flex-col items-center py-5 space-y-4 z-50 rounded-3xl"
>
{links.map((link, index) => (
<Link
key={index}
href={link.href}
onClick={() => setIsOpen(false)}
className="text-white hover:text-gray-300 text-lg"
>
{link.name}
</Link>
))}
<Link
href="https://github.com/apsinghdev/opensox"
target="_blank"
rel="noopener noreferrer"
onClick={() => {
setIsOpen(false);
handleContributeClick("mobile_menu");
}}
className="flex items-center gap-2 px-4 py-2 bg-github-bg hover:bg-github-hover rounded-lg border border-github-border text-white transition-colors"
>
<Github className="w-5 h-5" />
<span className="text-sm font-medium">Contribute</span>
</Link>
</motion.div>
)}
</motion.nav>
);
};
export default Navbar;