@@ -14,10 +14,13 @@ import { pasteBaseStyles } from "./styles/base";
14
14
import { pasteFonts } from "./styles/fonts" ;
15
15
import { pasteGlobalStyles } from "./styles/global" ;
16
16
import { DarkTheme , DefaultTheme , EvergreenTheme , SendGridTheme , TwilioDarkTheme , TwilioTheme } from "./themes" ;
17
+ import { CSSVariablesTheme } from "./themes/css-variables" ;
17
18
import { getThemeFromHash } from "./utils/getThemeFromHash" ;
18
19
19
20
export const StyledBase = styled . div ( pasteBaseStyles ) ;
20
21
22
+ const CSSVariablesThemeKey = "CSSVariables" ;
23
+
21
24
const useThemeOverwriteHook = ( ) : string | undefined => {
22
25
const [ overwriteTheme , setOverwriteTheme ] = React . useState ( getThemeFromHash ( ) ) ;
23
26
@@ -37,7 +40,7 @@ const useThemeOverwriteHook = (): string | undefined => {
37
40
} ;
38
41
39
42
// eslint-disable-next-line @typescript-eslint/ban-types
40
- function getProviderThemeProps ( theme : ThemeVariants , customBreakpoints ?: string [ ] ) : { } {
43
+ function getProviderThemeProps ( theme : ThemeVariants | typeof CSSVariablesThemeKey , customBreakpoints ?: string [ ] ) : { } {
41
44
switch ( theme ) {
42
45
case ThemeVariants . TWILIO :
43
46
return {
@@ -64,6 +67,11 @@ function getProviderThemeProps(theme: ThemeVariants, customBreakpoints?: string[
64
67
...EvergreenTheme ,
65
68
breakpoints : customBreakpoints || EvergreenTheme . breakpoints ,
66
69
} ;
70
+ case CSSVariablesThemeKey :
71
+ return {
72
+ ...CSSVariablesTheme ,
73
+ breakpoints : customBreakpoints || CSSVariablesTheme . breakpoints ,
74
+ } ;
67
75
case ThemeVariants . DEFAULT :
68
76
default :
69
77
return {
@@ -73,20 +81,32 @@ function getProviderThemeProps(theme: ThemeVariants, customBreakpoints?: string[
73
81
}
74
82
}
75
83
76
- export interface ThemeProviderProps {
84
+ interface BaseThemeProviderProps {
77
85
customBreakpoints ?: string [ ] ;
78
- theme ?: ThemeVariants ;
79
86
disableAnimations ?: boolean ;
80
87
cacheProviderProps ?: CreateCacheOptions ;
81
88
style ?: React . CSSProperties ;
82
89
}
83
90
91
+ interface ThemeProviderThemeProps extends BaseThemeProviderProps {
92
+ theme ?: ThemeVariants ;
93
+ useCSSVariables ?: never ;
94
+ }
95
+
96
+ interface ThemeProviderCSSVariablesProps extends BaseThemeProviderProps {
97
+ theme ?: never ;
98
+ useCSSVariables ?: boolean ;
99
+ }
100
+
101
+ export type ThemeProviderProps = ThemeProviderThemeProps | ThemeProviderCSSVariablesProps ;
102
+
84
103
const ThemeProvider : React . FunctionComponent < React . PropsWithChildren < ThemeProviderProps > > = ( {
85
104
customBreakpoints,
86
105
theme = ThemeVariants . DEFAULT ,
87
106
disableAnimations = false ,
88
107
// https://emotion.sh/docs/@emotion /cache#options
89
108
cacheProviderProps,
109
+ useCSSVariables,
90
110
...props
91
111
} ) => {
92
112
const [ cache ] = React . useState ( cacheProviderProps ? createCache ( cacheProviderProps ) : null ) ;
@@ -98,7 +118,10 @@ const ThemeProvider: React.FunctionComponent<React.PropsWithChildren<ThemeProvid
98
118
} , [ disableAnimations , prefersReducedMotion ] ) ;
99
119
const overwriteTheme = useThemeOverwriteHook ( ) ;
100
120
101
- const providerThemeProps = getProviderThemeProps ( overwriteTheme || theme , customBreakpoints ) ;
121
+ const providerThemeProps = getProviderThemeProps (
122
+ overwriteTheme || ( useCSSVariables ? CSSVariablesThemeKey : theme ) ,
123
+ customBreakpoints ,
124
+ ) ;
102
125
103
126
if ( cache ) {
104
127
return (
0 commit comments