@glasshome/ui 1.13.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 +7 -1
- package/dist/index.js +2 -2
- package/dist/lib/motion-classes.d.ts +2 -0
- package/dist/solid/dock-paging.d.ts +8 -0
- package/dist/solid/dock.d.ts +8 -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/{utils-CdUh67Y9.js → utils-DMaksjvy.js} +511 -511
- package/package.json +2 -2
- package/src/lib/motion-classes.ts +11 -0
- package/src/solid/dock-paging.ts +24 -0
- package/src/solid/dock.tsx +172 -22
- package/src/solid/index.ts +1 -0
- package/src/solid/schema-form.tsx +58 -18
- package/src/styles/globals.css +40 -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",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"@iconify/types": "^2.0.0",
|
|
85
85
|
"@iconify/utils": "^3.1.4",
|
|
86
86
|
"@kobalte/core": "^0.13.13",
|
|
87
|
+
"@types/json-schema": "^7.0.15",
|
|
87
88
|
"clsx": "^2.1.1",
|
|
88
89
|
"cva": "^1.0.0-beta.4",
|
|
89
90
|
"embla-carousel": "^8.5.1",
|
|
@@ -100,7 +101,6 @@
|
|
|
100
101
|
"@iconify-json/simple-icons": "^1.2.95",
|
|
101
102
|
"@solidjs/testing-library": "^0.8.10",
|
|
102
103
|
"@tailwindcss/vite": "^4.1.13",
|
|
103
|
-
"@types/json-schema": "^7.0.15",
|
|
104
104
|
"@types/node": "^25.2.2",
|
|
105
105
|
"fallow": "3.17.0",
|
|
106
106
|
"happy-dom": "^20.11.0",
|
|
@@ -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";
|
|
@@ -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/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 {
|
|
@@ -20,6 +20,7 @@ import { useMediaStore } from "./media-store.js";
|
|
|
20
20
|
import { NumberField } from "./number-field.js";
|
|
21
21
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
22
22
|
import { Switch } from "./switch.js";
|
|
23
|
+
import { ToggleGroup, ToggleGroupItem } from "./toggle-group.js";
|
|
23
24
|
|
|
24
25
|
export interface ExtendedJSONSchema extends JSONSchema7 {
|
|
25
26
|
/* Nested schemas carry the same extensions, so a whole tree types as one. */
|
|
@@ -105,6 +106,10 @@ function isStringArray(prop: ExtendedJSONSchema): boolean {
|
|
|
105
106
|
return prop.type === "array" && itemsOf(prop).type === "string";
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
function isChoiceArray(prop: ExtendedJSONSchema): boolean {
|
|
110
|
+
return prop.type === "array" && itemsOf(prop).enum !== undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
108
113
|
function isObjectGroup(prop: ExtendedJSONSchema): boolean {
|
|
109
114
|
return prop.type === "object" && prop.properties !== undefined && prop.formType === undefined;
|
|
110
115
|
}
|
|
@@ -168,7 +173,7 @@ export function switchVariantValue(
|
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
interface SchemaFormProps {
|
|
171
|
-
schema:
|
|
176
|
+
schema: ExtendedJSONSchema;
|
|
172
177
|
data: Record<string, unknown>;
|
|
173
178
|
onChange: (data: Record<string, unknown>) => void;
|
|
174
179
|
errors?: string[];
|
|
@@ -181,7 +186,7 @@ export function SchemaForm(props: SchemaFormProps) {
|
|
|
181
186
|
const properties = () => {
|
|
182
187
|
const schema = props.schema;
|
|
183
188
|
if (schema.type !== "object" || !schema.properties) return [];
|
|
184
|
-
return propertiesOf(schema
|
|
189
|
+
return propertiesOf(schema);
|
|
185
190
|
};
|
|
186
191
|
|
|
187
192
|
// Controlled: props.data is the single source of truth, so parent-driven
|
|
@@ -251,6 +256,7 @@ type ControlKind =
|
|
|
251
256
|
| "enum"
|
|
252
257
|
| "boolean"
|
|
253
258
|
| "number"
|
|
259
|
+
| "choices"
|
|
254
260
|
| "strings"
|
|
255
261
|
| "group"
|
|
256
262
|
| "text";
|
|
@@ -268,6 +274,7 @@ const CONTROL_KINDS: ReadonlyArray<
|
|
|
268
274
|
["enum", (prop) => prop.enum !== undefined],
|
|
269
275
|
["boolean", (prop) => prop.type === "boolean"],
|
|
270
276
|
["number", (prop) => prop.type === "number" || prop.type === "integer"],
|
|
277
|
+
["choices", (prop) => isChoiceArray(prop)],
|
|
271
278
|
["strings", (prop) => isStringArray(prop)],
|
|
272
279
|
["group", (prop) => isObjectGroup(prop)],
|
|
273
280
|
];
|
|
@@ -290,13 +297,14 @@ const LABEL_TARGET: Record<ControlKind, "for" | "labelledby" | "none"> = {
|
|
|
290
297
|
boolean: "labelledby",
|
|
291
298
|
list: "labelledby",
|
|
292
299
|
variants: "labelledby",
|
|
300
|
+
choices: "labelledby",
|
|
293
301
|
strings: "labelledby",
|
|
294
302
|
unknown: "none",
|
|
295
303
|
group: "none",
|
|
296
304
|
};
|
|
297
305
|
|
|
298
|
-
/* A
|
|
299
|
-
*
|
|
306
|
+
/* A hint belongs to the label above it, not to the control below: under the
|
|
307
|
+
* control it reads as the next field's. Groups carry their own caption. */
|
|
300
308
|
function LabeledField(props: FieldProps) {
|
|
301
309
|
const kind = () => controlKind(props.prop, props.name);
|
|
302
310
|
const labelId = () => `${props.id}-label`;
|
|
@@ -307,10 +315,10 @@ function LabeledField(props: FieldProps) {
|
|
|
307
315
|
<FieldLabel id={labelId()} for={target() === "for" ? props.id : undefined}>
|
|
308
316
|
{props.prop.title || props.name}
|
|
309
317
|
</FieldLabel>
|
|
310
|
-
<FieldControl {...props} labelledBy={target() === "labelledby" ? labelId() : undefined} />
|
|
311
318
|
<Show when={props.prop.description}>
|
|
312
319
|
{(description) => <FieldDescription>{description()}</FieldDescription>}
|
|
313
320
|
</Show>
|
|
321
|
+
<FieldControl {...props} labelledBy={target() === "labelledby" ? labelId() : undefined} />
|
|
314
322
|
</Field>
|
|
315
323
|
</Show>
|
|
316
324
|
);
|
|
@@ -319,6 +327,7 @@ function LabeledField(props: FieldProps) {
|
|
|
319
327
|
/** The one recursive dispatch: every nesting level renders through here. */
|
|
320
328
|
function FieldControl(props: FieldProps) {
|
|
321
329
|
const current = () => props.value ?? props.prop.default;
|
|
330
|
+
const enumLabel = (value: string) => props.prop.labels?.[value] ?? value;
|
|
322
331
|
const kind = () => controlKind(props.prop, props.name);
|
|
323
332
|
return (
|
|
324
333
|
<SwitchFlow
|
|
@@ -382,11 +391,13 @@ function FieldControl(props: FieldProps) {
|
|
|
382
391
|
}}
|
|
383
392
|
options={(props.prop.enum ?? []).map(String)}
|
|
384
393
|
itemComponent={(itemProps) => (
|
|
385
|
-
<SelectItem item={itemProps.item}>
|
|
394
|
+
<SelectItem item={itemProps.item}>
|
|
395
|
+
{enumLabel(String(itemProps.item.rawValue))}
|
|
396
|
+
</SelectItem>
|
|
386
397
|
)}
|
|
387
398
|
>
|
|
388
399
|
<SelectTrigger class="w-full" aria-labelledby={props.labelledBy}>
|
|
389
|
-
<SelectValue<string>>{(state) => state.selectedOption()}</SelectValue>
|
|
400
|
+
<SelectValue<string>>{(state) => enumLabel(state.selectedOption())}</SelectValue>
|
|
390
401
|
</SelectTrigger>
|
|
391
402
|
<SelectContent />
|
|
392
403
|
</Select>
|
|
@@ -411,6 +422,9 @@ function FieldControl(props: FieldProps) {
|
|
|
411
422
|
onInput={(e) => props.onChange(Number(e.currentTarget.value))}
|
|
412
423
|
/>
|
|
413
424
|
</Match>
|
|
425
|
+
<Match when={kind() === "choices"}>
|
|
426
|
+
<ChoicesControl {...props} />
|
|
427
|
+
</Match>
|
|
414
428
|
<Match when={kind() === "strings"}>
|
|
415
429
|
<StringListField
|
|
416
430
|
labelledBy={props.labelledBy}
|
|
@@ -493,19 +507,22 @@ function ListControl(props: FieldProps) {
|
|
|
493
507
|
return schema.labels?.[kind] ?? kind;
|
|
494
508
|
};
|
|
495
509
|
|
|
496
|
-
|
|
497
|
-
// labelField value, else "Item N".
|
|
498
|
-
const caption = (item: unknown, index: number) => {
|
|
499
|
-
const record = recordOf(item);
|
|
510
|
+
const labelFieldValue = (item: unknown): string | undefined => {
|
|
500
511
|
const labelField = props.prop.labelField;
|
|
501
|
-
if (labelField
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
return `Item ${index + 1}`;
|
|
512
|
+
if (labelField === undefined) return undefined;
|
|
513
|
+
const value = recordOf(item)[labelField];
|
|
514
|
+
if (typeof value === "string" && value.trim() !== "") return value;
|
|
515
|
+
if (typeof value === "number") return String(value);
|
|
516
|
+
return undefined;
|
|
507
517
|
};
|
|
508
518
|
|
|
519
|
+
const caption = (item: unknown, index: number) =>
|
|
520
|
+
labelFieldValue(item) ?? kindLabel(item) ?? `Item ${index + 1}`;
|
|
521
|
+
|
|
522
|
+
// Only a row the labelField already named has anything left for the badge.
|
|
523
|
+
const badgeLabel = (item: unknown) =>
|
|
524
|
+
labelFieldValue(item) === undefined ? undefined : kindLabel(item);
|
|
525
|
+
|
|
509
526
|
const replaceAt = (index: number, value: unknown) => {
|
|
510
527
|
props.onChange(items().map((item, i) => (i === index ? value : item)));
|
|
511
528
|
};
|
|
@@ -630,7 +647,7 @@ function ListControl(props: FieldProps) {
|
|
|
630
647
|
<span class="pointer-events-none relative min-w-0 flex-1 truncate text-left text-sm">
|
|
631
648
|
{caption(item(), index)}
|
|
632
649
|
</span>
|
|
633
|
-
<Show when={
|
|
650
|
+
<Show when={badgeLabel(item())}>
|
|
634
651
|
{(label) => (
|
|
635
652
|
<Badge class="pointer-events-none relative shrink-0">{label()}</Badge>
|
|
636
653
|
)}
|
|
@@ -774,6 +791,29 @@ function VariantsControl(props: FieldProps) {
|
|
|
774
791
|
);
|
|
775
792
|
}
|
|
776
793
|
|
|
794
|
+
function ChoicesControl(props: FieldProps) {
|
|
795
|
+
const current = () => props.value ?? props.prop.default;
|
|
796
|
+
const enumValues = () => (itemsOf(props.prop).enum ?? []).map(String);
|
|
797
|
+
const labelFor = (v: string) => props.prop.labels?.[v] ?? v;
|
|
798
|
+
|
|
799
|
+
return (
|
|
800
|
+
<ToggleGroup
|
|
801
|
+
multiple
|
|
802
|
+
aria-labelledby={props.labelledBy}
|
|
803
|
+
value={(current() as string[] | undefined) ?? []}
|
|
804
|
+
onChange={(vals) => {
|
|
805
|
+
const order = enumValues();
|
|
806
|
+
props.onChange((vals ?? []).slice().sort((a, b) => order.indexOf(a) - order.indexOf(b)));
|
|
807
|
+
}}
|
|
808
|
+
class="flex flex-wrap gap-1"
|
|
809
|
+
>
|
|
810
|
+
<For each={enumValues()}>
|
|
811
|
+
{(v) => <ToggleGroupItem value={v}>{labelFor(v)}</ToggleGroupItem>}
|
|
812
|
+
</For>
|
|
813
|
+
</ToggleGroup>
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
|
|
777
817
|
function StringListField(props: {
|
|
778
818
|
value: string[];
|
|
779
819
|
onChange: (value: string[]) => void;
|
package/src/styles/globals.css
CHANGED
|
@@ -213,6 +213,46 @@
|
|
|
213
213
|
pointer-events: none;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
/* A mode's rim: the masked ring of .glass-edge-gradient, but the gradient orbits,
|
|
217
|
+
* so a surface can say a mode is on for as long as it lasts. The mask sits on the
|
|
218
|
+
* parent and the gradient rotates as a child, or the ring would rotate with it. */
|
|
219
|
+
:where(.glass-edge-orbit) {
|
|
220
|
+
position: absolute;
|
|
221
|
+
inset: 0;
|
|
222
|
+
border-radius: inherit;
|
|
223
|
+
padding: 1px;
|
|
224
|
+
overflow: hidden;
|
|
225
|
+
mask:
|
|
226
|
+
linear-gradient(#fff 0 0) content-box,
|
|
227
|
+
linear-gradient(#fff 0 0);
|
|
228
|
+
mask-composite: exclude;
|
|
229
|
+
pointer-events: none;
|
|
230
|
+
/* A conic wedge crosses a wide pill's ends fast and its long edges slowly, so the
|
|
231
|
+
* ring keeps a constant floor and the orbit only adds the travelling highlight. */
|
|
232
|
+
background: color-mix(in oklab, var(--primary) 30%, transparent);
|
|
233
|
+
}
|
|
234
|
+
:where(.glass-edge-orbit) > * {
|
|
235
|
+
position: absolute;
|
|
236
|
+
top: 50%;
|
|
237
|
+
left: 50%;
|
|
238
|
+
width: 150%;
|
|
239
|
+
aspect-ratio: 1;
|
|
240
|
+
translate: -50% -50%;
|
|
241
|
+
background: conic-gradient(
|
|
242
|
+
from 0deg,
|
|
243
|
+
transparent 0deg,
|
|
244
|
+
color-mix(in oklab, var(--primary) 95%, transparent) 40deg,
|
|
245
|
+
transparent 100deg,
|
|
246
|
+
transparent 360deg
|
|
247
|
+
);
|
|
248
|
+
animation: spin-slow 8s linear infinite;
|
|
249
|
+
}
|
|
250
|
+
@media (prefers-reduced-motion: reduce) {
|
|
251
|
+
:where(.glass-edge-orbit) > * {
|
|
252
|
+
animation: none;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
216
256
|
/**
|
|
217
257
|
* Consistent, theme-aware overlay scrollbar across browsers. Firefox uses
|
|
218
258
|
* scrollbar-width/color; Chromium/WebKit use the ::-webkit-scrollbar pseudos
|