@stapel/tokens-antd 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stapel contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @stapel/tokens-antd
2
+
3
+ The Ant Design leg of the **token bridge** (frontend-guidelines §2.4; owner
4
+ decision §38 T3). It projects `@stapel/tokens` L2 core tokens onto an Ant Design
5
+ `ConfigProvider` theme — so integrating a `@stapel/*-react` pair's default skin
6
+ already carries the user's theme, light and dark.
7
+
8
+ There is exactly **one** L2 → design-system role mapping table, and it lives in
9
+ `@stapel/tokens` (`bridgeColorRoles` + the radius/font-size roles). This package
10
+ only renames those neutral roles to antd's flat token field names and picks the
11
+ `light`/`dark` half — it holds no colour decisions of its own, so it and
12
+ `@stapel/tokens-mui` cannot drift.
13
+
14
+ ## Usage
15
+
16
+ ```tsx
17
+ import { toAntdTheme } from "@stapel/tokens-antd";
18
+ import { ConfigProvider } from "antd";
19
+
20
+ <ConfigProvider theme={{ token: toAntdTheme(mode) }}>
21
+ <App />
22
+ </ConfigProvider>;
23
+ ```
24
+
25
+ `toAntdTheme(mode)` returns just the flat `theme.token`. For a config that also
26
+ flips antd's **derived** neutrals (borders, hovers, fills) to the dark palette —
27
+ not only the seed tokens — spread the full config instead:
28
+
29
+ ```tsx
30
+ import { toAntdThemeConfig } from "@stapel/tokens-antd";
31
+
32
+ <ConfigProvider theme={toAntdThemeConfig(mode)}>
33
+ <App />
34
+ </ConfigProvider>;
35
+ ```
36
+
37
+ ## The mapping (frontend-guidelines §2.4)
38
+
39
+ | `@stapel/tokens` role | L2 core token | antd `theme.token` |
40
+ | --- | --- | --- |
41
+ | `brand` | `accent` | `colorPrimary` |
42
+ | `success` | `text-positive` | `colorSuccess` |
43
+ | `warning` | `text-warning` | `colorWarning` |
44
+ | `danger` | `text-negative` | `colorError` |
45
+ | `info` | `text-info` | `colorInfo` |
46
+ | `bgContainer` | `upperground-primary` | `colorBgContainer` / `colorBgElevated` |
47
+ | `bgLayout` | `background-primary` | `colorBgLayout` |
48
+ | `textPrimary` | `text-primary` | `colorText` |
49
+ | `link` | `text-brand` | `colorLink` |
50
+ | radius `md` | — | `borderRadius` |
51
+ | font-size `md` | — | `fontSize` |
52
+
53
+ `antd` is a peer dependency — the consuming app brings its own copy.
@@ -0,0 +1,18 @@
1
+ import type { ThemeConfig } from "antd";
2
+ /** Light or dark — the half of every L2 core token's `{light,dark}` pair. */
3
+ export type ThemeMode = "light" | "dark";
4
+ /** The flat antd token map (`ThemeConfig["token"]`), never undefined. */
5
+ export type AntdThemeToken = NonNullable<ThemeConfig["token"]>;
6
+ /**
7
+ * `@stapel/tokens` L2 → antd `theme.token` (frontend-guidelines §2.4 table).
8
+ * Pure: same `mode` in, same object out; reads no globals.
9
+ */
10
+ export declare function toAntdTheme(mode: ThemeMode): AntdThemeToken;
11
+ /**
12
+ * The full antd `ThemeConfig`: {@link toAntdTheme}'s token plus the algorithm
13
+ * that recomputes antd's derived neutrals for the mode (so dark is actually
14
+ * dark, not just dark seeds over a light surface). Pass straight to
15
+ * `<ConfigProvider theme={toAntdThemeConfig(mode)}>`.
16
+ */
17
+ export declare function toAntdThemeConfig(mode: ThemeMode): ThemeConfig;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAYxC,6EAA6E;AAC7E,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAOzC,yEAAyE;AACzE,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,cAAc,CAoB3D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAM9D"}
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * `@stapel/tokens-antd` — the Ant Design leg of the token bridge
3
+ * (frontend-guidelines §2.4, owner decision §38 T3). It translates the ONE
4
+ * neutral role table in `@stapel/tokens` (`bridgeColorRoles` + the radius/
5
+ * font-size roles) into Ant Design's flat `ConfigProvider` theme token. The
6
+ * L2 → role decision is NOT duplicated here — this file only renames roles to
7
+ * antd field names and picks the light/dark half, so it and `@stapel/tokens-mui`
8
+ * cannot drift.
9
+ *
10
+ * ```tsx
11
+ * import { toAntdTheme } from "@stapel/tokens-antd";
12
+ * import { ConfigProvider } from "antd";
13
+ *
14
+ * <ConfigProvider theme={{ token: toAntdTheme(mode) }}>
15
+ * <App />
16
+ * </ConfigProvider>
17
+ * ```
18
+ *
19
+ * For a config that also flips antd's derived neutrals (borders/hovers/fills)
20
+ * to the dark palette — not just the seed tokens — use `toAntdThemeConfig(mode)`
21
+ * and spread it directly: `<ConfigProvider theme={toAntdThemeConfig(mode)}>`.
22
+ */
23
+ import { theme as antdTheme } from "antd";
24
+ import { bridgeColorRoles, bridgeFontSizeRole, bridgeRadiusRole, colors, fontFamily, fontSize, radii, } from "@stapel/tokens";
25
+ /** Resolve a neutral colour role to its hex for `mode` via the shared table. */
26
+ function role(name, mode) {
27
+ return colors[bridgeColorRoles[name]][mode];
28
+ }
29
+ /**
30
+ * `@stapel/tokens` L2 → antd `theme.token` (frontend-guidelines §2.4 table).
31
+ * Pure: same `mode` in, same object out; reads no globals.
32
+ */
33
+ export function toAntdTheme(mode) {
34
+ return {
35
+ colorPrimary: role("brand", mode),
36
+ colorLink: role("link", mode),
37
+ colorLinkHover: role("brandHover", mode),
38
+ colorSuccess: role("success", mode),
39
+ colorWarning: role("warning", mode),
40
+ colorError: role("danger", mode),
41
+ colorInfo: role("info", mode),
42
+ colorText: role("textPrimary", mode),
43
+ colorTextSecondary: role("textSecondary", mode),
44
+ colorBgContainer: role("bgContainer", mode),
45
+ colorBgLayout: role("bgLayout", mode),
46
+ colorBgElevated: role("bgContainer", mode),
47
+ colorBorder: role("border", mode),
48
+ colorBorderSecondary: role("borderSecondary", mode),
49
+ borderRadius: radii[bridgeRadiusRole],
50
+ fontSize: fontSize[bridgeFontSizeRole].fontSize,
51
+ fontFamily: fontFamily.sans,
52
+ };
53
+ }
54
+ /**
55
+ * The full antd `ThemeConfig`: {@link toAntdTheme}'s token plus the algorithm
56
+ * that recomputes antd's derived neutrals for the mode (so dark is actually
57
+ * dark, not just dark seeds over a light surface). Pass straight to
58
+ * `<ConfigProvider theme={toAntdThemeConfig(mode)}>`.
59
+ */
60
+ export function toAntdThemeConfig(mode) {
61
+ return {
62
+ algorithm: mode === "dark" ? antdTheme.darkAlgorithm : antdTheme.defaultAlgorithm,
63
+ token: toAntdTheme(mode),
64
+ };
65
+ }
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,MAAM,EACN,UAAU,EACV,QAAQ,EACR,KAAK,GACN,MAAM,gBAAgB,CAAC;AAMxB,gFAAgF;AAChF,SAAS,IAAI,CAAC,IAAqB,EAAE,IAAe;IAClD,OAAO,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC9C,CAAC;AAKD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAe;IACzC,OAAO;QACL,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC;QACjC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;QAC7B,cAAc,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;QACxC,YAAY,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC;QACnC,YAAY,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC;QACnC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;QAChC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC;QAC7B,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;QACpC,kBAAkB,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC;QAC/C,gBAAgB,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;QAC3C,aAAa,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;QACrC,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;QAC1C,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;QACjC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC;QACnD,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC;QACrC,QAAQ,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,QAAQ;QAC/C,UAAU,EAAE,UAAU,CAAC,IAAI;KAC5B,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAe;IAC/C,OAAO;QACL,SAAS,EACP,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,gBAAgB;QACxE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC;KACzB,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@stapel/tokens-antd",
3
+ "version": "0.1.0",
4
+ "description": "Token bridge (frontend-guidelines §2.4, §38 T3): projects @stapel/tokens L2 core tokens onto an Ant Design ConfigProvider theme. `toAntdTheme(mode)` → theme.token; `toAntdThemeConfig(mode)` → the full ThemeConfig (algorithm + token). Pure functions, one mapping table shared with @stapel/tokens-mui. Not components.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/usestapel/stapel-react.git",
9
+ "directory": "packages/tokens-antd"
10
+ },
11
+ "type": "module",
12
+ "sideEffects": false,
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "src",
25
+ "tsconfig.json",
26
+ "README.md"
27
+ ],
28
+ "size-limit": [
29
+ {
30
+ "path": "dist/index.js",
31
+ "limit": "4 KB"
32
+ }
33
+ ],
34
+ "peerDependencies": {
35
+ "antd": ">=5.20.0 <7"
36
+ },
37
+ "dependencies": {
38
+ "@stapel/tokens": "^0.3.0"
39
+ },
40
+ "devDependencies": {
41
+ "@size-limit/preset-small-lib": "^11.2.0",
42
+ "antd": "^6.5.0",
43
+ "react": "^19.1.0",
44
+ "react-dom": "^19.1.0",
45
+ "size-limit": "^11.2.0",
46
+ "typescript": "^5.8.3",
47
+ "vitest": "^3.2.4"
48
+ },
49
+ "engines": {
50
+ "node": ">=22"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc -p tsconfig.json",
57
+ "test": "vitest run",
58
+ "lint": "eslint .",
59
+ "size": "size-limit"
60
+ }
61
+ }
package/src/index.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * `@stapel/tokens-antd` — the Ant Design leg of the token bridge
3
+ * (frontend-guidelines §2.4, owner decision §38 T3). It translates the ONE
4
+ * neutral role table in `@stapel/tokens` (`bridgeColorRoles` + the radius/
5
+ * font-size roles) into Ant Design's flat `ConfigProvider` theme token. The
6
+ * L2 → role decision is NOT duplicated here — this file only renames roles to
7
+ * antd field names and picks the light/dark half, so it and `@stapel/tokens-mui`
8
+ * cannot drift.
9
+ *
10
+ * ```tsx
11
+ * import { toAntdTheme } from "@stapel/tokens-antd";
12
+ * import { ConfigProvider } from "antd";
13
+ *
14
+ * <ConfigProvider theme={{ token: toAntdTheme(mode) }}>
15
+ * <App />
16
+ * </ConfigProvider>
17
+ * ```
18
+ *
19
+ * For a config that also flips antd's derived neutrals (borders/hovers/fills)
20
+ * to the dark palette — not just the seed tokens — use `toAntdThemeConfig(mode)`
21
+ * and spread it directly: `<ConfigProvider theme={toAntdThemeConfig(mode)}>`.
22
+ */
23
+ import { theme as antdTheme } from "antd";
24
+ import type { ThemeConfig } from "antd";
25
+ import {
26
+ bridgeColorRoles,
27
+ bridgeFontSizeRole,
28
+ bridgeRadiusRole,
29
+ colors,
30
+ fontFamily,
31
+ fontSize,
32
+ radii,
33
+ } from "@stapel/tokens";
34
+ import type { BridgeColorRole } from "@stapel/tokens";
35
+
36
+ /** Light or dark — the half of every L2 core token's `{light,dark}` pair. */
37
+ export type ThemeMode = "light" | "dark";
38
+
39
+ /** Resolve a neutral colour role to its hex for `mode` via the shared table. */
40
+ function role(name: BridgeColorRole, mode: ThemeMode): string {
41
+ return colors[bridgeColorRoles[name]][mode];
42
+ }
43
+
44
+ /** The flat antd token map (`ThemeConfig["token"]`), never undefined. */
45
+ export type AntdThemeToken = NonNullable<ThemeConfig["token"]>;
46
+
47
+ /**
48
+ * `@stapel/tokens` L2 → antd `theme.token` (frontend-guidelines §2.4 table).
49
+ * Pure: same `mode` in, same object out; reads no globals.
50
+ */
51
+ export function toAntdTheme(mode: ThemeMode): AntdThemeToken {
52
+ return {
53
+ colorPrimary: role("brand", mode),
54
+ colorLink: role("link", mode),
55
+ colorLinkHover: role("brandHover", mode),
56
+ colorSuccess: role("success", mode),
57
+ colorWarning: role("warning", mode),
58
+ colorError: role("danger", mode),
59
+ colorInfo: role("info", mode),
60
+ colorText: role("textPrimary", mode),
61
+ colorTextSecondary: role("textSecondary", mode),
62
+ colorBgContainer: role("bgContainer", mode),
63
+ colorBgLayout: role("bgLayout", mode),
64
+ colorBgElevated: role("bgContainer", mode),
65
+ colorBorder: role("border", mode),
66
+ colorBorderSecondary: role("borderSecondary", mode),
67
+ borderRadius: radii[bridgeRadiusRole],
68
+ fontSize: fontSize[bridgeFontSizeRole].fontSize,
69
+ fontFamily: fontFamily.sans,
70
+ };
71
+ }
72
+
73
+ /**
74
+ * The full antd `ThemeConfig`: {@link toAntdTheme}'s token plus the algorithm
75
+ * that recomputes antd's derived neutrals for the mode (so dark is actually
76
+ * dark, not just dark seeds over a light surface). Pass straight to
77
+ * `<ConfigProvider theme={toAntdThemeConfig(mode)}>`.
78
+ */
79
+ export function toAntdThemeConfig(mode: ThemeMode): ThemeConfig {
80
+ return {
81
+ algorithm:
82
+ mode === "dark" ? antdTheme.darkAlgorithm : antdTheme.defaultAlgorithm,
83
+ token: toAntdTheme(mode),
84
+ };
85
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "_comment": "Self-contained on purpose: standalone-buildable per frontend-standard §7. Mirrors the root tsconfig.base.json settings.",
4
+ "compilerOptions": {
5
+ "target": "ES2022",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "module": "ESNext",
8
+ "moduleResolution": "bundler",
9
+ "jsx": "react-jsx",
10
+ "strict": true,
11
+ "noUncheckedIndexedAccess": true,
12
+ "noImplicitOverride": true,
13
+ "exactOptionalPropertyTypes": true,
14
+ "isolatedModules": true,
15
+ "isolatedDeclarations": true,
16
+ "verbatimModuleSyntax": true,
17
+ "declaration": true,
18
+ "declarationMap": true,
19
+ "sourceMap": true,
20
+ "skipLibCheck": true,
21
+ "forceConsistentCasingInFileNames": true,
22
+ "outDir": "dist",
23
+ "rootDir": "src"
24
+ },
25
+ "include": ["src"]
26
+ }