@@ -2,34 +2,43 @@ import { CSSObjectWithLabel, OptionProps, StylesConfig } from "react-select";
22
33import { Option } from "./types" ;
44
5- /**
6- * @url https://react-select.com/styles
7- */
5+ const getCssVar = ( varName : string ) : string => {
6+ return getComputedStyle ( document . documentElement )
7+ . getPropertyValue ( varName )
8+ . trim ( ) ;
9+ } ;
810
9- const color = "oklch(0.85 0.02 240)" ;
11+ const text = getCssVar ( "--color-text" ) || "oklch(0.85 0.02 240)" ;
12+ const background = getCssVar ( "--color-background" ) || "oklch(0.1 0.02 240)" ;
13+ const border = getCssVar ( "--color-border" ) || "oklch(0.3 0.02 240)" ;
14+ const muted = getCssVar ( "--color-muted" ) || "oklch(0.5 0.05 240)" ;
15+ const primary = getCssVar ( "--color-primary" ) || "oklch(0.8 0.2 80)" ;
16+ const secondary = getCssVar ( "--color-secondary" ) || "oklch(0.65 0.05 270)" ;
17+ const error = getCssVar ( "--color-error" ) || "oklch(0.6 0.2 30)" ;
18+ const accent = getCssVar ( "--color-accent" ) || "oklch(0.6 0.2 250)" ;
1019
1120export const styles : StylesConfig < Option | undefined , false | true > = {
1221 input : ( base : CSSObjectWithLabel ) => ( {
1322 ...base ,
1423 outline : "none" ,
1524 boxShadow : "none" ,
1625 padding : "4px 0" ,
17- color,
26+ color : text ,
1827 "input:focus" : {
1928 boxShadow : "none"
2029 }
2130 } ) ,
2231 control : ( base : CSSObjectWithLabel ) => {
2332 return {
2433 ...base ,
25- backgroundColor : "oklch(0.1 0.02 240)" ,
34+ backgroundColor : background ,
2635 borderWidth : "2px" ,
27- borderColor : "oklch(0.3 0.02 240)" ,
36+ borderColor : border ,
2837 borderRadius : 6 ,
2938 boxShadow : "none" ,
30- color,
39+ color : text ,
3140 "&:hover" : {
32- borderColor : "oklch(0.3 0.02 240)"
41+ borderColor : border
3342 }
3443 } ;
3544 } ,
@@ -38,51 +47,49 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
3847 props : OptionProps < Option | undefined , false | true >
3948 ) => ( {
4049 ...base ,
41- backgroundColor : props . isDisabled
42- ? "oklch(0.5 0.05 240)"
43- : "oklch(0.1 0.02 240)" ,
44- color : props . isDisabled ? "oklch(0.5 0.05 240)" : color ,
50+ backgroundColor : props . isDisabled ? muted : background ,
51+ color : props . isDisabled ? muted : text ,
4552 cursor : props . isDisabled ? "not-allowed" : "default" ,
4653 "&:active" : {
47- backgroundColor : ! props . isDisabled ? "oklch(0.6 0.2 250)" : undefined ,
48- color : ! props . isDisabled ? color : undefined
54+ backgroundColor : ! props . isDisabled ? primary : undefined ,
55+ color : ! props . isDisabled ? background : undefined
4956 }
5057 } ) ,
5158 multiValueRemove : ( base : CSSObjectWithLabel ) => {
5259 return {
5360 ...base ,
54- color : "oklch(0.65 0.05 270)" ,
61+ color : secondary ,
5562 cursor : "pointer" ,
5663 "&:hover" : {
57- color : color ,
58- backgroundColor : "oklch(0.6 0.2 30)"
64+ color : text ,
65+ backgroundColor : error
5966 }
6067 } ;
6168 } ,
6269 multiValue : ( base : CSSObjectWithLabel ) => {
6370 return {
6471 ...base ,
65- backgroundColor : "oklch(0.1 0.02 240)" ,
66- color
72+ backgroundColor : background ,
73+ color : text
6774 } ;
6875 } ,
6976 singleValue : ( base : CSSObjectWithLabel ) => {
7077 return {
7178 ...base ,
72- backgroundColor : "oklch(0.1 0.02 240)" ,
73- color
79+ backgroundColor : background ,
80+ color : text
7481 } ;
7582 } ,
7683 multiValueLabel : ( base : CSSObjectWithLabel ) => {
7784 return {
7885 ...base ,
79- color
86+ color : text
8087 } ;
8188 } ,
8289 placeholder : ( base : CSSObjectWithLabel ) => {
8390 return {
8491 ...base ,
85- color : "oklch(0.5 0.05 240)"
92+ color : muted
8693 } ;
8794 } ,
8895 valueContainer : ( base : CSSObjectWithLabel ) => {
@@ -97,28 +104,28 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
97104 menu : ( base : CSSObjectWithLabel ) => {
98105 return {
99106 ...base ,
100- backgroundColor : "oklch(0.1 0.02 240)" ,
101- color,
107+ backgroundColor : background ,
108+ color : text ,
102109 boxShadow : "none" ,
103110 borderWidth : "2px" ,
104- borderColor : "oklch(0.3 0.02 240)" ,
111+ borderColor : border ,
105112 borderRadius : 0 ,
106113 zIndex : 99999999
107114 } ;
108115 } ,
109116 indicatorSeparator : ( base : CSSObjectWithLabel ) => {
110117 return {
111118 ...base ,
112- backgroundColor : "oklch(0.3 0.02 240)"
119+ backgroundColor : border
113120 } ;
114121 } ,
115122 clearIndicator : ( base : CSSObjectWithLabel ) => {
116123 return {
117124 ...base ,
118- color : "oklch(0.3 0.02 240)" ,
125+ color : border ,
119126 cursor : "pointer" ,
120127 "&:hover" : {
121- color : "oklch(0.6 0.2 30)"
128+ color : error
122129 }
123130 } ;
124131 } ,
@@ -129,18 +136,18 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
129136 width : "10px"
130137 } ,
131138 "::-webkit-scrollbar-track" : {
132- background : "oklch(0.1 0.02 240)"
139+ background : background
133140 } ,
134141 "::-webkit-scrollbar-thumb" : {
135- background : "oklch(0.3 0.02 240)"
142+ background : border
136143 } ,
137144 "::-webkit-scrollbar-thumb:hover" : {
138- background : "oklch(0.6 0.2 250)"
145+ background : accent
139146 }
140147 } ) ,
141148 groupHeading : ( base : CSSObjectWithLabel ) => ( {
142149 ...base ,
143- color : "oklch(0.5 0.05 240)" ,
150+ color : muted ,
144151 padding : "5px 10px" ,
145152 fontSize : "0.75rem"
146153 } )
0 commit comments