Skip to content

Commit 7649464

Browse files
committed
feat: redesign the header component
1 parent 2da8651 commit 7649464

File tree

1 file changed

+86
-12
lines changed

1 file changed

+86
-12
lines changed

block-explorer/components/navigation.tsx

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
import { Fragment, useState } from 'react';
44

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';
512
import { cn } from '@/lib/utils';
13+
import { RiArrowDownSLine } from '@remixicon/react';
614
import { MenuIcon, XIcon } from 'lucide-react';
715
import Link from 'next/link';
816
import { usePathname } from 'next/navigation';
917

10-
import { Card, CardContent, CardHeader } from './ui/card';
11-
1218
const items = [
1319
{ title: 'Blocks', href: '/blocks' },
1420
{ title: 'Extrinsics', href: '/extrinsics' },
@@ -24,25 +30,93 @@ const items = [
2430
{ title: 'API', href: 'https://build.rootscan.io', newTab: true },
2531
];
2632

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+
2769
export function Navigation() {
2870
const pathname = usePathname();
2971
const formattedPathname = pathname?.split('/', 2)?.join('/');
3072

3173
return (
3274
<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'}
3786
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' : '',
4090
])}
4191
>
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+
})}
46120
</div>
47121
<MobileMenu />
48122
</Fragment>

0 commit comments

Comments
 (0)