11import ReactSelect from "react-select"
22import styled from "styled-components"
33
4- export const selectMenusZIndex = 100
5-
64const makeCustomTheme = theme => selectTheme => {
75 return {
86 ...selectTheme ,
@@ -27,47 +25,92 @@ const makeCustomTheme = theme => selectTheme => {
2725}
2826
2927const getOptionColor = ( theme , state ) => {
30- if ( state . isDisabled ) return theme . colors . border
28+ if ( state . isDisabled ) return theme . colors . placeholder
3129 if ( state . isSelected ) return theme . colors . bright
32- return theme . colors . text
30+ return theme . colors . textDescription
3331}
3432
35- const makeCustomStyles = ( theme , providedStyles ) => ( {
36- option : ( styles , state ) => ( {
33+ const makeCustomStyles = ( theme , { size , ... providedStyles } = { } ) => ( {
34+ control : ( styles , state ) => ( {
3735 ...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+ } ,
4043 } ) ,
41- control : styles => ( {
44+ input : ( styles , state ) => ( {
4245 ...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+ } : { } ) ,
4552 } ) ,
46- menu : styles => ( {
53+ menu : styles => ( { ...styles , zIndex : 100 } ) ,
54+ menuPortal : styles => ( { ...styles , zIndex : 9999 } ) ,
55+ multiValue : ( styles ) => ( {
4756 ...styles ,
48- zIndex : selectMenusZIndex ,
57+ fontSize : size === "tiny" ? "12px" : "14px" ,
58+ ...( size === "tiny" ? { minHeight : 18 } : { } ) ,
4959 } ) ,
50- multiValueLabel : ( styles , control ) => ( {
60+ multiValueLabel : ( styles , state ) => ( {
5161 ...styles ,
52- paddingRight : control . data . isDisabled ? "8px" : "" ,
53- borderRadius : "2px 0 0 2px" ,
5462 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" : "" ,
5567 } ) ,
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
5871 ? { ...styles , display : "none" }
5972 : {
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 ,
6778 } ,
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+ : { } ) ,
68110 ...providedStyles ,
69111} )
70112
113+ // @TODO check react-select for rendering data attributes
71114export const Select = styled ( ReactSelect ) . attrs ( props => ( {
72115 ...props ,
73116 theme : makeCustomTheme ( props . theme ) ,
0 commit comments