1
1
"use client" ;
2
2
3
- import React from "react" ;
3
+ import React , { useState } from "react" ;
4
4
import Link from "next/link" ;
5
5
import { usePathname } from "next/navigation" ;
6
- import { motion } from "framer-motion" ;
6
+ import { motion , AnimatePresence } from "framer-motion" ;
7
7
import {
8
8
PlusCircleIcon ,
9
9
UserIcon ,
10
10
HomeIcon ,
11
+ XMarkIcon ,
12
+ Bars3Icon ,
11
13
} from "@heroicons/react/24/outline" ;
12
14
import Web3Connect from "../Helper/Web3Connect" ;
13
15
import Image from "next/image" ;
@@ -20,61 +22,130 @@ const menuItems = [
20
22
21
23
const Header = ( ) => {
22
24
const pathname = usePathname ( ) ;
25
+ const [ isSidebarOpen , setIsSidebarOpen ] = useState ( false ) ;
26
+
27
+ const toggleSidebar = ( ) => setIsSidebarOpen ( ! isSidebarOpen ) ;
23
28
24
29
return (
25
- < motion . header
26
- className = "bg-white border-b border-gray-200 fixed w-full z-30 shadow-sm"
27
- initial = { { y : - 100 } }
28
- animate = { { y : 0 } }
29
- transition = { { type : "spring" , stiffness : 300 , damping : 30 } }
30
- >
31
- < div className = "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8" >
32
- < div className = "flex justify-between h-16" >
33
- < Link href = "/" className = "flex-shrink-0 flex items-center" >
34
- < Image
35
- width = { 32 }
36
- height = { 32 }
37
- className = "h-8 w-auto"
38
- src = "/aossie.png"
39
- alt = "Agora Blockchain"
40
- />
41
- < h1 className = "ml-3 text-xl font-bold text-gray-800 hidden sm:block" >
42
- Agora Blockchain
43
- </ h1 >
44
- </ Link >
30
+ < >
31
+ < motion . header
32
+ className = "bg-white border-b border-gray-200 fixed w-full z-30 shadow-sm"
33
+ initial = { { y : - 100 } }
34
+ animate = { { y : 0 } }
35
+ transition = { { type : "spring" , stiffness : 300 , damping : 30 } }
36
+ >
37
+ < div className = "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8" >
38
+ < div className = "flex justify-between h-16" >
39
+ < Link href = "/" className = "flex-shrink-0 flex items-center" >
40
+ < Image
41
+ width = { 32 }
42
+ height = { 32 }
43
+ className = "h-8 w-auto"
44
+ src = "/aossie.png"
45
+ alt = "Agora Blockchain"
46
+ />
47
+ < h1 className = "ml-3 text-xl font-bold text-gray-800 hidden sm:block" >
48
+ Agora Blockchain
49
+ </ h1 >
50
+ </ Link >
45
51
46
- < nav className = "flex items-center space-x-4" >
47
- { menuItems . map ( ( item ) => (
48
- < Link key = { item . name } href = { item . href } className = "relative" >
49
- < motion . button
50
- className = { `inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md ${
51
- pathname === item . href
52
- ? "text-indigo-600"
53
- : "text-gray-700 hover:text-indigo-600"
54
- } bg-white hover:bg-gray-50`}
55
- whileHover = { { scale : 1.05 } }
56
- whileTap = { { scale : 0.95 } }
57
- >
58
- < item . icon className = "h-5 w-5 mr-2" aria-hidden = "true" />
59
- < span className = "hidden sm:inline" > { item . name } </ span >
60
- </ motion . button >
61
- { pathname === item . href && (
62
- < motion . div
63
- className = "absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600"
64
- layoutId = "underline"
65
- initial = { { opacity : 0 } }
66
- animate = { { opacity : 1 } }
67
- transition = { { duration : 0.3 } }
68
- />
69
- ) }
70
- </ Link >
71
- ) ) }
72
- < Web3Connect />
73
- </ nav >
52
+ { /* Desktop/Tablet Navigation */ }
53
+ < nav className = "hidden lg:flex items-center space-x-4" >
54
+ { menuItems . map ( ( item ) => (
55
+ < Link key = { item . name } href = { item . href } className = "relative" >
56
+ < motion . button
57
+ className = { `inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md ${
58
+ pathname === item . href
59
+ ? "text-indigo-600"
60
+ : "text-gray-700 hover:text-indigo-600"
61
+ } bg-white hover:bg-gray-50`}
62
+ whileHover = { { scale : 1.05 } }
63
+ whileTap = { { scale : 0.95 } }
64
+ >
65
+ < item . icon className = "h-5 w-5 mr-2" aria-hidden = "true" />
66
+ < span > { item . name } </ span >
67
+ </ motion . button >
68
+ { pathname === item . href && (
69
+ < motion . div
70
+ className = "absolute bottom-0 left-0 right-0 h-0.5 bg-indigo-600"
71
+ layoutId = "underline"
72
+ initial = { { opacity : 0 } }
73
+ animate = { { opacity : 1 } }
74
+ transition = { { duration : 0.3 } }
75
+ />
76
+ ) }
77
+ </ Link >
78
+ ) ) }
79
+ < div className = "hidden lg:block" >
80
+ < Web3Connect />
81
+ </ div >
82
+ </ nav >
83
+
84
+ { /* Mobile/Tablet Menu Button */ }
85
+ < div className = "lg:hidden flex items-center space-x-2" >
86
+ < div className = "scale-90" >
87
+ < Web3Connect />
88
+ </ div >
89
+ < button
90
+ onClick = { toggleSidebar }
91
+ className = "p-2 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-100"
92
+ >
93
+ < Bars3Icon className = "h-6 w-6" />
94
+ </ button >
95
+ </ div >
96
+ </ div >
74
97
</ div >
75
- </ div >
76
- </ motion . header >
98
+ </ motion . header >
99
+
100
+ { /* Mobile/Tablet Sidebar */ }
101
+ < AnimatePresence >
102
+ { isSidebarOpen && (
103
+ < >
104
+ < motion . div
105
+ className = "fixed inset-0 bg-black bg-opacity-50 z-40"
106
+ initial = { { opacity : 0 } }
107
+ animate = { { opacity : 1 } }
108
+ exit = { { opacity : 0 } }
109
+ onClick = { toggleSidebar }
110
+ />
111
+ < motion . div
112
+ className = "fixed right-0 top-0 h-full w-72 bg-white z-50 shadow-lg"
113
+ initial = { { x : "100%" } }
114
+ animate = { { x : 0 } }
115
+ exit = { { x : "100%" } }
116
+ transition = { { type : "spring" , damping : 20 } }
117
+ >
118
+ < div className = "p-6" >
119
+ < button
120
+ onClick = { toggleSidebar }
121
+ className = "absolute top-4 right-4 p-2 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-100"
122
+ >
123
+ < XMarkIcon className = "h-6 w-6" />
124
+ </ button >
125
+ < div className = "mt-8 space-y-6" >
126
+ { menuItems . map ( ( item ) => (
127
+ < Link
128
+ key = { item . name }
129
+ href = { item . href }
130
+ onClick = { toggleSidebar }
131
+ className = { `flex items-center p-4 rounded-lg transition-colors ${
132
+ pathname === item . href
133
+ ? "bg-indigo-50 text-indigo-600"
134
+ : "text-gray-700 hover:bg-gray-50"
135
+ } `}
136
+ >
137
+ < item . icon className = "h-6 w-6 mr-4" />
138
+ < span className = "text-base font-medium" > { item . name } </ span >
139
+ </ Link >
140
+ ) ) }
141
+ </ div >
142
+ </ div >
143
+ </ motion . div >
144
+ </ >
145
+ ) }
146
+ </ AnimatePresence >
147
+ </ >
77
148
) ;
78
149
} ;
79
150
80
- export default Header ;
151
+ export default Header ;
0 commit comments