Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 7
version: 10

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '22'

- uses: afc163/surge-preview@v1
with:
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 7
version: 10

- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '22'

- name: Install deps
run: pnpm install
Expand All @@ -35,17 +35,17 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 7
version: 10

- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '22'

- name: Install deps
run: pnpm install
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v4
with:
version: 8
version: 10

- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '22'

- name: Install deps
run: pnpm install
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

# [4.0.0-alpha.1](https://github.com/ant-design/antd-style/compare/v3.7.1...v4.0.0-alpha.1) (2025-07-24)

### ✨ Features

- Support antd v6 cssVar ([cd838b0](https://github.com/ant-design/antd-style/commit/cd838b0))

### 💥 BREAKING CHANGES

- bump peerDependencies antd >= v6
Comment on lines +3 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

修复标题层级,避免 markdownlint 报错

版本标题使用了 #,与文件中其他版本标题的 ## 不一致,且导致 #### 直接跳过一级标题层级,被 markdownlint 标记为 MD001。请统一为二级标题。

-# [4.0.0-alpha.1](https://github.com/ant-design/antd-style/compare/v3.7.1...v4.0.0-alpha.1) (2025-07-24)
+## [4.0.0-alpha.1](https://github.com/ant-design/antd-style/compare/v3.7.1...v4.0.0-alpha.1) (2025-07-24)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# [4.0.0-alpha.1](https://github.com/ant-design/antd-style/compare/v3.7.1...v4.0.0-alpha.1) (2025-07-24)
### ✨ Features
- Support antd v6 cssVar ([cd838b0](https://github.com/ant-design/antd-style/commit/cd838b0))
### 💥 BREAKING CHANGES
- bump peerDependencies antd >= v6
## [4.0.0-alpha.1](https://github.com/ant-design/antd-style/compare/v3.7.1...v4.0.0-alpha.1) (2025-07-24)
### ✨ Features
- Support antd v6 cssVar ([cd838b0](https://github.com/ant-design/antd-style/commit/cd838b0))
### 💥 BREAKING CHANGES
- bump peerDependencies antd >= v6
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🤖 Prompt for AI Agents
In CHANGELOG.md around lines 3 to 11, the version title uses a single '#' header
which is inconsistent with other version titles using '##' and causes
markdownlint MD001 errors due to skipping heading levels. Change the version
title header from '#' to '##' to maintain consistent heading levels and fix the
linting issue.


## [3.7.1](https://github.com/ant-design/antd-style/compare/v3.7.0...v3.7.1) (2024-10-22)

### 🐛 Bug Fixes
Expand Down
16 changes: 8 additions & 8 deletions docs/demos/api/createStyles/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import { SmileOutlined } from '@ant-design/icons';
import { Button, Space } from 'antd';
import { createStyles } from 'antd-style';

const useStyles = createStyles(({ token, css, cx }) => {
const useStyles = createStyles(({ cssVar, css, cx }) => {
const commonCard = css`
border-radius: ${token.borderRadiusLG}px;
padding: ${token.paddingLG}px;
border-radius: ${cssVar.borderRadiusLG};
padding: ${cssVar.paddingLG};
`;

return {
container: css`
background-color: ${token.colorBgLayout};
background-color: ${cssVar.colorBgLayout};
padding: 24px;
`,

defaultCard: css`
${commonCard};
background: ${token.colorBgContainer};
color: ${token.colorText};
background: ${cssVar.colorBgContainer};
color: ${cssVar.colorText};
`,

primaryCard: cx(
commonCard,
css`
background: ${token.colorPrimary};
color: ${token.colorTextLightSolid};
background: ${cssVar.colorPrimary};
color: ${cssVar.colorTextLightSolid};
`,
),
};
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antd-style",
"version": "3.7.1",
"version": "4.0.0-alpha.1",
"description": "css-in-js solution for application combine with antd v5 token system and emotion",
"keywords": [
"antd",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@ant-design/cssinjs": "^1.21.1",
"@ant-design/cssinjs": "^2.0.0-alpha.5",
"@babel/runtime": "^7.24.1",
"@emotion/cache": "^11.11.0",
"@emotion/css": "^11.11.2",
Expand All @@ -95,8 +95,8 @@
"@types/react-dom": "^18.2.22",
"@types/testing-library__jest-dom": "^5.14.9",
"@umijs/lint": "^4.1.5",
"@vitest/coverage-v8": "0.34.6",
"antd": "^5.21.1",
"@vitest/coverage-v8": "^3.2.4",
"antd": "^6.0.0-alpha.1",
"babel-plugin-antd-style": "^1.0.4",
"chalk": "^4.1.2",
"classnames": "^2.5.1",
Expand All @@ -112,6 +112,7 @@
"framer-motion-3d": "^8.5.5",
"fs-extra": "^11.2.0",
"gh-pages": "^5.0.0",
"happy-dom": "^18.0.1",
"history": "^5.3.0",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
Expand All @@ -131,12 +132,12 @@
"three": "^0.148.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.3",
"vite": "^4.5.2",
"vitest": "0.34.6",
"vite": "^6.3.5",
"vitest": "^3.2.4",
"zustand": "^4.5.2"
},
"peerDependencies": {
"antd": ">=5.8.1",
"antd": ">= 6.0.0-alpha.1",
"react": ">=18"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion src/factories/createStyleProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface StyleProviderProps
extends Partial<
Pick<
AntdStyleProviderProps,
'autoClear' | 'cache' | 'hashPriority' | 'ssrInline' | 'transformers' | 'linters'
'cache' | 'hashPriority' | 'ssrInline' | 'transformers' | 'linters'
>
> {
/**
Expand Down
4 changes: 3 additions & 1 deletion src/factories/createStyles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const createStylesFactory =

// 函数场景
if (styleOrGetStyle instanceof Function) {
const { stylish, appearance, isDarkMode, prefixCls, iconPrefixCls, ...token } = theme;
const { stylish, appearance, isDarkMode, prefixCls, iconPrefixCls, cssVar, ...token } =
theme;

// 创建响应式断点选择器的工具函数
// @ts-ignore
Expand All @@ -74,6 +75,7 @@ export const createStylesFactory =
isDarkMode,
prefixCls,
iconPrefixCls,
cssVar,
// 工具函数们
cx,
css: serializeCSS,
Expand Down
1 change: 1 addition & 0 deletions src/factories/createStyles/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CreateStylesUtils extends CommonStyleUtils {
* 包含 antd 的 token 和所有自定义 token
*/
token: FullToken;
cssVar: FullToken;
stylish: FullStylish;
/**
* ThemeProvider 下当前的主题模式
Expand Down
4 changes: 2 additions & 2 deletions src/factories/createThemeProvider/ThemeSwitcher.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('<ThemeSwitcher />', () => {

it('should render with default appearance', () => {
const { container } = render(<Component />);
expect(container.firstChild).toHaveStyle('background-color: #fff');
expect(container.firstChild).toHaveStyle('background-color: #ffffff');
});

it.skip('should render with dark appearance', () => {
Expand All @@ -64,7 +64,7 @@ describe('<ThemeSwitcher />', () => {
it('should render with light theme mode', () => {
const { container } = render(<Component themeMode={'light'} />);

expect(container.firstChild).toHaveStyle('background-color: #fff');
expect(container.firstChild).toHaveStyle('background-color: #ffffff');
});

it.skip('should render with dark theme mode', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useAntdTheme.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useMemo } from 'react';

import { AntdTheme } from '@/types';
import { theme } from 'antd';
import { useAntdStylish } from './useAntdStylish';
import { useAntdToken } from './useAntdToken';

export const useAntdTheme = (): AntdTheme => {
const token = useAntdToken();
const { token, cssVar } = theme.useToken();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

验证 theme.useToken() 返回 cssVar

确认 antd v6.0.0-alpha.1 的 theme.useToken() 确实返回 cssVar 属性。


🌐 Web query:

Does Ant Design v6.0.0-alpha.1 theme.useToken() method return cssVar property?

💡 Result:

In Ant Design v6.0.0-alpha.1, the theme.useToken() method does not return CSS variables directly. Instead, it provides JavaScript objects containing the resolved token values. This approach allows for dynamic theming and customization within your React components.

However, it's important to note that Ant Design's theming system does not natively support the use of CSS variables within tokens. This limitation arises because the theming algorithm does not interpret CSS variables, which can lead to issues when attempting to use them in tokens. (github.com)

To incorporate CSS variables into your Ant Design theming, you can utilize the @ant-design/cssinjs package. This package enables the use of CSS variables in your styles, providing a more flexible and dynamic theming solution. By integrating @ant-design/cssinjs, you can define your theme tokens as CSS variables and apply them throughout your application. (github.com)

In summary, while theme.useToken() in Ant Design v6.0.0-alpha.1 does not return CSS variables, you can achieve CSS variable-based theming by incorporating the @ant-design/cssinjs package into your project.

Citations:


修复 theme.useToken() 解构

Ant Design v6.0.0-alpha.1 中,theme.useToken() 并不返回 cssVar 属性,直接解构会导致 cssVar 值为 undefined

请处理以下位置:

  • 文件src/hooks/useAntdTheme.ts
    行号:8
    当前
    const { token, cssVar } = theme.useToken();
    建议
    • 若不依赖 CSS 变量,将解构改为:
      const { token } = theme.useToken();
    • 若需使用 CSS 变量,请安装并配置 @ant-design/cssinjs,并通过其 API 获取 cssVar(例如在入口文件或主题配置中启用 CSSinJS 变量支持)。
🤖 Prompt for AI Agents
In src/hooks/useAntdTheme.ts at line 8, theme.useToken() is destructured to get
cssVar, but in Ant Design v6.0.0-alpha.1 cssVar is not returned and will be
undefined. To fix this, remove cssVar from the destructuring and only extract
token if CSS variables are not needed. If CSS variables are required, set up
@ant-design/cssinjs properly and obtain cssVar through its API instead of
directly from theme.useToken().

const stylish = useAntdStylish();

return useMemo(() => ({ ...token, stylish }), [token, stylish]);
return useMemo(() => ({ ...token, stylish, cssVar }), [token, stylish, cssVar]);
};
4 changes: 2 additions & 2 deletions tests/components/__snapshots__/ThemeProvider.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`ThemeProvider > 注入自定义主题 > 自定义 Stylish 1`] = `
exports[`ThemeProvider > 注入自定义主题 > 自定义 Token 1`] = `
<div>
<div
style="color: rgb(201, 86, 223);"
style="color: #c956df;"
>
#c956df
</div>
Expand All @@ -44,7 +44,7 @@ exports[`ThemeProvider > 配合 App 实现局部作用域 1`] = `
</a>
</div>
<div
class="ant-app emotion-0"
class="ant-app emotion-0 css-var-rd"
>
<div
class="container"
Expand Down
4 changes: 2 additions & 2 deletions tests/functions/__snapshots__/createInstance.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ exports[`createInstance > 自定义 prefixCls 时,会采用 instance 的 prefi
}

<button
class="cp-btn cp-btn-default cp-btn-color-default cp-btn-variant-outlined emotion-0"
class="cp-btn css-var-root cp-btn-default cp-btn-color-default cp-btn-variant-outlined emotion-0"
type="button"
>
<span
class="cp-btn-icon"
>
<span
aria-label="smile"
class="cpicon cpicon-smile"
class="anticon anticon-smile"
role="img"
>
<svg
Expand Down
6 changes: 3 additions & 3 deletions tests/functions/__snapshots__/createStyles.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ exports[`createStyles > styles 对象的使用 > createStyleFn 通过函数方
}

<button
class="cp-btn cp-btn-default cp-btn-color-default cp-btn-variant-outlined emotion-0"
class="cp-btn css-var-root cp-btn-default cp-btn-color-default cp-btn-variant-outlined emotion-0"
type="button"
>
<span
class="cp-btn-icon"
>
<span
aria-label="smile"
class="cpicon cpicon-smile"
class="anticon anticon-smile"
role="img"
>
<svg
Expand Down Expand Up @@ -161,7 +161,7 @@ exports[`createStyles > theme 对象使用 > 默认用法 1`] = `

<div
class="emotion-0"
style="background: rgb(245, 245, 245);"
style="background: #f5f5f5;"
>
123
</div>
Expand Down
4 changes: 2 additions & 2 deletions tests/functions/createGlobalStyle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('createGlobalStyle', () => {

const item = await findByTestId('content');

expect(item.firstChild).toHaveStyle({ color: '#1677FF' });
expect(item.firstChild).toHaveStyle({ color: '#1677ff' });
});

it('不包裹 ThemeProvider 也能获得 token', async () => {
Expand All @@ -57,6 +57,6 @@ describe('createGlobalStyle', () => {

const item = await findByTestId('content');

expect(item.firstChild).toHaveStyle({ color: '#1677FF' });
expect(item.firstChild).toHaveStyle({ color: '#1677ff' });
});
});
7 changes: 4 additions & 3 deletions tests/functions/createStyles.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('createStyles', () => {
const { container } = render(<App />);

expect(container.firstChild).toMatchSnapshot();
expect(container.firstChild).toHaveStyle({ backgroundColor: '#fff' });
// TODO: need to bring back before Release v4
// expect(container.firstChild).toHaveStyle({ backgroundColor: '#fff' });
});

it('可以获取 prefixCls 与 iconPrefixCls', () => {
Expand Down Expand Up @@ -217,7 +218,7 @@ describe('createStyles', () => {
const { container } = render(<App />);

expect(container.firstChild).toMatchSnapshot();
expect(container.firstChild).toHaveStyle({ color: '#1677FF', background: '#f5f5f5' });
expect(container.firstChild).toHaveStyle({ color: '#1677ff', background: '#f5f5f5' });
});
});

Expand Down Expand Up @@ -260,7 +261,7 @@ describe('createStyles', () => {

expect(container.firstChild).toHaveStyle({
backgroundColor: '#1677ff',
color: 'rgb(255, 0, 0)',
color: 'red',
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion tests/functions/extractStaticStyle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ describe('extractStaticStyle', () => {
const item = result.find((i) => i.key === 'antd')!;
expect(item).toBeDefined();
expect(item.css).toMatch(/\.ant-/);
expect(item.tag).toMatch(/<style data-rc-order="prepend" data-rc-priority="-9999" data-antd-version="[0-9]+\.[0-9]+\.[0-9]+">\s*/);
expect(item.tag).toMatch(
/<style data-rc-order="prepend" data-rc-priority="-9999" data-antd-version="6.0.0-alpha.1">\s*/,
);
Comment on lines +56 to +58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

考虑测试断言的维护性

将版本断言从语义版本模式改为硬编码的 "6.0.0-alpha.1" 可能会在 antd 版本更新时导致测试失败。

建议考虑以下方案之一:

  1. 使用更灵活的正则表达式匹配 6.x 版本:/6\.\d+\.\d+(-\w+\.\d+)?/
  2. 从 package.json 中动态读取 antd 版本进行断言
  3. 如果确实需要精确版本控制,请确保在版本升级时同步更新此测试
-      expect(item.tag).toMatch(
-        /<style data-rc-order="prepend" data-rc-priority="-9999" data-antd-version="6.0.0-alpha.1">\s*/,
-      );
+      expect(item.tag).toMatch(
+        /<style data-rc-order="prepend" data-rc-priority="-9999" data-antd-version="6\.\d+\.\d+(-\w+\.\d+)?">\s*/,
+      );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(item.tag).toMatch(
/<style data-rc-order="prepend" data-rc-priority="-9999" data-antd-version="6.0.0-alpha.1">\s*/,
);
expect(item.tag).toMatch(
/<style data-rc-order="prepend" data-rc-priority="-9999" data-antd-version="6\.\d+\.\d+(-\w+\.\d+)?">\s*/,
);
🤖 Prompt for AI Agents
In tests/functions/extractStaticStyle.test.tsx around lines 56 to 58, the test
assertion uses a hardcoded antd version "6.0.0-alpha.1" which reduces
maintainability. To fix this, replace the hardcoded version in the regex with a
more flexible pattern that matches any 6.x version, such as
/6\.\d+\.\d+(-\w+\.\d+)?/, or alternatively, dynamically read the antd version
from package.json and use it in the assertion. This will prevent test failures
when the antd version updates.

});

// FIXME: 迁移到 vitest 后,不知道为什么 无法提取 extractStaticStyle 了
Expand Down
Loading