@stapel/tokens-mui 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,41 @@
1
+ # @stapel/tokens-mui
2
+
3
+ The Material UI leg of the **token bridge** (frontend-guidelines §2.4; owner
4
+ decision §38 T3). It projects `@stapel/tokens` L2 core tokens onto a MUI `Theme`
5
+ — the explicit Material alternative to `@stapel/tokens-antd` (§2.3).
6
+
7
+ There is exactly **one** L2 → design-system role mapping table, and it lives in
8
+ `@stapel/tokens` (`bridgeColorRoles` + the radius/font-size roles). This package
9
+ only renames those neutral roles to MUI's nested `palette`/`shape`/`typography`
10
+ fields and picks the `light`/`dark` half — it holds no colour decisions of its
11
+ own, so it and `@stapel/tokens-antd` cannot drift.
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { toMuiTheme } from "@stapel/tokens-mui";
17
+ import { ThemeProvider, CssBaseline } from "@mui/material";
18
+
19
+ <ThemeProvider theme={toMuiTheme(mode)}>
20
+ <CssBaseline />
21
+ <App />
22
+ </ThemeProvider>;
23
+ ```
24
+
25
+ ## The mapping (frontend-guidelines §2.4)
26
+
27
+ | `@stapel/tokens` role | L2 core token | MUI theme field |
28
+ | --- | --- | --- |
29
+ | `brand` | `accent` | `palette.primary.main` |
30
+ | `success` | `text-positive` | `palette.success.main` |
31
+ | `warning` | `text-warning` | `palette.warning.main` |
32
+ | `danger` | `text-negative` | `palette.error.main` |
33
+ | `info` | `text-info` | `palette.info.main` |
34
+ | `bgContainer` | `upperground-primary` | `palette.background.paper` |
35
+ | `bgLayout` | `background-primary` | `palette.background.default` |
36
+ | `textPrimary` | `text-primary` | `palette.text.primary` |
37
+ | radius `md` | — | `shape.borderRadius` |
38
+ | font-size `md` | — | `typography.fontSize` |
39
+
40
+ `@mui/material` (and its `@emotion/*` peers) are peer dependencies — the
41
+ consuming app brings its own copy.
@@ -0,0 +1,9 @@
1
+ import type { Theme } from "@mui/material/styles";
2
+ /** Light or dark — the half of every L2 core token's `{light,dark}` pair. */
3
+ export type ThemeMode = "light" | "dark";
4
+ /**
5
+ * `@stapel/tokens` L2 → a MUI `Theme` (frontend-guidelines §2.4 table). Pure:
6
+ * same `mode` in, an equivalent theme out; reads no globals.
7
+ */
8
+ export declare function toMuiTheme(mode: ThemeMode): Theme;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAYlD,6EAA6E;AAC7E,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAOzC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,CA2BjD"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * `@stapel/tokens-mui` — the Material UI 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 a MUI `Theme`. The L2 → role decision is NOT duplicated
6
+ * here — this file only renames roles to MUI's nested `palette`/`shape`/
7
+ * `typography` fields and picks the light/dark half, so it and
8
+ * `@stapel/tokens-antd` cannot drift.
9
+ *
10
+ * ```tsx
11
+ * import { toMuiTheme } from "@stapel/tokens-mui";
12
+ * import { ThemeProvider, CssBaseline } from "@mui/material";
13
+ *
14
+ * <ThemeProvider theme={toMuiTheme(mode)}>
15
+ * <CssBaseline />
16
+ * <App />
17
+ * </ThemeProvider>
18
+ * ```
19
+ */
20
+ import { createTheme } from "@mui/material/styles";
21
+ import { bridgeColorRoles, bridgeFontSizeRole, bridgeRadiusRole, colors, fontFamily, fontSize, radii, } from "@stapel/tokens";
22
+ /** Resolve a neutral colour role to its hex for `mode` via the shared table. */
23
+ function role(name, mode) {
24
+ return colors[bridgeColorRoles[name]][mode];
25
+ }
26
+ /**
27
+ * `@stapel/tokens` L2 → a MUI `Theme` (frontend-guidelines §2.4 table). Pure:
28
+ * same `mode` in, an equivalent theme out; reads no globals.
29
+ */
30
+ export function toMuiTheme(mode) {
31
+ return createTheme({
32
+ palette: {
33
+ mode,
34
+ primary: { main: role("brand", mode), contrastText: role("textOnBrand", mode) },
35
+ success: { main: role("success", mode) },
36
+ warning: { main: role("warning", mode) },
37
+ error: { main: role("danger", mode) },
38
+ info: { main: role("info", mode) },
39
+ text: {
40
+ primary: role("textPrimary", mode),
41
+ secondary: role("textSecondary", mode),
42
+ },
43
+ background: {
44
+ default: role("bgLayout", mode),
45
+ paper: role("bgContainer", mode),
46
+ },
47
+ divider: role("border", mode),
48
+ },
49
+ shape: {
50
+ borderRadius: radii[bridgeRadiusRole],
51
+ },
52
+ typography: {
53
+ fontFamily: fontFamily.sans,
54
+ fontSize: fontSize[bridgeFontSizeRole].fontSize,
55
+ },
56
+ });
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,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;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAe;IACxC,OAAO,WAAW,CAAC;QACjB,OAAO,EAAE;YACP,IAAI;YACJ,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,EAAE;YAC/E,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE;YACxC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE;YACxC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE;YACrC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;YAClC,IAAI,EAAE;gBACJ,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;gBAClC,SAAS,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC;aACvC;YACD,UAAU,EAAE;gBACV,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;gBAC/B,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC;aACjC;YACD,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;SAC9B;QACD,KAAK,EAAE;YACL,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC;SACtC;QACD,UAAU,EAAE;YACV,UAAU,EAAE,UAAU,CAAC,IAAI;YAC3B,QAAQ,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,QAAQ;SAChD;KACF,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@stapel/tokens-mui",
3
+ "version": "0.1.0",
4
+ "description": "Token bridge (frontend-guidelines §2.4, §38 T3): projects @stapel/tokens L2 core tokens onto a Material UI theme. `toMuiTheme(mode)` → a MUI Theme (createTheme). Pure function, one mapping table shared with @stapel/tokens-antd. Not components.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/usestapel/stapel-react.git",
9
+ "directory": "packages/tokens-mui"
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": "3 KB"
32
+ }
33
+ ],
34
+ "peerDependencies": {
35
+ "@mui/material": ">=5.15.0 <8"
36
+ },
37
+ "dependencies": {
38
+ "@stapel/tokens": "^0.3.0"
39
+ },
40
+ "devDependencies": {
41
+ "@emotion/react": "^11.14.0",
42
+ "@emotion/styled": "^11.14.0",
43
+ "@mui/material": "^7.3.0",
44
+ "@size-limit/preset-small-lib": "^11.2.0",
45
+ "react": "^19.1.0",
46
+ "react-dom": "^19.1.0",
47
+ "size-limit": "^11.2.0",
48
+ "typescript": "^5.8.3",
49
+ "vitest": "^3.2.4"
50
+ },
51
+ "engines": {
52
+ "node": ">=22"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "scripts": {
58
+ "build": "tsc -p tsconfig.json",
59
+ "test": "vitest run",
60
+ "lint": "eslint .",
61
+ "size": "size-limit"
62
+ }
63
+ }
package/src/index.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `@stapel/tokens-mui` — the Material UI 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 a MUI `Theme`. The L2 → role decision is NOT duplicated
6
+ * here — this file only renames roles to MUI's nested `palette`/`shape`/
7
+ * `typography` fields and picks the light/dark half, so it and
8
+ * `@stapel/tokens-antd` cannot drift.
9
+ *
10
+ * ```tsx
11
+ * import { toMuiTheme } from "@stapel/tokens-mui";
12
+ * import { ThemeProvider, CssBaseline } from "@mui/material";
13
+ *
14
+ * <ThemeProvider theme={toMuiTheme(mode)}>
15
+ * <CssBaseline />
16
+ * <App />
17
+ * </ThemeProvider>
18
+ * ```
19
+ */
20
+ import { createTheme } from "@mui/material/styles";
21
+ import type { Theme } from "@mui/material/styles";
22
+ import {
23
+ bridgeColorRoles,
24
+ bridgeFontSizeRole,
25
+ bridgeRadiusRole,
26
+ colors,
27
+ fontFamily,
28
+ fontSize,
29
+ radii,
30
+ } from "@stapel/tokens";
31
+ import type { BridgeColorRole } from "@stapel/tokens";
32
+
33
+ /** Light or dark — the half of every L2 core token's `{light,dark}` pair. */
34
+ export type ThemeMode = "light" | "dark";
35
+
36
+ /** Resolve a neutral colour role to its hex for `mode` via the shared table. */
37
+ function role(name: BridgeColorRole, mode: ThemeMode): string {
38
+ return colors[bridgeColorRoles[name]][mode];
39
+ }
40
+
41
+ /**
42
+ * `@stapel/tokens` L2 → a MUI `Theme` (frontend-guidelines §2.4 table). Pure:
43
+ * same `mode` in, an equivalent theme out; reads no globals.
44
+ */
45
+ export function toMuiTheme(mode: ThemeMode): Theme {
46
+ return createTheme({
47
+ palette: {
48
+ mode,
49
+ primary: { main: role("brand", mode), contrastText: role("textOnBrand", mode) },
50
+ success: { main: role("success", mode) },
51
+ warning: { main: role("warning", mode) },
52
+ error: { main: role("danger", mode) },
53
+ info: { main: role("info", mode) },
54
+ text: {
55
+ primary: role("textPrimary", mode),
56
+ secondary: role("textSecondary", mode),
57
+ },
58
+ background: {
59
+ default: role("bgLayout", mode),
60
+ paper: role("bgContainer", mode),
61
+ },
62
+ divider: role("border", mode),
63
+ },
64
+ shape: {
65
+ borderRadius: radii[bridgeRadiusRole],
66
+ },
67
+ typography: {
68
+ fontFamily: fontFamily.sans,
69
+ fontSize: fontSize[bridgeFontSizeRole].fontSize,
70
+ },
71
+ });
72
+ }
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
+ }