@revikornmann/muka-ui 0.35.1 → 0.37.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.
Files changed (105) hide show
  1. package/cli/bin/muka-ui.js +18 -0
  2. package/cli/commands/check.js +174 -0
  3. package/cli/commands/init.js +8 -20
  4. package/cli/commands/install-skill.js +37 -26
  5. package/cli/commands/sync.js +90 -0
  6. package/cli/lib/agents-block.js +139 -0
  7. package/cli/lib/skills.js +182 -0
  8. package/cli/templates/{AGENTS.md → agents-block.md} +53 -16
  9. package/dist/cjs/components/Dialog/Dialog.css +10 -0
  10. package/dist/cjs/components/Dialog/Dialog.js +58 -48
  11. package/dist/cjs/components/Dialog/Dialog.js.map +1 -1
  12. package/dist/cjs/components/Dialog/index.js +5 -1
  13. package/dist/cjs/components/Dialog/index.js.map +1 -1
  14. package/dist/cjs/components/Drawer/Drawer.css +4 -24
  15. package/dist/cjs/components/Drawer/Drawer.js +20 -10
  16. package/dist/cjs/components/Drawer/Drawer.js.map +1 -1
  17. package/dist/cjs/components/NumberInput/NumberInput.js +88 -3
  18. package/dist/cjs/components/NumberInput/NumberInput.js.map +1 -1
  19. package/dist/cjs/components/Table/Table.css +12 -0
  20. package/dist/cjs/components/Table/Table.js +2 -1
  21. package/dist/cjs/components/Table/Table.js.map +1 -1
  22. package/dist/cjs/components/Toggle/Toggle.js +2 -2
  23. package/dist/cjs/components/Toggle/Toggle.js.map +1 -1
  24. package/dist/cjs/components/TopBar/TopBar.css +11 -10
  25. package/dist/cjs/components/TopBar/TopBar.js +33 -3
  26. package/dist/cjs/components/TopBar/TopBar.js.map +1 -1
  27. package/dist/cjs/components/View/View.js +11 -12
  28. package/dist/cjs/components/View/View.js.map +1 -1
  29. package/dist/cjs/components/index.js +6 -3
  30. package/dist/cjs/components/index.js.map +1 -1
  31. package/dist/cjs/utils/useDismissGuard.js +85 -0
  32. package/dist/cjs/utils/useDismissGuard.js.map +1 -0
  33. package/dist/esm/components/Dialog/Dialog.css +10 -0
  34. package/dist/esm/components/Dialog/Dialog.js +57 -49
  35. package/dist/esm/components/Dialog/Dialog.js.map +1 -1
  36. package/dist/esm/components/Dialog/index.js +2 -1
  37. package/dist/esm/components/Dialog/index.js.map +1 -1
  38. package/dist/esm/components/Drawer/Drawer.css +4 -24
  39. package/dist/esm/components/Drawer/Drawer.js +21 -11
  40. package/dist/esm/components/Drawer/Drawer.js.map +1 -1
  41. package/dist/esm/components/NumberInput/NumberInput.js +88 -3
  42. package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
  43. package/dist/esm/components/Table/Table.css +12 -0
  44. package/dist/esm/components/Table/Table.js +2 -1
  45. package/dist/esm/components/Table/Table.js.map +1 -1
  46. package/dist/esm/components/Toggle/Toggle.js +2 -2
  47. package/dist/esm/components/Toggle/Toggle.js.map +1 -1
  48. package/dist/esm/components/TopBar/TopBar.css +11 -10
  49. package/dist/esm/components/TopBar/TopBar.js +30 -3
  50. package/dist/esm/components/TopBar/TopBar.js.map +1 -1
  51. package/dist/esm/components/View/View.js +11 -12
  52. package/dist/esm/components/View/View.js.map +1 -1
  53. package/dist/esm/components/index.js +1 -1
  54. package/dist/esm/components/index.js.map +1 -1
  55. package/dist/esm/utils/useDismissGuard.js +79 -0
  56. package/dist/esm/utils/useDismissGuard.js.map +1 -0
  57. package/dist/styles/components/Dialog.css +10 -0
  58. package/dist/styles/components/Drawer.css +4 -24
  59. package/dist/styles/components/Table.css +12 -0
  60. package/dist/styles/index.css +874 -858
  61. package/dist/styles/muka-dark.css +874 -858
  62. package/dist/styles/muka-light.css +874 -858
  63. package/dist/styles/tokens-bouwplan-dark.css +2 -0
  64. package/dist/styles/tokens-bouwplan-light.css +2 -0
  65. package/dist/styles/tokens-fscl-dark.css +2 -0
  66. package/dist/styles/tokens-fscl-light.css +2 -0
  67. package/dist/styles/tokens-grip-dark.css +2 -0
  68. package/dist/styles/tokens-grip-light.css +2 -0
  69. package/dist/styles/tokens-muka-dark.css +2 -0
  70. package/dist/styles/tokens-muka-light.css +2 -0
  71. package/dist/styles/tokens-wireframe-dark.css +2 -0
  72. package/dist/styles/tokens-wireframe-light.css +2 -0
  73. package/dist/styles/wireframe-dark.css +874 -858
  74. package/dist/styles/wireframe-light.css +874 -858
  75. package/dist/types/components/Dialog/Dialog.d.ts +51 -11
  76. package/dist/types/components/Dialog/Dialog.d.ts.map +1 -1
  77. package/dist/types/components/Dialog/index.d.ts +2 -1
  78. package/dist/types/components/Dialog/index.d.ts.map +1 -1
  79. package/dist/types/components/Drawer/Drawer.d.ts +35 -5
  80. package/dist/types/components/Drawer/Drawer.d.ts.map +1 -1
  81. package/dist/types/components/NumberInput/NumberInput.d.ts +9 -0
  82. package/dist/types/components/NumberInput/NumberInput.d.ts.map +1 -1
  83. package/dist/types/components/Table/Table.d.ts +7 -0
  84. package/dist/types/components/Table/Table.d.ts.map +1 -1
  85. package/dist/types/components/Toggle/Toggle.d.ts +6 -0
  86. package/dist/types/components/Toggle/Toggle.d.ts.map +1 -1
  87. package/dist/types/components/TopBar/TopBar.d.ts +12 -1
  88. package/dist/types/components/TopBar/TopBar.d.ts.map +1 -1
  89. package/dist/types/components/View/View.d.ts +4 -3
  90. package/dist/types/components/View/View.d.ts.map +1 -1
  91. package/dist/types/components/index.d.ts +1 -1
  92. package/dist/types/components/index.d.ts.map +1 -1
  93. package/dist/types/utils/useDismissGuard.d.ts +68 -0
  94. package/dist/types/utils/useDismissGuard.d.ts.map +1 -0
  95. package/docs/consumers/README.md +6 -2
  96. package/docs/consumers/dialogs.md +102 -0
  97. package/docs/consumers/setup-instructions.md +55 -9
  98. package/docs/consumers/skills.md +29 -13
  99. package/eslint/index.js +284 -0
  100. package/package.json +14 -2
  101. package/skills/setup-muka/SKILL.md +59 -7
  102. package/templates/muka-check.yml +45 -0
  103. package/templates/update-muka.yml +17 -4
  104. package/tokens/t4-components/table.json +13 -0
  105. package/cli/templates/CLAUDE.md +0 -15
