1
- import createPalette from './createPalette' ;
1
+ import createPalette , { PaletteOptions } from './createPalette' ;
2
+ import { ColorSystemOptions } from './createThemeFoundation' ;
2
3
import createThemeWithVars , {
3
4
CssVarsThemeOptions ,
4
5
ColorSystem ,
5
6
DefaultColorScheme ,
6
7
} from './createThemeWithVars' ;
7
- import createThemeNoVars , { Theme , ThemeOptions } from './createThemeNoVars' ;
8
+ import createThemeNoVars , {
9
+ Theme ,
10
+ CssThemeVariables ,
11
+ ThemeOptions as ThemeNoVarsOptions ,
12
+ } from './createThemeNoVars' ;
8
13
9
- export type { ThemeOptions , Theme , CssThemeVariables } from './createThemeNoVars' ;
14
+ export type { Theme , CssThemeVariables } from './createThemeNoVars' ;
15
+
16
+ type CssVarsOptions = CssThemeVariables extends {
17
+ enabled : true ;
18
+ }
19
+ ? ColorSystemOptions
20
+ : { } ;
21
+
22
+ type CssVarsConfigList =
23
+ | 'colorSchemeSelector'
24
+ | 'rootSelector'
25
+ | 'disableCssColorScheme'
26
+ | 'cssVarPrefix'
27
+ | 'shouldSkipGeneratingVar'
28
+ | 'nativeColor' ;
29
+
30
+ export interface ThemeOptions extends CssVarsOptions , Omit < CssVarsThemeOptions , CssVarsConfigList > {
31
+ cssVariables ?: boolean | Pick < CssVarsThemeOptions , CssVarsConfigList > ;
32
+ palette ?: PaletteOptions ;
33
+ }
10
34
11
35
// eslint-disable-next-line consistent-return
12
36
function attachColorScheme (
@@ -35,20 +59,7 @@ function attachColorScheme(
35
59
* @returns A complete, ready-to-use theme object.
36
60
*/
37
61
export default function createTheme (
38
- options : Omit < ThemeOptions , 'components' > &
39
- Pick < CssVarsThemeOptions , 'defaultColorScheme' | 'colorSchemes' | 'components' > & {
40
- cssVariables ?:
41
- | boolean
42
- | Pick <
43
- CssVarsThemeOptions ,
44
- | 'colorSchemeSelector'
45
- | 'rootSelector'
46
- | 'disableCssColorScheme'
47
- | 'cssVarPrefix'
48
- | 'shouldSkipGeneratingVar'
49
- | 'nativeColor'
50
- > ;
51
- } = { } as any , // cast type to skip module augmentation test
62
+ options : ThemeOptions = { } as any , // cast type to skip module augmentation test
52
63
...args : object [ ]
53
64
) : Theme {
54
65
const {
@@ -75,7 +86,7 @@ export default function createTheme(
75
86
if ( cssVariables === false ) {
76
87
if ( ! ( 'colorSchemes' in options ) ) {
77
88
// Behaves exactly as v5
78
- return createThemeNoVars ( options as ThemeOptions , ...args ) ;
89
+ return createThemeNoVars ( options as ThemeNoVarsOptions , ...args ) ;
79
90
}
80
91
81
92
let paletteOptions = palette ;
@@ -91,7 +102,7 @@ export default function createTheme(
91
102
}
92
103
93
104
const theme = createThemeNoVars (
94
- { ...options , palette : paletteOptions } as ThemeOptions ,
105
+ { ...options , palette : paletteOptions } as ThemeNoVarsOptions ,
95
106
...args ,
96
107
) as unknown as Theme & {
97
108
defaultColorScheme ?: 'light' | 'dark' ;
0 commit comments