mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 10:59:19 +08:00
Compare commits
1 Commits
master
...
wuxh/try-o
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
202b12e3e3 |
@@ -2,6 +2,7 @@ import { useId } from 'react';
|
||||
import useMemo from '@rc-component/util/lib/hooks/useMemo';
|
||||
import isEqual from '@rc-component/util/lib/isEqual';
|
||||
import { devUseWarning } from '../../_util/warning';
|
||||
import extendsObject from '../../_util/extendsObject';
|
||||
import type { OverrideToken } from '../../theme/interface';
|
||||
import { defaultConfig } from '../../theme/internal';
|
||||
import type { ThemeConfig } from '../context';
|
||||
@@ -59,13 +60,14 @@ export default function useTheme(
|
||||
} as any;
|
||||
});
|
||||
|
||||
const cssVarKey = `css-var-${themeKey.replace(/:/g, '')}`;
|
||||
const mergedCssVar = {
|
||||
prefix: config?.prefixCls, // Same as prefixCls by default
|
||||
...parentThemeConfig.cssVar,
|
||||
...themeConfig.cssVar,
|
||||
key: themeConfig.cssVar?.key || cssVarKey,
|
||||
};
|
||||
const mergedCssVar = extendsObject(
|
||||
{
|
||||
prefix: config?.prefixCls, // Same as prefixCls by default
|
||||
key: `css-var-${themeKey.replace(/:/g, '')}`,
|
||||
},
|
||||
parentThemeConfig.cssVar,
|
||||
themeConfig.cssVar,
|
||||
);
|
||||
|
||||
// Base token
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import type { Theme } from '@ant-design/cssinjs';
|
||||
import { useCacheToken } from '@ant-design/cssinjs';
|
||||
import useMemo from '@rc-component/util/lib/hooks/useMemo';
|
||||
import isEqual from '@rc-component/util/lib/isEqual';
|
||||
|
||||
import version from '../version';
|
||||
import type { DesignTokenProviderProps } from './context';
|
||||
@@ -117,15 +119,22 @@ export default function useToken(): [
|
||||
zeroRuntime,
|
||||
} = React.useContext(DesignTokenContext);
|
||||
|
||||
const cssVar = {
|
||||
prefix: ctxCssVar?.prefix ?? 'ant',
|
||||
key: ctxCssVar?.key ?? 'css-var-root',
|
||||
};
|
||||
|
||||
const salt = `${version}-${hashed || ''}`;
|
||||
|
||||
const mergedTheme = theme || defaultTheme;
|
||||
|
||||
const cssVar = useMemo(
|
||||
() => ({
|
||||
prefix: ctxCssVar?.prefix ?? 'ant',
|
||||
key: ctxCssVar?.key ?? 'css-var-root',
|
||||
unitless,
|
||||
ignore,
|
||||
preserve,
|
||||
}),
|
||||
[ctxCssVar],
|
||||
(prev, next) => !isEqual(prev, next, true),
|
||||
);
|
||||
|
||||
const [token, hashId, realToken] = useCacheToken<GlobalToken, SeedToken>(
|
||||
mergedTheme,
|
||||
[defaultSeedToken, rootDesignToken],
|
||||
@@ -133,12 +142,7 @@ export default function useToken(): [
|
||||
salt,
|
||||
override,
|
||||
getComputedToken,
|
||||
cssVar: {
|
||||
...cssVar,
|
||||
unitless,
|
||||
ignore,
|
||||
preserve,
|
||||
},
|
||||
cssVar,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user