@glasshome/ui 1.40.0 → 1.42.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 (105) hide show
  1. package/SPEC.md +25 -2
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +3 -3
  4. package/dist/lib/anchor-placement.d.ts +30 -0
  5. package/dist/lib/behavior/anchored.d.ts +12 -0
  6. package/dist/lib/behavior/collection.d.ts +24 -0
  7. package/dist/lib/behavior/controllable.d.ts +8 -0
  8. package/dist/lib/behavior/dismiss.d.ts +11 -0
  9. package/dist/lib/behavior/focus-scope.d.ts +18 -0
  10. package/dist/lib/behavior/hide-outside.d.ts +7 -0
  11. package/dist/lib/behavior/layer-stack.d.ts +33 -0
  12. package/dist/lib/behavior/modal-root.d.ts +66 -0
  13. package/dist/lib/behavior/polymorphic.d.ts +6 -0
  14. package/dist/lib/behavior/presence.d.ts +18 -0
  15. package/dist/lib/behavior/solid.d.ts +13 -0
  16. package/dist/lib/motion-classes.d.ts +5 -2
  17. package/dist/lib/overlay-classes.d.ts +4 -1
  18. package/dist/lib/page-cover.d.ts +8 -0
  19. package/dist/lib/shadow-layer.d.ts +8 -6
  20. package/dist/solid/alert-dialog.d.ts +13 -15
  21. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -6
  22. package/dist/solid/bottom-sheet/constants.d.ts +1 -1
  23. package/dist/solid/confirm-dialog.d.ts +22 -0
  24. package/dist/solid/dialog-parts.d.ts +78 -15
  25. package/dist/solid/dialog.d.ts +9 -15
  26. package/dist/solid/docked-panel.d.ts +1 -5
  27. package/dist/solid/icon-nodes.d.ts +13 -0
  28. package/dist/solid/index.d.ts +9 -5
  29. package/dist/solid/index.js +8211 -7974
  30. package/dist/solid/responsive-dialog.d.ts +5 -6
  31. package/dist/solid/sheet.d.ts +6 -13
  32. package/dist/solid/stale-veil.d.ts +7 -0
  33. package/dist/solid/tabs.d.ts +29 -8
  34. package/dist/solid/toggle-group.d.ts +30 -5
  35. package/dist/solid/tooltip.d.ts +71 -9
  36. package/dist/{utils-DXEj_oXa.js → utils-CxAii-e9.js} +606 -414
  37. package/package.json +4 -2
  38. package/src/index.ts +1 -0
  39. package/src/lib/anchor-placement.ts +68 -2
  40. package/src/lib/behavior/anchored.ts +88 -0
  41. package/src/lib/behavior/collection.ts +181 -0
  42. package/src/lib/behavior/controllable.ts +22 -0
  43. package/src/lib/behavior/dismiss.ts +145 -0
  44. package/src/lib/behavior/focus-scope.ts +202 -0
  45. package/src/lib/behavior/hide-outside.ts +85 -0
  46. package/src/lib/behavior/layer-stack.ts +125 -0
  47. package/src/lib/behavior/modal-root.tsx +446 -0
  48. package/src/lib/behavior/polymorphic.tsx +30 -0
  49. package/src/lib/behavior/presence.ts +89 -0
  50. package/src/lib/behavior/solid.ts +30 -0
  51. package/src/lib/clipboard.ts +3 -2
  52. package/src/lib/motion-classes.ts +27 -2
  53. package/src/lib/overlay-classes.ts +9 -4
  54. package/src/lib/page-cover.ts +47 -0
  55. package/src/lib/shadow-layer.ts +48 -66
  56. package/src/solid/alert-dialog.tsx +45 -81
  57. package/src/solid/alert.tsx +1 -1
  58. package/src/solid/area-picker.tsx +2 -1
  59. package/src/solid/badge.tsx +5 -5
  60. package/src/solid/bottom-sheet/bottom-sheet.tsx +72 -128
  61. package/src/solid/bottom-sheet/constants.ts +3 -1
  62. package/src/solid/bottom-sheet/drag-controller.ts +11 -0
  63. package/src/solid/breadcrumb.tsx +4 -4
  64. package/src/solid/button-group.tsx +4 -4
  65. package/src/solid/card.tsx +5 -4
  66. package/src/solid/confirm-dialog.tsx +62 -0
  67. package/src/solid/context-menu.tsx +12 -2
  68. package/src/solid/dialog-parts.tsx +181 -42
  69. package/src/solid/dialog.tsx +46 -74
  70. package/src/solid/dock-edit.tsx +5 -4
  71. package/src/solid/dock.tsx +3 -3
  72. package/src/solid/dropdown-menu.tsx +15 -7
  73. package/src/solid/entity-selector.tsx +2 -1
  74. package/src/solid/form.tsx +4 -3
  75. package/src/solid/hover-card.tsx +7 -2
  76. package/src/solid/icon-nodes.ts +71 -0
  77. package/src/solid/icon-picker.tsx +2 -1
  78. package/src/solid/icon.tsx +42 -39
  79. package/src/solid/image-picker.tsx +14 -13
  80. package/src/solid/index.ts +9 -2
  81. package/src/solid/input-group.tsx +5 -3
  82. package/src/solid/input-otp.tsx +2 -1
  83. package/src/solid/item.tsx +4 -4
  84. package/src/solid/logo.tsx +5 -4
  85. package/src/solid/picker-row.tsx +5 -4
  86. package/src/solid/picker-search.tsx +2 -1
  87. package/src/solid/popover.tsx +18 -10
  88. package/src/solid/responsive-dialog.tsx +17 -10
  89. package/src/solid/sheet.tsx +47 -79
  90. package/src/solid/spotlight.tsx +23 -11
  91. package/src/solid/stale-veil.tsx +20 -0
  92. package/src/solid/switch.tsx +8 -6
  93. package/src/solid/tabs.tsx +373 -53
  94. package/src/solid/toggle-group.tsx +305 -93
  95. package/src/solid/tooltip.tsx +285 -26
  96. package/src/styles/globals.css +6 -2
  97. package/src/styles/theme.css +10 -5
  98. package/dist/lib/when-animations-settle.d.ts +0 -4
  99. package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
  100. package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
  101. package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
  102. package/src/lib/when-animations-settle.ts +0 -12
  103. package/src/solid/bottom-sheet/focus-trap.ts +0 -63
  104. package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
  105. package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
