11import {
22 defaultTheme as reactSelectDefaultTheme ,
33 type Theme as ReactSelectTheme ,
4- } from "react-select"
4+ } from "react-select" ;
55
66export type Colors = {
77 // select.control:boxShadow
88 // select.control:focused:borderColor
99 // select.control:hover:focused:borderColor
1010 // select.option:active:selected:backgroundColor
1111 // select.option:selected:backgroundColor
12- primary : string
13- primary75 : string
12+ primary : string ;
13+ primary75 : string ;
1414 // select.option:active:not(selected):backgroundColor
15- primary50 : string
15+ primary50 : string ;
1616 // select.option:focused:backgroundColor
17- primary25 : string
17+ primary25 : string ;
1818
1919 // select.multiValueRemove:hover:color
20- danger : string
20+ danger : string ;
2121 // select.multiValueRemove:focused:backgroundColor
2222 // select.multiValueRemove:hover:backgroundColor
23- dangerLight : string
23+ dangerLight : string ;
2424
2525 // select.control:backgroundColor
2626 // select.menu:backgroundColor
2727 // select.multiValue:backgroundColor
2828 // select.option:selected:color
29- neutral0 : string
29+ neutral0 : string ;
3030 // select.control:disabled:backgroundColor
31- neutral5 : string
31+ neutral5 : string ;
3232 // select.control:disabled:borderColor
3333 // select.indicatorSeparator:disabled:backgroundColor
34- neutral10 : string
34+ neutral10 : string ;
3535 // select.control:borderColor
3636 // select.indicatorContainer:color
3737 // select.indicatorSeparator:backgroundColor
3838 // select.loadingIndicator:color
3939 // select.option:disabled:color
40- neutral20 : string
40+ neutral20 : string ;
4141 // select.control:hover:not(focused):borderColor
42- neutral30 : string
42+ neutral30 : string ;
4343 // select.groupHeading:color
4444 // select.indicatorContainer:hover:not(focused):color
4545 // select.notice:color
4646 // select.singleValue:disabled:color
47- neutral40 : string
47+ neutral40 : string ;
4848 // select.placeholder:color
49- neutral50 : string
49+ neutral50 : string ;
5050 // select.indicatorContainer:focused:color
5151 // select.loadingIndicator:focused:color
52- neutral60 : string
53- neutral70 : string
52+ neutral60 : string ;
53+ neutral70 : string ;
5454 // select.indicatorContainer:hover:focused:color
5555 // select.input:color
5656 // select.multiValueLabel:color
5757 // select.singleValue:color
58- neutral80 : string
59- neutral90 : string
60- }
58+ neutral80 : string ;
59+ neutral90 : string ;
60+ } ;
6161
6262export type Shadows = {
63- button : string
64- input : string
65- card : string
66- dropdown : string
67- }
63+ button : string ;
64+ input : string ;
65+ card : string ;
66+ dropdown : string ;
67+ } ;
6868
6969export type ThemeSpacing = {
70- baseUnit : number
70+ baseUnit : number ;
7171 // The minimum height of the control
72- controlHeight : number
72+ controlHeight : number ;
7373 // The amount of space between the control and menu
74- menuGutter : number
75- }
74+ menuGutter : number ;
75+ } ;
7676
7777export type Theme = {
78- borderRadius ?: number | string
79- colors : Partial < Colors >
80- spacing : ThemeSpacing
81- boxShadow : Shadows
82- }
78+ borderRadius ?: number | string ;
79+ colors : Partial < Colors > ;
80+ spacing : ThemeSpacing ;
81+ boxShadow : Shadows ;
82+ } ;
8383
8484export type PartialTheme = {
85- borderRadius ?: Theme [ "borderRadius" ]
86- colors ?: Partial < Colors >
87- spacing ?: Partial < ThemeSpacing >
88- boxShadow ?: Partial < Shadows >
89- }
85+ borderRadius ?: Theme [ "borderRadius" ] ;
86+ colors ?: Partial < Colors > ;
87+ spacing ?: Partial < ThemeSpacing > ;
88+ boxShadow ?: Partial < Shadows > ;
89+ } ;
9090
91- export type CustomThemeConfig = PartialTheme | ( ( theme : Theme ) => PartialTheme )
91+ export type CustomThemeConfig = PartialTheme | ( ( theme : Theme ) => PartialTheme ) ;
9292
9393export const defaultTheme : Theme = {
9494 borderRadius : 4 ,
@@ -126,7 +126,7 @@ export const defaultTheme: Theme = {
126126 controlHeight : 32 ,
127127 menuGutter : 8 ,
128128 } ,
129- }
129+ } ;
130130
131131export const unstyledTheme : Theme = {
132132 colors : { } ,
@@ -141,25 +141,29 @@ export const unstyledTheme: Theme = {
141141 card : "none" ,
142142 dropdown : "none" ,
143143 } ,
144- }
144+ } ;
145145
146146export function getReactSelectTheme (
147- theme : CustomThemeConfig | undefined
147+ theme : CustomThemeConfig | undefined ,
148148) : ReactSelectTheme {
149- if ( ! theme ) return reactSelectDefaultTheme
150- const _theme = typeof theme == "function" ? theme ( defaultTheme ) : theme
151- const { colors, spacing, borderRadius } = mergeTheme (
149+ if ( ! theme ) return reactSelectDefaultTheme ;
150+ const _theme = typeof theme == "function"
151+ ? theme ( defaultTheme )
152+ : theme ;
153+ const {
154+ colors, spacing, borderRadius,
155+ } = mergeTheme (
152156 reactSelectDefaultTheme ,
153- _theme
154- )
157+ _theme ,
158+ ) ;
155159 return {
156160 borderRadius :
157161 typeof borderRadius !== "number"
158162 ? reactSelectDefaultTheme . borderRadius
159163 : borderRadius ,
160164 colors : colors as ReactSelectTheme [ "colors" ] ,
161165 spacing,
162- }
166+ } ;
163167}
164168
165169export function mergeTheme (
@@ -168,16 +172,22 @@ export function mergeTheme(
168172) : Theme {
169173 const merged = {
170174 borderRadius : target . borderRadius ,
171- colors : { ...target . colors } ,
172- spacing : { ...target . spacing } ,
173- boxShadow : { ...target . boxShadow } ,
174- }
175+ colors : {
176+ ...target . colors ,
177+ } ,
178+ spacing : {
179+ ...target . spacing ,
180+ } ,
181+ boxShadow : {
182+ ...target . boxShadow ,
183+ } ,
184+ } ;
175185 for ( const source of sources ) {
176- if ( ! source ) continue
177- merged . borderRadius = source . borderRadius ?? merged . borderRadius
178- Object . assign ( merged . boxShadow , source . boxShadow )
179- Object . assign ( merged . colors , source . colors )
180- Object . assign ( merged . spacing , source . spacing )
186+ if ( ! source ) continue ;
187+ merged . borderRadius = source . borderRadius ?? merged . borderRadius ;
188+ Object . assign ( merged . boxShadow , source . boxShadow ) ;
189+ Object . assign ( merged . colors , source . colors ) ;
190+ Object . assign ( merged . spacing , source . spacing ) ;
181191 }
182- return merged
192+ return merged ;
183193}
0 commit comments