@@ -148,8 +148,9 @@ cp node_modules/@revikornmann/muka-ui/templates/update-muka.yml \
148
148
  .github/workflows/update-muka.yml
149
149
  ```
150
150
 
151
- This workflow listens for the `muka-released` dispatch and installs the exact
152
- published version. You can also run it manually from the Actions tab
151
+ This workflow listens for the `muka-released` dispatch, installs the exact
152
+ published version, and refreshes the Muka rules in `AGENTS.md`
153
+ (`npx muka-ui sync`, see step 5). You can also run it manually from the Actions tab
153
154
  (installs `@latest`). The package is public, so it needs no secrets to install.
154
155
 
155
156
  The workflow auto-detects your package manager from the lockfile
@@ -181,14 +182,56 @@ for the `repository_dispatch` to succeed.
181
182
  npx muka-ui init
182
183
  ```
183
184
 
184
- Writes `AGENTS.md`, `CLAUDE.md`, and `docs/muka-ui-guidelines.md` into your repo
185
- (prompting before overwriting any of them), so agents working here compose Muka
186
- components and use token custom properties instead of inventing markup and
187
- hardcoding values. It also warns about styling libraries that conflict with Muka.
185
+ This writes the Muka rules into `AGENTS.md`, inside a marked block, makes
186
+ `CLAUDE.md` import it (`@AGENTS.md`), and writes `docs/muka-ui-guidelines.md`. It
187
+ also warns about styling libraries that conflict with Muka.
188
188
 
