You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
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 : ''];
|
|
}
|
|
|