1
- import React , { CSSProperties , FC } from 'react' ;
2
- import { components as ReactSelectComponents , IndicatorProps , Props , StylesConfig } from 'react-select' ;
1
+ import React , { FC } from 'react' ;
2
+ import {
3
+ components as ReactSelectComponents ,
4
+ DropdownIndicatorProps ,
5
+ ClearIndicatorProps ,
6
+ ControlProps ,
7
+ Props ,
8
+ StylesConfig
9
+ } from 'react-select' ;
3
10
import WindowedSelect from 'react-windowed-select' ;
4
11
5
12
import { Colors , Elevation } from '../../essentials' ;
@@ -12,8 +19,10 @@ import { Wrapper } from './components/Wrapper';
12
19
import { disabledStyles , errorStyles , variantStyles } from './styles' ;
13
20
import { SelectListProps } from './types' ;
14
21
22
+ type WithSelectProps < T > = T & { selectProps : SelectListProps } ;
23
+
15
24
const customStyles : StylesConfig = {
16
- container : ( provided , { selectProps } : Props & { selectProps : SelectListProps } ) => {
25
+ container : ( provided , { selectProps } : WithSelectProps < Props > ) => {
17
26
const bSize = {
18
27
small : {
19
28
fontSize : get ( 'fontSizes.1' ) ( selectProps )
@@ -28,11 +37,9 @@ const customStyles: StylesConfig = {
28
37
...bSize [ selectProps . size ]
29
38
} ;
30
39
} ,
31
- control : ( _ , state : Props & { selectProps : SelectListProps } ) => {
32
- const disabled =
33
- state . isDisabled && disabledStyles . control ( { isFocused : state . isFocused , ...state . selectProps } ) ;
34
- const error =
35
- state . selectProps . error && errorStyles . control ( { isFocused : state . isFocused , ...state . selectProps } ) ;
40
+ control : ( _ , state : WithSelectProps < ControlProps > ) => {
41
+ const disabled = state . isDisabled && disabledStyles . control ( state . selectProps ) ;
42
+ const error = state . selectProps . error && errorStyles . control ( state . selectProps ) ;
36
43
const variant = variantStyles . control ( { isFocused : state . isFocused , ...state . selectProps } ) ;
37
44
38
45
return {
@@ -55,7 +62,7 @@ const customStyles: StylesConfig = {
55
62
...provided ,
56
63
boxShadow : `0 0.125rem 0.5rem 0.0625rem ${ Colors . AUTHENTIC_BLUE_200 } `
57
64
} ) ,
58
- valueContainer : ( provided , { selectProps : { size, variant } } : Props & { selectProps : SelectListProps } ) => {
65
+ valueContainer : ( provided , { selectProps : { size, variant } } : WithSelectProps < Props > ) => {
59
66
let margin ;
60
67
61
68
if ( variant === 'boxed' ) {
@@ -94,7 +101,7 @@ const customStyles: StylesConfig = {
94
101
...provided ,
95
102
color : 'inherit'
96
103
} ) ,
97
- dropdownIndicator : ( provided , state : Props & { selectProps : SelectListProps } ) => {
104
+ dropdownIndicator : ( provided , state : WithSelectProps < Props > ) => {
98
105
const disabled = state . isDisabled && disabledStyles . icons ( state . selectProps ) ;
99
106
100
107
return {
@@ -106,7 +113,7 @@ const customStyles: StylesConfig = {
106
113
...disabled
107
114
} ;
108
115
} ,
109
- clearIndicator : ( provided , state : Props & { selectProps : SelectListProps } ) => {
116
+ clearIndicator : ( provided , state : WithSelectProps < Props > ) => {
110
117
const disabled = state . isDisabled && disabledStyles . icons ( state . selectProps ) ;
111
118
112
119
return {
@@ -117,7 +124,7 @@ const customStyles: StylesConfig = {
117
124
...disabled
118
125
} ;
119
126
} ,
120
- placeholder : ( provided : CSSProperties , state : Props & { selectProps : SelectListProps } ) => {
127
+ placeholder : ( provided , state : WithSelectProps < Props > ) => {
121
128
const disabled = state . isDisabled && disabledStyles . placeholder ( state . selectProps ) ;
122
129
123
130
return {
@@ -126,7 +133,7 @@ const customStyles: StylesConfig = {
126
133
...disabled
127
134
} ;
128
135
} ,
129
- option : ( provided , state : Props & { selectProps : SelectListProps } ) => {
136
+ option : ( provided , state : WithSelectProps < Props > ) => {
130
137
const colorsByState = {
131
138
isDisabled : {
132
139
color : Colors . AUTHENTIC_BLUE_350
@@ -162,7 +169,7 @@ const customStyles: StylesConfig = {
162
169
cursor : state . isDisabled ? 'not-allowed' : 'default'
163
170
} ;
164
171
} ,
165
- multiValue : ( provided : CSSProperties , { selectProps } : { selectProps : Props } ) => {
172
+ multiValue : ( provided , { selectProps } : { selectProps : Props } ) => {
166
173
const styles = {
167
174
...provided ,
168
175
color : Colors . ACTION_BLUE_900 ,
@@ -216,7 +223,7 @@ const customStyles: StylesConfig = {
216
223
217
224
const getIconSize = sizeAsString => ( sizeAsString === 'medium' ? 24 : 18 ) ;
218
225
219
- const DropdownIndicator = ( props : IndicatorProps < unknown > & { selectProps : Props } ) => (
226
+ const DropdownIndicator = ( props : WithSelectProps < DropdownIndicatorProps > ) => (
220
227
< ReactSelectComponents . DropdownIndicator { ...props } >
221
228
{ props . selectProps . menuIsOpen ? (
222
229
< ChevronUpIcon data-testid = "close-icon" color = "inherit" size = { getIconSize ( props . selectProps . size ) } />
@@ -226,7 +233,7 @@ const DropdownIndicator = (props: IndicatorProps<unknown> & { selectProps: Props
226
233
</ ReactSelectComponents . DropdownIndicator >
227
234
) ;
228
235
229
- const ClearIndicator = ( props : IndicatorProps < unknown > ) => (
236
+ const ClearIndicator = ( props : WithSelectProps < ClearIndicatorProps > ) => (
230
237
< ReactSelectComponents . ClearIndicator { ...props } >
231
238
< CloseIcon color = "inherit" size = { getIconSize ( props . selectProps . size ) } />
232
239
</ ReactSelectComponents . ClearIndicator >
@@ -255,6 +262,7 @@ const SelectList: FC<SelectListProps> = (props: SelectListProps) => {
255
262
< WindowedSelect
256
263
inputId = { id }
257
264
styles = { customStyles }
265
+ windowThreshold = { 100 }
258
266
components = { {
259
267
DropdownIndicator,
260
268
IndicatorSeparator,
0 commit comments