189
- `AGENTS.md` holds the rules, because that filename is the vendor-neutral
190
- convention most agents read. `CLAUDE.md` is a few lines pointing at it, so Claude
191
- Code finds them too without a second copy that can drift.
189
+ - **One file for every agent.** `AGENTS.md` is the filename Codex, Cursor,
190
+ Copilot and most other agents read; Claude Code reads it through the import.
191
+ There is no second copy to drift.
192
+ - **Kept current.** Muka owns only the block between `<!-- muka-ui:start -->`
193
+ and `<!-- muka-ui:end -->`. `npx muka-ui sync` rewrites it for the installed
194
+ version, and the auto-update workflow runs it on every bump. Put the repo's
195
+ own rules outside the block; they are never touched.
196
+
197
+ ## 6. Check the rules in CI
198
+
199
+ Written rules only hold while an agent reads them. `npx muka-ui check` lints the
200
+ source with Muka's ESLint rules and fails on Tailwind classes, CSS modules or
201
+ CSS-in-JS, hard-coded colours or pixel sizes in `style`, raw `<button>`,
202
+ `<dialog>`, `<select>` and `<textarea>`, and a Cancel in a `Dialog` or `Drawer`
203
+ footer that skips `DismissButton`. It also fails when `AGENTS.md` is behind the
204
+ installed version. It needs ESLint 9 and the TypeScript parser:
205
+
206
+ ```bash
207
+ npm install --save-dev eslint typescript-eslint
208
+ mkdir -p .github/workflows
209
+ cp node_modules/@revikornmann/muka-ui/templates/muka-check.yml \
210
+ .github/workflows/muka-check.yml
211
+ ```
212
+
213
+ The workflow runs the check on every pull request, whichever agent or person
214
+ wrote the code. A repo with its own ESLint setup can also add the rules there:
215
+
216
+ ```js
217
+ // eslint.config.mjs
218
+ import muka from '@revikornmann/muka-ui/eslint';
219
+ export default [/* your config */, ...muka.configs.recommended];
220
+ ```
221
+
222
+ A line that must break a rule gets
223
+ `// eslint-disable-next-line muka/<rule> -- reason`.
224
+
225
+ Adopting the check in a repo that already has violations? Record them once and
226
+ commit the result, so CI fails only on new ones while the old ones are cleaned
227
+ up:
228
+
229
+ ```bash
230
+ npx muka-ui check --update-baseline # writes .muka-check-baseline.json
231
+ ```
232
+
233
+ Re-run it after a cleanup so the baseline shrinks; never to let a new problem
234
+ through.
192
235
 
193
236
  ## Verify
194
237
 
@@ -197,6 +240,9 @@ Code finds them too without a second copy that can drift.
197
240
  - A component's computed `background-color` resolves to a real colour rather than
198
241
  falling back — that is the check that the token CSS actually loaded.
199
242
  - `.github/workflows/update-muka.yml` exists and is valid YAML.
243
+ - `AGENTS.md` has a `<!-- muka-ui:start` block and `CLAUDE.md` starts with
244
+ `@AGENTS.md`.
245
+ - `npx muka-ui check` passes, and `.github/workflows/muka-check.yml` exists.
200
246
 
201
247
  ## Next
202
248
 
@@ -6,8 +6,8 @@ a design into code, syncing tokens with Figma — into one command each.
6
6
 
7
7
  ## Installing them
8
8
 
9
- Agents discover skills under `.claude/skills/`, never inside `node_modules/`, so
10
- the package ships them and the CLI copies them in:
9
+ Agents discover skills in your repo, never inside `node_modules/`, so the package
10
+ ships them and the CLI copies them in:
11
11
 
12
12
  ```bash
13
13
  npx muka-ui install-skill # install all of them
@@ -15,23 +15,39 @@ npx muka-ui install-skill --list # see what's available first
15
15
  npx muka-ui install-skill add-brand figma-to-code # install specific ones
16
16
  ```
17
17
 
18
- Restart your agent afterwards so it picks up the new slash commands. Re-run the
19
- same command after a Muka upgrade to refresh them; it skips anything already
20
- identical and prompts before overwriting local edits.
18
+ Restart your agent afterwards so it picks up the new slash commands.
19
+
20
+ ## One copy, kept current
21
+
22
+ - **The files live in `.agents/skills/<name>/`**, the vendor-neutral location.
23
+ - **`.claude/skills/<name>` is a symlink to it**, because Claude Code and Cursor
24
+ read that path. Where symlinks aren't available (Windows without the
25
+ permission) it is a copy instead.
26
+ - **`.agents/skills/.muka-skills.json`** records which skills came from Muka and
27
+ what was installed. Commit all three.
28
+ - **`npx muka-ui sync` refreshes them** to the installed version, and the
29
+ auto-update workflow runs it on every bump. A skill you edited in the repo is
30
+ left alone and reported; `npx muka-ui install-skill <name>` replaces it with
31
+ the shipped version when you want that.
32
+ - **Your own skills are never touched**, in either directory.
33
+
34
+ Installed skills with an older `install-skill`? Those are plain copies in
35
+ `.claude/skills/`. Run `npx muka-ui install-skill` once: it asks before
36
+ replacing each copy, then moves it to `.agents/skills/` where `sync` keeps it
37
+ current.
21
38
 
22
39
  ## Which agents can use them
23
40
 
24
- The directory name is Claude's, but the contents are not: a skill is a plain
25
- markdown file with YAML frontmatter, and `.claude/skills/` is scanned by **Claude
26
- Code and Cursor** alike. For an agent that reads neither, the skills still work
27
- as documentation — point it at `.claude/skills/<name>/SKILL.md` and it has the
28
- same instructions, just without a slash command to trigger them.
41
+ A skill is a plain markdown file with YAML frontmatter, so it isn't tied to one
42
+ agent. Claude Code and Cursor find them through `.claude/skills/`; agents that
43
+ read `.agents/skills/` find the same files there. For an agent that reads
44
+ neither, point it at `.agents/skills/<name>/SKILL.md`: it has the same
45
+ instructions, just without a slash command to trigger them.
29
46
 
