From e58785b1dab800c3d3477fdf3c3d4888c7697a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Mon, 13 Oct 2025 14:50:37 +0800 Subject: [PATCH] fix: undefined error when consuming cssvar --- docs/demos/ThemeProvider/_app.tsx | 16 +++++++-- docs/demos/api/createStyles/default.tsx | 4 +-- .../createThemeProvider/TokenContainer.tsx | 17 +++++++-- src/hooks/useCustomToken.ts | 35 +++++++++++++++++++ src/types/theme.ts | 3 +- 5 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 src/hooks/useCustomToken.ts diff --git a/docs/demos/ThemeProvider/_app.tsx b/docs/demos/ThemeProvider/_app.tsx index a0d297b7..76ae127d 100644 --- a/docs/demos/ThemeProvider/_app.tsx +++ b/docs/demos/ThemeProvider/_app.tsx @@ -1,5 +1,5 @@ import { Space } from 'antd'; -import { useTheme } from 'antd-style'; +import { createStyles, useTheme } from 'antd-style'; import { FC } from 'react'; interface AppProps { @@ -7,11 +7,22 @@ interface AppProps { tokenName?: string; } -const App: FC = ({ title, tokenName }) => { +const useStyle = createStyles(({ cx, cssVar }, { tokenName }: AppProps) => ({ + box: { + width: 32, + height: 32, + background: { ...(cssVar as any) }[tokenName!] || 'pink', + borderRadius: 16, + }, +})); + +const App: FC = (props) => { + const { title, tokenName } = props; const token = useTheme(); // @ts-ignore const tokenColor = tokenName ? token[tokenName] : token.colorPrimary; + const { styles } = useStyle(props); return ( @@ -32,6 +43,7 @@ const App: FC = ({ title, tokenName }) => { borderRadius: 16, }} /> +
{tokenColor || 'None'}
diff --git a/docs/demos/api/createStyles/default.tsx b/docs/demos/api/createStyles/default.tsx index 26f46f35..eca0027b 100644 --- a/docs/demos/api/createStyles/default.tsx +++ b/docs/demos/api/createStyles/default.tsx @@ -3,7 +3,7 @@ * defaultShowCode: true */ import { SmileOutlined } from '@ant-design/icons'; -import { Button, Space } from 'antd'; +import { Button, Space, version } from 'antd'; import { createStyles } from 'antd-style'; const useStyles = createStyles(({ cssVar, css, cx }) => { @@ -38,7 +38,7 @@ const App = () => { const { styles } = useStyles(); return ( -
+