@@ -14,10 +14,13 @@ import { pasteBaseStyles } from "./styles/base";
1414import { pasteFonts } from "./styles/fonts" ;
1515import { pasteGlobalStyles } from "./styles/global" ;
1616import { DarkTheme , DefaultTheme , EvergreenTheme , SendGridTheme , TwilioDarkTheme , TwilioTheme } from "./themes" ;
17+ import { CSSVariablesTheme } from "./themes/css-variables" ;
1718import { getThemeFromHash } from "./utils/getThemeFromHash" ;
1819
1920export const StyledBase = styled . div ( pasteBaseStyles ) ;
2021
22+ const CSSVariablesThemeKey = "CSSVariables" ;
23+
2124const useThemeOverwriteHook = ( ) : string | undefined => {
2225 const [ overwriteTheme , setOverwriteTheme ] = React . useState ( getThemeFromHash ( ) ) ;
2326
@@ -37,7 +40,7 @@ const useThemeOverwriteHook = (): string | undefined => {
3740} ;
3841
3942// eslint-disable-next-line @typescript-eslint/ban-types
40- function getProviderThemeProps ( theme : ThemeVariants , customBreakpoints ?: string [ ] ) : { } {
43+ function getProviderThemeProps ( theme : ThemeVariants | typeof CSSVariablesThemeKey , customBreakpoints ?: string [ ] ) : { } {
4144 switch ( theme ) {
4245 case ThemeVariants . TWILIO :
4346 return {
@@ -64,6 +67,11 @@ function getProviderThemeProps(theme: ThemeVariants, customBreakpoints?: string[
6467 ...EvergreenTheme ,
6568 breakpoints : customBreakpoints || EvergreenTheme . breakpoints ,
6669 } ;
70+ case CSSVariablesThemeKey :
71+ return {
72+ ...CSSVariablesTheme ,
73+ breakpoints : customBreakpoints || CSSVariablesTheme . breakpoints ,
74+ } ;
6775 case ThemeVariants . DEFAULT :
6876 default :
6977 return {
@@ -73,20 +81,32 @@ function getProviderThemeProps(theme: ThemeVariants, customBreakpoints?: string[
7381 }
7482}
7583
76- export interface ThemeProviderProps {
84+ interface BaseThemeProviderProps {
7785 customBreakpoints ?: string [ ] ;
78- theme ?: ThemeVariants ;
7986 disableAnimations ?: boolean ;
8087 cacheProviderProps ?: CreateCacheOptions ;
8188 style ?: React . CSSProperties ;
8289}
8390
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+
84103const ThemeProvider : React . FunctionComponent < React . PropsWithChildren < ThemeProviderProps > > = ( {
85104 customBreakpoints,
86105 theme = ThemeVariants . DEFAULT ,
87106 disableAnimations = false ,
88107 // https://emotion.sh/docs/@emotion /cache#options
89108 cacheProviderProps,
109+ useCSSVariables,
90110 ...props
91111} ) => {
92112 const [ cache ] = React . useState ( cacheProviderProps ? createCache ( cacheProviderProps ) : null ) ;
@@ -98,7 +118,10 @@ const ThemeProvider: React.FunctionComponent<React.PropsWithChildren<ThemeProvid
98118 } , [ disableAnimations , prefersReducedMotion ] ) ;
99119 const overwriteTheme = useThemeOverwriteHook ( ) ;
100120
101- const providerThemeProps = getProviderThemeProps ( overwriteTheme || theme , customBreakpoints ) ;
121+ const providerThemeProps = getProviderThemeProps (
122+ overwriteTheme || ( useCSSVariables ? CSSVariablesThemeKey : theme ) ,
123+ customBreakpoints ,
124+ ) ;
102125
103126 if ( cache ) {
104127 return (
0 commit comments