@glasshome/ui 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/SPEC.md +2 -1
  2. package/dist/index.js +2 -2
  3. package/dist/lib/anchor-placement.d.ts +5 -0
  4. package/dist/lib/button-variants.d.ts +1 -1
  5. package/dist/lib/motion-classes.d.ts +1 -0
  6. package/dist/solid/color-disc.d.ts +33 -0
  7. package/dist/solid/dashboard-preview.d.ts +24 -0
  8. package/dist/solid/dialog-parts.d.ts +1 -0
  9. package/dist/solid/dialog.d.ts +3 -0
  10. package/dist/solid/image-picker.d.ts +3 -0
  11. package/dist/solid/index.d.ts +3 -1
  12. package/dist/solid/index.js +5952 -5538
  13. package/dist/solid/media-store.d.ts +10 -0
  14. package/dist/solid/option-card.d.ts +1 -0
  15. package/dist/solid/page-header.d.ts +2 -2
  16. package/dist/solid/preview-tile.d.ts +2 -0
  17. package/dist/solid/responsive-dialog.d.ts +2 -0
  18. package/dist/solid/schema-form.d.ts +6 -1
  19. package/dist/solid/sliding-indicator.d.ts +2 -0
  20. package/dist/solid/toggle-group.d.ts +4 -1
  21. package/dist/{utils-CV6G6fr8.js → utils-CMk7R3zM.js} +413 -413
  22. package/package.json +1 -1
  23. package/scripts/check-ui-drift.mjs +5 -0
  24. package/src/lib/anchor-placement.ts +30 -0
  25. package/src/lib/button-variants.ts +12 -12
  26. package/src/lib/motion-classes.ts +5 -0
  27. package/src/solid/bottom-sheet/bottom-sheet.tsx +8 -1
  28. package/src/solid/color-disc.tsx +253 -0
  29. package/src/solid/dashboard-preview.tsx +128 -0
  30. package/src/solid/dialog-parts.tsx +5 -1
  31. package/src/solid/dialog.tsx +47 -5
  32. package/src/solid/entity-selector.tsx +2 -2
  33. package/src/solid/image-picker.tsx +232 -147
  34. package/src/solid/index.ts +9 -0
  35. package/src/solid/media-store.ts +20 -1
  36. package/src/solid/option-card.tsx +2 -0
  37. package/src/solid/page-header.tsx +9 -16
  38. package/src/solid/preview-tile.tsx +10 -0
  39. package/src/solid/responsive-dialog.tsx +10 -2
  40. package/src/solid/schema-form.tsx +30 -4
  41. package/src/solid/sliding-indicator.tsx +21 -5
  42. package/src/solid/toggle-group.tsx +43 -5
  43. package/src/styles/theme.css +12 -3
@@ -16,8 +16,9 @@ import { IconPicker, type IconPickerProps } from "./icon-picker.js";
16
16
  import { ImagePicker } from "./image-picker.js";
17
17
  import { Input } from "./input.js";
18
18
  import { createListReorder } from "./list-reorder.js";
19
- import { useMediaStore } from "./media-store.js";
19
+ import { type ImagePreset, imagePreset, useMediaStore } from "./media-store.js";
20
20
  import { NumberField } from "./number-field.js";
21
+ import { OptionCard, OptionCardGroup } from "./option-card.js";
21
22
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
22
23
  import { Switch } from "./switch.js";
23
24
  import { ToggleGroup, ToggleGroupItem } from "./toggle-group.js";
