1
1
import ReactSelect from "react-select"
2
2
import styled from "styled-components"
3
3
4
- export const selectMenusZIndex = 100
5
-
6
4
const makeCustomTheme = theme => selectTheme => {
7
5
return {
8
6
...selectTheme ,
@@ -27,47 +25,92 @@ const makeCustomTheme = theme => selectTheme => {
27
25
}
28
26
29
27
const getOptionColor = ( theme , state ) => {
30
- if ( state . isDisabled ) return theme . colors . border
28
+ if ( state . isDisabled ) return theme . colors . placeholder
31
29
if ( state . isSelected ) return theme . colors . bright
32
- return theme . colors . text
30
+ return theme . colors . textDescription
33
31
}
34
32
35
- const makeCustomStyles = ( theme , providedStyles ) => ( {
36
- option : ( styles , state ) => ( {
33
+ const makeCustomStyles = ( theme , { size , ... providedStyles } = { } ) => ( {
34
+ control : ( styles , state ) => ( {
37
35
...styles ,
38
- color : getOptionColor ( theme , state ) ,
39
- fontWeight : "normal" ,
36
+ borderColor : state . isFocused ? theme . colors . inputBorderFocus : theme . colors . inputBorder ,
37
+ boxShadow : "none" ,
38
+ minWidth : 160 ,
39
+ ...( size === "tiny" ? { minHeight : 28 } : { } ) ,
40
+ ":hover" : {
41
+ borderColor : theme . colors . inputBorderHover ,
42
+ } ,
40
43
} ) ,
41
- control : styles => ( {
44
+ input : ( styles , state ) => ( {
42
45
...styles ,
43
- minWidth : 160 ,
44
- fontWeight : "normal" ,
46
+ color : state . isDisabled ? theme . colors . placeholder : theme . colors . textDescription ,
47
+ ...( size === "tiny" ? {
48
+ lineHeight : "18px" ,
49
+ paddingBottom : 0 ,
50
+ paddingTop : 0
51
+ } : { } ) ,
45
52
} ) ,
46
- menu : styles => ( {
53
+ menu : styles => ( { ...styles , zIndex : 100 } ) ,
54
+ menuPortal : styles => ( { ...styles , zIndex : 9999 } ) ,
55
+ multiValue : ( styles ) => ( {
47
56
...styles ,
48
- zIndex : selectMenusZIndex ,
57
+ fontSize : size === "tiny" ? "12px" : "14px" ,
58
+ ...( size === "tiny" ? { minHeight : 18 } : { } ) ,
49
59
} ) ,
50
- multiValueLabel : ( styles , control ) => ( {
60
+ multiValueLabel : ( styles , state ) => ( {
51
61
...styles ,
52
- paddingRight : control . data . isDisabled ? "8px" : "" ,
53
- borderRadius : "2px 0 0 2px" ,
54
62
backgroundColor : theme . colors . disabled ,
63
+ borderRadius : "2px 0 0 2px" ,
64
+ color : state . isDisabled ? theme . colors . placeholder : theme . colors . textDescription ,
65
+ ...( size === "tiny" ? { padding : "1px" } : { } ) ,
66
+ paddingRight : state . data . isDisabled ? "8px" : "" ,
55
67
} ) ,
56
- multiValueRemove : ( styles , control ) =>
57
- control . data . isDisabled
68
+ multiValueRemove : ( styles , state ) => ( {
69
+ color : state . isDisabled ? theme . colors . placeholder : theme . colors . textDescription ,
70
+ ...( state . data . isDisabled
58
71
? { ...styles , display : "none" }
59
72
: {
60
- ...styles ,
61
- color : theme . colors . text ,
62
- borderRadius : "0 2px 2px 0" ,
63
- background : theme . colors . disabled ,
64
- ":hover" : {
65
- background : theme . colors . borderSecondary ,
66
- } ,
73
+ ...styles ,
74
+ borderRadius : "0 2px 2px 0" ,
75
+ background : theme . colors . disabled ,
76
+ ":hover" : {
77
+ background : theme . colors . borderSecondary ,
67
78
} ,
79
+ } ) ,
80
+ } ) ,
81
+ option : ( styles , state ) => ( {
82
+ ...styles ,
83
+ color : getOptionColor ( theme , state ) ,
84
+ ...( size === "tiny" ? { fontSize : "12px" , minHeight : 28 , padding : "4px 8px" } : { } ) ,
85
+ } ) ,
86
+ placeholder : styles => ( {
87
+ ...styles ,
88
+ color : theme . colors . placeholder ,
89
+ ...( size === "tiny"
90
+ ? { fontSize : "12px" , lineHeight : "18px" }
91
+ : { } )
92
+ } ) ,
93
+ singleValue : ( styles , state ) => ( {
94
+ ...styles ,
95
+ color : state . isDisabled ? theme . colors . placeholder : theme . colors . textDescription ,
96
+ fontSize : size === "tiny" ? "12px" : "14px"
97
+ } ) ,
98
+ ...( size === "tiny"
99
+ ? {
100
+ dropdownIndicator : styles => ( { ...styles , padding : "3px" } ) ,
101
+ clearIndicator : styles => ( { ...styles , padding : "3px" } ) ,
102
+ indicatorsContainer : styles => ( { ...styles , minHeight : 28 } ) ,
103
+ valueContainer : styles => ( {
104
+ ...styles ,
105
+ minHeight : 28 ,
106
+ padding : "1px 6px" ,
107
+ } ) ,
108
+ }
109
+ : { } ) ,
68
110
...providedStyles ,
69
111
} )
70
112
113
+ // @TODO check react-select for rendering data attributes
71
114
export const Select = styled ( ReactSelect ) . attrs ( props => ( {
72
115
...props ,
73
116
theme : makeCustomTheme ( props . theme ) ,
0 commit comments