1
1
import ReactSelect , { ControlProps , MenuProps , Props as ReactSelectProps } from 'react-select'
2
2
import { ReactElement , ReactNode , useCallback , useMemo } from 'react'
3
3
import { ReactComponent as ErrorIcon } from '@Icons/ic-warning.svg'
4
+ import { ReactComponent as ICInfoFilledOverride } from '@Icons/ic-info-filled-override.svg'
4
5
import { getCommonSelectStyle } from './utils'
5
6
import {
6
7
SelectPickerControl ,
7
8
SelectPickerDropdownIndicator ,
9
+ SelectPickerLoadingIndicator ,
8
10
SelectPickerMenu ,
9
11
SelectPickerOption ,
10
- SelectPickerLoadingIndicator ,
11
12
} from './common'
12
13
import { SelectPickerOptionType } from './type'
13
14
15
+ type SelectProps = ReactSelectProps < SelectPickerOptionType >
16
+
14
17
export interface SelectPickerProps
15
18
extends Pick <
16
- ReactSelectProps < SelectPickerOptionType > ,
17
- | 'options'
18
- | 'value'
19
- | 'isMulti'
20
- | 'onChange'
21
- | 'isSearchable'
22
- | 'isClearable'
23
- | 'isLoading'
24
- | 'placeholder'
25
- | 'hideSelectedOptions'
26
- | 'controlShouldRenderValue'
27
- | 'backspaceRemovesValue'
28
- | 'closeMenuOnSelect'
29
- | 'isDisabled'
30
- | 'isLoading'
31
- | 'inputId'
32
- > {
19
+ SelectProps ,
20
+ | 'options'
21
+ | 'value'
22
+ | 'isMulti'
23
+ | 'onChange'
24
+ | 'isSearchable'
25
+ | 'isClearable'
26
+ | 'isLoading'
27
+ | 'placeholder'
28
+ | 'hideSelectedOptions'
29
+ | 'controlShouldRenderValue'
30
+ | 'backspaceRemovesValue'
31
+ | 'closeMenuOnSelect'
32
+ | 'isDisabled'
33
+ | 'isLoading'
34
+ | 'required'
35
+ > ,
36
+ Required < Pick < SelectProps , 'classNamePrefix' | 'inputId' > > {
33
37
icon ?: ReactElement
34
38
error ?: ReactNode
35
39
renderMenuListFooter ?: ( ) => ReactNode
40
+ helperText ?: ReactNode
41
+ label ?: ReactNode
36
42
}
37
43
38
44
const SelectPicker = ( {
39
45
error,
40
46
icon,
41
47
renderMenuListFooter,
48
+ helperText,
42
49
placeholder = 'Select a option' ,
50
+ label,
43
51
...props
44
52
} : SelectPickerProps ) => {
53
+ const { inputId, required } = props
54
+
45
55
const selectStyles = useMemo (
46
56
( ) =>
47
57
getCommonSelectStyle ( {
@@ -61,26 +71,53 @@ const SelectPicker = ({
61
71
)
62
72
63
73
return (
64
- < div >
65
- < ReactSelect < SelectPickerOptionType , boolean >
66
- { ...props }
67
- placeholder = { placeholder }
68
- components = { {
69
- IndicatorSeparator : null ,
70
- LoadingIndicator : SelectPickerLoadingIndicator ,
71
- DropdownIndicator : SelectPickerDropdownIndicator ,
72
- Control : renderControl ,
73
- Option : SelectPickerOption ,
74
- Menu : renderMenu ,
75
- } }
76
- styles = { selectStyles }
77
- />
74
+ < div className = "flex column left top dc__gap-4" >
75
+ { /* TODO Eshank: Common out for fields */ }
76
+ < div className = "flex column left top dc__gap-6 w-100" >
77
+ { label && (
78
+ < label
79
+ className = "fs-13 lh-20 cn-7 fw-4 dc__block mb-0"
80
+ htmlFor = { inputId }
81
+ data-testid = { `label-${ inputId } ` }
82
+ >
83
+ { typeof label === 'string' ? (
84
+ < span className = { `flex left ${ required ? 'dc__required-field' : '' } ` } >
85
+ < span className = "dc__truncate" > { label } </ span >
86
+ </ span >
87
+ ) : (
88
+ label
89
+ ) }
90
+ </ label >
91
+ ) }
92
+ < ReactSelect < SelectPickerOptionType , boolean >
93
+ { ...props }
94
+ placeholder = { placeholder }
95
+ components = { {
96
+ IndicatorSeparator : null ,
97
+ LoadingIndicator : SelectPickerLoadingIndicator ,
98
+ DropdownIndicator : SelectPickerDropdownIndicator ,
99
+ Control : renderControl ,
100
+ Option : SelectPickerOption ,
101
+ Menu : renderMenu ,
102
+ // TODO Eshank: need to export variants of ValueContainer: Icon, No Icon etc
103
+ } }
104
+ styles = { selectStyles }
105
+ className = "w-100"
106
+ />
107
+ </ div >
78
108
{ error && (
79
109
< div className = "flex left dc__gap-4 cr-5 fs-11 lh-16 fw-4" >
80
110
< div className = "dc__no-shrink dc__align-self-start p-2" >
81
111
< ErrorIcon className = "icon-dim-12 form__icon--error" />
82
112
</ div >
83
- < span > { error } </ span >
113
+ < span className = "dc__ellipsis-right__2nd-line" > { error } </ span >
114
+ </ div >
115
+ ) }
116
+ { /* TODO Eshank: Common out for input fields */ }
117
+ { helperText && (
118
+ < div className = "flex left dc__gap-4 fs-11 lh-16 cn-7" >
119
+ < ICInfoFilledOverride className = "icon-dim-16 dc__no-shrink dc__align-self-start" />
120
+ < span className = "dc__ellipsis-right__2nd-line" > { helperText } </ span >
84
121
</ div >
85
122
) }
86
123
</ div >
0 commit comments