2
2
3
3
import { Fragment , useState } from 'react' ;
4
4
5
- import { Card , CardContent , CardHeader } from '@/components/ui/card' ;
5
+ import { Card , CardContent } from '@/components/ui/card' ;
6
+ import { Collapsible , CollapsibleContent , CollapsibleTrigger } from '@/components/ui/collapsible.tsx' ;
6
7
import {
7
8
DropdownMenu ,
8
9
DropdownMenuContent ,
9
10
DropdownMenuItem ,
10
11
DropdownMenuTrigger ,
11
12
} from '@/components/ui/dropdown-menu.tsx' ;
12
13
import { cn } from '@/lib/utils' ;
13
- import { RiArrowDownSLine } from '@remixicon/react' ;
14
- import { MenuIcon , XIcon } from 'lucide-react' ;
14
+ import { RiArrowDownSLine , RiCloseLargeLine , RiMenuLine } from '@remixicon/react' ;
15
15
import Link from 'next/link' ;
16
16
import { usePathname } from 'next/navigation' ;
17
17
18
- const items = [
19
- { title : 'Blocks' , href : '/blocks' } ,
20
- { title : 'Extrinsics' , href : '/extrinsics' } ,
21
- { title : 'Events' , href : '/events' } ,
22
- { title : 'EVM Transactions' , href : '/evm-transactions' } ,
23
- { title : 'Addresses' , href : '/addresses' } ,
24
- { title : 'Bridge' , href : '/bridge' } ,
25
- { title : 'Tokens' , href : '/tokens' } ,
26
- { title : 'DEX' , href : '/dex' } ,
27
- { title : 'Staking' , href : '/staking' } ,
28
- { title : 'Verified Contracts' , href : '/verified-contracts' } ,
29
- { title : 'Ecosystem' , href : '/ecosystem' } ,
30
- { title : 'API' , href : 'https://build.rootscan.io' , newTab : true } ,
31
- ] ;
32
-
33
18
type HeaderMenuLink = {
34
19
title : string ;
35
20
href : string ;
@@ -41,7 +26,7 @@ type HeaderMenuGroupLink = {
41
26
subitems : Omit < HeaderMenuLink , 'target' > [ ] ;
42
27
} ;
43
28
44
- const items2 : Array < HeaderMenuLink | HeaderMenuGroupLink > = [
29
+ const items : Array < HeaderMenuLink | HeaderMenuGroupLink > = [
45
30
{
46
31
title : 'Blockchain' ,
47
32
subitems : [
@@ -73,7 +58,7 @@ export function Navigation() {
73
58
return (
74
59
< Fragment >
75
60
< div className = "hidden items-center gap-0.5 px-4 lg:flex" >
76
- { items2 . map ( ( item , _ ) => {
61
+ { items . map ( ( item , _ ) => {
77
62
const { title } = item ;
78
63
const { href, target } = item as HeaderMenuLink ;
79
64
const { subitems } = item as HeaderMenuGroupLink ;
@@ -103,12 +88,13 @@ export function Navigation() {
103
88
< DropdownMenuTrigger asChild > { headerMenuLink } </ DropdownMenuTrigger >
104
89
< DropdownMenuContent className = "flex flex-col gap-1 rounded-[12px] bg-popover p-2" >
105
90
{ subitems ?. map ( ( subitem , i ) => (
106
- < DropdownMenuItem
107
- asChild
108
- key = { i }
109
- className = "cursor-pointer rounded-[4px] px-3 py-2 text-[14px]/[20px] font-semibold"
110
- >
111
- < Link href = { subitem . href } > { subitem . title } </ Link >
91
+ < DropdownMenuItem key = { i } asChild >
92
+ < Link
93
+ href = { subitem . href }
94
+ className = "cursor-pointer rounded-[4px] px-3 py-2 text-[14px]/[20px] font-semibold"
95
+ >
96
+ { subitem . title }
97
+ </ Link >
112
98
</ DropdownMenuItem >
113
99
) ) }
114
100
</ DropdownMenuContent >
@@ -129,22 +115,58 @@ export const MobileMenu = () => {
129
115
return (
130
116
< Fragment >
131
117
< div className = "block lg:hidden" >
132
- < div className = "duration-300 animate-in animate-out fade-in fade-out" onClick = { ( ) => setOpen ( ! open ) } >
133
- { open ? < XIcon /> : < MenuIcon /> }
118
+ < div className = "p-1 duration-300 animate-in animate-out fade-in fade-out" onClick = { ( ) => setOpen ( ! open ) } >
119
+ { open ? < RiCloseLargeLine className = "size-6" /> : < RiMenuLine className = "size-6" /> }
134
120
</ div >
135
121
</ div >
136
122
< div className = { cn ( [ open ? 'absolute left-0 top-[64px] !m-0 w-full' : 'hidden' ] ) } >
137
- < Card className = "rounded-b-2xl rounded-t-none" >
138
- < CardHeader className = "pb-0" />
139
- < CardContent >
140
- < div className = "flex flex-col gap-4" >
141
- { items . map ( ( item , _ ) => (
142
- < Link href = { item . href } onClick = { ( ) => setOpen ( false ) } key = { _ } target = { item . newTab ? '_blank' : '_self' } >
143
- < div className = "flex items-center text-sm font-bold text-muted-foreground duration-150 ease-in hover:text-primary" >
144
- { item . title }
145
- </ div >
146
- </ Link >
147
- ) ) }
123
+ < Card className = "rounded-b-2xl rounded-t-none dark:bg-black" >
124
+ < CardContent className = "p-2" >
125
+ < div className = "flex flex-col gap-0.5" >
126
+ { items . map ( ( item , _ ) => {
127
+ const { title } = item ;
128
+ const { href } = item as HeaderMenuLink ;
129
+ const { subitems } = item as HeaderMenuGroupLink ;
130
+ const isLink = ! ! href ;
131
+
132
+ const headerMenuLink = (
133
+ < Link
134
+ className = "group flex items-center justify-between py-3.5 pl-2 pr-3.5 text-[14px]/[20px] font-semibold transition-all"
135
+ href = { isLink ? href : '#' }
136
+ onClick = { ( ) => isLink && setOpen ( false ) }
137
+ >
138
+ { title }
139
+ { ! isLink && (
140
+ < RiArrowDownSLine className = "size-5 transition-all group-data-[state=open]:rotate-180" />
141
+ ) }
142
+ </ Link >
143
+ ) ;
144
+
145
+ return (
146
+ < Fragment key = { _ } >
147
+ { isLink ? (
148
+ headerMenuLink
149
+ ) : (
150
+ < Collapsible >
151
+ < CollapsibleTrigger asChild > { headerMenuLink } </ CollapsibleTrigger >
152
+ < CollapsibleContent >
153
+ < div className = "flex flex-col gap-1 rounded-[12px] border p-2" >
154
+ { subitems ?. map ( ( subitem , i ) => (
155
+ < Link
156
+ key = { i }
157
+ href = { subitem . href }
158
+ className = "cursor-pointer rounded-[4px] px-3 py-2 text-[14px]/[20px] font-semibold"
159
+ >
160
+ { subitem . title }
161
+ </ Link >
162
+ ) ) }
163
+ </ div >
164
+ </ CollapsibleContent >
165
+ </ Collapsible >
166
+ ) }
167
+ </ Fragment >
168
+ ) ;
169
+ } ) }
148
170
</ div >
149
171
</ CardContent >
150
172
</ Card >
0 commit comments