main
tsx 79 lines 2.18 KB
Raw
1 'use client';
2
3 import React, { Suspense } from 'react';
4 import { usePathname, useSearchParams } from 'next/navigation';
5 import { HomeIcon } from '@heroicons/react/solid';
6
7 function Params() {
8 const searchParams = useSearchParams()!;
9
10 return searchParams.toString().length !== 0 ? (
11 <div className="px-2 text-gray-500">
12 <span>?</span>
13 {Array.from(searchParams.entries()).map(([key, value], index) => {
14 return (
15 <React.Fragment key={key}>
16 {index !== 0 ? <span>&</span> : null}
17 <span className="px-1">
18 <span
19 key={key}
20 className="animate-[highlight_1s_ease-in-out_1] text-gray-100"
21 >
22 {key}
23 </span>
24 <span>=</span>
25 <span
26 key={value}
27 className="animate-[highlight_1s_ease-in-out_1] text-gray-100"
28 >
29 {value}
30 </span>
31 </span>
32 </React.Fragment>
33 );
34 })}
35 </div>
36 ) : null;
37 }
38
39 export function AddressBar() {
40 const pathname = usePathname();
41 console.log('pathname', pathname);
42 return (
43 <div className="flex items-center gap-x-2 p-3.5 lg:px-5 lg:py-3">
44 <div className="text-gray-600">
45 <HomeIcon width={16} />
46 </div>
47 <div className="flex gap-x-1 text-sm font-medium">
48 {pathname ? (
49 <>
50 <span className="text-gray-600">/</span>
51 {pathname
52 .split('/')
53 .slice(1)
54 .map((segment) => {
55 return (
56 <React.Fragment key={segment}>
57 <span>
58 <span
59 key={segment}
60 className="animate-[highlight_1s_ease-in-out_1] rounded-full px-1.5 py-0.5 text-gray-100"
61 >
62 {segment}
63 </span>
64 </span>
65
66 <span className="text-gray-600">/</span>
67 </React.Fragment>
68 );
69 })}
70 </>
71 ) : null}
72
73 <Suspense>
74 <Params />
75 </Suspense>
76 </div>
77 </div>
78 );
79 }