mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 09:39:10 +08:00
b88ac06b8c
* refactor: solve theme circular dependency issue * refactor: solve theme circular dependency issue * refactor: solve theme circular dependency issue * refactor: solve theme circular dependency issue * refactor: solve theme circular dependency issue * refactor: solve theme circular dependency issue
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import type { Theme } from '@ant-design/cssinjs';
|
|
import { useCacheToken } from '@ant-design/cssinjs';
|
|
import React from 'react';
|
|
import version from '../version';
|
|
import type { GlobalToken, MapToken, SeedToken } from './interface';
|
|
|
|
import { DesignTokenContext, defaultTheme } from './context';
|
|
import defaultSeedToken from './themes/seed';
|
|
import formatToken from './util/alias';
|
|
|
|
// ================================== Hook ==================================
|
|
export default function useToken(): [Theme<SeedToken, MapToken>, GlobalToken, string] {
|
|
const {
|
|
token: rootDesignToken,
|
|
hashed,
|
|
theme,
|
|
components,
|
|
} = React.useContext(DesignTokenContext);
|
|
|
|
const salt = `${version}-${hashed || ''}`;
|
|
|
|
const mergedTheme = theme || defaultTheme;
|
|
|
|
const [token, hashId] = useCacheToken<GlobalToken, SeedToken>(
|
|
mergedTheme,
|
|
[defaultSeedToken, rootDesignToken],
|
|
{
|
|
salt,
|
|
override: { override: rootDesignToken, ...components },
|
|
formatToken,
|
|
},
|
|
);
|
|
|
|
return [mergedTheme, token, hashed ? hashId : ''];
|
|
}
|