30
47
  Nothing else Muka ships is agent-specific. The tokens are CSS custom properties,
31
48
  the components are React, and these consumer docs are prose — none of that cares
32
- what is editing your repo. `npx muka-ui init` writes the house rules to
33
- `AGENTS.md`, the vendor-neutral convention, and leaves a short `CLAUDE.md`
34
- pointing at it.
49
+ what is editing your repo. The house rules live in `AGENTS.md`, which every agent
50
+ reads, and `CLAUDE.md` imports it.
35
51
 
36
52
  ## The skills
37
53
 
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Muka UI ESLint plugin: the consumer guardrails from AGENTS.md as code, so
3
+ * they hold whichever agent (or person) writes the code.
4
+ *
5
+ * // eslint.config.mjs
6
+ * import muka from '@revikornmann/muka-ui/eslint';
7
+ * export default [...muka.configs.recommended];
8
+ *
9
+ * Or without an ESLint setup of your own: `npx muka-ui check`.
10
+ */
11
+
12
+ const pkg = require('../package.json');
13
+
14
+ // ─── helpers ────────────────────────────────────────────
15
+
16
+ /** Tailwind utilities: a variant prefix (md:, hover:) and a known utility. */
17
+ const TAILWIND_EXACT = new Set([
18
+ 'flex', 'inline-flex', 'grid', 'inline-grid', 'block', 'inline-block', 'inline',
19
+ 'hidden', 'contents', 'relative', 'absolute', 'fixed', 'sticky', 'static',
20
+ 'truncate', 'italic', 'underline', 'uppercase', 'lowercase', 'capitalize',
21
+ 'grow', 'shrink', 'container', 'border', 'rounded', 'shadow',
22
+ ]);
23
+ const TAILWIND_PREFIX = new RegExp(
24
+ '^(?:' +
25
+ [
26
+ 'p[xytrblse]?', 'm[xytrblse]?', 'gap(?:-[xy])?', 'space-[xy]',
27
+ 'w', 'h', 'size', 'min-[wh]', 'max-[wh]', 'inset(?:-[xy])?', 'top', 'right', 'bottom', 'left', 'z',
28
+ 'order', 'basis', 'text', 'font', 'leading', 'tracking', 'bg', 'from', 'via', 'to',
29
+ 'border(?:-[xytrblse])?', 'rounded(?:-[a-z]+)?', 'shadow', 'ring', 'opacity',
30
+ 'items', 'justify', 'content', 'self', 'place-[a-z]+', 'grid-(?:cols|rows)', 'col-span', 'row-span',
31
+ 'flex', 'overflow(?:-[xy])?', 'object', 'cursor', 'translate-[xy]', 'scale', 'rotate',
32
+ 'duration', 'ease', 'transition', 'fill', 'stroke', 'outline', 'divide-[xy]', 'aspect',
33
+ 'line-clamp', 'decoration', 'whitespace', 'break',
34
+ ].join('|') +
35
+ ')-[A-Za-z0-9.[\\]/%#:_-]+$'
36
+ );
37
+
38
+ function tailwindClass(token) {
39
+ const core = token.replace(/^(?:[a-z0-9-]+:)+/, '').replace(/^!/, '').replace(/^-/, '');
40
+ if (!core) return false;
41
+ return TAILWIND_EXACT.has(core) || TAILWIND_PREFIX.test(core);
42
+ }
43
+
44
+ /** Static text of a string literal or template literal, else null. */
45
+ function staticText(node) {
46
+ if (!node) return null;
47
+ if (node.type === 'Literal' && typeof node.value === 'string') return node.value;
48
+ if (node.type === 'TemplateLiteral') return node.quasis.map((q) => q.value.cooked).join(' ');
49
+ return null;
50
+ }
51
+
52
+ const HARD_COLOUR = /#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?)\(/;
53
+ const HARD_LENGTH = /(?:^|[^\w-])-?(?:\d*\.)?\d+(?:px|rem|em)\b/;
54
+ /** Style properties whose bare numbers mean pixels. */
55
+ const PX_PROPS = /^(?:padding|margin|gap|rowGap|columnGap|fontSize|borderRadius|inset|top|right|bottom|left)/;
56
+
57
+ /** A raw element and the Muka component to use instead. */
58
+ const RAW_ELEMENTS = {
59
+ button: 'Button (or TextLink for a link)',
60
+ dialog: 'Dialog or Drawer',
61
+ select: 'Select or DropdownSelect',
62
+ textarea: 'Textarea',
63
+ };
64
+
65
+ const propName = (prop) =>
66
+ prop.key && (prop.key.type === 'Identifier' ? prop.key.name : prop.key.value);
67
+
68
+ function jsxName(node) {
69
+ const n = node && node.name;
70
+ if (!n) return null;
71
+ if (n.type === 'JSXIdentifier') return n.name;
72
+ if (n.type === 'JSXMemberExpression') return n.property.name;
73
+ return null;
74
+ }
75
+
76
+ function attr(openingElement, name) {
77
+ return openingElement.attributes.find(
78
+ (a) => a.type === 'JSXAttribute' && a.name && a.name.name === name
79
+ );
80
+ }
81
+
82
+ /** Every JSXElement inside `node` (not crossing into functions). */
83
+ function* jsxElements(node) {
84
+ if (!node || typeof node.type !== 'string') return;
85
+ if (node.type === 'JSXElement') yield node;
86
+ for (const key of Object.keys(node)) {
87
+ if (key === 'parent') continue;
88
+ const value = node[key];
89
+ if (Array.isArray(value)) for (const v of value) yield* jsxElements(v);
90
+ else if (value && typeof value.type === 'string') yield* jsxElements(value);
91
+ }
92
+ }
93
+
94
+ // ─── rules ──────────────────────────────────────────────
95
+
96
+ const rules = {
97
+ 'no-tailwind-classes': {
98
+ meta: {
99
+ type: 'problem',
100
+ docs: { description: 'Style with Muka components and tokens, not Tailwind utilities.' },
101
+ messages: {
102
+ tailwind:
103
+ '"{{token}}" is a Tailwind utility. Use a Muka component, or layout with `style` and `var(--…)` tokens.',
104
+ },
105
+ schema: [],
106
+ },
107
+ create(context) {
108
+ return {
109
+ JSXAttribute(node) {
110
+ if (!node.name || node.name.name !== 'className' || !node.value) return;
111
+ const value = node.value.type === 'JSXExpressionContainer' ? node.value.expression : node.value;
112
+ const text = staticText(value);
113
+ if (!text) return;
114
+ for (const token of text.split(/\s+/)) {
115
+ if (tailwindClass(token)) {
116
+ context.report({ node, messageId: 'tailwind', data: { token } });
117
+ return;
118
+ }
119
+ }
120
+ },
121
+ };
122
+ },
123
+ },
124
+
125
+ 'no-other-styling': {
126
+ meta: {
127
+ type: 'problem',
128
+ docs: { description: 'Style with Muka components and tokens, not CSS modules, styled-components or Emotion.' },
129
+ messages: {
130
+ cssModule: 'CSS modules are not used with Muka UI. Use a Muka component or token-based `style`.',
131
+ cssInJs: '`{{source}}` is not used with Muka UI. Use a Muka component or token-based `style`.',
132
+ },
133
+ schema: [],
134
+ },
135
+ create(context) {
136
+ return {
137
+ ImportDeclaration(node) {
138
+ const source = node.source.value;
139
+ if (/\.module\.(?:css|scss|sass|less)$/.test(source)) {
140
+ context.report({ node, messageId: 'cssModule' });
141
+ } else if (/^(?:styled-components|@emotion\/(?:styled|react|css))$/.test(source)) {
142
+ context.report({ node, messageId: 'cssInJs', data: { source } });
143
+ }
144
+ },
145
+ };
146
+ },
147
+ },
148
+
149
+ 'no-raw-style-values': {
150
+ meta: {
151
+ type: 'problem',
152
+ docs: { description: 'Inline styles use Muka tokens, not hard-coded colours or pixel sizes.' },
153
+ messages: {
154
+ colour: '`{{prop}}` has a hard-coded colour. Use a colour token, e.g. `var(--color-text-default-default)`.',
155
+ length: '`{{prop}}` has a hard-coded size. Use a token, e.g. `var(--spacing-4)`.',
156
+ },
157
+ schema: [],
158
+ },
159
+ create(context) {
160
+ return {
161
+ JSXAttribute(node) {
162
+ if (!node.name || node.name.name !== 'style' || !node.value) return;
163
+ const expr = node.value.expression;
164
+ if (!expr || expr.type !== 'ObjectExpression') return;
165
+ for (const prop of expr.properties) {
166
+ if (prop.type !== 'Property') continue;
167
+ const name = propName(prop);
168
+ const v = prop.value;
169
+ if (v.type === 'Literal' && typeof v.value === 'number') {
170
+ if (v.value !== 0 && PX_PROPS.test(String(name))) {
171
+ context.report({ node: prop, messageId: 'length', data: { prop: name } });
172
+ }
173
+ continue;
174
+ }
175
+ const text = staticText(v);
176
+ if (text == null) continue;
177
+ // A var() fallback is part of the token reference, not a raw value.
178
+ const bare = text.replace(/var\([^)]*\)/g, '');
179
+ if (HARD_COLOUR.test(bare)) {
180
+ context.report({ node: prop, messageId: 'colour', data: { prop: name } });
181
+ } else if (HARD_LENGTH.test(bare)) {
182
+ context.report({ node: prop, messageId: 'length', data: { prop: name } });
183
+ }
184
+ }
185
+ },
186
+ };
187
+ },
188
+ },
189
+
190
+ 'no-raw-elements': {
191
+ meta: {
192
+ type: 'problem',
193
+ docs: { description: 'Use the Muka component where one exists.' },
194
+ messages: { raw: 'Use Muka {{component}} instead of a raw <{{element}}>.' },
195
+ schema: [
196
+ {
197
+ type: 'object',
198
+ properties: { allow: { type: 'array', items: { type: 'string' } } },
199
+ additionalProperties: false,
200
+ },
201
+ ],
202
+ },
203
+ create(context) {
204
+ const allow = new Set((context.options[0] && context.options[0].allow) || []);
205
+ return {
206
+ JSXOpeningElement(node) {
207
+ const name = node.name.type === 'JSXIdentifier' ? node.name.name : null;
208
+ if (name && RAW_ELEMENTS[name] && !allow.has(name)) {
209
+ context.report({ node, messageId: 'raw', data: { element: name, component: RAW_ELEMENTS[name] } });
210
+ }
211
+ },
212
+ };
213
+ },
214
+ },
215
+
216
+ 'dismiss-button-for-cancel': {
217
+ meta: {
218
+ type: 'problem',
219
+ docs: {
220
+ description:
221
+ 'A Cancel in a Dialog or Drawer footer goes through DismissButton, so a modal with unsaved changes asks to discard them.',
222
+ },
223
+ messages: {
224
+ dismiss:
225
+ 'This Button closes the {{overlay}} with `onClose` directly and skips the unsaved-changes guard. Use `DismissButton`.',
226
+ },
227
+ schema: [],
228
+ },
229
+ create(context) {
230
+ const source = context.sourceCode || context.getSourceCode();
231
+ const text = (node) => source.getText(node).replace(/\s+/g, '');
232
+ return {
233
+ JSXElement(node) {
234
+ const overlay = jsxName(node.openingElement);
235
+ if (overlay !== 'Dialog' && overlay !== 'Drawer') return;
236
+ const onClose = attr(node.openingElement, 'onClose');
237
+ if (!onClose || !onClose.value || onClose.value.type !== 'JSXExpressionContainer') return;
238
+ const closeText = text(onClose.value.expression);
239
+ // `onClose={close}` matches `onClick={close}` and `onClick={() => close()}`.
240
+ const callsClose = (expr) => {
241
+ const t = text(expr);
242
+ return t === closeText || t === `()=>${closeText}()` || t === `()=>{${closeText}();}` ||
243
+ t === `()=>${closeText}` || t === `()=>{${closeText}}`;
244
+ };
245
+ for (const name of ['footerActions', 'footer']) {
246
+ const slot = attr(node.openingElement, name);
247
+ if (!slot || !slot.value) continue;
248
+ for (const el of jsxElements(slot.value)) {
249
+ if (jsxName(el.openingElement) !== 'Button') continue;
250
+ const onClick = attr(el.openingElement, 'onClick');
251
+ if (onClick && onClick.value && onClick.value.type === 'JSXExpressionContainer' &&
252
+ callsClose(onClick.value.expression)) {
253
+ context.report({ node: el.openingElement, messageId: 'dismiss', data: { overlay } });
254
+ }
255
+ }
256
+ }
257
+ },
258
+ };
259
+ },
260
+ },
261
+ };
262
+
263
+ const plugin = {
264
+ meta: { name: '@revikornmann/muka-ui/eslint', version: pkg.version },
265
+ rules,
266
+ configs: {},
267
+ };
268
+
269
+ plugin.configs.recommended = [
270
+ {
271
+ name: 'muka-ui/recommended',
272
+ files: ['**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}'],
273
+ plugins: { muka: plugin },
274
+ rules: {
275
+ 'muka/no-tailwind-classes': 'error',
276
+ 'muka/no-other-styling': 'error',
277
+ 'muka/no-raw-style-values': 'error',
278
+ 'muka/no-raw-elements': 'error',
279
+ 'muka/dismiss-button-for-cancel': 'error',
280
+ },
281
+ },
282
+ ];
283
+
284
+ module.exports = plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revikornmann/muka-ui",
3
- "version": "0.35.1",
3
+ "version": "0.37.0",
4
4
  "description": "Muka Design System - Multi-brand design tokens and React components",
