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.
- package/.github/workflows/gh-pages.yml +49 -0
- package/.vscode/settings.json +25 -0
- package/README.en-US.md +136 -0
- package/README.md +136 -0
- package/oxfmt.config.ts +22 -0
- package/oxlint.config.ts +6 -0
- package/package.json +59 -0
- package/playground/index.html +12 -0
- package/playground/src/App.tsx +226 -0
- package/playground/src/global.css +4 -0
- package/playground/src/index.tsx +15 -0
- package/src/components.test.tsx +56 -0
- package/src/components.tsx +33 -0
- package/src/constants/index.ts +1 -0
- package/src/core/genCssVarByToken.test.ts +46 -0
- package/src/core/genCssVarByTokens.ts +45 -0
- package/src/core/genTailwindTheme.test.ts +95 -0
- package/src/core/genTailwindTheme.ts +62 -0
- package/src/plugin.ts +71 -0
- package/src/preset/index.ts +13 -0
- package/src/preset/tokens/borderRadius.ts +6 -0
- package/src/preset/tokens/colorPalettes.ts +24 -0
- package/src/preset/tokens/fontSizes.ts +6 -0
- package/src/preset/tokens/functionalColors.ts +72 -0
- package/src/preset/tokens/margins.ts +11 -0
- package/src/preset/tokens/semanticColors.ts +29 -0
- package/src/utils/index.ts +10 -0
- package/tsconfig.json +21 -0
- package/tsdown.config.ts +14 -0
- package/vite.config.ts +23 -0
- package/vitest.setup.ts +11 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { render, cleanup } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it, beforeEach, afterEach } from "vitest";
|
|
3
|
+
import AntdTokenCssVar from "./components";
|
|
4
|
+
|
|
5
|
+
describe("AntdTokenCssVar", () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
document.head.innerHTML = "";
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
cleanup();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should render correctly", () => {
|
|
15
|
+
const { container } = render(<AntdTokenCssVar />);
|
|
16
|
+
expect(container).toBeDefined();
|
|
17
|
+
const style = document.querySelector("style#antd-token-inject");
|
|
18
|
+
expect(style?.textContent).toContain("--a-");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should inject style element with CSS variables", () => {
|
|
22
|
+
render(<AntdTokenCssVar />);
|
|
23
|
+
const style = document.querySelector("style#antd-token-inject");
|
|
24
|
+
expect(style).toBeTruthy();
|
|
25
|
+
expect(style?.getAttribute("plugin-name")).toBe("tailwind-preset-antd");
|
|
26
|
+
expect(style?.textContent).toContain(":root{");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should use custom cssVarPrefix", () => {
|
|
30
|
+
render(<AntdTokenCssVar cssVarPrefix="custom" />);
|
|
31
|
+
const style = document.querySelector("style#antd-token-inject");
|
|
32
|
+
expect(style?.textContent).toContain("--custom-");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should remove style element on unmount", () => {
|
|
36
|
+
const { unmount } = render(<AntdTokenCssVar />);
|
|
37
|
+
let style = document.querySelector("style#antd-token-inject");
|
|
38
|
+
expect(style).toBeTruthy();
|
|
39
|
+
|
|
40
|
+
unmount();
|
|
41
|
+
style = document.querySelector("style#antd-token-inject");
|
|
42
|
+
expect(style).toBeFalsy();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should update CSS variables when token changes", () => {
|
|
46
|
+
const { rerender } = render(<AntdTokenCssVar cssVarPrefix="test" />);
|
|
47
|
+
const style = document.querySelector("style#antd-token-inject");
|
|
48
|
+
const firstContent = style?.textContent;
|
|
49
|
+
expect(firstContent).toContain("--test-");
|
|
50
|
+
|
|
51
|
+
rerender(<AntdTokenCssVar cssVarPrefix="test2" />);
|
|
52
|
+
const style2 = document.querySelector("style#antd-token-inject");
|
|
53
|
+
const secondContent = style2?.textContent;
|
|
54
|
+
expect(secondContent).toContain("--test2-");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { theme } from "antd";
|
|
2
|
+
import { useInsertionEffect } from "react";
|
|
3
|
+
|
|
4
|
+
import { genCSSVarByTokens } from "./core/genCssVarByTokens";
|
|
5
|
+
|
|
6
|
+
const styleId = "antd-token-inject";
|
|
7
|
+
|
|
8
|
+
interface AntdTokenCssVarProps {
|
|
9
|
+
cssVarPrefix?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function AntdTokenCssVar(props: AntdTokenCssVarProps) {
|
|
13
|
+
const { cssVarPrefix } = props;
|
|
14
|
+
const { token } = theme.useToken();
|
|
15
|
+
|
|
16
|
+
useInsertionEffect(() => {
|
|
17
|
+
const cssVar = genCSSVarByTokens(token, cssVarPrefix);
|
|
18
|
+
|
|
19
|
+
const style = document.querySelector(`#${styleId}`) || document.createElement("style");
|
|
20
|
+
style.id = styleId;
|
|
21
|
+
style.setAttribute("plugin-name", "tailwind-preset-antd");
|
|
22
|
+
|
|
23
|
+
style.textContent = `:root{${cssVar}}`;
|
|
24
|
+
document.head.appendChild(style);
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
document.head.removeChild(style);
|
|
28
|
+
};
|
|
29
|
+
}, [token, cssVarPrefix]);
|
|
30
|
+
|
|
31
|
+
// return <style id={styleId}>{`:root{${cssVar}}`}</style>;
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_CSS_VAR_PREFIX = "a";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { genCSSVarByTokens } from "./genCssVarByTokens";
|
|
3
|
+
|
|
4
|
+
describe("createColorPalettes", () => {
|
|
5
|
+
it("should generate css variables correctly", () => {
|
|
6
|
+
const tokens = {
|
|
7
|
+
colorPrimary: "#ff0000",
|
|
8
|
+
colorSuccess: "#00ff00",
|
|
9
|
+
} as any;
|
|
10
|
+
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
11
|
+
expect(result).toContain("--css-var-colorPrimary:255, 0, 0;");
|
|
12
|
+
expect(result).toContain("--css-var-colorSuccess:0, 255, 0;");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should generate css variables for color palettes", () => {
|
|
16
|
+
const tokens = {
|
|
17
|
+
red: "#ff0000",
|
|
18
|
+
"red-1": "#ff7875",
|
|
19
|
+
blue: "#1890ff",
|
|
20
|
+
"blue-5": "#096dd9",
|
|
21
|
+
} as any;
|
|
22
|
+
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
23
|
+
expect(result).toContain("--css-var-red:255, 0, 0;");
|
|
24
|
+
expect(result).toContain("--css-var-red-1:255, 120, 117;");
|
|
25
|
+
expect(result).toContain("--css-var-blue:24, 144, 255;");
|
|
26
|
+
expect(result).toContain("--css-var-blue-5:9, 109, 217;");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should ignore startWith rgb", () => {
|
|
30
|
+
const tokens = { colorText: "rgb(255, 255, 255)" } as any;
|
|
31
|
+
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
32
|
+
expect(result).toContain("--css-var-colorText:rgb(255, 255, 255);");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should generate CSS variables for fontSize, margin, and borderRadius tokens", () => {
|
|
36
|
+
const tokens = {
|
|
37
|
+
fontSize: 14,
|
|
38
|
+
margin: 8,
|
|
39
|
+
borderRadius: 6,
|
|
40
|
+
} as any;
|
|
41
|
+
const result = genCSSVarByTokens(tokens, "--css-var");
|
|
42
|
+
expect(result).toContain("--css-var-fontSize:14px;");
|
|
43
|
+
expect(result).toContain("--css-var-margin:8px;");
|
|
44
|
+
expect(result).toContain("--css-var-borderRadius:6px;");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GlobalToken } from "antd";
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_CSS_VAR_PREFIX } from "../constants";
|
|
4
|
+
|
|
5
|
+
import { hexToRgb, isRGBColor } from "../utils";
|
|
6
|
+
import {
|
|
7
|
+
borderRadius,
|
|
8
|
+
colorPalettes,
|
|
9
|
+
fontSizes,
|
|
10
|
+
functionalColors,
|
|
11
|
+
margins,
|
|
12
|
+
semanticColors,
|
|
13
|
+
} from "../preset";
|
|
14
|
+
|
|
15
|
+
export function genCSSVarByTokens(
|
|
16
|
+
tokens: GlobalToken,
|
|
17
|
+
cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX
|
|
18
|
+
) {
|
|
19
|
+
let colorsVariables = "";
|
|
20
|
+
|
|
21
|
+
for (const [key, value] of Object.entries(tokens)) {
|
|
22
|
+
// https://v3.tailwindcss.com/docs/customizing-colors#using-css-variables
|
|
23
|
+
if (colorPalettes.includes(key)) {
|
|
24
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${hexToRgb(value)};`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (functionalColors.includes(key)) {
|
|
28
|
+
const rgb = hexToRgb(value);
|
|
29
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${rgb};`;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (semanticColors.includes(key)) {
|
|
34
|
+
const rgb = isRGBColor(value) ? value : `rgb(${hexToRgb(value)})`;
|
|
35
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${rgb};`;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (fontSizes.includes(key) || margins.includes(key) || borderRadius.includes(key)) {
|
|
40
|
+
colorsVariables += `--${cssVarPrefix}-${key}:${value}px;`;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return colorsVariables;
|
|
45
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
createColorPalettes,
|
|
4
|
+
createFontSize,
|
|
5
|
+
createSpacing,
|
|
6
|
+
createBorderRadius,
|
|
7
|
+
} from "../core/genTailwindTheme";
|
|
8
|
+
import { colorPalettes } from "../preset";
|
|
9
|
+
|
|
10
|
+
describe("createColorPalettes", () => {
|
|
11
|
+
it("should create color palette variables with default prefix", () => {
|
|
12
|
+
const result = createColorPalettes();
|
|
13
|
+
|
|
14
|
+
expect(result["red"]).toBe("rgb(var(--a-red))");
|
|
15
|
+
expect(result["blue"]).toBe("rgb(var(--a-blue))");
|
|
16
|
+
expect(result["colorPrimary"]).toBe("rgb(var(--a-colorPrimary))");
|
|
17
|
+
expect(result["colorSuccess"]).toBe("rgb(var(--a-colorSuccess))");
|
|
18
|
+
expect(result["colorText"]).toBe("var(--a-colorText)");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should create color palette variables with custom cssVarPrefix", () => {
|
|
22
|
+
const result = createColorPalettes("custom");
|
|
23
|
+
|
|
24
|
+
expect(result["red"]).toBe("rgb(var(--custom-red))");
|
|
25
|
+
expect(result["blue"]).toBe("rgb(var(--custom-blue))");
|
|
26
|
+
expect(result["colorPrimary"]).toBe("rgb(var(--custom-colorPrimary))");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should create color palette variables with custom twPrefix", () => {
|
|
30
|
+
const result = createColorPalettes("a", "ant");
|
|
31
|
+
|
|
32
|
+
expect(result["ant-red"]).toBe("rgb(var(--a-red))");
|
|
33
|
+
expect(result["ant-blue"]).toBe("rgb(var(--a-blue))");
|
|
34
|
+
expect(result["ant-colorPrimary"]).toBe("rgb(var(--a-colorPrimary))");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should use rgb() wrapper for colorPalettes", () => {
|
|
38
|
+
const result = createColorPalettes();
|
|
39
|
+
colorPalettes.forEach((color) => {
|
|
40
|
+
expect(result[color]).toMatch(/^rgb\(var\(--a-[^)]+\)\)$/);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("createFontSize", () => {
|
|
46
|
+
it("should create font size variables with default prefix", () => {
|
|
47
|
+
const result = createFontSize();
|
|
48
|
+
|
|
49
|
+
expect(result["fontSizeSM"]).toBe("var(--a-fontSizeSM)");
|
|
50
|
+
expect(result["fontSize"]).toBe("var(--a-fontSize)");
|
|
51
|
+
expect(result["fontSizeLG"]).toBe("var(--a-fontSizeLG)");
|
|
52
|
+
expect(result["fontSizeXL"]).toBe("var(--a-fontSizeXL)");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should create font size variables with custom cssVarPrefix", () => {
|
|
56
|
+
const result = createFontSize("custom");
|
|
57
|
+
|
|
58
|
+
expect(result["fontSizeSM"]).toBe("var(--custom-fontSizeSM)");
|
|
59
|
+
expect(result["fontSize"]).toBe("var(--custom-fontSize)");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should create font size variables with custom twPrefix", () => {
|
|
63
|
+
const result = createFontSize("a", "ant");
|
|
64
|
+
|
|
65
|
+
expect(result["ant-fontSizeSM"]).toBe("var(--a-fontSizeSM)");
|
|
66
|
+
expect(result["ant-fontSize"]).toBe("var(--a-fontSize)");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should create all font size entries", () => {
|
|
70
|
+
const result = createFontSize();
|
|
71
|
+
expect(Object.keys(result).length).toBe(4);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("createSpacing", () => {
|
|
76
|
+
it("should create spacing variables with default prefix", () => {
|
|
77
|
+
const result = createSpacing();
|
|
78
|
+
|
|
79
|
+
expect(result["marginXXS"]).toBe("var(--a-marginXXS)");
|
|
80
|
+
expect(result["marginXS"]).toBe("var(--a-marginXS)");
|
|
81
|
+
expect(result["marginSM"]).toBe("var(--a-marginSM)");
|
|
82
|
+
expect(result["margin"]).toBe("var(--a-margin)");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("createBorderRadius", () => {
|
|
87
|
+
it("should create border radius variables with default prefix", () => {
|
|
88
|
+
const result = createBorderRadius();
|
|
89
|
+
|
|
90
|
+
expect(result["borderRadiusXS"]).toBe("var(--a-borderRadiusXS)");
|
|
91
|
+
expect(result["borderRadiusSM"]).toBe("var(--a-borderRadiusSM)");
|
|
92
|
+
expect(result["borderRadius"]).toBe("var(--a-borderRadius)");
|
|
93
|
+
expect(result["borderRadiusLG"]).toBe("var(--a-borderRadiusLG)");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DEFAULT_CSS_VAR_PREFIX } from "../constants";
|
|
2
|
+
import {
|
|
3
|
+
borderRadius,
|
|
4
|
+
fontSizes,
|
|
5
|
+
functionalColors,
|
|
6
|
+
margins,
|
|
7
|
+
semanticColors,
|
|
8
|
+
colorPalettes,
|
|
9
|
+
} from "../preset";
|
|
10
|
+
|
|
11
|
+
function genTwPrefixKey(key: string, prefix?: string) {
|
|
12
|
+
return prefix ? `${prefix}-${key}` : key;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createColorPalettes(
|
|
16
|
+
cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX,
|
|
17
|
+
twPrefix?: string
|
|
18
|
+
) {
|
|
19
|
+
// eg: twPrefix='ant': bg-ant-colorPrimary --> background-color: var(--a-colorPrimary)
|
|
20
|
+
const colorPaletteVar: Record<string, string> = {};
|
|
21
|
+
|
|
22
|
+
colorPalettes.forEach((color) => {
|
|
23
|
+
colorPaletteVar[genTwPrefixKey(color, twPrefix)] = `rgb(var(--${cssVarPrefix}-${color}))`;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
functionalColors.forEach((key) => {
|
|
27
|
+
colorPaletteVar[genTwPrefixKey(key, twPrefix)] = `rgb(var(--${cssVarPrefix}-${key}))`;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
semanticColors.forEach((key) => {
|
|
31
|
+
colorPaletteVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return colorPaletteVar;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createFontSize(cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX, twPrefix?: string) {
|
|
38
|
+
const fontSizeVar: Record<string, string> = {};
|
|
39
|
+
fontSizes.forEach((key) => {
|
|
40
|
+
fontSizeVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
41
|
+
});
|
|
42
|
+
return fontSizeVar;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createSpacing(cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX, twPrefix?: string) {
|
|
46
|
+
const spacingVar: Record<string, string> = {};
|
|
47
|
+
margins.forEach((key) => {
|
|
48
|
+
spacingVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
49
|
+
});
|
|
50
|
+
return spacingVar;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createBorderRadius(
|
|
54
|
+
cssVarPrefix: string = DEFAULT_CSS_VAR_PREFIX,
|
|
55
|
+
twPrefix?: string
|
|
56
|
+
) {
|
|
57
|
+
const radiusVar: Record<string, string> = {};
|
|
58
|
+
borderRadius.forEach((key) => {
|
|
59
|
+
radiusVar[genTwPrefixKey(key, twPrefix)] = `var(--${cssVarPrefix}-${key})`;
|
|
60
|
+
});
|
|
61
|
+
return radiusVar;
|
|
62
|
+
}
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Config } from "tailwindcss";
|
|
2
|
+
// import type { PluginAPI } from "tailwindcss/plugin";
|
|
3
|
+
import plugin from "tailwindcss/plugin";
|
|
4
|
+
|
|
5
|
+
import { DEFAULT_CSS_VAR_PREFIX } from "./constants";
|
|
6
|
+
import {
|
|
7
|
+
createBorderRadius,
|
|
8
|
+
createColorPalettes,
|
|
9
|
+
createFontSize,
|
|
10
|
+
createSpacing,
|
|
11
|
+
} from "./core/genTailwindTheme";
|
|
12
|
+
|
|
13
|
+
interface PluginOptions {
|
|
14
|
+
/**
|
|
15
|
+
* @description tw class prefix
|
|
16
|
+
* @default '''
|
|
17
|
+
*/
|
|
18
|
+
twPrefix?: string;
|
|
19
|
+
/**
|
|
20
|
+
* @description css variables prefix
|
|
21
|
+
* @default 'a'
|
|
22
|
+
*/
|
|
23
|
+
cssVarPrefix?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// override private plugin interface
|
|
27
|
+
interface PluginWithOptions<T> {
|
|
28
|
+
(options?: T): {
|
|
29
|
+
handler: (api: any) => void;
|
|
30
|
+
};
|
|
31
|
+
__isOptionsFunction: true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @description 使用 Ant Design 的 Design Token 扩展 Tailwind CSS 类名,相关扩展有 color radius fontSize padding
|
|
36
|
+
* @example `bg-colorPrimary` --> `backgroundColor: token.colorPrimary`;
|
|
37
|
+
* @see https://ant-design.antgroup.com/docs/react/customize-theme-cn#seedtoken
|
|
38
|
+
* @see https://github.com/tailwindlabs/tailwindcss/discussions/13292#discussioncomment-14256365
|
|
39
|
+
*/
|
|
40
|
+
const twAntdPresetPlugin: PluginWithOptions<PluginOptions> = plugin.withOptions(
|
|
41
|
+
() => () => {
|
|
42
|
+
/* empty */
|
|
43
|
+
},
|
|
44
|
+
(options: PluginOptions = {}) => {
|
|
45
|
+
const { cssVarPrefix = DEFAULT_CSS_VAR_PREFIX, twPrefix = "" } = options;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
theme: {
|
|
49
|
+
/**
|
|
50
|
+
* @see https://tailwindcss.com/docs/customizing-colors#using-css-variables
|
|
51
|
+
*/
|
|
52
|
+
extend: {
|
|
53
|
+
colors: {
|
|
54
|
+
...createColorPalettes(cssVarPrefix, twPrefix),
|
|
55
|
+
white: "rgb(255 255 255)",
|
|
56
|
+
black: "rgb(0 0 0)",
|
|
57
|
+
current: "currentColor",
|
|
58
|
+
inherit: "inherit",
|
|
59
|
+
transparent: "transparent",
|
|
60
|
+
},
|
|
61
|
+
fontSize: { ...createFontSize(cssVarPrefix, twPrefix) },
|
|
62
|
+
radius: { ...createBorderRadius(cssVarPrefix, twPrefix) }, // v4
|
|
63
|
+
borderRadius: { ...createBorderRadius(cssVarPrefix, twPrefix) }, // v3
|
|
64
|
+
spacing: { ...createSpacing(cssVarPrefix, twPrefix) },
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
} satisfies Partial<Config>;
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
export default twAntdPresetPlugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { functionalColors } from "./tokens/functionalColors";
|
|
2
|
+
import { colorPalettes } from "./tokens/colorPalettes";
|
|
3
|
+
import { semanticColors } from "./tokens/semanticColors";
|
|
4
|
+
|
|
5
|
+
export { margins } from "./tokens/margins";
|
|
6
|
+
export { fontSizes } from "./tokens/fontSizes";
|
|
7
|
+
export { borderRadius } from "./tokens/borderRadius";
|
|
8
|
+
|
|
9
|
+
export { functionalColors };
|
|
10
|
+
export { colorPalettes };
|
|
11
|
+
export { semanticColors };
|
|
12
|
+
|
|
13
|
+
export const colorPresets = [...colorPalettes, ...functionalColors, ...semanticColors];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// https://ant.design/docs/spec/colors#base-color-palettes
|
|
2
|
+
export const colors = [
|
|
3
|
+
"red",
|
|
4
|
+
"volcano",
|
|
5
|
+
"orange",
|
|
6
|
+
"lime",
|
|
7
|
+
"gold",
|
|
8
|
+
"yellow",
|
|
9
|
+
"green",
|
|
10
|
+
"cyan",
|
|
11
|
+
"blue",
|
|
12
|
+
"geekblue",
|
|
13
|
+
"purple",
|
|
14
|
+
"magenta",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const colorPaletteCount = 10;
|
|
18
|
+
/**
|
|
19
|
+
* `['red', 'red-1', 'red-2', ……, 'red-10', 'magenta',……]`
|
|
20
|
+
*/
|
|
21
|
+
export const colorPalettes = colors.flatMap((color) => [
|
|
22
|
+
color,
|
|
23
|
+
...Array.from({ length: colorPaletteCount }, (_, i) => `${color}-${i + 1}`),
|
|
24
|
+
]);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const brandColors = [
|
|
2
|
+
"colorPrimary",
|
|
3
|
+
"colorPrimaryBg",
|
|
4
|
+
"colorPrimaryBgHover",
|
|
5
|
+
"colorPrimaryBorder",
|
|
6
|
+
"colorPrimaryBorderHover",
|
|
7
|
+
"colorPrimaryHover",
|
|
8
|
+
"colorPrimaryActive",
|
|
9
|
+
"colorPrimaryTextHover",
|
|
10
|
+
"colorPrimaryText",
|
|
11
|
+
"colorPrimaryTextActive",
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const successColors = [
|
|
15
|
+
"colorSuccess",
|
|
16
|
+
"colorSuccessBg",
|
|
17
|
+
"colorSuccessBgHover",
|
|
18
|
+
"colorSuccessBorder",
|
|
19
|
+
"colorSuccessBorderHover",
|
|
20
|
+
"colorSuccessHover",
|
|
21
|
+
"colorSuccessActive",
|
|
22
|
+
"colorSuccessTextHover",
|
|
23
|
+
"colorSuccessText",
|
|
24
|
+
"colorSuccessTextActive",
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const warningColors = [
|
|
28
|
+
"colorWarning",
|
|
29
|
+
"colorWarningBg",
|
|
30
|
+
"colorWarningBgHover",
|
|
31
|
+
"colorWarningBorder",
|
|
32
|
+
"colorWarningBorderHover",
|
|
33
|
+
"colorWarningHover",
|
|
34
|
+
"colorWarningActive",
|
|
35
|
+
"colorWarningTextHover",
|
|
36
|
+
"colorWarningText",
|
|
37
|
+
"colorWarningTextActive",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const errorColors = [
|
|
41
|
+
"colorError",
|
|
42
|
+
"colorErrorBg",
|
|
43
|
+
"colorErrorBgHover",
|
|
44
|
+
"colorErrorBorder",
|
|
45
|
+
"colorErrorBorderHover",
|
|
46
|
+
"colorErrorHover",
|
|
47
|
+
"colorErrorActive",
|
|
48
|
+
"colorErrorTextHover",
|
|
49
|
+
"colorErrorText",
|
|
50
|
+
"colorErrorTextActive",
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const infoColors = [
|
|
54
|
+
"colorInfo",
|
|
55
|
+
"colorInfoBg",
|
|
56
|
+
"colorInfoBgHover",
|
|
57
|
+
"colorInfoBorder",
|
|
58
|
+
"colorInfoBorderHover",
|
|
59
|
+
"colorInfoHover",
|
|
60
|
+
"colorInfoActive",
|
|
61
|
+
"colorInfoTextHover",
|
|
62
|
+
"colorInfoText",
|
|
63
|
+
"colorInfoTextActive",
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
export const functionalColors = [
|
|
67
|
+
...brandColors,
|
|
68
|
+
...successColors,
|
|
69
|
+
...warningColors,
|
|
70
|
+
...errorColors,
|
|
71
|
+
...infoColors,
|
|
72
|
+
];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const semanticColors = [
|
|
2
|
+
// Text
|
|
3
|
+
"colorText",
|
|
4
|
+
"colorTextSecondary",
|
|
5
|
+
"colorTextTertiary",
|
|
6
|
+
"colorTextQuaternary",
|
|
7
|
+
"colorTextDescription",
|
|
8
|
+
"colorTextDisabled",
|
|
9
|
+
"colorTextHeading",
|
|
10
|
+
"colorTextLabel",
|
|
11
|
+
"colorTextLightSolid",
|
|
12
|
+
"colorTextPlaceholder",
|
|
13
|
+
|
|
14
|
+
// BG
|
|
15
|
+
"colorBgContainer",
|
|
16
|
+
"colorBgElevated",
|
|
17
|
+
"colorBgLayout",
|
|
18
|
+
"colorBgSpotlight",
|
|
19
|
+
"colorBgMask",
|
|
20
|
+
|
|
21
|
+
// Border Color
|
|
22
|
+
"colorBorder",
|
|
23
|
+
"colorBorderSecondary",
|
|
24
|
+
// Fill Color
|
|
25
|
+
"colorFill",
|
|
26
|
+
"colorFillSecondary",
|
|
27
|
+
"colorFillTertiary",
|
|
28
|
+
"colorFillQuaternary",
|
|
29
|
+
];
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"moduleDetection": "force",
|
|
6
|
+
"module": "preserve",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"jsx": "preserve",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"types": ["node", "vite/client"],
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"declaration": true,
|
|
14
|
+
"emitDeclarationOnly": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"verbatimModuleSyntax": true,
|
|
18
|
+
"skipLibCheck": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src", "playground", "vitest.setup.ts"]
|
|
21
|
+
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
target: ["es6", "node16"],
|
|
5
|
+
exports: true,
|
|
6
|
+
platform: "neutral",
|
|
7
|
+
unbundle: true,
|
|
8
|
+
dts: true,
|
|
9
|
+
entry: {
|
|
10
|
+
components: "./src/components.tsx",
|
|
11
|
+
plugin: "./src/plugin.ts",
|
|
12
|
+
preset: "./src/preset/index.ts",
|
|
13
|
+
},
|
|
14
|
+
});
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="vitest/config" />
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
root: "./playground",
|
|
8
|
+
plugins: [react(), tailwindcss()],
|
|
9
|
+
base: "/tailwind-preset-antd/",
|
|
10
|
+
build: {
|
|
11
|
+
outDir: "docs-dist",
|
|
12
|
+
},
|
|
13
|
+
test: {
|
|
14
|
+
root: ".",
|
|
15
|
+
setupFiles: "./vitest.setup.ts",
|
|
16
|
+
environment: "jsdom",
|
|
17
|
+
coverage: {
|
|
18
|
+
provider: "v8",
|
|
19
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
20
|
+
exclude: ["**/*.test.{ts,tsx}", "**/*.spec.{ts,tsx}"],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
package/vitest.setup.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "@testing-library/jest-dom/vitest";
|
|
2
|
+
|
|
3
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
4
|
+
import { cleanup } from "@testing-library/react";
|
|
5
|
+
import { afterEach, expect } from "vitest";
|
|
6
|
+
|
|
7
|
+
expect.extend(matchers);
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
cleanup();
|
|
11
|
+
});
|