1
- import React , { useState , useEffect , useRef , useMemo } from 'react'
1
+ import React , { useState , useEffect , useRef , useMemo , Ref } from 'react'
2
2
import Fuse from 'fuse.js'
3
3
import type { Chain } from '../types'
4
4
import { AppContext } from '../AppContext'
5
- import { useIntl } from 'react-intl'
5
+ import intl , { useIntl } from 'react-intl'
6
+ import { Dropdown } from 'react-bootstrap'
6
7
7
8
function getChainDescriptor ( chain : Chain ) : string {
8
9
if ( ! chain ) return ''
@@ -16,6 +17,44 @@ interface DropdownProps {
16
17
selectedChain : Chain
17
18
}
18
19
20
+ export const CustomToggle = React . forwardRef (
21
+ (
22
+ {
23
+ children,
24
+ onClick,
25
+ icon,
26
+ className = ''
27
+ } : {
28
+ children : React . ReactNode
29
+ onClick : ( e ) => void
30
+ icon : string
31
+ className : string
32
+ } ,
33
+ ref : Ref < HTMLButtonElement >
34
+ ) => (
35
+ < button
36
+ ref = { ref }
37
+ onClick = { ( e ) => {
38
+ e . preventDefault ( )
39
+ onClick ( e )
40
+ } }
41
+ className = { className . replace ( 'dropdown-toggle' , '' ) }
42
+ >
43
+ < div className = "d-flex" >
44
+ < div className = "mr-auto text-nowrap text-truncate overflow-hidden" data-id = { `dropdown-content` } > { children } </ div >
45
+ { icon && (
46
+ < div className = "pr-1" >
47
+ < i className = { `${ icon } pr-1` } > </ i >
48
+ </ div >
49
+ ) }
50
+ < div >
51
+ < i className = "fad fa-sort-circle" > </ i >
52
+ </ div >
53
+ </ div >
54
+ </ button >
55
+ )
56
+ )
57
+
19
58
export const SearchableChainDropdown : React . FC < DropdownProps > = ( { label, id, setSelectedChain, selectedChain } ) => {
20
59
const { chains } = React . useContext ( AppContext )
21
60
const ethereumChainIds = [ 1 , 11155111 , 17000 ]
@@ -88,32 +127,20 @@ export const SearchableChainDropdown: React.FC<DropdownProps> = ({ label, id, se
88
127
}
89
128
90
129
return (
91
- < div className = "dropdown mb-3" ref = { dropdownRef } >
92
- { ' ' }
93
- { /* Add ref here */ }
94
- < label htmlFor = { id } > { label } </ label >
95
- < input
96
- type = "text"
97
- value = { searchTerm }
98
- onChange = { handleInputChange }
99
- onClick = { openDropdown }
100
- data-id = "chainDropdownbox"
101
- placeholder = { intl . formatMessage ( { id : "contract-verification.searchableChainDropdown" , defaultMessage : "Select a chain" } ) }
102
- className = "form-control"
103
- />
104
- < ul className = "dropdown-menu show w-100" style = { { maxHeight : '400px' , overflowY : 'auto' , display : isOpen ? 'initial' : 'none' } } >
130
+ < Dropdown >
131
+ < Dropdown . Toggle as = { CustomToggle } icon = { null } className = "btn btn-light btn-block w-100 d-inline-block form-control" data-id = "chainDropdownbox" >
132
+ { searchTerm . length > 0 ? searchTerm : intl . formatMessage ( { id : "contract-verification.searchableChainDropdown" , defaultMessage : "Select a chain" } ) }
133
+ </ Dropdown . Toggle >
134
+ < Dropdown . Menu className = "w-100 custom-dropdown-items border bg-light" >
105
135
{ filteredOptions . map ( ( chain ) => (
106
- < li
107
- key = { chain . chainId }
108
- onClick = { ( ) => handleOptionClick ( chain ) }
136
+ < Dropdown . Item key = { chain . chainId } onClick = { ( ) => handleOptionClick ( chain ) }
137
+ className = { `${ getChainDescriptor ( chain ) . length > 30 ? 'text-truncate text-decoration-none' : 'text-decoration-none' } ` }
109
138
data-id = { chain . chainId }
110
- className = { `dropdown-item ${ selectedChain ?. chainId === chain . chainId ? 'active' : '' } ` }
111
- style = { { cursor : 'pointer' , whiteSpace : 'normal' } }
112
139
>
113
140
{ getChainDescriptor ( chain ) }
114
- </ li >
141
+ </ Dropdown . Item >
115
142
) ) }
116
- </ ul >
117
- </ div >
143
+ </ Dropdown . Menu >
144
+ </ Dropdown >
118
145
)
119
146
}
0 commit comments