1
1
import React , { MouseEvent , useEffect , useMemo , useRef , useState } from "react" ;
2
2
import DownArrow from "../../assets/DropdownArrow.svg" ;
3
- import CheckMark from "../../assets/CheckBox.svg" ;
4
3
import SearchComponent from "./searchComponent" ;
5
4
import { MultiSelectPropType , OptionType } from "./types" ;
6
5
import { DEFAULT_PLACEHOLDER , Elements } from "./constants" ;
6
+ import { renderAsImage } from "./utils/utils" ;
7
7
import classes from "./styles.module.scss" ;
8
8
import Chips from "./chips" ;
9
9
import MenuListing from "./menuItems" ;
@@ -28,11 +28,12 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
28
28
icons = { } ,
29
29
onSearch = undefined ,
30
30
onItemClick = undefined ,
31
- setSelectedValues = undefined
31
+ setSelectedValues = undefined ,
32
+ clearSearchClick = undefined
32
33
} = props ;
33
34
34
- const { Checked = CheckMark , Search, ChipClose, Arrow } = icons ;
35
-
35
+ const { Checked, Search, ChipClose, Arrow, ClearSearch } = icons ;
36
+ const arrowIcon = Arrow ;
36
37
// to show/hide div containing the checkboxes
37
38
const [ isModalVisible , setIsModalVisible ] = useState < boolean > ( false ) ;
38
39
const [ list , setList ] = useState < OptionType [ ] > ( [ ] ) ;
@@ -55,7 +56,7 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
55
56
} , [ options ] ) ;
56
57
57
58
useEffect ( ( ) => {
58
- if ( typeof document !== undefined ) {
59
+ if ( typeof document !== ' undefined' ) {
59
60
document . addEventListener ( "mouseup" , onMouseUp ) ;
60
61
return ( ) => document . removeEventListener ( "mouseup" , onMouseUp ) ;
61
62
}
@@ -131,15 +132,18 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
131
132
[ options , selectedIds ]
132
133
) ;
133
134
135
+ const onClick = ( ) : void => {
136
+ setShowAllChips ( true ) ;
137
+ setIsModalVisible ( true ) ;
138
+ }
139
+
134
140
return (
135
141
< div className = { classes . container } style = { styles [ Elements . Container ] } >
136
142
< div
137
143
className = { `${ classes . box } ${ hasError && classes . errorBorder } ` }
138
144
ref = { intractableAreaRef }
139
145
style = { styles [ Elements . InputBox ] }
140
- onClick = { ( ) : void => {
141
- setShowAllChips ( true ) ;
142
- } }
146
+ onClick = { onClick }
143
147
role = "presentation"
144
148
>
145
149
< div className = { classes . headSection } >
@@ -161,11 +165,12 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
161
165
onFocus = { triggerModalOpen }
162
166
ref = { inputRef }
163
167
icon = { Search }
168
+ onCloseClick = { clearSearchClick }
169
+ closeIcon = { ClearSearch }
164
170
/>
165
171
) }
166
172
{ hideSearch && ! selectedIds . length && (
167
- // same style for the search box is used
168
- < div style = { styles [ Elements . SearchComponent ] } > { placeholder } </ div >
173
+ < div className = { `${ classes . searchInput } ${ classes . label } ` } > { placeholder } </ div >
169
174
) }
170
175
</ div >
171
176
< button
@@ -174,14 +179,16 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
174
179
onClick = { ( e : MouseEvent < HTMLButtonElement > ) : void => onArrowClick ( e ) }
175
180
id = "down-arrow"
176
181
>
177
- < img
178
- src = { Arrow ?? DownArrow }
179
- className = { classes . rotation }
180
- style = { {
181
- transform : `rotate(${ isModalVisible ? "180deg" : "0deg" } )` ,
182
- ...styles [ Elements . ArrowIcon ]
183
- } }
184
- />
182
+ { renderAsImage ( arrowIcon ) ?
183
+ < img
184
+ src = { arrowIcon as string ?? DownArrow }
185
+ className = { classes . rotation }
186
+ style = { {
187
+ transform : `rotate(${ isModalVisible ? "180deg" : "0deg" } )` ,
188
+ ...styles [ Elements . ArrowIcon ]
189
+ } }
190
+ /> :
191
+ arrowIcon }
185
192
</ button >
186
193
</ div >
187
194
{ ! isModalVisible && helperText && (
0 commit comments