forked from paritytech/metadata-portal
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNetworkAndPortalSelectMobile.tsx
123 lines (121 loc) · 4.57 KB
/
NetworkAndPortalSelectMobile.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Listbox } from "@headlessui/react";
import { XMarkIcon } from "@heroicons/react/24/solid";
import { icon } from "../icons";
import { Chains, Portals } from "../scheme";
import { capitalizeFirstLetter, cn, currentPortalKey } from "../utils";
import { ChevronIcon } from "./ChevronIcon";
import { Hr } from "./Hr";
export const NetworkAndPortalSelectMobile = ({
chains,
portals,
currentChain,
onSelect,
}: {
chains: Chains;
portals: Portals;
currentChain: string;
onSelect: (v: string) => void;
}) => {
const current = currentPortalKey(portals);
const hasManyPortals = Boolean(current) && Object.keys(portals).length > 1;
return (
<div className="border border-neutral-200 p-4 rounded-4xl space-y-3">
{hasManyPortals && (
<>
<div>
<Listbox value={current}>
<Listbox.Button className="block w-full text-left">
<div className="text-sm text-black opacity-70">
Metadata Portal
</div>
<div className="flex items-center justify-between w-full text-lg">
<span>{portals[current].name}</span>
<ChevronIcon />
</div>
</Listbox.Button>
<Listbox.Options className="fixed inset-0 p-4 space-y-1 z-10 min-h-screen overflow-y-scroll bg-white">
<div className="flex items-center justify-between text-2xl mb-4">
<div>Metadata Portal</div>
<Listbox.Button>
<XMarkIcon className="w-6 h-6" />
</Listbox.Button>
</div>
{Object.keys(portals).map((portal) => (
<Listbox.Option key={portal} value={portal}>
{({ selected }) =>
selected ? (
<div
className={cn(
"flex items-center space-x-2 px-2 py-1",
selected && "bg-neutral-100 rounded-full"
)}
>
<div className="text-xl">{portals[portal].name}</div>
</div>
) : (
<a
className={cn(
"flex items-center space-x-2 px-2 py-1",
selected && "bg-neutral-100 rounded-full"
)}
href={portals[portal].url}
>
<div className="text-xl">{portals[portal].name}</div>
</a>
)
}
</Listbox.Option>
))}
</Listbox.Options>
</Listbox>
</div>
<Hr />
</>
)}
<div>
<Listbox value={currentChain} onChange={onSelect}>
<Listbox.Button className="block w-full text-left">
<div className="text-sm text-black opacity-70">
Selected Network
</div>
<div className="flex items-center justify-between w-full text-lg">
<span>
{currentChain === "node-subtensor"
? "Bittensor"
: capitalizeFirstLetter(chains[currentChain]?.title)}
</span>
<ChevronIcon />
</div>
</Listbox.Button>
<Listbox.Options className="fixed inset-0 p-4 space-y-1 z-10 min-h-screen overflow-y-scroll bg-white">
<div className="flex items-center justify-between text-2xl mb-4">
<div>Selected Network</div>
<Listbox.Button>
<XMarkIcon className="w-6 h-6" />
</Listbox.Button>
</div>
{Object.keys(chains).map((chain) => (
<Listbox.Option key={chain} value={chain}>
{({ selected }) => (
<div
className={cn(
"flex items-center space-x-2 px-2 py-1",
selected && "bg-neutral-100 rounded-full"
)}
>
<img src={icon(chain)} className="w-8 rounded-full" />
<div className="text-xl">
{chain === "node-subtensor"
? "Bittensor"
: capitalizeFirstLetter(chains[chain].title)}
</div>
</div>
)}
</Listbox.Option>
))}
</Listbox.Options>
</Listbox>
</div>
</div>
);
};