1
1
import React from 'react' ;
2
- import type { Theme } from '@ant-design/cssinjs' ;
2
+ import type { Theme , TokenType } from '@ant-design/cssinjs' ;
3
3
4
- import defaultSeedToken from '../themes/seed ' ;
4
+ import type { OverrideTokenMap , TokenMap } from '../interface ' ;
5
5
6
- import type { AliasToken , OverrideToken , MapToken , SeedToken , GlobalToken } from '../interface' ;
7
-
8
- type ComponentsToken < CompTokenMap extends Object > = {
9
- [ key in keyof OverrideToken < CompTokenMap > ] ?: OverrideToken < CompTokenMap > [ key ] & {
10
- theme ?: Theme < SeedToken , MapToken > ;
6
+ export type TokenMapWithTheme <
7
+ CompTokenMap extends TokenMap ,
8
+ DesignToken extends TokenType ,
9
+ AliasToken extends TokenType ,
10
+ > = {
11
+ [ key in keyof OverrideTokenMap < CompTokenMap > ] ?: OverrideTokenMap < CompTokenMap > [ key ] & {
12
+ theme ?: Theme < DesignToken , AliasToken > ;
13
+ } ;
11
14
} ;
12
- } ;
13
15
14
- export interface DesignTokenProviderProps < CompTokenMap extends Object > {
15
- token : GlobalToken < CompTokenMap > ;
16
+ export interface DesignTokenProviderProps <
17
+ CompTokenMap extends TokenMap ,
18
+ DesignToken extends TokenType ,
19
+ AliasToken extends TokenType ,
20
+ > {
21
+ token : OverrideTokenMap < CompTokenMap > ;
22
+ realToken ?: OverrideTokenMap < CompTokenMap > ;
16
23
/** Just merge `token` & `override` at top to save perf */
17
- override : { override : Partial < AliasToken > } & ComponentsToken < CompTokenMap > ;
18
- realToken ?: GlobalToken < CompTokenMap > ;
24
+ override : { override : OverrideTokenMap < CompTokenMap > } ;
25
+ theme ?: Theme < DesignToken , AliasToken > ;
26
+ components ?: TokenMapWithTheme < CompTokenMap , DesignToken , AliasToken > ;
19
27
hashId ?: string ;
20
- theme ?: Theme < SeedToken , MapToken > ;
21
- components ?: ComponentsToken < CompTokenMap > ;
22
28
hashed ?: string | boolean ;
23
29
cssVar ?: {
24
30
prefix ?: string ;
@@ -28,17 +34,27 @@ export interface DesignTokenProviderProps<CompTokenMap extends Object> {
28
34
29
35
// To ensure snapshot stable. We disable hashed in test env.
30
36
export const DefaultThemeProviderContextConfig = {
31
- token : defaultSeedToken ,
32
- override : { override : defaultSeedToken } ,
37
+ token : { } ,
38
+ override : { override : { } } ,
33
39
hashed : true ,
34
40
} ;
35
41
36
- export type GetThemeProviderContext < CompTokenMap extends Object > = ( ) => [ React . Context < DesignTokenProviderProps < CompTokenMap > > ] ;
42
+ export type GetThemeProviderContext <
43
+ CompTokenMap extends TokenMap ,
44
+ DesignToken extends TokenType ,
45
+ AliasToken extends TokenType ,
46
+ > = ( ) => [ React . Context < DesignTokenProviderProps < CompTokenMap , DesignToken , AliasToken > > ] ;
37
47
38
- export function useMergedThemeContext < CompTokenMap extends Object > ( getThemeProviderContext ?: GetThemeProviderContext < CompTokenMap > ) {
39
- const DefaultThemeProviderContext = React . createContext < DesignTokenProviderProps < CompTokenMap > > (
40
- DefaultThemeProviderContextConfig as DesignTokenProviderProps < CompTokenMap >
41
- ) ;
48
+ export function useMergedThemeContext <
49
+ CompTokenMap extends TokenMap ,
50
+ DesignToken extends TokenType ,
51
+ AliasToken extends TokenType ,
52
+ > ( getThemeProviderContext ?: GetThemeProviderContext < CompTokenMap , DesignToken , AliasToken > ) {
53
+ const DefaultThemeProviderContext = React . createContext < DesignTokenProviderProps < CompTokenMap , DesignToken , AliasToken > > ( {
54
+ token : { } ,
55
+ override : { override : { } } ,
56
+ hashed : true ,
57
+ } ) ;
42
58
43
59
const [ ThemeProviderContext = { } ] = getThemeProviderContext ?.( ) ?? [ ] ;
44
60
0 commit comments