@@ -14,15 +14,22 @@ import {
14
14
  useContext,
15
15
  type ValidComponent,
16
16
  } from "solid-js";
17
- import { Dynamic, Portal } from "solid-js/web";
17
+ import { Portal } from "solid-js/web";
18
+ import { Polymorphic } from "../../lib/behavior/polymorphic.js";
18
19
  import { usePortalMount } from "../portal-mount.js";
20
+ import { createControllableSignal } from "../../lib/behavior/controllable.js";
19
21
  import { Z } from "../../lib/layers.js";
20
- import { OVERLAY_SURFACE_OPAQUE } from "../../lib/overlay-classes.js";
22
+ import {
23
+ OVERLAY_SURFACE_OPAQUE,
24
+ SCRIM_CONTAIN,
25
+ SCROLL_CONTAIN,
26
+ } from "../../lib/overlay-classes.js";
27
+ import { coverNow } from "../../lib/page-cover.js";
28
+ import { callEventHandler, effect } from "../../lib/behavior/solid.js";
21
29
  import { cn } from "../../lib/utils.js";
22
- import { whenAnimationsSettle } from "../../lib/when-animations-settle.js";
23
- import { isSheetMotion } from "./sheet-motion.js";
30
+ import { type MotionEvent, watchMotion } from "../../lib/behavior/presence.js";
31
+ import { MOTION_EXIT_MS } from "../../lib/motion-classes.js";
24
32
  import {
25
- callEventHandler,
26
33
  createModalLabels,
27
34
  createModalParts,
28
35
  MODAL_DESCRIPTION,
@@ -33,9 +40,11 @@ import {
33
40
  } from "../dialog-parts.js";
34
41
  import { EASE, TRANSITION_MS } from "./constants.js";
35
42
  import { attachDrag } from "./drag-controller.js";
36
- import { type InitialFocus, trapFocus } from "./focus-trap.js";
43
+ import { createDismiss } from "../../lib/behavior/dismiss.js";
44
+ import { createFocusScope, type InitialFocus } from "../../lib/behavior/focus-scope.js";
45
+ import { createHideOutside } from "../../lib/behavior/hide-outside.js";
46
+ import { registerLayer } from "../../lib/behavior/layer-stack.js";
37
47
  import { watchKeyboard } from "./keyboard.js";
38
- import { acquireScrollLock, releaseScrollLock } from "./scroll-lock.js";
39
48
  import { assertTransition, type SheetState } from "./state-machine.js";
40
49
 
41
50
  interface BottomSheetContextValue {
@@ -48,6 +57,11 @@ interface BottomSheetContextValue {
48
57
  setContentRef: (el: HTMLDivElement | undefined) => void;
49
58
  }
50
59
 
60
+ const isSheetMotion = (e: MotionEvent) =>
61
+ "animationName" in e
62
+ ? e.animationName === "bs-slide-up" || e.animationName === "bs-slide-down"
63
+ : e.propertyName === "transform";
64
+
51
65
  const BottomSheetContext = createContext<BottomSheetContextValue>();
52
66
 
53
67
  function useBottomSheetContext(): BottomSheetContextValue {
@@ -65,18 +79,14 @@ interface BottomSheetRootProps {
65
79
  }
66
80
 
67
81
  const BottomSheet: ParentComponent<BottomSheetRootProps> = (props) => {
68
- const [uncontrolled, setUncontrolled] = createSignal(props.defaultOpen ?? false);
82
+ const [open, setOpen] = createControllableSignal<boolean>({
83
+ value: () => props.open,
84
+ defaultValue: () => props.defaultOpen ?? false,
85
+ onChange: (next) => props.onOpenChange?.(next),
86
+ });
69
87
  const [state, setStateRaw] = createSignal<SheetState>("closed");
70
88
  const [contentRef, setContentRef] = createSignal<HTMLDivElement | undefined>(undefined);
71
89
 
72
- const isControlled = () => props.open !== undefined;
73
- const open = (): boolean => (isControlled() ? props.open === true : uncontrolled());
74
-
75
- const setOpen = (next: boolean) => {
76
- if (!isControlled()) setUncontrolled(next);
77
- props.onOpenChange?.(next);
78
- };
79
-
80
90
  const setState = (next: SheetState) => {
81
91
  const current = state();
82
92
  assertTransition(current, next);
@@ -122,11 +132,10 @@ type SheetButtonProps = ComponentProps<"button"> &
122
132
  const BottomSheetTrigger: ParentComponent<SheetButtonProps> = (props) => {
123
133
  const [local, rest] = splitProps(props, ["children", "onClick", "as"]);
124
134
  const ctx = useBottomSheetContext();
125
- const component = () => local.as ?? "button";
126
135
  return (
127
- <Dynamic
128
- component={component()}
129
- type={component() === "button" ? "button" : undefined}
136
+ <Polymorphic
137
+ defaultAs="button"
138
+ as={local.as}
130
139
  data-slot="bottom-sheet-trigger"
131
140
  aria-haspopup="dialog"
132
141
  aria-expanded={ctx.open()}
@@ -137,7 +146,7 @@ const BottomSheetTrigger: ParentComponent<SheetButtonProps> = (props) => {
137
146
  {...rest}
138
147
  >
139
148
  {local.children}
140
- </Dynamic>
149
+ </Polymorphic>
141
150
  );
142
151
  };
143
152
 
@@ -175,7 +184,7 @@ const BottomSheetOverlay: Component<ComponentProps<"div">> = (props) => {
175
184
  data-state={dataState()}
176
185
  aria-hidden="true"
177
186
  class={cn(
178
- "fixed inset-0 bg-black/80 transition-opacity duration-300 ease-out",
187
+ `fixed inset-0 bg-black/80 transition-opacity duration-300 ease-out ${SCRIM_CONTAIN}`,
179
188
  "data-[state=closing]:opacity-0 data-[state=open]:opacity-100",
180
189
  local.class,
181
190
  )}
@@ -203,15 +212,9 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
203
212
  const labels = createModalLabels();
204
213
  let el: HTMLDivElement | undefined;
205
214
 
206
- /* Keyed on presence, not on mount: a sheet rendered without
207
- * BottomSheetPortal stays in the tree while closed and must not hold the
208
- * page lock. Release also runs on unmount, so no animation can strand it. */
209
215
  const present = createMemo(() => ctx.state() !== "closed");
210
- createEffect(() => {
211
- if (!present()) return;
212
- acquireScrollLock();
213
- onCleanup(releaseScrollLock);
214
- });
216
+
217
+ effect(present, (on) => (on && el ? coverNow(el) : undefined));
215
218
 
216
219
  const clearAnimInline = () => {
217
220
  if (!el) return;
@@ -225,16 +228,20 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
225
228
  if (s !== "opening" && s !== "closing" && s !== "snapping") return;
226
229
  const node = el;
227
230
  if (!node) return;
228
- let stale = false;
229
- onCleanup(() => (stale = true));
230
- void whenAnimationsSettle(node, { filter: isSheetMotion }).then(() => {
231
- if (stale) return;
232
- if (s === "opening") ctx.setState("open");
233
- else {
234
- ctx.setState(s === "snapping" ? "open" : "closed");
235
- clearAnimInline();
236
- }
237
- });
231
+ onCleanup(
232
+ watchMotion(
233
+ node,
234
+ MOTION_EXIT_MS.sheet,
235
+ () => {
236
+ if (s === "opening") ctx.setState("open");
237
+ else {
238
+ ctx.setState(s === "snapping" ? "open" : "closed");
239
+ clearAnimInline();
240
+ }
241
+ },
242
+ isSheetMotion,
243
+ ),
244
+ );
238
245
  });
239
246
 
240
247
  createEffect(() => {
@@ -257,92 +264,30 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
257
264
  onCleanup(() => handle.destroy());
258
265
  });
259
266
 
260
- createEffect(() => {
261
- const s = ctx.state();
262
- if (s !== "open" && s !== "opening") return;
263
- if (!el) return;
264
- const handle = trapFocus(el, local.initialFocus ?? "container");
265
- onCleanup(() => handle.release());
267
+ const handle = registerLayer({
268
+ element: ctx.contentRef,
269
+ open: ctx.open,
270
+ kind: "modal",
271
+ escape: ctx.dismissible,
272
+ dismiss: () => ctx.setOpen(false),
266
273
  });
267
274
 
268
- createEffect(() => {
269
- if (ctx.state() === "closed") return;
270
- const onKey = (e: KeyboardEvent) => {
271
- if (e.key !== "Escape") return;
272
- if (!ctx.dismissible()) return;
273
- e.preventDefault();
274
- ctx.setOpen(false);
275
- };
276
- document.addEventListener("keydown", onKey);
277
- onCleanup(() => document.removeEventListener("keydown", onKey));
275
+ createHideOutside({ layer: handle, active: ctx.open });
276
+
277
+ createFocusScope({
278
+ container: ctx.contentRef,
279
+ active: () => ctx.state() !== "closed" && ctx.state() !== "closing",
280
+ trapped: () => true,
281
+ initialFocus: local.initialFocus ?? "container",
278
282
  });
279
283
 
280
- // setTimeout(0) lets the click that opened the sheet finish bubbling
281
- // before the dismiss listener is attached. Touch defers to `click` so
282
- // drag/scroll intent can be detected first.
283
- createEffect(() => {
284
- if (ctx.state() === "closed") return;
285
- if (!ctx.dismissible()) return;
286
-
287
- let attached = false;
288
- let pendingClick: ((click: Event) => void) | null = null;
289
-
290
- const PORTAL_LAYER_SELECTOR =
291
- '[data-kb-top-layer], [role="dialog"], [role="menu"], [role="listbox"], [role="combobox"], [role="tooltip"]';
292
- // Judged along the composed path: a press inside an icon's own shadow root is still inside the
293
- // sheet. Only the part below the listening root counts: a realm's host inside a page dialog
294
- // must not make every press in the realm look like one inside a layer.
295
- const isOutside = (e: Event): boolean => {
296
- if (!el || !(e.target instanceof Element)) return false;
297
- const full = e.composedPath();
298
- const listener = e.currentTarget;
299
- const end = listener && listener !== document ? full.indexOf(listener) : -1;
300
- const path = end >= 0 ? full.slice(0, end) : full;
301
- if (path.includes(el)) return false;
302
- return !path.some(
303
- (node) =>
304
- node instanceof Element &&
305
- (node.matches("[data-sheet-content]") || node.matches(PORTAL_LAYER_SELECTOR)),
306
- );
307
- };
308
-
309
- // Inside a shadow root the page sees every press there as one on the root's host, so the
310
- // sheet judges those from its own root and only the page's other presses from the document.
311
- const scope = (el?.getRootNode() ?? document) as Document | ShadowRoot;
312
- const scopes: (Document | ShadowRoot)[] = scope === document ? [document] : [scope, document];
313
- const host = scope instanceof ShadowRoot ? scope.host : undefined;
314
- const onPointerDown = (e: Event) => {
315
- if (e.currentTarget === document && host && e.target === host) return;
316
- // Every press starts over: a touch that scrolled never clicked, and its close must not wait for the next tap.
317
- if (pendingClick) document.removeEventListener("click", pendingClick);
318
- pendingClick = null;
319
- if (!isOutside(e)) return;
320
- const dismiss = () => {
321
- if (ctx.state() === "open") ctx.setOpen(false);
322
- };
323
- if ((e as PointerEvent).pointerType === "touch") {
324
- pendingClick = (click: Event) => {
325
- pendingClick = null;
326
- // The click lands where the touch ended; it closes only if that is still outside.
327
- if (el && !click.composedPath().includes(el)) dismiss();
328
- };
329
- document.addEventListener("click", pendingClick, { once: true });
330
- } else {
331
- dismiss();
332
- }
333
- };
334
-
335
- const timer = window.setTimeout(() => {
336
- for (const s of scopes) s.addEventListener("pointerdown", onPointerDown, true);
337
- attached = true;
338
- }, 0);
339
-
340
- onCleanup(() => {
341
- window.clearTimeout(timer);
342
- if (attached)
343
- for (const s of scopes) s.removeEventListener("pointerdown", onPointerDown, true);
344
- if (pendingClick) document.removeEventListener("click", pendingClick);
345
- });
284
+ createDismiss({
285
+ layer: handle,
286
+ outsidePress: ctx.dismissible,
287
+ onDismiss: (reason) => {
288
+ if (reason === "outside-press" && ctx.state() !== "open") return;
289
+ ctx.setOpen(false);
290
+ },
346
291
  });
347
292
 
348
293
  const setRef = (node: HTMLDivElement) => {
@@ -383,7 +328,7 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
383
328
  }}
384
329
  class={cn(
385
330
  "bs-content",
386
- `fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none`,
331
+ `fixed inset-x-0 bottom-0 flex ${MODAL_MAX_H} flex-col ${SCROLL_CONTAIN} rounded-t-xl ${OVERLAY_SURFACE_OPAQUE} outline-none`,
387
332
  "after:absolute after:inset-x-0 after:top-full after:h-1/2 after:bg-inherit",
388
333
  local.class,
389
334
  )}
@@ -448,11 +393,10 @@ const BottomSheetDescription: Component<ComponentProps<"p">> = (props) => {
448
393
  const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
449
394
  const [local, rest] = splitProps(props, ["children", "onClick", "as"]);
450
395
  const ctx = useBottomSheetContext();
451
- const component = () => local.as ?? "button";
452
396
  return (
453
- <Dynamic
454
- component={component()}
455
- type={component() === "button" ? "button" : undefined}
397
+ <Polymorphic
398
+ defaultAs="button"
399
+ as={local.as}
456
400
  data-slot="bottom-sheet-close"
457
401
  onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
458
402
  callEventHandler(event, local.onClick);
@@ -461,7 +405,7 @@ const BottomSheetClose: ParentComponent<SheetButtonProps> = (props) => {
461
405
  {...rest}
462
406
  >
463
407
  {local.children}
464
- </Dynamic>
408
+ </Polymorphic>
465
409
  );
466
410
  };
467
411
 
@@ -1,5 +1,7 @@
1
+ import { MOTION_EXIT_MS } from "../../lib/motion-classes.js";
2
+
1
3
  export const EASE = "cubic-bezier(0.32, 0.72, 0, 1)";
2
- export const TRANSITION_MS = 500;
4
+ export const TRANSITION_MS = MOTION_EXIT_MS.sheet;
3
5
 
4
6
  export const DEAD_ZONE_PX = 6;
5
7
  export const CLOSE_DISTANCE_RATIO = 0.4;
@@ -43,6 +43,7 @@ export function attachDrag(opts: DragOptions): DragHandle {
43
43
  let dragAborted = false;
44
44
  let height = 0;
45
45
  let lastTotalDy = 0;
46
+ let shownDy = 0;
46
47
 
47
48
  const isDraggableState = (): boolean => {
48
49
  const s = getState();
@@ -55,6 +56,7 @@ export function attachDrag(opts: DragOptions): DragHandle {
55
56
  const value = pendingDy;
56
57
  pendingDy = null;
57
58
  const applied = value < 0 ? dampen(-value) * -1 : value;
59
+ shownDy = applied;
58
60
  el.style.transform = `translate3d(0, ${applied}px, 0)`;
59
61
  };
60
62
 
@@ -77,6 +79,7 @@ export function attachDrag(opts: DragOptions): DragHandle {
77
79
  startX = e.clientX;
78
80
  pointerTarget = target;
79
81
  dy = 0;
82
+ shownDy = 0;
80
83
  lastTotalDy = 0;
81
84
  movedPastDeadZone = false;
82
85
  dragAborted = false;
@@ -141,6 +144,14 @@ export function attachDrag(opts: DragOptions): DragHandle {
141
144
 
142
145
  const settleSnap = () => {
143
146
  setState("snapping");
147
+ if (shownDy === 0) {
148
+ el.style.transition = "";
149
+ el.style.animation = "";
150
+ el.style.transform = "";
151
+ setState("open");
152
+ return;
153
+ }
154
+ shownDy = 0;
144
155
  el.style.transition = TRANSITION_CSS;
145
156
  el.style.animation = "";
146
157
  el.style.transform = "translate3d(0, 0, 0)";
@@ -5,7 +5,7 @@ import {
5
5
  splitProps,
6
6
  type ValidComponent,
7
7
  } from "solid-js";
8
- import { Dynamic } from "solid-js/web";
8
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
9
9
  import { cn } from "../lib/utils.js";
10
10
  import { Icon } from "./icon.js";
11
11
 
@@ -40,10 +40,10 @@ const BreadcrumbItem: Component<ComponentProps<"li">> = (props) => {
40
40
 
41
41
  const BreadcrumbLink: Component<ComponentProps<"a"> & { as?: ValidComponent }> = (props) => {
42
42
  const [local, rest] = splitProps(props, ["class", "as"]);
43
- const Comp = () => local.as || "a";
44
43
  return (
45
- <Dynamic
46
- component={Comp()}
44
+ <Polymorphic
45
+ defaultAs="a"
46
+ as={local.as}
47
47
  data-slot="breadcrumb-link"
48
48
  class={cn("hover:text-foreground transition-colors", local.class)}
49
49
  {...rest}
@@ -1,6 +1,6 @@
1
1
  import { cva, type VariantProps } from "cva";
2
2
  import { type Component, type ComponentProps, splitProps, type ValidComponent } from "solid-js";
3
- import { Dynamic } from "solid-js/web";
3
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
4
4
  import { cn } from "../lib/utils.js";
5
5
  import { Separator } from "./separator.js";
6
6
 
@@ -35,10 +35,10 @@ const ButtonGroup: Component<ComponentProps<"div"> & VariantProps<typeof buttonG
35
35
 
36
36
  const ButtonGroupText: Component<ComponentProps<"div"> & { as?: ValidComponent }> = (props) => {
37
37
  const [local, rest] = splitProps(props, ["class", "as"] as const);
38
- const Comp = () => local.as || "div";
39
38
  return (
40
- <Dynamic
41
- component={Comp()}
39
+ <Polymorphic
40
+ defaultAs="div"
41
+ as={local.as}
42
42
  class={cn(
43
43
  "glass text-muted-foreground flex items-center gap-2 rounded-md px-4 text-sm font-medium [--glass-edge:var(--border)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
44
44
  local.class,
@@ -5,7 +5,7 @@ import {
5
5
  splitProps,
6
6
  type ValidComponent,
7
7
  } from "solid-js";
8
- import { Dynamic } from "solid-js/web";
8
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
9
9
  import {
10
10
  CARD_ACTION_CLASS,
11
11
  CARD_CONTENT_CLASS,
@@ -48,8 +48,9 @@ const Card: Component<CardProps> = (props) => {
48
48
  "children",
49
49
  ]);
50
50
  return (
51
- <Dynamic
52
- component={local.as ?? "div"}
51
+ <Polymorphic
52
+ defaultAs="div"
53
+ as={local.as}
53
54
  data-slot="card"
54
55
  class={cn(
55
56
  local.opaque ? CARD_SURFACE_OPAQUE : CARD_SURFACE,
@@ -63,7 +64,7 @@ const Card: Component<CardProps> = (props) => {
63
64
  >
64
65
  <Show when={local.ornament}>{(kind) => <Ornament kind={kind()} />}</Show>
65
66
  {local.children}
66
- </Dynamic>
67
+ </Polymorphic>
67
68
  );
68
69
  };
69
70
 
@@ -0,0 +1,62 @@
1
+ import type { JSX } from "solid-js";
2
+ import { children, Show } from "solid-js";
3
+ import {
4
+ AlertDialog,
5
+ AlertDialogAction,
6
+ AlertDialogBody,
7
+ AlertDialogCancel,
8
+ AlertDialogContent,
9
+ AlertDialogFooter,
10
+ AlertDialogHead,
11
+ } from "./alert-dialog.js";
12
+
13
+ export interface ConfirmDialogProps {
14
+ open: boolean;
15
+ onOpenChange: (open: boolean) => void;
16
+ /** The glyph that tells this confirm from the next. */
17
+ icon: string;
18
+ /** Defaults to destructive red when `destructive`, else the material accent. */
19
+ tone?: string;
20
+ /** The question or the outcome, naming its object: "Remove Anna?". */
21
+ title: string;
22
+ /** The consequence, one line. */
23
+ line: JSX.Element;
24
+ actionLabel: string;
25
+ /** Defaults to true: nearly every confirm is a delete or a removal. */
26
+ destructive?: boolean;
27
+ busy?: boolean;
28
+ onConfirm: () => void;
29
+ /** The thing the confirm is about (avatars, a preview), shown instead of described. */
30
+ children?: JSX.Element;
31
+ }
32
+
33
+ /** A yes/no on one object: media, a short question, the consequence, Cancel and the action. */
34
+ export function ConfirmDialog(props: ConfirmDialogProps): JSX.Element {
35
+ const destructive = () => props.destructive ?? true;
36
+ const thing = children(() => props.children);
37
+ return (
38
+ <AlertDialog open={props.open} onOpenChange={props.onOpenChange}>
39
+ <AlertDialogContent>
40
+ <AlertDialogHead
41
+ icon={props.icon}
42
+ tone={props.tone ?? (destructive() ? "var(--destructive)" : "var(--material-accent)")}
43
+ title={props.title}
44
+ line={props.line}
45
+ />
46
+ <Show when={thing()}>
47
+ <AlertDialogBody>{thing()}</AlertDialogBody>
48
+ </Show>
49
+ <AlertDialogFooter>
50
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
51
+ <AlertDialogAction
52
+ variant={destructive() ? "destructive" : "default"}
53
+ busy={props.busy}
54
+ onClick={() => props.onConfirm()}
55
+ >
56
+ {props.actionLabel}
57
+ </AlertDialogAction>
58
+ </AlertDialogFooter>
59
+ </AlertDialogContent>
60
+ </AlertDialog>
61
+ );
62
+ }
@@ -9,7 +9,12 @@ import {
9
9
  splitProps,
10
10
  } from "solid-js";
11
11
  import { OVERLAY_MOTION } from "../lib/motion-classes.js";
12
- import { inShadowRoot, shadowLayer } from "../lib/shadow-layer.js";
12
+ import {
13
+ createCoveredRoot,
14
+ inShadowRoot,
15
+ ReportCovered,
16
+ shadowLayer,
17
+ } from "../lib/shadow-layer.js";
13
18
  import { cn } from "../lib/utils.js";
14
19
  import {
15
20
  MENU_CONTENT_CLASS,
@@ -26,7 +31,12 @@ import {
26
31
  const ContextMenuRoot: Component<ComponentProps<typeof ContextMenuPrimitive>> = (props) => {
27
32
  // Modal in a shadow root, Kobalte would aria-hide the realm's host, menu included.
28
33
  const inShadow = inShadowRoot(usePortalMount());
29
- return <ContextMenuPrimitive {...props} modal={inShadow ? false : props.modal} />;
34
+ const cover = createCoveredRoot();
35
+ return (
36
+ <ReportCovered.Provider value={cover.report}>
37
+ <ContextMenuPrimitive {...props} modal={inShadow || cover.covered() ? false : props.modal} />
38
+ </ReportCovered.Provider>
39
+ );
30
40
  };
31
41
  const ContextMenu = Object.assign(ContextMenuRoot, ContextMenuPrimitive) as Component<
32
42
  ComponentProps<typeof ContextMenuPrimitive>