5
5
  "main": "dist/cjs/components/index.js",
6
6
  "module": "dist/esm/components/index.js",
@@ -16,6 +16,7 @@
16
16
  "./build": "./scripts/build-tokens.js",
17
17
  "./tokens/*": "./tokens/*",
18
18
  "./manifest": "./build/manifest.json",
19
+ "./eslint": "./eslint/index.js",
19
20
  "./package.json": "./package.json"
20
21
  },
21
22
  "sideEffects": [
@@ -27,6 +28,7 @@
27
28
  "files": [
28
29
  "dist",
29
30
  "cli",
31
+ "eslint",
30
32
  "skills",
31
33
  "scripts/build-tokens.js",
32
34
  "scripts/build-fonts.js",
@@ -97,8 +99,18 @@
97
99
  "vaul": "^1.1.2"
98
100
  },
99
101
  "peerDependencies": {
102
+ "eslint": ">=9.0.0",
100
103
  "react": ">=16.8.0",
101
- "react-dom": ">=16.8.0"
104
+ "react-dom": ">=16.8.0",
105
+ "typescript-eslint": ">=8.0.0"
106
+ },
107
+ "peerDependenciesMeta": {
108
+ "eslint": {
109
+ "optional": true
110
+ },
111
+ "typescript-eslint": {
112
+ "optional": true
113
+ }
102
114
  },
103
115
  "devDependencies": {
104
116
  "@eslint/js": "^9.39.4",
@@ -138,7 +138,8 @@ cp node_modules/@revikornmann/muka-ui/templates/update-muka.yml \
138
138
  ```
139
139
 
140
140
  The workflow listens for the `muka-released` dispatch and installs the exact
141
- published version (manual runs install `@latest`). No secrets needed — the
141
+ published version (manual runs install `@latest`), then refreshes the Muka
142
+ rules in `AGENTS.md` with `npx muka-ui sync`. No secrets needed — the
142
143
  package is public. It auto-detects the package manager from the lockfile
143
144
  (pnpm/yarn/npm).
144
145
 
@@ -167,13 +168,61 @@ this repo for the `repository_dispatch` to succeed.
167
168
  npx muka-ui init
168
169
  ```
169
170
 
170
- This writes `AGENTS.md`, `CLAUDE.md`, and `docs/muka-ui-guidelines.md` into the
171
- repo (it prompts before overwriting any of them) so any agent working here knows
172
- to compose Muka components and use token custom properties instead of hardcoded
173
- values. It also warns about styling libraries that conflict with Muka.
171
+ This writes the Muka rules into `AGENTS.md`, inside a marked block, makes
172
+ `CLAUDE.md` import it (`@AGENTS.md`), and writes `docs/muka-ui-guidelines.md`. It
173
+ also warns about styling libraries that conflict with Muka.
174
174
 
175
- `AGENTS.md` carries the rules — it is the filename most agents read — and
176
- `CLAUDE.md` is a short pointer to it, so there is only one copy to keep current.
175
+ - **One file for every agent.** `AGENTS.md` is the filename Codex, Cursor,
176
+ Copilot and most other agents read; Claude Code reads it through the import.
177
+ There is no second copy to drift.
178
+ - **Kept current.** Muka owns only the block between `<!-- muka-ui:start -->`
179
+ and `<!-- muka-ui:end -->`. `npx muka-ui sync` rewrites it for the installed
180
+ version, and the auto-update workflow runs it on every bump. Put the repo's
181
+ own rules outside the block; they are never touched.
182
+
183
+ ## Step 6: Check the rules in CI
184
+
185
+ Written rules only hold while an agent reads them. `npx muka-ui check` lints the
186
+ source with Muka's ESLint rules and fails on Tailwind classes, CSS modules or
187
+ CSS-in-JS, hard-coded colours or pixel sizes in `style`, raw `<button>`,
188
+ `<dialog>`, `<select>` and `<textarea>`, and a Cancel in a `Dialog` or `Drawer`
189
+ footer that skips `DismissButton`. It also fails when `AGENTS.md` is behind the
190
+ installed version. It needs ESLint 9 and the TypeScript parser:
191
+
192
+ ```bash
193
+ npm install --save-dev eslint typescript-eslint
194
+ mkdir -p .github/workflows
195
+ cp node_modules/@revikornmann/muka-ui/templates/muka-check.yml \
196
+ .github/workflows/muka-check.yml
197
+ ```
198
+
199
+ The workflow runs the check on every pull request, whichever agent or person
200
+ wrote the code. A repo with its own ESLint setup can also add the rules there:
201
+
202
+ ```js
203
+ // eslint.config.mjs
204
+ import muka from '@revikornmann/muka-ui/eslint';
205
+ export default [/* your config */, ...muka.configs.recommended];
206
+ ```
207
+
208
+ A line that must break a rule gets
209
+ `// eslint-disable-next-line muka/<rule> -- reason`.
210
+
211
+ Adopting the check in a repo that already has violations? Record them once and
212
+ commit the result, so CI fails only on new ones while the old ones are cleaned
213
+ up:
214
+
215
+ ```bash
216
+ npx muka-ui check --update-baseline # writes .muka-check-baseline.json
217
+ ```
218
+
219
+ Re-run it after a cleanup so the baseline shrinks; never to let a new problem
220
+ through.
221
+
222
+ If the repo already had an `AGENTS.md` or `CLAUDE.md` with copied Muka rules,
223
+ `sync` inserts the block under the first heading and says so: move the repo's
224
+ own rules (anything not about Muka) below the block, delete the old copied Muka
225
+ rules, and keep only Claude-specific notes in `CLAUDE.md` under `@AGENTS.md`.
177
226
 
178
227
  ## Verify
179
228
 
@@ -183,6 +232,9 @@ values. It also warns about styling libraries that conflict with Muka.
183
232
  `var(...)` fallback — that is the check that the token CSS actually loaded.
184
233
  - `.github/workflows/update-muka.yml` exists and is valid YAML.
185
234
  - This repo appears in Muka's `.github/consumers.txt` (or a PR is open for it).
235
+ - `AGENTS.md` has a `<!-- muka-ui:start` block and `CLAUDE.md` starts with
236
+ `@AGENTS.md`.
237
+ - `npx muka-ui check` passes, and `.github/workflows/muka-check.yml` exists.
186
238
 
187
239
  ## Next
188
240
 
@@ -0,0 +1,45 @@
1
+ # Muka UI guardrails — consumer workflow template
2
+ #
3
+ # Copy this file into the CONSUMER repo at:
4
+ # .github/workflows/muka-check.yml
5
+ #
6
+ # Runs `npx muka-ui check` on every pull request: Muka's ESLint rules (no
7
+ # Tailwind, no CSS modules or CSS-in-JS, no hard-coded colours or pixel sizes in
8
+ # `style`, Muka components instead of raw elements, DismissButton for a Cancel
9
+ # in a Dialog or Drawer) and a check that AGENTS.md carries the rules of the
10
+ # installed Muka version. It holds whichever agent or person wrote the code.
11
+ #
12
+ # Needs eslint (9+) and typescript-eslint as devDependencies:
13
+ # npm install --save-dev eslint typescript-eslint
14
+
15
+ name: Muka UI guardrails
16
+
17
+ on:
18
+ pull_request:
19
+
20
+ jobs:
21
+ check:
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ - name: Checkout
25
+ uses: actions/checkout@v4
26
+
27
+ - name: Setup Node.js
28
+ uses: actions/setup-node@v4
29
+ with:
30
+ node-version: '22'
31
+
32
+ - name: Enable corepack (pnpm / yarn shims)
33
+ run: corepack enable
34
+
35
+ - name: Install
36
+ env:
37
+ COREPACK_ENABLE_DOWNLOAD_PROMPT: '0'
38
+ run: |
39
+ if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile
40
+ elif [ -f yarn.lock ]; then yarn install --frozen-lockfile
41
+ else npm ci
42
+ fi
43
+
44
+ - name: Muka UI guardrails
45
+ run: npx --no-install muka-ui check
@@ -7,8 +7,10 @@
7
7
  # muka-ui's publish.yml publishes a new version to the public npm registry on
8
8
  # every release, then fires a `muka-released` repository_dispatch (carrying the
9
9
  # version) to each repo in .github/consumers.txt. This workflow receives that
10
- # dispatch, installs the exact published version, and commits the lockfile
11
- # bump. Pushing to the default branch lets your host (e.g. Vercel) redeploy.
10
+ # dispatch, installs the exact published version, refreshes the Muka rules in
11
+ # AGENTS.md (`muka-ui sync`) so every coding agent reads the rules of the
12
+ # installed version, and commits both. Pushing to the default branch lets
13
+ # your host (e.g. Vercel) redeploy.
12
14
  #
13
15
  # Muka UI is a public npm package, so installing needs no registry config or
14
16
  # auth token. The install step auto-detects your package manager from the
@@ -70,15 +72,23 @@ jobs:
70
72
  npm install "$SPEC" --save
71
73
  fi
72
74
 
75
+ - name: Refresh the Muka rules and skills
76
+ # Rewrites only the marked Muka block in AGENTS.md, makes CLAUDE.md
77
+ # import AGENTS.md, and refreshes the Muka skills in .agents/skills
78
+ # (skipping any edited in this repo). The repo's own rules and skills
79
+ # stay as they are.
80
+ run: npx --no-install muka-ui sync
81
+
73
82
  - name: Check for changes
74
83
  id: changes
75
84
  run: |
76
- if git diff --quiet -- package.json package-lock.json pnpm-lock.yaml yarn.lock; then
85
+ if git diff --quiet -- package.json package-lock.json pnpm-lock.yaml yarn.lock AGENTS.md CLAUDE.md .agents/skills .claude/skills && \
86
+ [ -z "$(git ls-files --others --exclude-standard -- AGENTS.md CLAUDE.md .agents/skills .claude/skills)" ]; then
77
87
  echo "changed=false" >> "$GITHUB_OUTPUT"
78
88
  echo "Already on the target muka version — nothing to update."
79
89
  else
80
90
  echo "changed=true" >> "$GITHUB_OUTPUT"
81
- echo "muka updated — will commit lockfile."
91
+ echo "muka updated — will commit lockfile and agent rules."
82
92
  fi
83
93
 
84
94
  - name: Commit and push update
@@ -88,6 +98,9 @@ jobs:
88
98
  git config --local user.name "GitHub Action"
89
99
  # Stage package.json plus whichever lockfile this repo uses.
90
100
  git add package.json
101
+ for f in AGENTS.md CLAUDE.md .agents/skills .claude/skills; do
102
+ [ -e "$f" ] && git add "$f"
103
+ done
91
104
  for lock in package-lock.json pnpm-lock.yaml yarn.lock; do
92
105
  [ -f "$lock" ] && git add "$lock"
93
106
  done