Skip to content

Commit cd838b0

Browse files
committed
✨ feat: support antd v6 cssVar
BREAKING CHANGES: bump peerDependencies antd >= v6
1 parent a132d47 commit cd838b0

5 files changed

Lines changed: 17 additions & 14 deletions

File tree

docs/demos/api/createStyles/default.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ import { SmileOutlined } from '@ant-design/icons';
66
import { Button, Space } from 'antd';
77
import { createStyles } from 'antd-style';
88

9-
const useStyles = createStyles(({ token, css, cx }) => {
9+
const useStyles = createStyles(({ cssVar, css, cx }) => {
1010
const commonCard = css`
11-
border-radius: ${token.borderRadiusLG}px;
12-
padding: ${token.paddingLG}px;
11+
border-radius: ${cssVar.borderRadiusLG};
12+
padding: ${cssVar.paddingLG};
1313
`;
1414

1515
return {
1616
container: css`
17-
background-color: ${token.colorBgLayout};
17+
background-color: ${cssVar.colorBgLayout};
1818
padding: 24px;
1919
`,
2020

2121
defaultCard: css`
2222
${commonCard};
23-
background: ${token.colorBgContainer};
24-
color: ${token.colorText};
23+
background: ${cssVar.colorBgContainer};
24+
color: ${cssVar.colorText};
2525
`,
2626

2727
primaryCard: cx(
2828
commonCard,
2929
css`
30-
background: ${token.colorPrimary};
31-
color: ${token.colorTextLightSolid};
30+
background: ${cssVar.colorPrimary};
31+
color: ${cssVar.colorTextLightSolid};
3232
`,
3333
),
3434
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"@types/testing-library__jest-dom": "^5.14.9",
9797
"@umijs/lint": "^4.1.5",
9898
"@vitest/coverage-v8": "0.34.6",
99-
"antd": "^5.21.1",
99+
"antd": "^6.0.0-alpha.1",
100100
"babel-plugin-antd-style": "^1.0.4",
101101
"chalk": "^4.1.2",
102102
"classnames": "^2.5.1",
@@ -136,7 +136,7 @@
136136
"zustand": "^4.5.2"
137137
},
138138
"peerDependencies": {
139-
"antd": ">=5.8.1",
139+
"antd": ">= 6.0.0-alpha.1",
140140
"react": ">=18"
141141
},
142142
"publishConfig": {

src/factories/createStyles/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export const createStylesFactory =
5757

5858
// 函数场景
5959
if (styleOrGetStyle instanceof Function) {
60-
const { stylish, appearance, isDarkMode, prefixCls, iconPrefixCls, ...token } = theme;
60+
const { stylish, appearance, isDarkMode, prefixCls, iconPrefixCls, cssVar, ...token } =
61+
theme;
6162

6263
// 创建响应式断点选择器的工具函数
6364
// @ts-ignore
@@ -74,6 +75,7 @@ export const createStylesFactory =
7475
isDarkMode,
7576
prefixCls,
7677
iconPrefixCls,
78+
cssVar,
7779
// 工具函数们
7880
cx,
7981
css: serializeCSS,

src/factories/createStyles/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface CreateStylesUtils extends CommonStyleUtils {
1616
* 包含 antd 的 token 和所有自定义 token
1717
*/
1818
token: FullToken;
19+
cssVar: FullToken;
1920
stylish: FullStylish;
2021
/**
2122
* ThemeProvider 下当前的主题模式

src/hooks/useAntdTheme.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useMemo } from 'react';
22

33
import { AntdTheme } from '@/types';
4+
import { theme } from 'antd';
45
import { useAntdStylish } from './useAntdStylish';
5-
import { useAntdToken } from './useAntdToken';
66

77
export const useAntdTheme = (): AntdTheme => {
8-
const token = useAntdToken();
8+
const { token, cssVar } = theme.useToken();
99
const stylish = useAntdStylish();
1010

11-
return useMemo(() => ({ ...token, stylish }), [token, stylish]);
11+
return useMemo(() => ({ ...token, stylish, cssVar }), [token, stylish, cssVar]);
1212
};

0 commit comments

Comments
 (0)