2
2
3
3
import { Fragment , useState } from 'react' ;
4
4
5
+ import { Card , CardContent , CardHeader } from '@/components/ui/card' ;
6
+ import {
7
+ DropdownMenu ,
8
+ DropdownMenuContent ,
9
+ DropdownMenuItem ,
10
+ DropdownMenuTrigger ,
11
+ } from '@/components/ui/dropdown-menu.tsx' ;
5
12
import { cn } from '@/lib/utils' ;
13
+ import { RiArrowDownSLine } from '@remixicon/react' ;
6
14
import { MenuIcon , XIcon } from 'lucide-react' ;
7
15
import Link from 'next/link' ;
8
16
import { usePathname } from 'next/navigation' ;
9
17
10
- import { Card , CardContent , CardHeader } from './ui/card' ;
11
-
12
18
const items = [
13
19
{ title : 'Blocks' , href : '/blocks' } ,
14
20
{ title : 'Extrinsics' , href : '/extrinsics' } ,
@@ -24,25 +30,93 @@ const items = [
24
30
{ title : 'API' , href : 'https://build.rootscan.io' , newTab : true } ,
25
31
] ;
26
32
33
+ type HeaderMenuLink = {
34
+ title : string ;
35
+ href : string ;
36
+ target ?: '_blank' ;
37
+ } ;
38
+
39
+ type HeaderMenuGroupLink = {
40
+ title : string ;
41
+ subitems : Omit < HeaderMenuLink , 'target' > [ ] ;
42
+ } ;
43
+
44
+ const items2 : Array < HeaderMenuLink | HeaderMenuGroupLink > = [
45
+ {
46
+ title : 'Blockchain' ,
47
+ subitems : [
48
+ { title : 'Blocks' , href : '/blocks' } ,
49
+ { title : 'Extrinsics' , href : '/extrinsics' } ,
50
+ { title : 'Events' , href : '/events' } ,
51
+ { title : 'EVM Transactions' , href : '/evm-transactions' } ,
52
+ ] ,
53
+ } ,
54
+ {
55
+ title : 'Track' ,
56
+ subitems : [
57
+ { title : 'Bridge' , href : '/bridge' } ,
58
+ { title : 'DEX' , href : '/dex' } ,
59
+ { title : 'Staking' , href : '/staking' } ,
60
+ ] ,
61
+ } ,
62
+ { title : 'Addresses' , href : '/addresses' } ,
63
+ { title : 'Tokens' , href : '/tokens' } ,
64
+ { title : 'Verified Contracts' , href : '/verified-contracts' } ,
65
+ { title : 'Ecosystem' , href : '/ecosystem' } ,
66
+ { title : 'API Portal' , href : 'https://build.rootscan.io' , target : '_blank' } ,
67
+ ] ;
68
+
27
69
export function Navigation ( ) {
28
70
const pathname = usePathname ( ) ;
29
71
const formattedPathname = pathname ?. split ( '/' , 2 ) ?. join ( '/' ) ;
30
72
31
73
return (
32
74
< Fragment >
33
- < div className = "hidden items-center gap-4 px-4 lg:flex" >
34
- { items . map ( ( item , _ ) => (
35
- < Link href = { item . href } key = { _ } target = { item . newTab ? '_blank' : '_self' } >
36
- < div
75
+ < div className = "hidden items-center gap-0.5 px-4 lg:flex" >
76
+ { items2 . map ( ( item , _ ) => {
77
+ const { title } = item ;
78
+ const { href, target } = item as HeaderMenuLink ;
79
+ const { subitems } = item as HeaderMenuGroupLink ;
80
+ const isLink = ! ! href ;
81
+
82
+ const headerMenuLink = (
83
+ < Link
84
+ href = { isLink ? href : '#' }
85
+ target = { target ? '_blank' : '_self' }
37
86
className = { cn ( [
38
- 'text-muted-foreground hover:text-primary flex items-center text-sm font-bold duration-150 ease-in' ,
39
- formattedPathname === item . href ? 'text-primary' : '' ,
87
+ 'group font-semibold gap-2 inline-flex items-center py-1.5 px-3 transition-colors text-[14px]/[20px] text-muted-foreground data-[state=open]:text-primary hover:text-primary focus:outline-0' ,
88
+ ! isLink && 'pr-2.5' ,
89
+ formattedPathname === href ? 'text-primary' : '' ,
40
90
] ) }
41
91
>
42
- { item . title }
43
- </ div >
44
- </ Link >
45
- ) ) }
92
+ { title }
93
+ { ! isLink && < RiArrowDownSLine className = "size-4 transition-all group-data-[state=open]:rotate-180" /> }
94
+ </ Link >
95
+ ) ;
96
+
97
+ return (
98
+ < Fragment key = { _ } >
99
+ { isLink ? (
100
+ headerMenuLink
101
+ ) : (
102
+ < DropdownMenu >
103
+ < DropdownMenuTrigger asChild > { headerMenuLink } </ DropdownMenuTrigger >
104
+ < DropdownMenuContent className = "flex flex-col gap-1 rounded-[12px] bg-popover p-2" >
105
+ { 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 >
112
+ </ DropdownMenuItem >
113
+ ) ) }
114
+ </ DropdownMenuContent >
115
+ </ DropdownMenu >
116
+ ) }
117
+ </ Fragment >
118
+ ) ;
119
+ } ) }
46
120
</ div >
47
121
< MobileMenu />
48
122
</ Fragment >
0 commit comments