Skip to content

Commit 33d5ee5

Browse files
authored
Merge pull request #733 from Akshay1833/navbar-changes
Navbar Hover Effect changes
2 parents 80ce2c1 + bf58649 commit 33d5ee5

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

components/layout.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { type Metadata } from 'next'
2+
import {
3+
ClerkProvider,
4+
SignInButton,
5+
SignUpButton,
6+
SignedIn,
7+
SignedOut,
8+
UserButton,
9+
} from '@clerk/nextjs'
10+
import { Geist, Geist_Mono } from 'next/font/google'
11+
import './globals.css'
12+
13+
const geistSans = Geist({
14+
variable: '--font-geist-sans',
15+
subsets: ['latin'],
16+
})
17+
18+
const geistMono = Geist_Mono({
19+
variable: '--font-geist-mono',
20+
subsets: ['latin'],
21+
})
22+
23+
export const metadata: Metadata = {
24+
title: 'Clerk Next.js Quickstart',
25+
description: 'Generated by create next app',
26+
}
27+
28+
export default function RootLayout({
29+
children,
30+
}: Readonly<{
31+
children: React.ReactNode
32+
}>) {
33+
return (
34+
<ClerkProvider>
35+
<html lang="en">
36+
<body className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
37+
<header className="flex justify-end items-center p-4 gap-4 h-16">
38+
<SignedOut>
39+
<SignInButton />
40+
<SignUpButton>
41+
<button className="bg-[#6c47ff] text-ceramic-white rounded-full font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 cursor-pointer">
42+
Sign Up
43+
</button>
44+
</SignUpButton>
45+
</SignedOut>
46+
<SignedIn>
47+
<UserButton />
48+
</SignedIn>
49+
</header>
50+
{children}
51+
</body>
52+
</html>
53+
</ClerkProvider>
54+
)
55+
}

components/layout/Header.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@ const Header = () => {
1818
const [isFrameworkDropdownOpen, setFrameworkDropdownOpen] = useState(false)
1919
const [isGitSelectionDropdownOpen, setGitSelectionDropdownOpen] =
2020
useState(false)
21-
const [isRoadmapDropdownOpen, setRoadmapDropdownOpen] = useState(false)
21+
const [isRoadmapDropdownOpen, setRoadmapDropdownOpen ] = useState(false)
2222
const node = useRef<HTMLLIElement | null>(null)
2323
const frameworkNode = useRef<HTMLLIElement | null>(null)
2424
const gitSelectionNode = useRef<HTMLLIElement | null>(null)
2525
const roadmapNode = useRef<HTMLLIElement | null>(null)
2626
const router = useRouter()
2727
const [starCount, setStarCount] = useState<number | null>(null)
2828
const { user, isLoaded } = useUser()
29+
const [dropdownTimeouts, setDropdownTimeouts] = useState<Record<string, NodeJS.Timeout | null>>({
30+
language: null,
31+
framework: null,
32+
git: null,
33+
roadmap: null,
34+
})
2935

3036
useEffect(() => {
3137
fetch('/api/repo-stats')
@@ -117,6 +123,26 @@ const Header = () => {
117123
setGitSelectionDropdownOpen(false)
118124
}
119125

126+
const handleMouseEnter = (menu: string) => {
127+
if (dropdownTimeouts[menu]) {
128+
clearTimeout(dropdownTimeouts[menu]) // Cancel the collapse timeout for this menu
129+
}
130+
if (menu === 'language') setLanguageDropdownOpen(true)
131+
if (menu === 'framework') setFrameworkDropdownOpen(true)
132+
if (menu === 'git') setGitSelectionDropdownOpen(true)
133+
if (menu === 'roadmap') setRoadmapDropdownOpen(true)
134+
}
135+
136+
const handleMouseLeave = (menu: string) => {
137+
const timeout = setTimeout(() => {
138+
if (menu === 'language') setLanguageDropdownOpen(false)
139+
if (menu === 'framework') setFrameworkDropdownOpen(false)
140+
if (menu === 'git') setGitSelectionDropdownOpen(false)
141+
if (menu === 'roadmap') setRoadmapDropdownOpen(false)
142+
}, 100)
143+
setDropdownTimeouts((prev) => ({ ...prev, [menu]: timeout }))
144+
}
145+
120146
return (
121147
<nav className='border-b border-gray-200 bg-gray-100 shadow-md dark:border-gray-900'>
122148
<div className='modern-container'>
@@ -135,6 +161,8 @@ const Header = () => {
135161
<div
136162
className='relative'
137163
ref={node as React.RefObject<HTMLDivElement>}
164+
onMouseEnter={() => handleMouseEnter('language')}
165+
onMouseLeave={() => handleMouseLeave('language')}
138166
>
139167
<button
140168
onClick={toggleLanguageDropdown}
@@ -185,6 +213,8 @@ const Header = () => {
185213
<div
186214
className='relative'
187215
ref={frameworkNode as React.RefObject<HTMLDivElement>}
216+
onMouseEnter={() => handleMouseEnter('framework')}
217+
onMouseLeave={() => handleMouseLeave('framework')}
188218
>
189219
<button
190220
onClick={toggleFrameworkDropdown}
@@ -235,6 +265,8 @@ const Header = () => {
235265
<div
236266
className='relative'
237267
ref={gitSelectionNode as React.RefObject<HTMLDivElement>}
268+
onMouseEnter={() => handleMouseEnter('git')}
269+
onMouseLeave={() => handleMouseLeave('git')}
238270
>
239271
<button
240272
onClick={toggleGitSelectionDropdown}
@@ -283,6 +315,8 @@ const Header = () => {
283315
<div
284316
className='relative'
285317
ref={roadmapNode as React.RefObject<HTMLDivElement>}
318+
onMouseEnter={() => handleMouseEnter('roadmap')}
319+
onMouseLeave={() => handleMouseLeave('roadmap')}
286320
>
287321
<button
288322
onClick={toggleRoadmapDropdown}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@ant-design/icons": "^6.0.0",
17-
"@clerk/nextjs": "^6.35.0",
17+
"@clerk/nextjs": "^6.35.6",
1818
"@clerk/themes": "^2.2.3",
1919
"@heroicons/react": "^2.0.18",
2020
"framer-motion": "^12.0.0",

0 commit comments

Comments
 (0)