@glasshome/ui 1.13.0 → 1.15.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 +8 -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 +2 -0
- package/dist/solid/index.js +5345 -5118
- package/dist/solid/picker-trigger.d.ts +11 -0
- 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/area-picker.tsx +18 -14
- package/src/solid/dock-paging.ts +24 -0
- package/src/solid/dock.tsx +172 -22
- package/src/solid/entity-selector.tsx +30 -47
- package/src/solid/icon-picker.tsx +13 -15
- package/src/solid/image-picker.tsx +15 -15
- package/src/solid/index.ts +2 -0
- package/src/solid/picker-trigger.tsx +68 -0
- package/src/solid/schema-form.tsx +58 -18
- package/src/styles/globals.css +40 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type JSX, Show, splitProps } from "solid-js";
|
|
2
|
+
import { PICKER_TRIGGER } from "../lib/picker-classes.js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Icon } from "./icon.js";
|
|
5
|
+
|
|
6
|
+
export interface PickerTriggerProps
|
|
7
|
+
extends Omit<JSX.ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> {
|
|
8
|
+
/** data-slot for the button, so each picker keeps its own test and style hook. */
|
|
9
|
+
slot: string;
|
|
10
|
+
open: boolean;
|
|
11
|
+
onToggle: () => void;
|
|
12
|
+
/** Passed only when there is a value to drop: its presence paints the clear button. */
|
|
13
|
+
onClear?: () => void;
|
|
14
|
+
clearLabel?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function PickerTrigger(props: PickerTriggerProps) {
|
|
18
|
+
const [own, rest] = splitProps(props, [
|
|
19
|
+
"slot",
|
|
20
|
+
"open",
|
|
21
|
+
"onToggle",
|
|
22
|
+
"onClear",
|
|
23
|
+
"clearLabel",
|
|
24
|
+
"class",
|
|
25
|
+
"children",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div class="relative">
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
data-slot={own.slot}
|
|
33
|
+
data-expanded={own.open || undefined}
|
|
34
|
+
class={cn(PICKER_TRIGGER, own.class)}
|
|
35
|
+
onClick={() => own.onToggle()}
|
|
36
|
+
{...rest}
|
|
37
|
+
>
|
|
38
|
+
{own.children}
|
|
39
|
+
{/* The clear button cannot nest inside the trigger button, so it is
|
|
40
|
+
positioned over this gap, left of the chevron. */}
|
|
41
|
+
<Show when={own.onClear}>
|
|
42
|
+
<span class="w-6 shrink-0" />
|
|
43
|
+
</Show>
|
|
44
|
+
<Icon
|
|
45
|
+
icon="lucide:chevron-down"
|
|
46
|
+
width={16}
|
|
47
|
+
height={16}
|
|
48
|
+
class={cn(
|
|
49
|
+
"shrink-0 text-muted-foreground transition-transform",
|
|
50
|
+
own.open && "rotate-180",
|
|
51
|
+
)}
|
|
52
|
+
/>
|
|
53
|
+
</button>
|
|
54
|
+
<Show when={own.onClear}>
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
data-slot="picker-trigger-clear"
|
|
58
|
+
aria-label={own.clearLabel ?? "Clear selection"}
|
|
59
|
+
disabled={rest.disabled}
|
|
60
|
+
class="absolute top-1/2 right-9 flex -translate-y-1/2 items-center rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-50"
|
|
61
|
+
onClick={() => own.onClear?.()}
|
|
62
|
+
>
|
|
63
|
+
<Icon icon="lucide:circle-x" width={16} height={16} />
|
|
64
|
+
</button>
|
|
65
|
+
</Show>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -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
|