@tokamaq/ui 0.0.0-stage → 0.1.0-dev.2
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 +21 -0
- package/README.md +23 -2
- package/lint/index.js +22 -0
- package/lint/oxlint.json +58 -0
- package/lint/plugin.js +411 -0
- package/package.json +82 -4
- package/src/avatar.tsx +34 -0
- package/src/button.tsx +109 -0
- package/src/chip.tsx +52 -0
- package/src/cn.ts +71 -0
- package/src/code-block.tsx +58 -0
- package/src/collapsible.tsx +76 -0
- package/src/command.tsx +101 -0
- package/src/dialog.tsx +93 -0
- package/src/file-name.tsx +41 -0
- package/src/fonts/Geist-Variable.woff2 +0 -0
- package/src/fonts/GeistMono-Variable.woff2 +0 -0
- package/src/fonts/OFL.txt +92 -0
- package/src/fonts.css +15 -0
- package/src/icon.tsx +30 -0
- package/src/icons.ts +23 -0
- package/src/index.ts +24 -0
- package/src/input.tsx +86 -0
- package/src/kbd.tsx +33 -0
- package/src/kit/command.tsx +45 -0
- package/src/kit/contrast.ts +31 -0
- package/src/kit/controls.tsx +233 -0
- package/src/kit/disclosure.tsx +39 -0
- package/src/kit/frame.tsx +34 -0
- package/src/kit/inputs.tsx +53 -0
- package/src/kit/kit.tsx +76 -0
- package/src/kit/overlays.tsx +79 -0
- package/src/kit/rows.tsx +160 -0
- package/src/kit/tokens.tsx +189 -0
- package/src/menu.tsx +99 -0
- package/src/resizable.tsx +40 -0
- package/src/row-list.tsx +65 -0
- package/src/row.tsx +147 -0
- package/src/scroll-area.tsx +64 -0
- package/src/select.tsx +67 -0
- package/src/status-icon.tsx +49 -0
- package/src/switch.tsx +73 -0
- package/src/tabs.tsx +44 -0
- package/src/textarea.tsx +30 -0
- package/src/theme.css +397 -0
- package/src/tooltip.tsx +40 -0
- package/tests/setup.ts +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pixelscortex
|
|
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
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tokamaq/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tokamaq's Solid 2 primitives and Tailwind tokens. The rules are in the wiki's
|
|
4
|
+
design page (`wiki/content/docs/design/index.mdx`).
|
|
5
|
+
|
|
6
|
+
- `@tokamaq/ui`: the primitives. Each source file starts with a comment that
|
|
7
|
+
shows how to use it.
|
|
8
|
+
- `@tokamaq/ui/theme.css`: the tokens (colours, type sizes, radii) as a
|
|
9
|
+
Tailwind `@theme`.
|
|
10
|
+
- `@tokamaq/ui/kit`: the app's `/kit` page, which draws every token and
|
|
11
|
+
primitive in every state, in both themes.
|
|
12
|
+
- `@tokamaq/ui/lint`: the lint rules that keep plugins on the primitives.
|
|
13
|
+
|
|
14
|
+
Primitives are built on `@ui-sdk/solid`. Single elements:
|
|
15
|
+
|
|
16
|
+
- `Avatar`, `Chip`, `CodeBlock`, `FileName`, `Icon`, `Kbd`, `Row`,
|
|
17
|
+
`ScrollArea`, `StatusIcon`, `Textarea`
|
|
18
|
+
- `Button`: `sm` 24, `md` 32 (default) or `lg` 48 tall
|
|
19
|
+
- `Input`: one line; `md` 40 or `lg` 48 tall, radius 12; `mono`, `invalid`,
|
|
20
|
+
a leading `icon` and a `trail` action
|
|
21
|
+
- `Switch`: 28 × 16, on or off; toggles with click, Space and Enter
|
|
22
|
+
|
|
23
|
+
Namespaces (several parts): `Collapsible`, `Command`, `Dialog`, `Menu`,
|
|
24
|
+
`Resizable`, `RowList`, `Select`, `Tabs`, `Tooltip`.
|
package/lint/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Lint config for Tokamaq plugin UIs. Oxlint: "extends": ["<path to>/@tokamaq/ui/lint/oxlint.json"].
|
|
2
|
+
// ESLint (flat config):
|
|
3
|
+
// import { tokamaq } from "@tokamaq/ui/lint";
|
|
4
|
+
// import tsParser from "@typescript-eslint/parser";
|
|
5
|
+
// export default [tokamaq({ files: ["src/client/**/*.tsx"], parser: tsParser })];
|
|
6
|
+
import { plugin as shadcn } from "@shadcn/lint";
|
|
7
|
+
import { plugin } from "./plugin.js";
|
|
8
|
+
import config from "./oxlint.json" with { type: "json" };
|
|
9
|
+
|
|
10
|
+
export { plugin };
|
|
11
|
+
export const rules = config.rules;
|
|
12
|
+
export const settings = config.settings;
|
|
13
|
+
|
|
14
|
+
export function tokamaq({ files = ["**/*.{tsx,jsx}"], parser } = {}) {
|
|
15
|
+
return {
|
|
16
|
+
files,
|
|
17
|
+
languageOptions: parser ? { parser, parserOptions: { ecmaFeatures: { jsx: true } } } : {},
|
|
18
|
+
plugins: { shadcn, tokamaq: plugin },
|
|
19
|
+
settings,
|
|
20
|
+
rules,
|
|
21
|
+
};
|
|
22
|
+
}
|
package/lint/oxlint.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
"jsPlugins": ["@shadcn/lint", "./plugin.js"],
|
|
4
|
+
"settings": {
|
|
5
|
+
"shadcn": {
|
|
6
|
+
"ui": "@tokamaq/ui",
|
|
7
|
+
"themeImports": ["^@tokamaq/ui/"],
|
|
8
|
+
"note": "Tokamaq design rules: wiki docs/design. Tokens: @tokamaq/ui/theme.css."
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"rules": {
|
|
12
|
+
"shadcn/no-raw-colors": "error",
|
|
13
|
+
"shadcn/no-arbitrary-values": [
|
|
14
|
+
"error",
|
|
15
|
+
{
|
|
16
|
+
"message": "\"{{className}}\" is an arbitrary value. Use the scale: spacing 1 2 3 4 5 6 8 10 12 16 (4 to 64 px), radius rounded-xs, sm, md, lg (4 to 16 px), text roles text-read, text-row, text-label, text-data, and the colour tokens in @tokamaq/ui/theme.css."
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"shadcn/no-unknown-classes": [
|
|
20
|
+
"error",
|
|
21
|
+
{
|
|
22
|
+
"message": "\"{{className}}\" does not exist in the Tokamaq theme. {{suggestions}} Spacing steps are 1 2 3 4 5 6 8 10 12 16, radii xs sm md lg, text roles read row label data, and shadow-raised is the only shadow."
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"shadcn/no-inline-styles": "error",
|
|
26
|
+
"shadcn/require-static-classes": "error",
|
|
27
|
+
"shadcn/no-restyle": [
|
|
28
|
+
"error",
|
|
29
|
+
{
|
|
30
|
+
"allow": ["layout"],
|
|
31
|
+
"contracts": [
|
|
32
|
+
{
|
|
33
|
+
"pattern": "^Icon$",
|
|
34
|
+
"allow": ["layout", "color"]
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"message": {
|
|
38
|
+
"spacing": "<{{component}}> owns its padding. Use a size ({{sizes|none defined}}), or {{around}}.",
|
|
39
|
+
"default": "<{{component}}> owns its look; only layout classes (margin, width, flex and grid placement) may be added. Use a variant ({{variants|none defined}}) or build your own element from tokens."
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"tokamaq/concentric-radius": "error",
|
|
44
|
+
"tokamaq/density-inward": "error",
|
|
45
|
+
"tokamaq/no-negative-margin": "error",
|
|
46
|
+
"tokamaq/no-raw-button": "error",
|
|
47
|
+
"tokamaq/no-text-style-in-button": "error"
|
|
48
|
+
},
|
|
49
|
+
"overrides": [
|
|
50
|
+
{
|
|
51
|
+
"files": ["**/packages/ui/src/**"],
|
|
52
|
+
"rules": {
|
|
53
|
+
"tokamaq/no-negative-margin": "off",
|
|
54
|
+
"tokamaq/no-raw-button": "off"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
package/lint/plugin.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
// Tokamaq's own lint rules, in the ESLint plugin format (Oxlint loads it as a
|
|
2
|
+
// JS plugin).
|
|
3
|
+
// concentric-radius: inside a rounded parent, a rounded child's radius equals
|
|
4
|
+
// max(0, parent radius − parent padding). It applies when the child sits
|
|
5
|
+
// inside the corner's curve (padding < outer radius). nest-*/rounded-inner
|
|
6
|
+
// are concentric by construction.
|
|
7
|
+
// density-inward: a density-* region inside a tighter one is an error.
|
|
8
|
+
|
|
9
|
+
const radii = { none: 0, xs: 4, sm: 8, md: 12, lg: 16 };
|
|
10
|
+
const nameOf = Object.fromEntries(Object.entries(radii).map(([name, px]) => [px, name]));
|
|
11
|
+
const spacing = { 0: 0, 1: 4, 2: 8, 3: 12, 4: 16, 5: 20, 6: 24, 8: 32, 10: 40, 12: 48, 16: 64 };
|
|
12
|
+
const stepOf = Object.fromEntries(Object.entries(spacing).map(([step, px]) => [px, step]));
|
|
13
|
+
|
|
14
|
+
// Primitives that draw their own surface: [radius, padding to their children].
|
|
15
|
+
// tests/lint.test.ts checks these against the primitives' own classes.
|
|
16
|
+
export const primitiveShapes = {
|
|
17
|
+
Button: [8, null],
|
|
18
|
+
"Menu.Trigger": [8, null],
|
|
19
|
+
"Dialog.Trigger": [8, null],
|
|
20
|
+
"Dialog.Close": [8, null],
|
|
21
|
+
"Tooltip.Trigger": [8, null],
|
|
22
|
+
"Select.Trigger": [8, null],
|
|
23
|
+
Chip: [8, null],
|
|
24
|
+
Row: [8, null],
|
|
25
|
+
"RowList.Option": [8, null],
|
|
26
|
+
Textarea: [8, null],
|
|
27
|
+
"Tabs.Tab": [8, null],
|
|
28
|
+
"Command.Item": [8, null],
|
|
29
|
+
"Menu.RadioItem": [8, null],
|
|
30
|
+
"Collapsible.Trigger": [8, null],
|
|
31
|
+
Input: [12, null],
|
|
32
|
+
CodeBlock: [12, 4],
|
|
33
|
+
"Menu.Content": [12, 4],
|
|
34
|
+
"Select.Content": [12, 4],
|
|
35
|
+
"Dialog.Content": [16, 24],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function classValue(element) {
|
|
39
|
+
const attribute = element.openingElement.attributes.find(
|
|
40
|
+
(attr) => attr.type === "JSXAttribute" && (attr.name.name === "class" || attr.name.name === "className"),
|
|
41
|
+
);
|
|
42
|
+
return attribute?.value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function staticClass(element) {
|
|
46
|
+
const value = classValue(element);
|
|
47
|
+
if (!value) return "";
|
|
48
|
+
const expression = value.type === "JSXExpressionContainer" ? value.expression : value;
|
|
49
|
+
if (expression.type === "Literal" && typeof expression.value === "string") return expression.value;
|
|
50
|
+
if (expression.type === "TemplateLiteral" && expression.expressions.length === 0)
|
|
51
|
+
return expression.quasis[0].value.cooked;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function elementName(element) {
|
|
56
|
+
const name = element.openingElement.name;
|
|
57
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
58
|
+
if (name.type === "JSXMemberExpression" && name.object.type === "JSXIdentifier")
|
|
59
|
+
return `${name.object.name}.${name.property.name}`;
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Reads the base classes (no variants such as hover: or md:) that matter here.
|
|
64
|
+
function shape(element) {
|
|
65
|
+
const classes = staticClass(element);
|
|
66
|
+
const name = elementName(element);
|
|
67
|
+
const primitive = name ? primitiveShapes[name] : undefined;
|
|
68
|
+
if (classes === undefined) return undefined;
|
|
69
|
+
const result = {
|
|
70
|
+
radius: primitive ? primitive[0] : 0,
|
|
71
|
+
radiusClass: undefined,
|
|
72
|
+
padding: primitive ? primitive[1] : 0,
|
|
73
|
+
paints: Boolean(primitive),
|
|
74
|
+
clips: false,
|
|
75
|
+
primitive: Boolean(primitive) && name,
|
|
76
|
+
inner: false,
|
|
77
|
+
};
|
|
78
|
+
let px;
|
|
79
|
+
let py;
|
|
80
|
+
for (const token of classes.split(/\s+/)) {
|
|
81
|
+
if (!token || token.includes(":")) continue;
|
|
82
|
+
let match;
|
|
83
|
+
if (token === "rounded-inner") result.inner = true;
|
|
84
|
+
else if ((match = /^nest-(xs|sm|md|lg)(?:\/(\d+))?$/.exec(token))) {
|
|
85
|
+
result.radius = radii[match[1]];
|
|
86
|
+
result.padding = spacing[match[2] ?? 0] ?? null;
|
|
87
|
+
} else if ((match = /^rounded(?:-(none|xs|sm|md|lg|full))?$/.exec(token))) {
|
|
88
|
+
const key = match[1] ?? "sm";
|
|
89
|
+
result.radius = key === "full" ? Infinity : radii[key];
|
|
90
|
+
result.radiusClass = token;
|
|
91
|
+
} else if ((match = /^p-(\d+)$/.exec(token)) && match[1] in spacing) result.padding = spacing[match[1]];
|
|
92
|
+
else if ((match = /^px-(\d+)$/.exec(token)) && match[1] in spacing) px = spacing[match[1]];
|
|
93
|
+
else if ((match = /^py-(\d+)$/.exec(token)) && match[1] in spacing) py = spacing[match[1]];
|
|
94
|
+
else if (token.startsWith("bg-") && token !== "bg-transparent") result.paints = true;
|
|
95
|
+
else if (/^overflow-(hidden|clip)$/.test(token)) result.clips = true;
|
|
96
|
+
}
|
|
97
|
+
if (px !== undefined || py !== undefined) result.padding = px === py ? px : null;
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function describe(px) {
|
|
102
|
+
return px === 0 ? "square (no rounded-* class)" : `rounded-${nameOf[px]} (${px} px)`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const concentricRadius = {
|
|
106
|
+
meta: {
|
|
107
|
+
type: "suggestion",
|
|
108
|
+
docs: { description: "Nested corners stay concentric: inner radius = outer radius − padding." },
|
|
109
|
+
schema: [],
|
|
110
|
+
},
|
|
111
|
+
create(context) {
|
|
112
|
+
return {
|
|
113
|
+
JSXElement(parent) {
|
|
114
|
+
const outer = shape(parent);
|
|
115
|
+
if (!outer || !outer.radius || outer.radius === Infinity || outer.padding === null) return;
|
|
116
|
+
for (const child of parent.children) {
|
|
117
|
+
if (child.type !== "JSXElement") continue;
|
|
118
|
+
const inner = shape(child);
|
|
119
|
+
if (!inner || inner.inner || !inner.paints || inner.radius === Infinity) continue;
|
|
120
|
+
if (outer.padding === 0 && outer.clips) continue;
|
|
121
|
+
// A child further from the edge than the corner is deep sits clear of
|
|
122
|
+
// the curve, like a button in a dialog's body: nothing to align.
|
|
123
|
+
if (outer.padding >= outer.radius) continue;
|
|
124
|
+
const expected = Math.max(0, outer.radius - outer.padding);
|
|
125
|
+
if (inner.radius === expected) continue;
|
|
126
|
+
const where = `inside a ${outer.radius} px corner with ${outer.padding} px padding`;
|
|
127
|
+
let advice;
|
|
128
|
+
if (inner.primitive) {
|
|
129
|
+
const parentRadius = inner.radius + outer.padding;
|
|
130
|
+
const padding = outer.radius - inner.radius;
|
|
131
|
+
const options = [];
|
|
132
|
+
if (nameOf[parentRadius] !== undefined)
|
|
133
|
+
options.push(`give the parent rounded-${nameOf[parentRadius]}`);
|
|
134
|
+
if (padding >= 0 && stepOf[padding] !== undefined)
|
|
135
|
+
options.push(`give the parent p-${stepOf[padding]}`);
|
|
136
|
+
advice = `<${inner.primitive}> has a fixed ${inner.radius} px radius, so ${
|
|
137
|
+
options.length ? options.join(" or ") : "drop the parent's rounding"
|
|
138
|
+
}.`;
|
|
139
|
+
} else {
|
|
140
|
+
advice = `Use ${describe(expected)} here.`;
|
|
141
|
+
}
|
|
142
|
+
context.report({
|
|
143
|
+
node: child.openingElement,
|
|
144
|
+
message: `Corner is not concentric: ${describe(inner.radius)} ${where} should be ${describe(
|
|
145
|
+
expected,
|
|
146
|
+
)}, because inner radius = outer radius − the gap. ${advice}`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const tightness = { roomy: 0, normal: 1, dense: 2 };
|
|
155
|
+
|
|
156
|
+
function densityOf(element) {
|
|
157
|
+
const classes = staticClass(element);
|
|
158
|
+
const match = classes && /(?:^|\s)density-(roomy|normal|dense)(?:\s|$)/.exec(classes);
|
|
159
|
+
return match ? match[1] : undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const densityInward = {
|
|
163
|
+
meta: {
|
|
164
|
+
type: "problem",
|
|
165
|
+
docs: { description: "Density only gets tighter inward." },
|
|
166
|
+
schema: [],
|
|
167
|
+
},
|
|
168
|
+
create(context) {
|
|
169
|
+
return {
|
|
170
|
+
JSXElement(element) {
|
|
171
|
+
const own = densityOf(element);
|
|
172
|
+
if (!own) return;
|
|
173
|
+
for (let node = element.parent; node; node = node.parent) {
|
|
174
|
+
if (node.type !== "JSXElement") continue;
|
|
175
|
+
const outer = densityOf(node);
|
|
176
|
+
if (!outer) continue;
|
|
177
|
+
if (tightness[own] < tightness[outer])
|
|
178
|
+
context.report({
|
|
179
|
+
node: element.openingElement,
|
|
180
|
+
message: `density-${own} sits inside density-${outer}; density only gets tighter inward. Use density-${outer} or remove it here.`,
|
|
181
|
+
});
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
function utility(token) {
|
|
190
|
+
// Variants can contain colons inside selectors, and arbitrary values can
|
|
191
|
+
// contain colons too. Only a colon outside brackets separates the utility.
|
|
192
|
+
let depth = 0;
|
|
193
|
+
let start = 0;
|
|
194
|
+
for (let index = 0; index < token.length; index++) {
|
|
195
|
+
const char = token[index];
|
|
196
|
+
if (char === "[" || char === "(") depth++;
|
|
197
|
+
else if (char === "]" || char === ")") depth--;
|
|
198
|
+
else if (char === ":" && depth === 0) start = index + 1;
|
|
199
|
+
}
|
|
200
|
+
return token.slice(start).replace(/^!|!$/g, "");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function* templateStrings({ quasis, expressions }) {
|
|
204
|
+
for (const [index, quasi] of quasis.entries()) {
|
|
205
|
+
const text = quasi.value.cooked ?? "";
|
|
206
|
+
// Only take whole utilities, not pieces joined to a dynamic value.
|
|
207
|
+
const start = index > 0 ? text.replace(/^\S+/, "") : text;
|
|
208
|
+
yield index < expressions.length ? start.replace(/\S+$/, "") : start;
|
|
209
|
+
if (index === expressions.length) continue;
|
|
210
|
+
const next = quasis[index + 1].value.cooked ?? "";
|
|
211
|
+
if (
|
|
212
|
+
(/\s$/.test(text) || (index === 0 && !text)) &&
|
|
213
|
+
(/^\s/.test(next) || (!next && index + 1 === expressions.length))
|
|
214
|
+
)
|
|
215
|
+
yield* classStrings(expressions[index]);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function properties(node) {
|
|
220
|
+
return node?.type === "ObjectExpression" ? node.properties.filter((prop) => prop.type === "Property") : [];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function keyOf(prop) {
|
|
224
|
+
return prop.key.type === "Literal" ? prop.key.value : !prop.computed ? prop.key.name : undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function* styleValues(node) {
|
|
228
|
+
if (node?.type === "ObjectExpression") {
|
|
229
|
+
for (const prop of properties(node)) yield* styleValues(prop.value);
|
|
230
|
+
} else yield* classStrings(node);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function* variantStrings(config) {
|
|
234
|
+
for (const prop of properties(config)) {
|
|
235
|
+
const key = keyOf(prop);
|
|
236
|
+
if (key === "base" || key === "slots" || key === "variants") yield* styleValues(prop.value);
|
|
237
|
+
if ((key === "compoundVariants" || key === "compoundSlots") && prop.value.type === "ArrayExpression") {
|
|
238
|
+
for (const entry of prop.value.elements) {
|
|
239
|
+
for (const field of properties(entry)) {
|
|
240
|
+
if (keyOf(field) === "class" || keyOf(field) === "className") yield* styleValues(field.value);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function* classStrings(node) {
|
|
248
|
+
switch (node?.type) {
|
|
249
|
+
case "Literal":
|
|
250
|
+
if (typeof node.value === "string") yield node.value;
|
|
251
|
+
break;
|
|
252
|
+
case "JSXExpressionContainer":
|
|
253
|
+
case "TSAsExpression":
|
|
254
|
+
case "TSSatisfiesExpression":
|
|
255
|
+
yield* classStrings(node.expression);
|
|
256
|
+
break;
|
|
257
|
+
case "TemplateLiteral":
|
|
258
|
+
yield* templateStrings(node);
|
|
259
|
+
break;
|
|
260
|
+
case "ConditionalExpression":
|
|
261
|
+
yield* classStrings(node.consequent);
|
|
262
|
+
yield* classStrings(node.alternate);
|
|
263
|
+
break;
|
|
264
|
+
case "LogicalExpression":
|
|
265
|
+
if (node.operator !== "&&") yield* classStrings(node.left);
|
|
266
|
+
yield* classStrings(node.right);
|
|
267
|
+
break;
|
|
268
|
+
case "ArrayExpression":
|
|
269
|
+
for (const entry of node.elements) yield* classStrings(entry);
|
|
270
|
+
break;
|
|
271
|
+
case "SpreadElement":
|
|
272
|
+
yield* classStrings(node.argument);
|
|
273
|
+
break;
|
|
274
|
+
case "ObjectExpression":
|
|
275
|
+
for (const prop of properties(node)) {
|
|
276
|
+
const key = keyOf(prop);
|
|
277
|
+
if (typeof key === "string") yield key;
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
280
|
+
case "CallExpression":
|
|
281
|
+
yield* callStrings(node);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function* callStrings({ callee, arguments: args }) {
|
|
287
|
+
if (callee.type === "Identifier" && callee.name === "cn") {
|
|
288
|
+
for (const arg of args) yield* classStrings(arg);
|
|
289
|
+
} else if (callee.type === "Identifier" && callee.name === "tv") {
|
|
290
|
+
yield* variantStrings(args[0]);
|
|
291
|
+
} else if (callee.type === "CallExpression") {
|
|
292
|
+
yield* callStrings(callee);
|
|
293
|
+
} else if (callee.type === "MemberExpression" && callee.object.type === "CallExpression") {
|
|
294
|
+
yield* callStrings(callee.object);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function matchingClass(element, matches) {
|
|
299
|
+
for (const classes of classStrings(classValue(element))) {
|
|
300
|
+
const token = classes.split(/\s+/).find((part) => matches(utility(part)));
|
|
301
|
+
if (token) return token;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const noNegativeMargin = {
|
|
306
|
+
meta: {
|
|
307
|
+
type: "problem",
|
|
308
|
+
docs: { description: "Use size, density or layout instead of negative margins." },
|
|
309
|
+
schema: [],
|
|
310
|
+
},
|
|
311
|
+
create(context) {
|
|
312
|
+
return {
|
|
313
|
+
JSXElement(element) {
|
|
314
|
+
const token = matchingClass(element, (name) => /^-m[xysetrbl]?-/.test(name));
|
|
315
|
+
if (token)
|
|
316
|
+
context.report({
|
|
317
|
+
node: element.openingElement,
|
|
318
|
+
message: `"${token}" is a negative margin. Use a size or density, or gap on the parent.`,
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const noRawButton = {
|
|
326
|
+
meta: {
|
|
327
|
+
type: "problem",
|
|
328
|
+
docs: { description: "Use the shared button or row primitive." },
|
|
329
|
+
schema: [],
|
|
330
|
+
},
|
|
331
|
+
create(context) {
|
|
332
|
+
return {
|
|
333
|
+
JSXElement(element) {
|
|
334
|
+
if (elementName(element) === "button")
|
|
335
|
+
context.report({
|
|
336
|
+
node: element.openingElement,
|
|
337
|
+
message: 'Use Button from @tokamaq/ui, or Row with as="button" for list rows.',
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const buttonLooks = new Set([
|
|
345
|
+
"Button",
|
|
346
|
+
"Menu.Trigger",
|
|
347
|
+
"Dialog.Trigger",
|
|
348
|
+
"Dialog.Close",
|
|
349
|
+
"Tooltip.Trigger",
|
|
350
|
+
"Select.Trigger",
|
|
351
|
+
]);
|
|
352
|
+
const textLayout =
|
|
353
|
+
/^text-(?:start|end|left|right|center|justify|wrap|nowrap|balance|pretty|ellipsis|clip|trim)$/;
|
|
354
|
+
const textStyle =
|
|
355
|
+
/^(?:(?:text|font|tracking|leading)-|(?:uppercase|lowercase|capitalize|italic|underline|line-through)$)/;
|
|
356
|
+
|
|
357
|
+
function leadOwner(attribute) {
|
|
358
|
+
const owner = attribute.parent?.parent;
|
|
359
|
+
if (attribute.name.name !== "lead" || owner?.type !== "JSXElement") return undefined;
|
|
360
|
+
const name = elementName(owner);
|
|
361
|
+
return buttonLooks.has(name) ? name : undefined;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function buttonAncestor(element) {
|
|
365
|
+
for (let node = element.parent; node; node = node.parent) {
|
|
366
|
+
// Only the lead prop renders inside the button, beside its children.
|
|
367
|
+
if (node.type === "JSXAttribute") return leadOwner(node);
|
|
368
|
+
if (node.type === "JSXSpreadAttribute") return undefined;
|
|
369
|
+
if (node.type !== "JSXElement") continue;
|
|
370
|
+
const name = elementName(node);
|
|
371
|
+
if (buttonLooks.has(name)) return name;
|
|
372
|
+
}
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const noTextStyleInButton = {
|
|
377
|
+
meta: {
|
|
378
|
+
type: "problem",
|
|
379
|
+
docs: {
|
|
380
|
+
description: "Button labels and leads inherit typography and tone; Row buttons have their own slots.",
|
|
381
|
+
},
|
|
382
|
+
schema: [],
|
|
383
|
+
},
|
|
384
|
+
create(context) {
|
|
385
|
+
return {
|
|
386
|
+
JSXElement(element) {
|
|
387
|
+
const token = matchingClass(element, (name) => textStyle.test(name) && !textLayout.test(name));
|
|
388
|
+
if (!token) return;
|
|
389
|
+
const button = buttonAncestor(element);
|
|
390
|
+
if (button)
|
|
391
|
+
context.report({
|
|
392
|
+
node: element.openingElement,
|
|
393
|
+
message: `<${button}> owns its text size, weight and tone. Remove "${token}" and let the text inherit.`,
|
|
394
|
+
});
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
export const plugin = {
|
|
401
|
+
meta: { name: "tokamaq" },
|
|
402
|
+
rules: {
|
|
403
|
+
"concentric-radius": concentricRadius,
|
|
404
|
+
"density-inward": densityInward,
|
|
405
|
+
"no-negative-margin": noNegativeMargin,
|
|
406
|
+
"no-raw-button": noRawButton,
|
|
407
|
+
"no-text-style-in-button": noTextStyleInButton,
|
|
408
|
+
},
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokamaq/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-dev.2",
|
|
4
|
+
"description": "Solid components and theme for Tokamaq plugin windows.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/pixelscortex/tokamaq.git",
|
|
9
|
+
"directory": "packages/ui"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lint/index.js",
|
|
13
|
+
"lint/oxlint.json",
|
|
14
|
+
"lint/plugin.js",
|
|
15
|
+
"src/avatar.tsx",
|
|
16
|
+
"src/button.tsx",
|
|
17
|
+
"src/chip.tsx",
|
|
18
|
+
"src/cn.ts",
|
|
19
|
+
"src/code-block.tsx",
|
|
20
|
+
"src/collapsible.tsx",
|
|
21
|
+
"src/command.tsx",
|
|
22
|
+
"src/dialog.tsx",
|
|
23
|
+
"src/file-name.tsx",
|
|
24
|
+
"src/fonts",
|
|
25
|
+
"src/fonts.css",
|
|
26
|
+
"src/icon.tsx",
|
|
27
|
+
"src/icons.ts",
|
|
28
|
+
"src/index.ts",
|
|
29
|
+
"src/input.tsx",
|
|
30
|
+
"src/kbd.tsx",
|
|
31
|
+
"src/kit",
|
|
32
|
+
"src/menu.tsx",
|
|
33
|
+
"src/resizable.tsx",
|
|
34
|
+
"src/row-list.tsx",
|
|
35
|
+
"src/row.tsx",
|
|
36
|
+
"src/scroll-area.tsx",
|
|
37
|
+
"src/select.tsx",
|
|
38
|
+
"src/status-icon.tsx",
|
|
39
|
+
"src/switch.tsx",
|
|
40
|
+
"src/tabs.tsx",
|
|
41
|
+
"src/textarea.tsx",
|
|
42
|
+
"src/theme.css",
|
|
43
|
+
"src/tooltip.tsx",
|
|
44
|
+
"tests/setup.ts"
|
|
45
|
+
],
|
|
46
|
+
"type": "module",
|
|
47
|
+
"exports": {
|
|
48
|
+
".": "./src/index.ts",
|
|
49
|
+
"./test-setup": "./tests/setup.ts",
|
|
50
|
+
"./theme.css": "./src/theme.css",
|
|
51
|
+
"./kit": "./src/kit/kit.tsx",
|
|
52
|
+
"./lint": "./lint/index.js",
|
|
53
|
+
"./lint/oxlint.json": "./lint/oxlint.json"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"tag": "dev"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@shadcn/lint": "0.2.5",
|
|
61
|
+
"@solidjs/web": "2.0.0",
|
|
62
|
+
"@ui-sdk/core": "0.1.0-beta.6",
|
|
63
|
+
"@ui-sdk/solid": "0.1.0-beta.6",
|
|
64
|
+
"solid-js": "2.0.0",
|
|
65
|
+
"tailwind-variants": "4.0.2"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@solidjs/vite-plugin": "3.0.0",
|
|
69
|
+
"@testing-library/dom": "10.4.2",
|
|
70
|
+
"@testing-library/user-event": "14.6.12",
|
|
71
|
+
"jsdom": "31.0.1",
|
|
72
|
+
"tailwindcss": "4.3.5",
|
|
73
|
+
"typescript": "5.9.3",
|
|
74
|
+
"vitest": "5.1.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"vitest": "5.1.0"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"vitest": {
|
|
81
|
+
"optional": true
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/avatar.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<Avatar name="Sam Lee" />
|
|
3
|
+
<Avatar name="Sam Lee" src={photo} size={16} />
|
|
4
|
+
|
|
5
|
+
A round image with the first initial as fallback. 24 by default, 16 in a
|
|
6
|
+
row's trail, 18 before a message's author.
|
|
7
|
+
*/
|
|
8
|
+
import { Avatar as Base, AvatarFallback, AvatarImage } from "@ui-sdk/solid/avatar";
|
|
9
|
+
import type { JSX } from "@solidjs/web";
|
|
10
|
+
import { cn } from "./cn.ts";
|
|
11
|
+
|
|
12
|
+
export type AvatarProps = { name: string; src?: string; size?: 16 | 18 | 24; class?: string };
|
|
13
|
+
|
|
14
|
+
export function Avatar(props: AvatarProps): JSX.Element {
|
|
15
|
+
return (
|
|
16
|
+
<Base
|
|
17
|
+
data-slot="avatar"
|
|
18
|
+
class={cn(
|
|
19
|
+
"inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full bg-lifted text-ink-2",
|
|
20
|
+
props.size === 16
|
|
21
|
+
? "size-4 text-label"
|
|
22
|
+
: props.size === 18
|
|
23
|
+
? "size-avatar text-initial"
|
|
24
|
+
: "size-6 text-label",
|
|
25
|
+
props.class,
|
|
26
|
+
)}
|
|
27
|
+
>
|
|
28
|
+
{props.src && <AvatarImage src={props.src} alt={props.name} class="size-full object-cover" />}
|
|
29
|
+
<AvatarFallback role="img" aria-label={props.name}>
|
|
30
|
+
{props.name.trim().charAt(0).toUpperCase()}
|
|
31
|
+
</AvatarFallback>
|
|
32
|
+
</Base>
|
|
33
|
+
);
|
|
34
|
+
}
|