tailwind-preset-antd 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ name: github pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ deploy:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Setup Node.js
16
+ uses: actions/setup-node@v4
17
+ with:
18
+ node-version: 24
19
+
20
+ - name: Install pnpm
21
+ uses: pnpm/action-setup@v4
22
+ with:
23
+ version: 10
24
+
25
+ # pnpm cache
26
+ - name: Get pnpm store directory
27
+ shell: bash
28
+ run: |
29
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
30
+
31
+ - name: Setup pnpm cache
32
+ uses: actions/cache@v4
33
+ with:
34
+ path: ${{ env.STORE_PATH }}
35
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
36
+ restore-keys: |
37
+ ${{ runner.os }}-pnpm-store-
38
+
39
+ - name: Install workspace dependencies
40
+ run: pnpm install
41
+
42
+ - name: Build Docs
43
+ run: pnpm build:play
44
+
45
+ - name: Deploy to GitHub Pages
46
+ uses: peaceiris/actions-gh-pages@v4
47
+ with:
48
+ github_token: ${{ secrets.GITHUB_TOKEN }}
49
+ publish_dir: ./playground/docs-dist
@@ -0,0 +1,25 @@
1
+ {
2
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
3
+ "editor.formatOnSave": true,
4
+ "editor.codeActionsOnSave": {
5
+ "source.fixAll.oxc": "explicit"
6
+ },
7
+ "[json]": {
8
+ "editor.defaultFormatter": "oxc.oxc-vscode"
9
+ },
10
+ "[jsonc]": {
11
+ "editor.defaultFormatter": "oxc.oxc-vscode"
12
+ },
13
+ "[markdown]": {
14
+ "editor.defaultFormatter": "oxc.oxc-vscode"
15
+ },
16
+ "[typescript]": {
17
+ "editor.defaultFormatter": "oxc.oxc-vscode"
18
+ },
19
+ "[typescriptreact]": {
20
+ "editor.defaultFormatter": "oxc.oxc-vscode"
21
+ },
22
+ "[yaml]": {
23
+ "editor.defaultFormatter": "oxc.oxc-vscode"
24
+ }
25
+ }
@@ -0,0 +1,136 @@
1
+ A tailwindcss plugin based on antd Design Token.
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ # Project Introduction
6
+
7
+ Version requirements:
8
+
9
+ - antd >= 5
10
+ - tailwindcss >= 3
11
+
12
+ Before:
13
+
14
+ ```tsx
15
+ import { theme } from "antd";
16
+
17
+ function App() {
18
+ const { token } = theme.useToken();
19
+
20
+ return <div style={{ backgroundColor: token.colorPrimary }}></div>;
21
+ }
22
+ ```
23
+
24
+ Now:
25
+
26
+ ```tsx
27
+ function App() {
28
+ return <div className="bg-colorPrimary"></div>;
29
+ }
30
+ ```
31
+
32
+ ## Basic Usage
33
+
34
+ ### tailwindcss v3
35
+
36
+ 1. Register tailwind plugin
37
+
38
+ ```js
39
+ // tailwind.config.ts
40
+ import type { Config } from "tailwindcss/types/config";
41
+ import antdThemePreset from "tailwind-preset-antd/plugin";
42
+
43
+ const config: Config = {
44
+ // ...
45
+ // or custom plugins config: [antdThemePreset({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
46
+ plugins: [antdThemePreset],
47
+ };
48
+
49
+ export default config;
50
+ ```
51
+
52
+ 2. Register global css variables based on antd token
53
+
54
+ ```jsx
55
+ import { AntdTokenCssVar } from "tailwind-preset-antd/components";
56
+
57
+ export default function App() {
58
+ return (
59
+ <>
60
+ <AntdTokenCssVar />
61
+ </>
62
+ );
63
+ }
64
+ ```
65
+
66
+ If you use the `tailwind-merge` plugin, you need to add `fontSizes` to its configuration. See [Using with tailwind-merge](#using-with-tailwind-merge) for details
67
+
68
+ ### tailwindcss v4
69
+
70
+ See [How can I pass parameters to a TailwindCSS plugin in a CSS-first configuration?](https://github.com/tailwindlabs/tailwindcss/discussions/15997)
71
+
72
+ ```css
73
+ @plugin "tailwind-preset-antd/plugin";
74
+
75
+ /* or
76
+ @plugin "tailwind-preset-antd/plugin" {
77
+ twPrefix: "ant";
78
+ cssVarPrefix: "abcd";
79
+ }
80
+ */
81
+ ```
82
+
83
+ ```jsx
84
+ import { AntdTokenCssVar } from "tailwind-preset-antd/components";
85
+
86
+ export default function App() {
87
+ return (
88
+ <>
89
+ <AntdTokenCssVar />
90
+ </>
91
+ );
92
+ }
93
+ ```
94
+
95
+ ## Configuration Options
96
+
97
+ - `twPrefix`: tw class name prefix, default is `''`
98
+ - `cssVarPrefix`: Generated css var variable prefix, default is `'a'`
99
+
100
+ For example: when `twPrefix` is `ant` and `cssVarPrefix` is `abcd`, the generated css var variable and style are as follows:
101
+
102
+ ```jsx
103
+ /**
104
+ * :root{
105
+ * --abcd-colorPrimary: 47 84 235;
106
+ * }
107
+ */
108
+ function App() {
109
+ return <div className="bg-ant-colorPrimary"></div>;
110
+ }
111
+
112
+ // Generated css: .bg-ant-colorPrimary { background-color: rgb(var(--a-colorPrimary)); }
113
+ ```
114
+
115
+ ### Using with tailwind-merge
116
+
117
+ If you use `tailwind-merge`, additional configuration is required. See [discussions](https://github.com/tailwindlabs/tailwindcss/discussions/19260) for details on this issue
118
+
119
+ ```js
120
+ import { extendTailwindMerge } from "tailwind-merge";
121
+ import { fontSizes } from "tailwind-preset-antd/preset";
122
+
123
+ const twMerge = extendTailwindMerge({
124
+ // prefix:"" // if twPrefix is configured
125
+ extend: {
126
+ theme: {
127
+ text: [...fontSizes], // tw-merge v3
128
+ // colors:[...colorPresets] // tw-merge v2
129
+ },
130
+ },
131
+ });
132
+ ```
133
+
134
+ ## Acknowledgments
135
+
136
+ - [react-antd-admin](https://github.com/condorheroblog/react-antd-admin): The tailwindcss plugin used in this project inspired the development of this repository
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ 基于 Antd Design Token 的 tailwindcss 插件。
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ # 项目介绍
6
+
7
+ 版本要求:
8
+
9
+ - antd >= 5
10
+ - tailwindcss >= 3
11
+
12
+ 以前:
13
+
14
+ ```tsx
15
+ import { theme } from "antd";
16
+
17
+ function App() {
18
+ const { cssVar } = theme.useToken(); // antd v6
19
+
20
+ return <div style={{ backgroundColor: cssVar.colorPrimary }}></div>;
21
+ }
22
+ ```
23
+
24
+ 现在:
25
+
26
+ ```tsx
27
+ function App() {
28
+ return <div className="bg-colorPrimary"></div>;
29
+ }
30
+ ```
31
+
32
+ ## 基础使用
33
+
34
+ ### tailwindcss v3
35
+
36
+ 1. 注册 tailwind 插件
37
+
38
+ ```js
39
+ // tailwind.config.ts
40
+ import type { Config } from "tailwindcss/types/config";
41
+ import antdThemePreset from "tailwind-preset-antd/plugin";
42
+
43
+ const config: Config = {
44
+ // ...
45
+ // or custom plugins config: [antdThemePreset({ twPrefix: 'ant', cssVarPrefix: 'abcd' })],
46
+ plugins: [antdThemePreset],
47
+ };
48
+
49
+ export default config;
50
+ ```
51
+
52
+ 2. 注册基于 antd token 的全局 css 变量
53
+
54
+ ```jsx
55
+ import { AntdTokenCssVar } from "tailwind-preset-antd/components";
56
+
57
+ export default function App() {
58
+ return (
59
+ <>
60
+ <AntdTokenCssVar />
61
+ </>
62
+ );
63
+ }
64
+ ```
65
+
66
+ 如果使用了 `tailwind-merge` 插件,则需要将 `fontSizes` 添加至其配置中,具体使用见 [与 tailwind-merge 配合使用](#与-tailwind-merge-配合使用)
67
+
68
+ ### tailwindcss v4
69
+
70
+ 查看 [How can I pass parameters to a TailwindCSS plugin in a CSS-first configuration?](https://github.com/tailwindlabs/tailwindcss/discussions/15997)
71
+
72
+ ```css
73
+ @plugin "tailwind-preset-antd/plugin";
74
+
75
+ /* or
76
+ @plugin "tailwind-preset-antd/plugin" {
77
+ twPrefix: "ant";
78
+ cssVarPrefix: "abcd";
79
+ }
80
+ */
81
+ ```
82
+
83
+ ```jsx
84
+ import { AntdTokenCssVar } from "tailwind-preset-antd/components";
85
+
86
+ export default function App() {
87
+ return (
88
+ <>
89
+ <AntdTokenCssVar />
90
+ </>
91
+ );
92
+ }
93
+ ```
94
+
95
+ ## 配置项
96
+
97
+ - `twPrefix`: tw 类名前缀,默认为 `''`
98
+ - `cssVarPrefix`: 生成的 css var 变量前缀,默认为 `'a'`
99
+
100
+ 例如:当 twPrefix 为 `ant` 时,`cssVarPrefix` 为 `abcd` 时,生成的 css var 变量及样式如下:
101
+
102
+ ```jsx
103
+ /**
104
+ * :root{
105
+ * --abcd-colorPrimary: 47 84 235;
106
+ * }
107
+ */
108
+ function App() {
109
+ return <div className="bg-ant-colorPrimary"></div>;
110
+ }
111
+
112
+ // 生成的 css: .bg-ant-colorPrimary { background-color: rgb(var(--a-colorPrimary)); }
113
+ ```
114
+
115
+ ### 与 tailwind-merge 配合使用
116
+
117
+ 如果使用 `tailwind-merge`,需进行额外配置,此问题详见 [discussions](https://github.com/tailwindlabs/tailwindcss/discussions/19260)
118
+
119
+ ```js
120
+ import { extendTailwindMerge } from "tailwind-merge";
121
+ import { fontSizes } from "tailwind-preset-antd/preset";
122
+
123
+ const twMerge = extendTailwindMerge({
124
+ // prefix:"" // 如果配置了 twPrefix
125
+ extend: {
126
+ theme: {
127
+ text: [...fontSizes], // tw-merge v3
128
+ // colors:[...colorPresets] // tw-merge v2
129
+ },
130
+ },
131
+ });
132
+ ```
133
+
134
+ ## 鸣谢
135
+
136
+ - [react-antd-admin](https://github.com/condorheroblog/react-antd-admin):此项目的 tailwindcss 插件使用启发了此仓库的开发
@@ -0,0 +1,22 @@
1
+ import { defineConfig } from "oxfmt";
2
+
3
+ export default defineConfig({
4
+ useTabs: false,
5
+ tabWidth: 2,
6
+ printWidth: 100,
7
+ arrowParens: "always",
8
+ bracketSameLine: false,
9
+ bracketSpacing: true,
10
+ endOfLine: "lf",
11
+ jsxSingleQuote: false,
12
+ quoteProps: "as-needed",
13
+ semi: true,
14
+ singleQuote: false,
15
+ sortPackageJson: true,
16
+ trailingComma: "es5",
17
+ sortTailwindcss: {
18
+ functions: ["clsx", "cn"],
19
+ preserveWhitespace: true,
20
+ },
21
+ ignorePatterns: ["**/node_modules/**", "**/dist/**", "**/pnpm-lock.yaml"],
22
+ });
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from "oxlint";
2
+
3
+ export default defineConfig({
4
+ plugins: ["eslint", "typescript", "unicorn", "oxc", "node"],
5
+ ignorePatterns: ["**/node_modules/**", "**/dist/**", "**/pnpm-lock.yaml"],
6
+ });
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "tailwind-preset-antd",
3
+ "version": "0.0.1",
4
+ "description": "Use Tailwind CSS with Ant Design tokens",
5
+ "type": "module",
6
+ "exports": {
7
+ "./components": "./dist/components.js",
8
+ "./plugin": "./dist/plugin.js",
9
+ "./preset": "./dist/preset.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "scripts": {
13
+ "play": "vite",
14
+ "build:play": "vite build",
15
+ "preview:play": "vite preview",
16
+ "build": "tsdown",
17
+ "dev": "tsdown --watch",
18
+ "test": "vitest",
19
+ "ui": "vitest --ui",
20
+ "snapshot": "vitest -u",
21
+ "coverage": "vitest --coverage",
22
+ "release": "bumpp",
23
+ "prepublishOnly": "pnpm run build",
24
+ "typecheck": "tsc --noEmit",
25
+ "lint": "oxlint",
26
+ "lint:fix": "oxlint --fix",
27
+ "fmt": "oxfmt",
28
+ "fmt:check": "oxfmt --check"
29
+ },
30
+ "dependencies": {
31
+ "hex-rgb": "^5.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@tailwindcss/vite": "^4.2.4",
35
+ "@testing-library/jest-dom": "^6.9.1",
36
+ "@testing-library/react": "^16.3.2",
37
+ "@types/node": "^25.6.0",
38
+ "@types/react": "^19.2.14",
39
+ "@types/react-dom": "^19.2.3",
40
+ "@vitejs/plugin-react": "^6.0.1",
41
+ "@vitest/coverage-v8": "4.1.5",
42
+ "bumpp": "^11.0.1",
43
+ "jsdom": "^29.1.1",
44
+ "oxfmt": "^0.48.0",
45
+ "oxlint": "^1.63.0",
46
+ "postcss": "^8.5.14",
47
+ "react-dom": "^19.2.6",
48
+ "tailwindcss": "^4.2.4",
49
+ "tsdown": "^0.21.10",
50
+ "typescript": "^6.0.3",
51
+ "vite": "^8.0.10",
52
+ "vitest": "^4.1.5"
53
+ },
54
+ "peerDependencies": {
55
+ "antd": ">=5",
56
+ "react": ">=18",
57
+ "tailwindcss": "^3 || ^4"
58
+ }
59
+ }
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>tailwind-preset-antd</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/src/index.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,226 @@
1
+ import { Divider } from "antd";
2
+
3
+ const colorPalettes = [
4
+ "red",
5
+ "volcano",
6
+ "orange",
7
+ "lime",
8
+ "gold",
9
+ "yellow",
10
+ "green",
11
+ "cyan",
12
+ "blue",
13
+ "geekblue",
14
+ "purple",
15
+ "magenta",
16
+ ];
17
+
18
+ const getColorClass = (color: string, index: number) => {
19
+ const classes = {
20
+ red: [
21
+ "bg-red-1",
22
+ "bg-red-2",
23
+ "bg-red-3",
24
+ "bg-red-4",
25
+ "bg-red-5",
26
+ "bg-red-6",
27
+ "bg-red-7",
28
+ "bg-red-8",
29
+ "bg-red-9",
30
+ "bg-red-10",
31
+ ],
32
+ volcano: [
33
+ "bg-volcano-1",
34
+ "bg-volcano-2",
35
+ "bg-volcano-3",
36
+ "bg-volcano-4",
37
+ "bg-volcano-5",
38
+ "bg-volcano-6",
39
+ "bg-volcano-7",
40
+ "bg-volcano-8",
41
+ "bg-volcano-9",
42
+ "bg-volcano-10",
43
+ ],
44
+ orange: [
45
+ "bg-orange-1",
46
+ "bg-orange-2",
47
+ "bg-orange-3",
48
+ "bg-orange-4",
49
+ "bg-orange-5",
50
+ "bg-orange-6",
51
+ "bg-orange-7",
52
+ "bg-orange-8",
53
+ "bg-orange-9",
54
+ "bg-orange-10",
55
+ ],
56
+ lime: [
57
+ "bg-lime-1",
58
+ "bg-lime-2",
59
+ "bg-lime-3",
60
+ "bg-lime-4",
61
+ "bg-lime-5",
62
+ "bg-lime-6",
63
+ "bg-lime-7",
64
+ "bg-lime-8",
65
+ "bg-lime-9",
66
+ "bg-lime-10",
67
+ ],
68
+ gold: [
69
+ "bg-gold-1",
70
+ "bg-gold-2",
71
+ "bg-gold-3",
72
+ "bg-gold-4",
73
+ "bg-gold-5",
74
+ "bg-gold-6",
75
+ "bg-gold-7",
76
+ "bg-gold-8",
77
+ "bg-gold-9",
78
+ "bg-gold-10",
79
+ ],
80
+ yellow: [
81
+ "bg-yellow-1",
82
+ "bg-yellow-2",
83
+ "bg-yellow-3",
84
+ "bg-yellow-4",
85
+ "bg-yellow-5",
86
+ "bg-yellow-6",
87
+ "bg-yellow-7",
88
+ "bg-yellow-8",
89
+ "bg-yellow-9",
90
+ "bg-yellow-10",
91
+ ],
92
+ green: [
93
+ "bg-green-1",
94
+ "bg-green-2",
95
+ "bg-green-3",
96
+ "bg-green-4",
97
+ "bg-green-5",
98
+ "bg-green-6",
99
+ "bg-green-7",
100
+ "bg-green-8",
101
+ "bg-green-9",
102
+ "bg-green-10",
103
+ ],
104
+ cyan: [
105
+ "bg-cyan-1",
106
+ "bg-cyan-2",
107
+ "bg-cyan-3",
108
+ "bg-cyan-4",
109
+ "bg-cyan-5",
110
+ "bg-cyan-6",
111
+ "bg-cyan-7",
112
+ "bg-cyan-8",
113
+ "bg-cyan-9",
114
+ "bg-cyan-10",
115
+ ],
116
+ blue: [
117
+ "bg-blue-1",
118
+ "bg-blue-2",
119
+ "bg-blue-3",
120
+ "bg-blue-4",
121
+ "bg-blue-5",
122
+ "bg-blue-6",
123
+ "bg-blue-7",
124
+ "bg-blue-8",
125
+ "bg-blue-9",
126
+ "bg-blue-10",
127
+ ],
128
+ geekblue: [
129
+ "bg-geekblue-1",
130
+ "bg-geekblue-2",
131
+ "bg-geekblue-3",
132
+ "bg-geekblue-4",
133
+ "bg-geekblue-5",
134
+ "bg-geekblue-6",
135
+ "bg-geekblue-7",
136
+ "bg-geekblue-8",
137
+ "bg-geekblue-9",
138
+ "bg-geekblue-10",
139
+ ],
140
+ purple: [
141
+ "bg-purple-1",
142
+ "bg-purple-2",
143
+ "bg-purple-3",
144
+ "bg-purple-4",
145
+ "bg-purple-5",
146
+ "bg-purple-6",
147
+ "bg-purple-7",
148
+ "bg-purple-8",
149
+ "bg-purple-9",
150
+ "bg-purple-10",
151
+ ],
152
+ magenta: [
153
+ "bg-magenta-1",
154
+ "bg-magenta-2",
155
+ "bg-magenta-3",
156
+ "bg-magenta-4",
157
+ "bg-magenta-5",
158
+ "bg-magenta-6",
159
+ "bg-magenta-7",
160
+ "bg-magenta-8",
161
+ "bg-magenta-9",
162
+ "bg-magenta-10",
163
+ ],
164
+ };
165
+ return classes[color as keyof typeof classes][index];
166
+ };
167
+
168
+ export default function App() {
169
+ return (
170
+ <div className="text-fontSize p-8">
171
+ <Divider>Tailwindcss color palettes for antd</Divider>
172
+ <div className="flex flex-col items-center gap-4 p-4">
173
+ {colorPalettes.map((color) => (
174
+ <div key={color} className="flex gap-1">
175
+ <div className="w-16 text-sm font-bold">{color}</div>
176
+ <div className="flex gap-1">
177
+ {Array.from({ length: 10 }, (_, i) => (
178
+ <div
179
+ key={i}
180
+ className={`${getColorClass(color, i)} text-colorTextLightSolid flex h-8 w-8 items-center justify-center rounded text-xs`}
181
+ >
182
+ {i + 1}
183
+ </div>
184
+ ))}
185
+ </div>
186
+ </div>
187
+ ))}
188
+ </div>
189
+
190
+ <Divider>Rewrite antd component use plugin</Divider>
191
+ <div className="flex justify-center gap-6">
192
+ {/* Card */}
193
+ <div
194
+ style={{ width: 300 }}
195
+ className="text-colorTextHeading border-colorBorderSecondary rounded-borderRadiusLG flex flex-col justify-center border border-solid"
196
+ >
197
+ {/* header */}
198
+ <div className="px-marginLG border-colorBorderSecondary flex h-14 items-center border-b border-solid font-semibold">
199
+ <div className="flex w-full items-center">
200
+ <div className="inline-block flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
201
+ Default size card
202
+ </div>
203
+ <div className="text-fontSize font-normal">
204
+ <a className="text-colorPrimary cursor-pointer">More</a>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ {/* content */}
209
+ <div className="p-marginLG">
210
+ <p>Card content</p>
211
+ <p>Card content</p>
212
+ <p>Card content</p>
213
+ </div>
214
+ </div>
215
+
216
+ {/* Button */}
217
+ <button
218
+ type="button"
219
+ className="px-margin rounded-borderRadius bg-colorPrimary text-colorTextLightSolid hover:bg-colorPrimaryHover active:bg-colorPrimaryActive h-8 cursor-pointer transition-colors"
220
+ >
221
+ Primary Button
222
+ </button>
223
+ </div>
224
+ </div>
225
+ );
226
+ }
@@ -0,0 +1,4 @@
1
+ @import "tailwindcss";
2
+
3
+ /* prettier-ignore */
4
+ @plugin "../../src/plugin.ts";
@@ -0,0 +1,15 @@
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { ConfigProvider } from "antd";
4
+ import App from "./App";
5
+ import AntdTokenCssVar from "../../src/components";
6
+ import "./global.css";
7
+
8
+ createRoot(document.querySelector("#app")!).render(
9
+ <StrictMode>
10
+ <ConfigProvider>
11
+ <AntdTokenCssVar />
12
+ <App />
13
+ </ConfigProvider>
14
+ </StrictMode>
15
+ );