@@ -33,8 +34,12 @@ export interface ExtendedJSONSchema extends JSONSchema7 {
33
34
  deviceClass?: string;
34
35
  /** formType "variants": the property that selects the active branch. */
35
36
  discriminator?: string;
36
- /** formType "variants": kind → display name for the discriminator Select. */
37
+ /** Enum value → display name (field.choice, field.choices, the variants selector). */
37
38
  labels?: Record<string, string>;
39
+ /** field.choice: enum value → icon name; set, the choice renders as icon cards. */
40
+ icons?: Record<string, string>;
41
+ /** formType "image-picker": built-in pictures offered beside the uploads. */
42
+ presets?: Record<string, ImagePreset>;
38
43
  /** formType "list": add-button caption. */
39
44
  addLabel?: string;
40
45
  /** formType "list": item field whose value captions the collapsed row. */
@@ -372,6 +377,7 @@ function FieldControl(props: FieldProps) {
372
377
  <Match when={kind() === "image"}>
373
378
  <ImagePicker
374
379
  id={props.id}
380
+ presets={props.prop.presets}
375
381
  value={String(current() ?? "")}
376
382
  onChange={(val) => props.onChange(val)}
377
383
  />
@@ -383,6 +389,22 @@ function FieldControl(props: FieldProps) {
383
389
  onChange={(val) => props.onChange(val)}
384
390
  />
385
391
  </Match>
392
+ <Match when={kind() === "enum" && props.prop.icons}>
393
+ {(icons) => (
394
+ <OptionCardGroup
395
+ aria-labelledby={props.labelledBy}
396
+ value={String(current() ?? "")}
397
+ onChange={(val) => props.onChange(val)}
398
+ class="grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))]"
399
+ >
400
+ <For each={(props.prop.enum ?? []).map(String)}>
401
+ {(value) => (
402
+ <OptionCard value={value} title={enumLabel(value)} icon={icons()[value]} />
403
+ )}
404
+ </For>
405
+ </OptionCardGroup>
406
+ )}
407
+ </Match>
386
408
  <Match when={kind() === "enum"}>
387
409
  <Select
388
410
  value={String(current() ?? "")}
@@ -479,10 +501,14 @@ function ListControl(props: FieldProps) {
479
501
 
480
502
  const thumbUrl = (item: unknown) => {
481
503
  const key = imageKey();
482
- const store = mediaStore;
483
- if (key === undefined || !store) return undefined;
504
+ if (key === undefined) return undefined;
484
505
  const id = recordOf(item)[key];
485
506
  if (typeof id !== "string" || id === "") return undefined;
507
+ const preset = imagePreset(id);
508
+ if (preset !== undefined)
509
+ return propertiesOf(itemSchema()).find(([k]) => k === key)?.[1].presets?.[preset]?.thumb;
510
+ const store = mediaStore;
511
+ if (!store) return undefined;
486
512
  // A 32px row chip: the thumb variant, never the original.
487
513
  return store.url(id, "thumb");
488
514
  };
@@ -45,10 +45,12 @@ interface SlidingIndicatorProps extends ComponentProps<"div"> {
45
45
  indicatorTone?: string;
46
46
  /** Selector for the measurable items. Default: direct children (minus the indicator). */
47
47
  itemSelector?: string;
48
+ /** Items wrap onto rows: the indicator follows the active item's row as well as its place in it. */
49
+ wrapped?: boolean;
48
50
  children: JSX.Element;
49
51
  }
50
52
 
51
- type Pos = { offset: number; size: number; cross: number };
53
+ type Pos = { offset: number; size: number; cross: number; crossOffset: number };
52
54
 
53
55
  // One duration for both the slide (transform transition) and the scale dip, so
54
56
  // they always overlap exactly. Shorter = snappier.
@@ -73,6 +75,7 @@ export function SlidingIndicator(props: SlidingIndicatorProps) {
73
75
  "indicatorClass",
74
76
  "indicatorTone",
75
77
  "itemSelector",
78
+ "wrapped",
76
79
  "class",
77
80
  "children",
78
81
  "ref",
@@ -174,11 +177,14 @@ export function SlidingIndicator(props: SlidingIndicatorProps) {
174
177
  (er.left - cr.left) / sx - tx - containerRef.clientLeft + containerRef.scrollLeft,
175
178
  size: er.width / sx,
176
179
  cross: er.height / sy,
180
+ crossOffset:
181
+ (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
177
182
  }
178
183
  : {
179
184
  offset: (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
180
185
  size: er.height / sy,
181
186
  cross: er.width / sx,
187
+ crossOffset: 0,
182
188
  },
183
189
  );
184
190
  };
@@ -275,16 +281,26 @@ export function SlidingIndicator(props: SlidingIndicatorProps) {
275
281
  aria-hidden="true"
276
282
  class={cn(
277
283
  "pointer-events-none absolute -z-10",
278
- horizontal() ? "inset-y-0 left-0" : "inset-x-0 top-0",
284
+ local.wrapped
285
+ ? "top-0 left-0"
286
+ : horizontal()
287
+ ? "inset-y-0 left-0"
288
+ : "inset-x-0 top-0",
279
289
  "glass glass-tint",
280
290
  local.indicatorClass ?? "rounded-lg",
281
291
  )}
282
292
  style={{
283
293
  transition: `transform ${SLIDE_MS}ms ease-in-out, width ${SLIDE_MS}ms ease-in-out, height ${SLIDE_MS}ms ease-in-out`,
284
294
  "--glass-tone": local.indicatorTone ?? "var(--primary)",
285
- ...(horizontal()
286
- ? { transform: `translateX(${p().offset}px)`, width: `${p().size}px` }
287
- : { transform: `translateY(${p().offset}px)`, height: `${p().size}px` }),
295
+ ...(local.wrapped && horizontal()
296
+ ? {
297
+ transform: `translate(${p().offset}px, ${p().crossOffset}px)`,
298
+ width: `${p().size}px`,
299
+ height: `${p().cross}px`,
300
+ }
301
+ : horizontal()
302
+ ? { transform: `translateX(${p().offset}px)`, width: `${p().size}px` }
303
+ : { transform: `translateY(${p().offset}px)`, height: `${p().size}px` }),
288
304
  }}
289
305
  />
290
306
  )}
@@ -4,6 +4,9 @@ import {
4
4
  type Component,
5
5
  type ComponentProps,
6
6
  createContext,
7
+ createSignal,
8
+ onCleanup,
9
+ onMount,
7
10
  type ParentComponent,
8
11
  Show,
9
12
  splitProps,
@@ -27,20 +30,53 @@ const ToggleGroupContext = createContext<ToggleGroupContextValue>({
27
30
  });
28
31
 
29
32
  const ToggleGroup: ParentComponent<
30
- ComponentProps<typeof ToggleGroupPrimitive> & VariantProps<typeof toggleVariants>
33
+ ComponentProps<typeof ToggleGroupPrimitive> &
34
+ VariantProps<typeof toggleVariants> & {
35
+ /** CSS colour for the selected segment's glass. Default `var(--primary)`. */
36
+ tone?: string;
37
+ }
31
38
  > = (props) => {
32
- const [local, rest] = splitProps(props, ["class", "variant", "size", "children"] as const);
39
+ const [local, rest] = splitProps(props, [
40
+ "class",
41
+ "variant",
42
+ "size",
43
+ "tone",
44
+ "children",
45
+ ] as const);
33
46
  // Read `multiple` without splitting it out: Kobalte's root is a single/multiple
34
47
  // discriminated union, so pulling `multiple` into a separate prop collapses the
35
48
  // union and mistypes `value`. Leave it in `rest` and just peek at it here.
36
49
  const sliding = () => !(props as { multiple?: boolean }).multiple;
50
+ // Items that overflow the width they are given wrap onto rows; measured, so labels of any length work.
51
+ const [wrap, setWrap] = createSignal(false);
52
+ let root: HTMLDivElement | undefined;
53
+ const measure = () => {
54
+ if (!root) return;
55
+ const items = root.querySelectorAll<HTMLElement>('[data-slot="toggle-group-item"]');
56
+ let needed = 8 + 4 * Math.max(0, items.length - 1);
57
+ for (const item of items) needed += item.scrollWidth;
58
+ const room = root.parentElement?.clientWidth ?? root.clientWidth;
59
+ setWrap(needed > room + 1);
60
+ };
61
+ onMount(() => {
62
+ if (!root || typeof ResizeObserver === "undefined") return;
63
+ const ro = new ResizeObserver(measure);
64
+ ro.observe(root);
65
+ if (root.parentElement) ro.observe(root.parentElement);
66
+ onCleanup(() => ro.disconnect());
67
+ });
37
68
  return (
38
69
  <ToggleGroupPrimitive
70
+ ref={(el: HTMLDivElement) => {
71
+ root = el;
72
+ }}
39
73
  data-slot="toggle-group"
40
74
  data-variant={local.variant}
41
75
  data-size={local.size}
76
+ data-wrap={wrap() ? "" : undefined}
42
77
  class={cn(
43
- `group/toggle-group flex w-fit items-center rounded-lg ${TRACK_SURFACE} p-1 data-[variant=outline]:shadow-xs`,
78
+ `group/toggle-group flex w-fit max-w-full items-center rounded-lg ${TRACK_SURFACE} p-1 data-[variant=outline]:shadow-xs`,
79
+ wrap() && "flex-wrap gap-1",
44
80
  local.class,
45
81
  )}
46
82
  {...rest}
@@ -54,7 +90,9 @@ const ToggleGroup: ParentComponent<
54
90
  <SlidingIndicator
55
91
  activeSelector="[data-pressed]"
56
92
  indicatorClass="rounded-md"
57
- class="flex w-full items-center"
93
+ indicatorTone={local.tone}
94
+ wrapped={wrap()}
95
+ class={cn("flex w-full items-center", wrap() && "flex-wrap gap-1")}
58
96
  >
59
97
  {local.children}
60
98
  </SlidingIndicator>
@@ -80,7 +118,7 @@ const ToggleGroupItem: Component<
80
118
  variant: context.variant || local.variant,
81
119
  size: context.size || local.size,
82
120
  }),
83
- "min-w-0 flex-1 shrink-0 rounded-md px-4 shadow-none focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first-of-type:border-l",
121
+ "min-w-0 flex-1 shrink-0 rounded-md px-4 shadow-none focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first-of-type:border-l group-data-[wrap]/toggle-group:flex-none",
84
122
  // Single-select: the sliding indicator paints the active segment, so the
85
123
  // item needs no pressed fill of its own and hover only tints the text.
86
124
  // Multi-select has no single indicator, so each pressed segment carries
@@ -68,10 +68,13 @@
68
68
 
69
69
  /* Trigger morph: the panel is anchored over the trigger's top edge and starts
70
70
  * clipped to the trigger's own box and radius (--morph-w/h/radius, written by
71
- * the content from its trigger), then unrolls into its own box. The pill
71
+ * the content from its trigger; --morph-x/y when the panel had to shift off
72
+ * the trigger's corner to stay on screen), then unrolls into its own box. The pill
72
73
  * becomes the panel; nothing scales, so no row or radius distorts. */
73
74
  --animate-morph-in: morph-in var(--duration-morph) var(--ease-morph) both;
74
75
  --animate-morph-out: morph-out calc(var(--duration-morph) / 2) var(--ease-contract) both;
76
+ /* Unfilled once done, so the anchored panel's clip lets go and its shadow shows. */
77
+ --animate-anchored-in: morph-in var(--duration-morph) var(--ease-morph) backwards;
75
78
  }
76
79
 
77
80
  @keyframes collapsible-down {
@@ -120,7 +123,8 @@
120
123
  from {
121
124
  opacity: 0;
122
125
  clip-path: inset(
123
- 0 calc(100% - var(--morph-w, 100%)) calc(100% - var(--morph-h, 2.5rem)) 0 round
126
+ var(--morph-y, 0px) calc(100% - var(--morph-x, 0px) - var(--morph-w, 100%))
127
+ calc(100% - var(--morph-y, 0px) - var(--morph-h, 2.5rem)) var(--morph-x, 0px) round
124
128
  var(--morph-radius, 9999px)
125
129
  );
126
130
  pointer-events: none;
@@ -145,7 +149,8 @@
145
149
  to {
146
150
  opacity: 0;
147
151
  clip-path: inset(
148
- 0 calc(100% - var(--morph-w, 100%)) calc(100% - var(--morph-h, 2.5rem)) 0 round
152
+ var(--morph-y, 0px) calc(100% - var(--morph-x, 0px) - var(--morph-w, 100%))
153
+ calc(100% - var(--morph-y, 0px) - var(--morph-h, 2.5rem)) var(--morph-x, 0px) round
149
154
  var(--morph-radius, 9999px)
150
155
  );
151
156
  }
@@ -583,6 +588,10 @@ html[data-motion="live"] {
583
588
  backdrop-filter: none !important;
584
589
  -webkit-backdrop-filter: none !important;
585
590
  }
591
+ /* A control that cannot blur takes the opaque card fill, never bare see-through. */
592
+ .reduce-blur .glass-control {
593
+ --glass-base: var(--card);
594
+ }
586
595
 
587
596
  /* Accessibility: minimize animations/transitions when reduce-motion is active */
588
597
  .reduce-motion,