2023-10-13 11:54:05 +08:00
|
|
|
import React from 'react';
|
2023-06-06 17:44:30 +08:00
|
|
|
import type { Theme } from '@ant-design/cssinjs';
|
|
|
|
import { createTheme } from '@ant-design/cssinjs';
|
2023-10-13 11:54:05 +08:00
|
|
|
|
2023-06-06 17:44:30 +08:00
|
|
|
import type { AliasToken, MapToken, OverrideToken, SeedToken } from './interface';
|
|
|
|
import defaultDerivative from './themes/default';
|
|
|
|
import defaultSeedToken from './themes/seed';
|
|
|
|
|
|
|
|
export const defaultTheme = createTheme(defaultDerivative);
|
|
|
|
|
|
|
|
// ================================ Context =================================
|
|
|
|
// To ensure snapshot stable. We disable hashed in test env.
|
|
|
|
export const defaultConfig = {
|
|
|
|
token: defaultSeedToken,
|
2023-10-13 11:54:05 +08:00
|
|
|
override: { override: defaultSeedToken },
|
2023-06-06 17:44:30 +08:00
|
|
|
hashed: true,
|
|
|
|
};
|
|
|
|
|
2023-10-13 11:54:05 +08:00
|
|
|
export type ComponentsToken = {
|
|
|
|
[key in keyof OverrideToken]?: OverrideToken[key] & {
|
|
|
|
theme?: Theme<SeedToken, MapToken>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-27 11:31:38 +08:00
|
|
|
export interface DesignTokenProviderProps {
|
2023-06-06 17:44:30 +08:00
|
|
|
token: Partial<AliasToken>;
|
|
|
|
theme?: Theme<SeedToken, MapToken>;
|
2023-10-13 11:54:05 +08:00
|
|
|
components?: ComponentsToken;
|
|
|
|
/** Just merge `token` & `override` at top to save perf */
|
|
|
|
override: { override: Partial<AliasToken> } & ComponentsToken;
|
2023-06-06 17:44:30 +08:00
|
|
|
hashed?: string | boolean;
|
2023-11-06 10:31:51 +08:00
|
|
|
cssVar?: {
|
|
|
|
prefix?: string;
|
|
|
|
key?: string;
|
|
|
|
};
|
2023-07-27 11:31:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const DesignTokenContext = React.createContext<DesignTokenProviderProps>(defaultConfig);
|