@glasshome/ui 1.12.0 → 1.14.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/SPEC.md +11 -1
- package/dist/index.js +2 -2
- package/dist/lib/motion-classes.d.ts +2 -0
- package/dist/solid/area-picker.d.ts +1 -0
- package/dist/solid/dock-paging.d.ts +8 -0
- package/dist/solid/dock.d.ts +8 -0
- package/dist/solid/form.d.ts +1 -0
- package/dist/solid/index.d.ts +1 -0
- package/dist/solid/index.js +4801 -4646
- package/dist/solid/schema-form.d.ts +1 -1
- package/dist/tokens/index.d.ts +1 -0
- package/dist/tokens/index.js +25 -1
- package/dist/tokens/theme-css.d.ts +4 -0
- package/dist/{utils-CdUh67Y9.js → utils-DMaksjvy.js} +511 -511
- package/package.json +6 -2
- package/scripts/check-gallery.ts +190 -0
- package/scripts/check-tokens.ts +2 -13
- package/src/lib/motion-classes.ts +11 -0
- package/src/solid/area-picker.tsx +1 -0
- package/src/solid/card.tsx +1 -0
- package/src/solid/dock-paging.ts +24 -0
- package/src/solid/dock.tsx +172 -22
- package/src/solid/form.tsx +1 -0
- package/src/solid/index.ts +1 -0
- package/src/solid/schema-form.tsx +58 -18
- package/src/solid/section-card.tsx +1 -0
- package/src/solid/widget-card.tsx +1 -0
- package/src/styles/globals.css +40 -0
- package/src/tokens/index.ts +1 -0
- package/src/tokens/theme-css.ts +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glasshome/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "SolidJS component library for GlassHome, built on Kobalte",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/glasshome/ui#readme",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"build": "rm -rf dist && vite build && tsc",
|
|
64
64
|
"check:structural": "bun scripts/check-structural-classes.ts",
|
|
65
65
|
"check:dead": "fallow dead-code --fail-on-issues",
|
|
66
|
+
"check:gallery": "bun scripts/check-gallery.ts",
|
|
66
67
|
"check:styling": "fallow health --css",
|
|
67
68
|
"check:tokens": "bun scripts/check-tokens.ts",
|
|
68
69
|
"check:types": "tsc --noEmit -p tsconfig.test.json",
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
"@iconify/types": "^2.0.0",
|
|
84
85
|
"@iconify/utils": "^3.1.4",
|
|
85
86
|
"@kobalte/core": "^0.13.13",
|
|
87
|
+
"@types/json-schema": "^7.0.15",
|
|
86
88
|
"clsx": "^2.1.1",
|
|
87
89
|
"cva": "^1.0.0-beta.4",
|
|
88
90
|
"embla-carousel": "^8.5.1",
|
|
@@ -94,9 +96,11 @@
|
|
|
94
96
|
"devDependencies": {
|
|
95
97
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
96
98
|
"@biomejs/biome": "2.4.15",
|
|
99
|
+
"@iconify-json/lucide": "^1.2.130",
|
|
100
|
+
"@iconify-json/mdi": "^1.2.3",
|
|
101
|
+
"@iconify-json/simple-icons": "^1.2.95",
|
|
97
102
|
"@solidjs/testing-library": "^0.8.10",
|
|
98
103
|
"@tailwindcss/vite": "^4.1.13",
|
|
99
|
-
"@types/json-schema": "^7.0.15",
|
|
100
104
|
"@types/node": "^25.2.2",
|
|
101
105
|
"fallow": "3.17.0",
|
|
102
106
|
"happy-dom": "^20.11.0",
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import {
|
|
5
|
+
type Identifier,
|
|
6
|
+
isIdentifier,
|
|
7
|
+
isJsxAttribute,
|
|
8
|
+
isJsxElement,
|
|
9
|
+
isJsxSelfClosingElement,
|
|
10
|
+
isStringLiteral,
|
|
11
|
+
type JsxOpeningElement,
|
|
12
|
+
type JsxSelfClosingElement,
|
|
13
|
+
type Node,
|
|
14
|
+
} from "typescript/unstable/ast";
|
|
15
|
+
import {
|
|
16
|
+
API,
|
|
17
|
+
type Checker,
|
|
18
|
+
SignatureKind,
|
|
19
|
+
SymbolFlags,
|
|
20
|
+
type Symbol as TsSymbol,
|
|
21
|
+
} from "typescript/unstable/async";
|
|
22
|
+
import { ALLOW } from "../dev/coverage-allow";
|
|
23
|
+
|
|
24
|
+
const pkg = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
25
|
+
const CONFIG = join(pkg, "tsconfig.test.json");
|
|
26
|
+
const ENTRY = join(pkg, "src/solid/index.ts");
|
|
27
|
+
const GROUPS = join(pkg, "dev/groups");
|
|
28
|
+
const SCREAMING_CASE = /^[A-Z][A-Z0-9_]*$/;
|
|
29
|
+
|
|
30
|
+
export type Component = { name: string; module: string };
|
|
31
|
+
export type SpecimenUse = { name: string; renders: string[] };
|
|
32
|
+
export type Inventory = { exports: string[]; components: Component[]; specimens: SpecimenUse[] };
|
|
33
|
+
export type Report = {
|
|
34
|
+
uncovered: string[];
|
|
35
|
+
unknownSpecimens: string[];
|
|
36
|
+
emptyReasons: string[];
|
|
37
|
+
staleAllows: string[];
|
|
38
|
+
};
|
|
39
|
+
type Allow = ReadonlyArray<readonly [name: string, reason: string]>;
|
|
40
|
+
|
|
41
|
+
export function judge(inventory: Inventory, allow: Allow): Report {
|
|
42
|
+
const moduleOf = new Map(inventory.components.map((c) => [c.name, c.module]));
|
|
43
|
+
const named = new Set(inventory.specimens.map((s) => s.name));
|
|
44
|
+
const exportNames = new Set(inventory.exports);
|
|
45
|
+
const renderedByOwnModule = (c: Component) =>
|
|
46
|
+
inventory.specimens.some(
|
|
47
|
+
(s) => moduleOf.get(s.name) === c.module && s.renders.includes(c.name),
|
|
48
|
+
);
|
|
49
|
+
const uncovered = inventory.components
|
|
50
|
+
.filter((c) => !named.has(c.name) && !renderedByOwnModule(c))
|
|
51
|
+
.map((c) => c.name);
|
|
52
|
+
const unknown = [...named].filter((name) => !exportNames.has(name));
|
|
53
|
+
const allowed = new Set(allow.map(([name]) => name));
|
|
54
|
+
const failing = new Set([...uncovered, ...unknown]);
|
|
55
|
+
return {
|
|
56
|
+
uncovered: uncovered.filter((name) => !allowed.has(name)),
|
|
57
|
+
unknownSpecimens: unknown.filter((name) => !allowed.has(name)),
|
|
58
|
+
emptyReasons: allow.filter(([, reason]) => reason.trim() === "").map(([name]) => name),
|
|
59
|
+
staleAllows: allow.filter(([name]) => !failing.has(name)).map(([name]) => name),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function resolveAlias(checker: Checker, symbol: TsSymbol): Promise<TsSymbol> {
|
|
64
|
+
return symbol.flags & SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function returnsJsx(checker: Checker, symbol: TsSymbol): Promise<boolean> {
|
|
68
|
+
const type = await checker.getTypeOfSymbol(symbol);
|
|
69
|
+
if (!type) return false;
|
|
70
|
+
const signatures = await checker.getSignaturesOfType(type, SignatureKind.Call);
|
|
71
|
+
if (signatures.length === 0) return false;
|
|
72
|
+
for (const signature of signatures) {
|
|
73
|
+
const returned = await checker.getReturnTypeOfSignature(signature);
|
|
74
|
+
const alias = await returned?.getAliasSymbol();
|
|
75
|
+
const namespace = await alias?.getParent();
|
|
76
|
+
if (alias?.name !== "Element" || namespace?.name !== "JSX") return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function openingOf(node: Node): JsxOpeningElement | JsxSelfClosingElement | undefined {
|
|
82
|
+
if (isJsxElement(node)) return node.openingElement;
|
|
83
|
+
return isJsxSelfClosingElement(node) ? node : undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function jsxTag(node: Node): Identifier | undefined {
|
|
87
|
+
const opening = openingOf(node);
|
|
88
|
+
return opening && isIdentifier(opening.tagName) ? opening.tagName : undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function specimenName(node: Node): string | undefined {
|
|
92
|
+
const opening = openingOf(node);
|
|
93
|
+
if (!opening || jsxTag(node)?.text !== "Specimen") return undefined;
|
|
94
|
+
for (const attribute of opening.attributes.properties) {
|
|
95
|
+
if (!isJsxAttribute(attribute) || !isIdentifier(attribute.name)) continue;
|
|
96
|
+
if (attribute.name.text !== "name") continue;
|
|
97
|
+
return attribute.initializer && isStringLiteral(attribute.initializer)
|
|
98
|
+
? attribute.initializer.text
|
|
99
|
+
: "{non-literal name}";
|
|
100
|
+
}
|
|
101
|
+
return "{no name}";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function collectInventory(): Promise<Inventory> {
|
|
105
|
+
const api = new API({ cwd: pkg });
|
|
106
|
+
try {
|
|
107
|
+
const snapshot = await api.updateSnapshot({ openProjects: [CONFIG] });
|
|
108
|
+
const project = snapshot.getProject(CONFIG);
|
|
109
|
+
if (!project) throw new Error(`typescript did not load ${CONFIG}`);
|
|
110
|
+
const { checker, program } = project;
|
|
111
|
+
|
|
112
|
+
const entry = await program.getSourceFile(ENTRY);
|
|
113
|
+
const entrySymbol = entry && (await checker.getSymbolAtLocation(entry));
|
|
114
|
+
if (!entrySymbol) throw new Error(`typescript did not load ${ENTRY}`);
|
|
115
|
+
|
|
116
|
+
const exports: string[] = [];
|
|
117
|
+
const components: Component[] = [];
|
|
118
|
+
const exportsByTarget = new Map<number, string[]>();
|
|
119
|
+
for (const exported of await checker.getExportsOfModule(entrySymbol)) {
|
|
120
|
+
const target = await resolveAlias(checker, exported);
|
|
121
|
+
if (!(target.flags & SymbolFlags.Value)) continue;
|
|
122
|
+
exports.push(exported.name);
|
|
123
|
+
if (SCREAMING_CASE.test(exported.name) || !(await returnsJsx(checker, target))) continue;
|
|
124
|
+
const declaration = target.valueDeclaration ?? target.declarations[0];
|
|
125
|
+
components.push({ name: exported.name, module: declaration?.path ?? "" });
|
|
126
|
+
exportsByTarget.set(target.id, [...(exportsByTarget.get(target.id) ?? []), exported.name]);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const specimens = new Map<string, Set<string>>();
|
|
130
|
+
for (const file of readdirSync(GROUPS).filter((f) => f.endsWith(".tsx"))) {
|
|
131
|
+
const source = await program.getSourceFile(join(GROUPS, file));
|
|
132
|
+
if (!source) throw new Error(`typescript did not load dev/groups/${file}`);
|
|
133
|
+
const tags: Array<{ specimen: string; tag: Node }> = [];
|
|
134
|
+
const visit = (node: Node, specimen: string | undefined) => {
|
|
135
|
+
const name = specimenName(node);
|
|
136
|
+
const inside = name ?? specimen;
|
|
137
|
+
if (name !== undefined && !specimens.has(name)) specimens.set(name, new Set());
|
|
138
|
+
const tag = name === undefined ? jsxTag(node) : undefined;
|
|
139
|
+
if (tag && inside) tags.push({ specimen: inside, tag });
|
|
140
|
+
node.forEachChild((child) => {
|
|
141
|
+
visit(child, inside);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
visit(source, undefined);
|
|
145
|
+
|
|
146
|
+
const symbols = await checker.getSymbolAtLocation(tags.map((t) => t.tag));
|
|
147
|
+
for (const [i, symbol] of symbols.entries()) {
|
|
148
|
+
const use = tags[i];
|
|
149
|
+
if (!symbol || !use) continue;
|
|
150
|
+
const target = await resolveAlias(checker, symbol);
|
|
151
|
+
for (const exported of exportsByTarget.get(target.id) ?? []) {
|
|
152
|
+
specimens.get(use.specimen)?.add(exported);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
exports,
|
|
159
|
+
components,
|
|
160
|
+
specimens: [...specimens].map(([name, renders]) => ({ name, renders: [...renders] })),
|
|
161
|
+
};
|
|
162
|
+
} finally {
|
|
163
|
+
await api.close();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function galleryReport(allow: Allow = ALLOW): Promise<Report> {
|
|
168
|
+
return judge(await collectInventory(), allow);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
172
|
+
const report = await galleryReport();
|
|
173
|
+
const failures = [
|
|
174
|
+
...report.uncovered.map(
|
|
175
|
+
(name) => `${name}: component export with no <Specimen name="${name}">`,
|
|
176
|
+
),
|
|
177
|
+
...report.unknownSpecimens.map(
|
|
178
|
+
(name) => `<Specimen name="${name}">: not an export of src/solid`,
|
|
179
|
+
),
|
|
180
|
+
...report.emptyReasons.map((name) => `dev/coverage-allow.ts ${name}: empty reason`),
|
|
181
|
+
...report.staleAllows.map(
|
|
182
|
+
(name) => `dev/coverage-allow.ts ${name}: nothing to allow any more, drop the entry`,
|
|
183
|
+
),
|
|
184
|
+
];
|
|
185
|
+
if (failures.length > 0) {
|
|
186
|
+
console.error(`check:gallery, ${failures.length} failing:\n${failures.join("\n")}`);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
console.log("check:gallery: every component export has a specimen");
|
|
190
|
+
}
|
package/scripts/check-tokens.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Fails when styles/theme.css and tokens/presets.ts (midnight-glass) drift.
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { DEFAULT_THEME_ID, getPreset, type ThemeColors } from "../src/tokens";
|
|
4
|
+
import { DEFAULT_THEME_ID, getPreset, parseThemeBlock, type ThemeColors } from "../src/tokens";
|
|
5
5
|
|
|
6
6
|
const css = readFileSync(
|
|
7
7
|
path.resolve(path.dirname(new URL(import.meta.url).pathname), "../src/styles/theme.css"),
|
|
@@ -23,17 +23,6 @@ const KEYS: Record<string, keyof ThemeColors> = {
|
|
|
23
23
|
"--popover": "popover",
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
function cssVars(block: string): Record<string, string> {
|
|
27
|
-
const match = css.match(new RegExp(`${block}\\s*\\{([^}]*)\\}`));
|
|
28
|
-
if (!match) throw new Error(`block not found in theme.css: ${block}`);
|
|
29
|
-
const vars: Record<string, string> = {};
|
|
30
|
-
for (const line of match[1].split("\n")) {
|
|
31
|
-
const m = line.match(/^\s*(--[\w-]+):\s*(.+?);\s*$/);
|
|
32
|
-
if (m) vars[m[1]] = m[2];
|
|
33
|
-
}
|
|
34
|
-
return vars;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
26
|
const preset = getPreset(DEFAULT_THEME_ID);
|
|
38
27
|
if (!preset) throw new Error(`preset missing: ${DEFAULT_THEME_ID}`);
|
|
39
28
|
|
|
@@ -42,7 +31,7 @@ for (const [mode, block] of [
|
|
|
42
31
|
["light", ":root"],
|
|
43
32
|
["dark", ".dark"],
|
|
44
33
|
] as const) {
|
|
45
|
-
const vars =
|
|
34
|
+
const vars = parseThemeBlock(css, block);
|
|
46
35
|
for (const [cssKey, tokenKey] of Object.entries(KEYS)) {
|
|
47
36
|
const cssValue = vars[cssKey];
|
|
48
37
|
const tokenValue = preset.colors[mode][tokenKey];
|
|
@@ -38,3 +38,14 @@ export const SETTLE_MOTION =
|
|
|
38
38
|
|
|
39
39
|
/* Every pressable dips the same amount. */
|
|
40
40
|
export const PRESS_DIP = "active:scale-[0.97]";
|
|
41
|
+
|
|
42
|
+
/* Hold progress: a fill grows out of the touch while held, dissolves once the
|
|
43
|
+
* hold fires, and drains back faster if let go early. The host sets data-hold / data-fired. */
|
|
44
|
+
export const HOLD_MOTION =
|
|
45
|
+
"scale-0 opacity-0 transition-[scale,opacity] duration-(--duration-state) ease-(--ease-contract) data-[hold]:scale-100 data-[hold]:opacity-100 data-[hold]:duration-(--duration-morph) data-[hold]:ease-linear data-[fired]:scale-100 data-[fired]:opacity-0";
|
|
46
|
+
|
|
47
|
+
/* MODAL_MOTION's twin for a surface that stays mounted: it rises out of what
|
|
48
|
+
* opened it, and its closed state is a resting style, since a mount door's exit
|
|
49
|
+
* ends and leaves the element showing. */
|
|
50
|
+
export const RISE_MOTION =
|
|
51
|
+
"origin-bottom transition-[opacity,scale,translate] data-[expanded]:duration-(--duration-expand) data-[expanded]:ease-(--ease-expand) data-[closed]:duration-(--duration-micro) data-[closed]:ease-(--ease-contract) data-[closed]:pointer-events-none data-[closed]:translate-y-2 data-[closed]:scale-95 data-[closed]:opacity-0";
|
|
@@ -15,6 +15,7 @@ interface AreaPickerBaseProps {
|
|
|
15
15
|
class?: string;
|
|
16
16
|
/** false: a re-tap on the picked area keeps it instead of clearing. */
|
|
17
17
|
allowClear?: boolean;
|
|
18
|
+
/** A read-only caller renders the real picker dimmed, never a plain text line. */
|
|
18
19
|
disabled?: boolean;
|
|
19
20
|
/** Id of the element naming the trigger, for forms that label it outside. */
|
|
20
21
|
"aria-labelledby"?: string;
|
package/src/solid/card.tsx
CHANGED
|
@@ -36,6 +36,7 @@ type CardProps = ComponentProps<"div"> &
|
|
|
36
36
|
ornament?: "arrow" | "check";
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
// The card owns the padding: every part below carries none, and no part has a margin.
|
|
39
40
|
const Card: Component<CardProps> = (props) => {
|
|
40
41
|
const [local, others] = splitProps(props, [
|
|
41
42
|
"class",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A page is one strip-width of items. The last one is whatever is left. */
|
|
2
|
+
export function pageCount(scrollWidth: number, viewport: number): number {
|
|
3
|
+
if (viewport <= 0) return 1;
|
|
4
|
+
return Math.max(1, Math.ceil(scrollWidth / viewport));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** The page a scroll position sits on, counting a half-page as turned. */
|
|
8
|
+
export function pageOf(scrollLeft: number, viewport: number): number {
|
|
9
|
+
if (viewport <= 0) return 0;
|
|
10
|
+
return Math.round(scrollLeft / viewport);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Where to scroll for a page, clamped to the end of the strip. */
|
|
14
|
+
export function pageOffset(page: number, viewport: number, scrollWidth: number): number {
|
|
15
|
+
const max = Math.max(0, scrollWidth - viewport);
|
|
16
|
+
return Math.min(max, Math.max(0, page * viewport));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The strip shows whole items: a half-drawn icon at the edge reads as damage, not as a hint. */
|
|
20
|
+
export function stripWidth(available: number, itemWidth: number, gap: number): number {
|
|
21
|
+
if (available <= 0 || itemWidth <= 0) return available;
|
|
22
|
+
const count = Math.max(1, Math.floor((available + gap) / (itemWidth + gap)));
|
|
23
|
+
return Math.min(available, count * itemWidth + (count - 1) * gap);
|
|
24
|
+
}
|
package/src/solid/dock.tsx
CHANGED
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
} from "solid-js";
|
|
13
13
|
import { Dynamic } from "solid-js/web";
|
|
14
14
|
import { CARD_SURFACE } from "../lib/card-classes.js";
|
|
15
|
-
import { PRESS_DIP } from "../lib/motion-classes.js";
|
|
15
|
+
import { HOLD_MOTION, PRESS_DIP } from "../lib/motion-classes.js";
|
|
16
16
|
import { cn } from "../lib/utils.js";
|
|
17
17
|
import { Badge } from "./badge.js";
|
|
18
|
+
import { pageCount, pageOf, pageOffset, stripWidth } from "./dock-paging.js";
|
|
18
19
|
import { SlidingIndicator } from "./sliding-indicator.js";
|
|
19
20
|
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
20
21
|
|
|
@@ -31,6 +32,10 @@ interface DockItem {
|
|
|
31
32
|
interface DockProps extends ComponentProps<"div"> {
|
|
32
33
|
items: DockItem[];
|
|
33
34
|
dockMode?: "floating" | "docked";
|
|
35
|
+
/** Where a hold started, relative to the surface; `fired` once it has triggered. */
|
|
36
|
+
hold?: { x: number; y: number; fired: boolean } | null;
|
|
37
|
+
/** A rim light that orbits for as long as a mode is on. */
|
|
38
|
+
glow?: boolean;
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
interface DockIconButtonProps extends ComponentProps<"button"> {
|
|
@@ -95,10 +100,28 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
|
|
|
95
100
|
};
|
|
96
101
|
|
|
97
102
|
const Dock: Component<DockProps> = (props) => {
|
|
98
|
-
const [local, rest] = splitProps(props, ["items", "class", "dockMode"]);
|
|
103
|
+
const [local, rest] = splitProps(props, ["items", "class", "dockMode", "hold", "glow"]);
|
|
104
|
+
// The drain plays where the fill grew, so the point outlives the hold.
|
|
105
|
+
const [holdPoint, setHoldPoint] = createSignal({ x: 0, y: 0, r: 0 });
|
|
106
|
+
let surfaceRef: HTMLDivElement | undefined;
|
|
107
|
+
createEffect(() => {
|
|
108
|
+
const h = local.hold;
|
|
109
|
+
if (!h) return;
|
|
110
|
+
const w = surfaceRef?.clientWidth ?? 0;
|
|
111
|
+
const ht = surfaceRef?.clientHeight ?? 0;
|
|
112
|
+
// Reaches the farthest corner exactly at full scale, so the fill ends as the hold does.
|
|
113
|
+
setHoldPoint({
|
|
114
|
+
x: h.x,
|
|
115
|
+
y: h.y,
|
|
116
|
+
r: Math.hypot(Math.max(h.x, w - h.x), Math.max(h.y, ht - h.y)),
|
|
117
|
+
});
|
|
118
|
+
});
|
|
99
119
|
const dockMode = () => local.dockMode ?? "floating";
|
|
100
120
|
let containerRef!: HTMLDivElement;
|
|
101
121
|
const [needsScroll, setNeedsScroll] = createSignal(false);
|
|
122
|
+
const [pages, setPages] = createSignal(1);
|
|
123
|
+
const [page, setPage] = createSignal(0);
|
|
124
|
+
const [viewportWidth, setViewportWidth] = createSignal(0);
|
|
102
125
|
|
|
103
126
|
// The moving background: the shared SlidingIndicator tracks the active item.
|
|
104
127
|
const activeIndex = () => {
|
|
@@ -106,34 +129,95 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
106
129
|
return i < 0 ? null : i;
|
|
107
130
|
};
|
|
108
131
|
|
|
132
|
+
const gapWidth = () =>
|
|
133
|
+
containerRef ? Number.parseFloat(getComputedStyle(containerRef).columnGap) || 0 : 0;
|
|
134
|
+
const itemWidth = () =>
|
|
135
|
+
containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect().width ?? 0;
|
|
136
|
+
|
|
109
137
|
const checkOverflow = () => {
|
|
110
|
-
if (containerRef)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
setNeedsScroll(
|
|
138
|
+
if (!containerRef) return;
|
|
139
|
+
const surface = containerRef.parentElement;
|
|
140
|
+
if (!surface) {
|
|
141
|
+
setNeedsScroll(containerRef.scrollWidth > window.innerWidth);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const surfaceStyle = getComputedStyle(surface);
|
|
145
|
+
const paddingX =
|
|
146
|
+
(Number.parseFloat(surfaceStyle.paddingLeft) || 0) +
|
|
147
|
+
(Number.parseFloat(surfaceStyle.paddingRight) || 0);
|
|
148
|
+
let siblingWidth = 0;
|
|
149
|
+
for (const child of Array.from(surface.children)) {
|
|
150
|
+
if (child === containerRef) continue;
|
|
151
|
+
const childStyle = getComputedStyle(child);
|
|
152
|
+
// The page dots overlay the bar out of flow; they do not narrow it.
|
|
153
|
+
if (childStyle.position === "absolute" || childStyle.position === "fixed") continue;
|
|
154
|
+
siblingWidth +=
|
|
155
|
+
child.getBoundingClientRect().width +
|
|
156
|
+
(Number.parseFloat(childStyle.marginLeft) || 0) +
|
|
157
|
+
(Number.parseFloat(childStyle.marginRight) || 0);
|
|
158
|
+
}
|
|
159
|
+
const availableWidth = surface.clientWidth - paddingX - siblingWidth;
|
|
160
|
+
const overflowing = containerRef.scrollWidth > availableWidth;
|
|
161
|
+
const trimmed = overflowing ? stripWidth(availableWidth, itemWidth(), gapWidth()) : 0;
|
|
162
|
+
if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
|
|
163
|
+
setNeedsScroll(overflowing);
|
|
164
|
+
const viewport = trimmed > 0 ? trimmed : containerRef.clientWidth;
|
|
165
|
+
setViewportWidth(viewport);
|
|
166
|
+
setPages(pageCount(containerRef.scrollWidth, viewport));
|
|
167
|
+
setPage(pageOf(containerRef.scrollLeft, viewport));
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// The surface animates its width, so a read taken right after we set one is
|
|
171
|
+
// mid-transition: clearing our trim has to settle before the next measure.
|
|
172
|
+
let settleId: ReturnType<typeof setTimeout> | undefined;
|
|
173
|
+
const remeasure = () => {
|
|
174
|
+
if (!containerRef) return;
|
|
175
|
+
if (!containerRef.style.width) {
|
|
176
|
+
checkOverflow();
|
|
177
|
+
return;
|
|
114
178
|
}
|
|
179
|
+
containerRef.style.width = "";
|
|
180
|
+
clearTimeout(settleId);
|
|
181
|
+
settleId = setTimeout(checkOverflow, 250);
|
|
115
182
|
};
|
|
116
183
|
|
|
184
|
+
const goToPage = (next: number) => {
|
|
185
|
+
if (!containerRef) return;
|
|
186
|
+
containerRef.scrollTo({
|
|
187
|
+
left: pageOffset(next, viewportWidth(), containerRef.scrollWidth),
|
|
188
|
+
behavior: "smooth",
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// The active dashboard may sit on another page after a switch elsewhere.
|
|
193
|
+
createEffect(() => {
|
|
194
|
+
const i = activeIndex();
|
|
195
|
+
if (i === null || !containerRef || !needsScroll()) return;
|
|
196
|
+
const item = containerRef.querySelectorAll('[data-slot="dock-item"]')[i];
|
|
197
|
+
item?.scrollIntoView({ inline: "nearest", block: "nearest", behavior: "smooth" });
|
|
198
|
+
});
|
|
199
|
+
|
|
117
200
|
onMount(() => {
|
|
118
|
-
const timeoutId = setTimeout(
|
|
119
|
-
//
|
|
120
|
-
//
|
|
201
|
+
const timeoutId = setTimeout(remeasure, 100);
|
|
202
|
+
// Watching the bar would see its own trim and re-trim forever; the viewport
|
|
203
|
+
// is the only width the dock does not derive from itself.
|
|
121
204
|
let resizeTimeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
122
|
-
const
|
|
205
|
+
const onResize = () => {
|
|
123
206
|
clearTimeout(resizeTimeoutId);
|
|
124
|
-
resizeTimeoutId = setTimeout(
|
|
125
|
-
}
|
|
126
|
-
|
|
207
|
+
resizeTimeoutId = setTimeout(remeasure, 50);
|
|
208
|
+
};
|
|
209
|
+
window.addEventListener("resize", onResize);
|
|
127
210
|
onCleanup(() => {
|
|
128
211
|
clearTimeout(timeoutId);
|
|
129
212
|
clearTimeout(resizeTimeoutId);
|
|
130
|
-
|
|
213
|
+
clearTimeout(settleId);
|
|
214
|
+
window.removeEventListener("resize", onResize);
|
|
131
215
|
});
|
|
132
216
|
});
|
|
133
217
|
|
|
134
218
|
createEffect(() => {
|
|
135
219
|
local.items.length;
|
|
136
|
-
const timeoutId = setTimeout(
|
|
220
|
+
const timeoutId = setTimeout(remeasure, 150);
|
|
137
221
|
onCleanup(() => clearTimeout(timeoutId));
|
|
138
222
|
});
|
|
139
223
|
|
|
@@ -141,22 +225,66 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
141
225
|
<div
|
|
142
226
|
data-slot="dock"
|
|
143
227
|
class={cn(
|
|
144
|
-
"flex items-center justify-center",
|
|
228
|
+
"flex max-w-full items-center justify-center",
|
|
145
229
|
dockMode() === "floating" ? "p-1 sm:p-2" : "",
|
|
146
230
|
local.class,
|
|
147
231
|
)}
|
|
148
232
|
{...rest}
|
|
149
233
|
>
|
|
150
|
-
<div
|
|
234
|
+
<div
|
|
235
|
+
ref={surfaceRef}
|
|
236
|
+
data-slot="dock-surface"
|
|
237
|
+
class={cn(
|
|
238
|
+
// isolate: the layers behind the icons stay inside the dock even with blur off.
|
|
239
|
+
"relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
|
|
240
|
+
// Room for the page dots inside the glass; outside it they sit on
|
|
241
|
+
// the screen edge and get clipped.
|
|
242
|
+
pages() > 1 && "pb-4 sm:pb-5",
|
|
243
|
+
CARD_SURFACE,
|
|
244
|
+
"[--glass-lift:0.55]",
|
|
245
|
+
dockMode() === "floating" ? "rounded-xl" : "rounded-t-xl",
|
|
246
|
+
)}
|
|
247
|
+
>
|
|
248
|
+
<div
|
|
249
|
+
aria-hidden="true"
|
|
250
|
+
class="pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-[inherit]"
|
|
251
|
+
>
|
|
252
|
+
<span
|
|
253
|
+
data-slot="dock-flood"
|
|
254
|
+
data-hold={local.hold && !local.hold.fired ? "" : undefined}
|
|
255
|
+
data-fired={local.hold?.fired ? "" : undefined}
|
|
256
|
+
class={cn(
|
|
257
|
+
"absolute -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary/45",
|
|
258
|
+
HOLD_MOTION,
|
|
259
|
+
)}
|
|
260
|
+
style={{
|
|
261
|
+
left: `${holdPoint().x}px`,
|
|
262
|
+
top: `${holdPoint().y}px`,
|
|
263
|
+
width: `${holdPoint().r * 2}px`,
|
|
264
|
+
height: `${holdPoint().r * 2}px`,
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
<Show when={local.glow}>
|
|
269
|
+
<div
|
|
270
|
+
data-slot="dock-glow"
|
|
271
|
+
aria-hidden="true"
|
|
272
|
+
class="glass-edge-orbit fade-in-0 animate-in duration-(--duration-state)"
|
|
273
|
+
>
|
|
274
|
+
<div />
|
|
275
|
+
</div>
|
|
276
|
+
</Show>
|
|
151
277
|
<div
|
|
152
278
|
ref={containerRef}
|
|
153
279
|
data-slot="dock-bar"
|
|
280
|
+
onScroll={() => {
|
|
281
|
+
if (containerRef) setPage(pageOf(containerRef.scrollLeft, viewportWidth()));
|
|
282
|
+
}}
|
|
154
283
|
class={cn(
|
|
155
|
-
"flex items-center gap-0.5
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
needsScroll() ? "scrollbar-hide overflow-x-auto" : "overflow-visible",
|
|
284
|
+
"flex items-center gap-0.5 sm:gap-1",
|
|
285
|
+
needsScroll()
|
|
286
|
+
? "scrollbar-hide snap-x snap-mandatory overflow-x-auto overscroll-x-contain scroll-smooth"
|
|
287
|
+
: "overflow-visible",
|
|
160
288
|
!needsScroll() && "justify-center",
|
|
161
289
|
)}
|
|
162
290
|
style={{
|
|
@@ -167,6 +295,7 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
167
295
|
<Index each={local.items}>
|
|
168
296
|
{(item) => (
|
|
169
297
|
<DockIconButton
|
|
298
|
+
class={needsScroll() ? "snap-start" : undefined}
|
|
170
299
|
icon={item().icon}
|
|
171
300
|
label={item().label}
|
|
172
301
|
onClick={item().onClick}
|
|
@@ -177,6 +306,27 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
177
306
|
</Index>
|
|
178
307
|
</SlidingIndicator>
|
|
179
308
|
</div>
|
|
309
|
+
<Show when={pages() > 1}>
|
|
310
|
+
<div
|
|
311
|
+
data-slot="dock-pages"
|
|
312
|
+
class="pointer-events-auto absolute inset-x-0 bottom-1.5 flex justify-center gap-1.5"
|
|
313
|
+
>
|
|
314
|
+
<Index each={Array.from({ length: pages() })}>
|
|
315
|
+
{(_, i) => (
|
|
316
|
+
<button
|
|
317
|
+
type="button"
|
|
318
|
+
aria-label={`Page ${i + 1}`}
|
|
319
|
+
aria-current={page() === i ? "true" : undefined}
|
|
320
|
+
onClick={() => goToPage(i)}
|
|
321
|
+
class={cn(
|
|
322
|
+
"h-1.5 rounded-full transition-glass",
|
|
323
|
+
page() === i ? "w-4 bg-foreground/70" : "w-1.5 bg-foreground/25",
|
|
324
|
+
)}
|
|
325
|
+
/>
|
|
326
|
+
)}
|
|
327
|
+
</Index>
|
|
328
|
+
</div>
|
|
329
|
+
</Show>
|
|
180
330
|
</div>
|
|
181
331
|
</div>
|
|
182
332
|
);
|
package/src/solid/form.tsx
CHANGED
|
@@ -43,6 +43,7 @@ const FormContext = createContext<FormContextValue>();
|
|
|
43
43
|
|
|
44
44
|
const Form: ParentComponent<
|
|
45
45
|
ComponentProps<"form"> & {
|
|
46
|
+
/** Headless: the parent's validation lib owns these; label, control aria-invalid and message all react to them. */
|
|
46
47
|
errors?: Record<string, string>;
|
|
47
48
|
onSetError?: (name: string, error: string) => void;
|
|
48
49
|
onClearError?: (name: string) => void;
|
package/src/solid/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
export { type Color, parseColor } from "@kobalte/core/colors";
|
|
6
6
|
// Floating glass panel + its shared surface token.
|
|
7
7
|
export { SECTION_ROW_SURFACE } from "../lib/card-classes.js";
|
|
8
|
+
export { RISE_MOTION } from "../lib/motion-classes.js";
|
|
8
9
|
export { OVERLAY_SURFACE } from "../lib/overlay-classes.js";
|
|
9
10
|
// Section tokens re-exported from the Solid entry for convenience.
|
|
10
11
|
export {
|