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,74 @@ 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
+
58
+ // export const CustomInputToggle = React.forwardRef(
59
+ // (
60
+ // {
61
+ // children,
62
+ // onClick,
63
+ // icon,
64
+ // className = ''
65
+ // }: {
66
+ // children: React.ReactNode
67
+ // onClick: (e) => void
68
+ // icon: string
69
+ // className: string
70
+ // },
71
+ // ref: Ref<HTMLInputElement>
72
+ // ) => {
73
+ // const intl = useIntl()
74
+ // return (
75
+ // <input
76
+ // ref={ref}
77
+ // placeholder={intl.formatMessage({ id: "contract-verification.searchableChainDropdown", defaultMessage: "Select a chain" })}
78
+ // type="text"
79
+ // onClick={(e) => {
80
+ // e.preventDefault()
81
+ // onClick(e)
82
+ // }}
83
+ // className={className.replace('dropdown-toggle', '')}
84
+ // />
85
+ // )}
86
+ // )
87
+
19
88
export const SearchableChainDropdown : React . FC < DropdownProps > = ( { label, id, setSelectedChain, selectedChain } ) => {
20
89
const { chains } = React . useContext ( AppContext )
21
90
const ethereumChainIds = [ 1 , 11155111 , 17000 ]
@@ -87,6 +156,38 @@ export const SearchableChainDropdown: React.FC<DropdownProps> = ({ label, id, se
87
156
)
88
157
}
89
158
159
+ const CustomInputToggle = React . forwardRef (
160
+ (
161
+ {
162
+ children,
163
+ onClick,
164
+ icon,
165
+ className = ''
166
+ } : {
167
+ children : React . ReactNode
168
+ onClick : ( e ) => void
169
+ icon : string
170
+ className : string
171
+ } ,
172
+ ref : Ref < HTMLInputElement >
173
+ ) => {
174
+ const intl = useIntl ( )
175
+ return (
176
+ < input
177
+ ref = { ref }
178
+ placeholder = { intl . formatMessage ( { id : "contract-verification.searchableChainDropdown" , defaultMessage : "Select a chain" } ) }
179
+ type = "text"
180
+ onClick = { ( e ) => {
181
+ e . preventDefault ( )
182
+ onClick ( e )
183
+ } }
184
+ onChange = { handleInputChange }
185
+ value = { searchTerm }
186
+ className = { className . replace ( 'dropdown-toggle' , '' ) }
187
+ />
188
+ ) }
189
+ )
190
+
90
191
return (
91
192
< div className = "dropdown mb-3" ref = { dropdownRef } >
92
193
{ ' ' }
@@ -101,7 +202,7 @@ export const SearchableChainDropdown: React.FC<DropdownProps> = ({ label, id, se
101
202
placeholder = { intl . formatMessage ( { id : "contract-verification.searchableChainDropdown" , defaultMessage : "Select a chain" } ) }
102
203
className = "form-control"
103
204
/>
104
- < ul className = "dropdown-menu show w-100" style = { { maxHeight : '400px' , overflowY : 'auto' , display : isOpen ? 'initial' : 'none' } } >
205
+ < ul className = "dropdown-menu custom-dropdown-items border bg-light show w-100" style = { { maxHeight : '400px' , overflowY : 'auto' , display : isOpen ? 'initial' : 'none' } } >
105
206
{ filteredOptions . map ( ( chain ) => (
106
207
< li
107
208
key = { chain . chainId }
0 commit comments