forked from paritytech/metadata-portal
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNetworkSelect.tsx
63 lines (60 loc) · 1.98 KB
/
NetworkSelect.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
import { Listbox } from "@headlessui/react";
import { icon } from "../icons";
import { Chains } from "../scheme";
import { capitalizeFirstLetter, cn } from "../utils";
import { useState } from "react";
import { SearchBar } from "./SearchBar";
export const NetworkSelect = ({
chains,
currentChain,
onSelect,
}: {
chains: Chains;
currentChain: string;
onSelect: (v: string) => void;
}) => {
const chainList = Object.keys(chains);
const [searchString, setSearchString] = useState("");
const handleSearch = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchString(event.target.value);
};
const filteredItems = chainList.filter((item) =>
item.toLowerCase().includes(searchString.toLowerCase())
);
return (
<div className="w-full">
<div className="text-black opacity-70 mb-4">Networks</div>
{chainList.length > 10 && (
<SearchBar
searchString={searchString}
setSearchString={setSearchString}
onChange={handleSearch}
/>
)}
<Listbox value={currentChain} onChange={onSelect}>
<Listbox.Options static className="space-y-2">
{filteredItems.map((chain) => (
<Listbox.Option key={chain} value={chain}>
{({ selected }) => (
<div
className={cn(
"flex items-center space-x-2 p-2 transition-colors rounded-full hover:bg-neutral-100",
selected && "bg-neutral-100",
selected ? "cursor-default" : "cursor-pointer"
)}
>
<img src={icon(chain)} className="w-8 rounded-full" />
<div className="text-lg">
{chain === "node-subtensor"
? "Bittensor"
: capitalizeFirstLetter(chains[chain].title)}
</div>
</div>
)}
</Listbox.Option>
))}
</Listbox.Options>
</Listbox>
</div>
);
};