@@ -5,13 +5,14 @@ import {
5
5
OptionProps ,
6
6
MenuProps ,
7
7
ClearIndicatorProps ,
8
+ ValueContainerProps ,
8
9
} from 'react-select'
9
10
import { Progressing } from '@Common/Progressing'
10
11
import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
11
12
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
12
13
import { SelectPickerOptionType , SelectPickerProps } from './type'
13
14
14
- export const SelectPickerDropdownIndicator = ( props : DropdownIndicatorProps ) => {
15
+ export const SelectPickerDropdownIndicator = ( props : DropdownIndicatorProps < SelectPickerOptionType > ) => {
15
16
const { isDisabled } = props
16
17
17
18
return (
@@ -21,23 +22,52 @@ export const SelectPickerDropdownIndicator = (props: DropdownIndicatorProps) =>
21
22
)
22
23
}
23
24
24
- export const SelectPickerClearIndicator = ( props : ClearIndicatorProps ) => (
25
+ export const SelectPickerClearIndicator = ( props : ClearIndicatorProps < SelectPickerOptionType > ) => (
25
26
< components . ClearIndicator { ...props } >
26
27
< ICClose className = "icon-dim-16 fcn-6 dc__no-shrink" />
27
28
</ components . ClearIndicator >
28
29
)
29
30
30
- export const SelectPickerControl = ( { icon, ...props } : ControlProps & Pick < SelectPickerProps , 'icon' > ) => {
31
- const { children } = props
31
+ export const SelectPickerControl = ( {
32
+ icon,
33
+ showSelectedOptionIcon,
34
+ ...props
35
+ } : ControlProps < SelectPickerOptionType > & Pick < SelectPickerProps , 'icon' | 'showSelectedOptionIcon' > ) => {
36
+ const { children, getValue } = props
37
+ const { startIcon, endIcon } = getValue ( ) ?. [ 0 ] ?? { }
38
+ // Show the display icon if either the selected option icon is not to be shown or not available
39
+ const showDisplayIcon = ! ! ( icon && ( ! showSelectedOptionIcon || ! ( startIcon || endIcon ) ) )
32
40
33
41
return (
34
42
< components . Control { ...props } >
35
- { icon && < div className = "dc__no-shrink icon-dim-20 flex dc__fill-available-space" > { icon } </ div > }
43
+ { showDisplayIcon && < div className = "dc__no-shrink icon-dim-20 flex dc__fill-available-space" > { icon } </ div > }
36
44
{ children }
37
45
</ components . Control >
38
46
)
39
47
}
40
48
49
+ export const SelectPickerValueContainer = ( {
50
+ showSelectedOptionIcon,
51
+ ...props
52
+ } : ValueContainerProps < SelectPickerOptionType > & Pick < SelectPickerProps , 'showSelectedOptionIcon' > ) => {
53
+ const { children, getValue, hasValue } = props
54
+ const { startIcon, endIcon } = getValue ( ) ?. [ 0 ] ?? { }
55
+ const showIcon = ! ! ( showSelectedOptionIcon && hasValue && ( startIcon || endIcon ) )
56
+
57
+ return (
58
+ < components . ValueContainer { ...props } >
59
+ < div className = "flex left dc__gap-8" >
60
+ { showIcon && (
61
+ < div className = "dc__no-shrink icon-dim-20 flex dc__fill-available-space" >
62
+ { startIcon || endIcon }
63
+ </ div >
64
+ ) }
65
+ { children }
66
+ </ div >
67
+ </ components . ValueContainer >
68
+ )
69
+ }
70
+
41
71
export const SelectPickerLoadingIndicator = ( ) => < Progressing />
42
72
43
73
export const SelectPickerOption = ( props : OptionProps < SelectPickerOptionType > ) => {
@@ -65,7 +95,7 @@ export const SelectPickerOption = (props: OptionProps<SelectPickerOptionType>) =
65
95
export const SelectPickerMenu = ( {
66
96
renderMenuListFooter,
67
97
...props
68
- } : MenuProps & Pick < SelectPickerProps , 'renderMenuListFooter' > ) => {
98
+ } : MenuProps < SelectPickerOptionType > & Pick < SelectPickerProps , 'renderMenuListFooter' > ) => {
69
99
const { children } = props
70
100
71
101
return (
0 commit comments