From 0214fc64f9c20c6df66571e08c8572fac311e9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 23 Oct 2024 15:23:04 +0800 Subject: [PATCH] fix: has cssVar config (#164) * fix: has cssVar config * fix: lint --- components/theme/useToken.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/components/theme/useToken.ts b/components/theme/useToken.ts index 6c820dd3..7bf660da 100644 --- a/components/theme/useToken.ts +++ b/components/theme/useToken.ts @@ -1,5 +1,6 @@ import { createTheme, useCacheToken } from '@ant-design/cssinjs'; import { theme as antdTheme } from 'antd'; +import { ignore, unitless } from 'antd/es/theme/useToken'; import formatToken from 'antd/es/theme/util/alias'; import React from 'react'; @@ -11,6 +12,28 @@ import type { AliasToken, GlobalToken, SeedToken } from './cssinjs-utils'; const defaultTheme: Theme = createTheme(antdTheme.defaultAlgorithm); +const preserve: { + [key in keyof AliasToken]?: boolean; +} = { + screenXS: true, + screenXSMin: true, + screenXSMax: true, + screenSM: true, + screenSMMin: true, + screenSMMax: true, + screenMD: true, + screenMDMin: true, + screenMDMax: true, + screenLG: true, + screenLGMin: true, + screenLGMax: true, + screenXL: true, + screenXLMin: true, + screenXLMax: true, + screenXXL: true, + screenXXLMin: true, +}; + export const getComputedToken = ( originToken: SeedToken, overrideToken: DesignTokenProviderProps['components'] & { @@ -75,7 +98,13 @@ export function useInternalToken(): [ salt: `${version}-${hashed || ''}`, override, getComputedToken, - cssVar, + cssVar: cssVar && { + prefix: cssVar.prefix, + key: cssVar.key, + unitless, + ignore, + preserve, + }, }, ); return [theme as Theme, realToken, hashed ? hashId : '', token, cssVar];