@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
@@ -1,11 +1,11 @@
1
1
  import { Button as KobalteButton } from "@kobalte/core/button";
2
- import { useDialogContext } from "@kobalte/core/dialog";
3
2
  import {
4
3
  type Accessor,
5
4
  children,
6
5
  type Component,
7
6
  type ComponentProps,
8
7
  createContext,
8
+ createEffect,
9
9
  createSignal,
10
10
  createUniqueId,
11
11
  type JSX,
@@ -17,18 +17,114 @@ import {
17
17
  useContext,
18
18
  type ValidComponent,
19
19
  } from "solid-js";
20
- import { Dynamic } from "solid-js/web";
20
+ import {
21
+ type FocusOutsideEvent,
22
+ type InteractOutsideEvent,
23
+ ModalDescription,
24
+ type ModalPartProps,
25
+ type PointerDownOutsideEvent,
26
+ type ModalRole,
27
+ ModalRoot,
28
+ ModalTitle,
29
+ ModalTrigger,
30
+ } from "../lib/behavior/modal-root.js";
31
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
32
+ import { callEventHandler } from "../lib/behavior/solid.js";
21
33
  import { busyProps } from "../lib/busy.js";
22
34
  import { Z_CLASS } from "../lib/layers.js";
23
35
  import { ANCHORED_MOTION, MODAL_MOTION, SCRIM_MOTION } from "../lib/motion-classes.js";
24
- import { OVERLAY_SURFACE, SCRIM_CLASS } from "../lib/overlay-classes.js";
36
+ import {
37
+ OVERLAY_SURFACE,
38
+ SCRIM_CLASS,
39
+ SCRIM_CONTAIN,
40
+ SCROLL_CONTAIN,
41
+ } from "../lib/overlay-classes.js";
42
+ import { coverOnceOpen } from "../lib/page-cover.js";
43
+ import { inShadowRoot } from "../lib/shadow-layer.js";
25
44
  import { cn } from "../lib/utils.js";
26
- import { acquireScrollLock, releaseScrollLock } from "./bottom-sheet/scroll-lock.js";
45
+ import { usePortalMount } from "./portal-mount.js";
46
+ import { SectionIcon } from "./section-card.js";
27
47
 
28
- /* kobalte 0.13.13 builds AlertDialog with Object.assign(DialogRoot, ...), the
29
- * same object Dialog is built from, so whichever of the two modules a bundle
30
- * evaluates last owns .Content for both. Every family therefore states its own
31
- * role instead of trusting the primitive's default. */
48
+ export interface ModalRootSkinProps {
49
+ open?: boolean;
50
+ defaultOpen?: boolean;
51
+ onOpenChange?: (open: boolean) => void;
52
+ /** Modal toward the page. Defaults to true on the page and false inside a shadow root. */
53
+ modal?: boolean;
54
+ /** Stays mounted and dormant after it closes, so the next open shows the same nodes instead of building them. */
55
+ keep?: boolean;
56
+ /** @deprecated No effect; the panel takes its own id. */
57
+ id?: string;
58
+ /** @deprecated No effect; the panel stays mounted through its exit on its own. */
59
+ forceMount?: boolean;
60
+ /** @deprecated No effect; a dialog never locks page scroll. */
61
+ preventScroll?: boolean;
62
+ /** @deprecated No effect. */
63
+ translations?: Record<string, string>;
64
+ children?: JSX.Element;
65
+ }
66
+
67
+ export function createModalRootSkin(role: ModalRole): ParentComponent<ModalRootSkinProps> {
68
+ return (props) => {
69
+ const mount = usePortalMount();
70
+ return (
71
+ <ModalRoot
72
+ open={props.open}
73
+ defaultOpen={props.defaultOpen}
74
+ onOpenChange={props.onOpenChange}
75
+ modal={props.modal ?? !inShadowRoot(mount)}
76
+ keep={props.keep}
77
+ role={role}
78
+ >
79
+ {props.children}
80
+ </ModalRoot>
81
+ );
82
+ };
83
+ }
84
+
85
+ export type ModalContentProps = Omit<ComponentProps<"div">, "style" | "role"> & {
86
+ as?: ValidComponent;
87
+ style?: JSX.CSSProperties | string;
88
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
89
+ onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
90
+ onInteractOutside?: (event: InteractOutsideEvent) => void;
91
+ onOpenAutoFocus?: (event: Event) => void;
92
+ onCloseAutoFocus?: (event: Event) => void;
93
+ /** @deprecated No effect; focus never leaves an open dialog. */
94
+ onFocusOutside?: (event: FocusOutsideEvent) => void;
95
+ /** @deprecated No effect; the panel stays mounted through its exit on its own. */
96
+ forceMount?: boolean;
97
+ };
98
+
99
+ export interface ModalTextParts {
100
+ Trigger: <T extends ValidComponent = "button">(props: ModalPartProps<T>) => JSX.Element;
101
+ Title: <T extends ValidComponent = "h2">(props: ModalPartProps<T>) => JSX.Element;
102
+ Description: <T extends ValidComponent = "p">(props: ModalPartProps<T>) => JSX.Element;
103
+ }
104
+
105
+ export function createModalTextParts(slot: string): ModalTextParts {
106
+ return {
107
+ Trigger: (props) => (
108
+ <ModalTrigger data-slot={`${slot}-trigger`} {...(props as ModalPartProps<"button">)} />
109
+ ),
110
+ Title: (props) => {
111
+ const [local, rest] = splitProps(props as ModalPartProps<"h2">, ["class"]);
112
+ return (
113
+ <ModalTitle data-slot={`${slot}-title`} class={cn(MODAL_TITLE, local.class)} {...rest} />
114
+ );
115
+ },
116
+ Description: (props) => {
117
+ const [local, rest] = splitProps(props as ModalPartProps<"p">, ["class"]);
118
+ return (
119
+ <ModalDescription
120
+ data-slot={`${slot}-description`}
121
+ class={cn(MODAL_DESCRIPTION, local.class)}
122
+ {...rest}
123
+ />
124
+ );
125
+ },
126
+ };
127
+ }
32
128
 
33
129
  export type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
34
130
 
@@ -61,13 +157,13 @@ export const MODAL_ANCHOR: Record<ModalSize, string> = {
61
157
  /* The panel: it clips, it never scrolls, and it carries no padding. Every inset
62
158
  * belongs to Header, Body or Footer, so the Body scrollbar rides inside the
63
159
  * panel edge instead of under the header. */
64
- export const MODAL_PANEL = `${OVERLAY_SURFACE} ${MODAL_MOTION} fixed left-1/2 flex ${MODAL_MAX_H} w-[calc(100%-2rem)] -translate-x-1/2 flex-col overflow-hidden rounded-lg outline-none ${Z_CLASS.overlay}`;
160
+ export const MODAL_PANEL = `${OVERLAY_SURFACE} ${MODAL_MOTION} fixed left-1/2 flex ${MODAL_MAX_H} w-[calc(100%-2rem)] -translate-x-1/2 flex-col overflow-hidden ${SCROLL_CONTAIN} rounded-lg outline-none ${Z_CLASS.overlay}`;
65
161
 
66
162
  /* A panel anchored on the element that opened it: placed and sized inline (lib/anchor-placement),
67
163
  * so it drops the centring, and it unrolls out of that element instead of rising in. */
68
- export const ANCHORED_PANEL = `${OVERLAY_SURFACE} ${ANCHORED_MOTION} fixed flex ${MODAL_MAX_H} flex-col overflow-hidden rounded-lg outline-none ${Z_CLASS.overlay}`;
164
+ export const ANCHORED_PANEL = `${OVERLAY_SURFACE} ${ANCHORED_MOTION} fixed flex ${MODAL_MAX_H} flex-col overflow-hidden ${SCROLL_CONTAIN} rounded-lg outline-none ${Z_CLASS.overlay}`;
69
165
 
70
- export const MODAL_SCRIM = `${SCRIM_MOTION} fixed inset-0 ${Z_CLASS.overlay} ${SCRIM_CLASS}`;
166
+ export const MODAL_SCRIM = `${SCRIM_MOTION} fixed inset-0 ${Z_CLASS.overlay} ${SCRIM_CLASS} ${SCRIM_CONTAIN}`;
71
167
 
72
168
  const MODAL_HEADER =
73
169
  "flex shrink-0 items-start gap-4 px-6 pt-6 pb-3 in-data-[slot=bottom-sheet-content]:px-4 [[data-slot=bottom-sheet-handle]+&]:pt-1";
@@ -80,9 +176,8 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
80
176
 
81
177
  /* The only scroll container.
82
178
  * - The inset is the full one and a Header or Footer sibling shortens it, keyed
83
- * on data-slot rather than on position: kobalte parks a focus-trap <span> at
84
- * each end of the panel, and Sheet's `above` and the sheet handle add more
85
- * element siblings, so `first:`/`first-of-type:` all lie.
179
+ * on data-slot rather than on position: Sheet's `above` and the sheet handle
180
+ * add element siblings, so `first:`/`first-of-type:` lie.
86
181
  * - `pan-y pinch-zoom` leaves the single-finger vertical gesture to the sheet's
87
182
  * drag arbitration without taking two-finger zoom away.
88
183
  * - The reserved scrollbar lives inside the right inset, so the content column
@@ -96,7 +191,7 @@ const MODAL_FOOTER =
96
191
  export const MODAL_TITLE = "font-semibold text-foreground text-lg leading-none tracking-tight";
97
192
  export const MODAL_DESCRIPTION = "text-muted-foreground text-sm";
98
193
 
99
- type ModalHeaderProps = ComponentProps<"div"> & {
194
+ export type ModalHeaderProps = ComponentProps<"div"> & {
100
195
  /** Avatar or icon, rendered ahead of the title column. */
101
196
  media?: JSX.Element;
102
197
  action?: JSX.Element;
@@ -154,8 +249,9 @@ export function createModalParts(slot: string): ModalParts {
154
249
  if (el) el.style.setProperty("--scrollbar-gutter", `${el.offsetWidth - el.clientWidth}px`);
155
250
  });
156
251
  return (
157
- <Dynamic
158
- component={local.as ?? "div"}
252
+ <Polymorphic
253
+ defaultAs="div"
254
+ as={local.as}
159
255
  ref={(node: HTMLElement) => {
160
256
  el = node;
161
257
  if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
@@ -176,16 +272,53 @@ export function createModalParts(slot: string): ModalParts {
176
272
  return { Header, Body, Footer };
177
273
  }
178
274
 
179
- /** Solid's handler prop is a union: a plain function, or the bound
180
- * `[handler, data]` form that calls `handler(data, event)`. A wrapper that
181
- * only checks for a function silently drops the bound one. */
182
- export function callEventHandler<T, E extends Event>(
183
- event: E & { currentTarget: T; target: Element },
184
- handler: JSX.EventHandlerUnion<T, E> | undefined,
185
- ): void {
186
- if (!handler) return;
187
- if (typeof handler === "function") handler(event);
188
- else handler[0](handler[1], event);
275
+ export type ModalMedia =
276
+ | { icon: string; tone?: string; avatar?: never }
277
+ | { avatar: JSX.Element; icon?: never; tone?: never };
278
+
279
+ export type ModalHeadProps = ModalMedia & {
280
+ /** A few words: the outcome or the question. */
281
+ title: string;
282
+ /** One line under the title; a `Term` goes here. */
283
+ line?: JSX.Element;
284
+ /** Badges after the title. */
285
+ status?: JSX.Element;
286
+ /** The title is a key or an id: mono, breaks anywhere. */
287
+ mono?: boolean;
288
+ /** A step indicator, tabs, a close or a link; the work's buttons live in the Footer. */
289
+ action?: JSX.Element;
290
+ wrap?: boolean;
291
+ };
292
+
293
+ /** The header door: media, a title and one line, no free children. A family
294
+ * hands in its own Header, Title and Description so ResponsiveDialog still
295
+ * switches between dialog and sheet parts at render time. */
296
+ export function createModalHead<P extends ModalHeadProps = ModalHeadProps>(
297
+ Header: Component<ModalHeaderProps>,
298
+ Title: Component<ComponentProps<"h2">>,
299
+ Description: Component<ComponentProps<"p">>,
300
+ ): Component<P> {
301
+ return (props) => {
302
+ const line = children(() => props.line);
303
+ const status = children(() => props.status);
304
+ return (
305
+ <Header
306
+ wrap={props.wrap}
307
+ action={props.action}
308
+ media={props.avatar ?? <SectionIcon icon={props.icon} tone={props.tone} size="md" />}
309
+ >
310
+ <Title
311
+ class={cn(status() && "flex items-center gap-2", props.mono && "font-mono break-all")}
312
+ >
313
+ {props.title}
314
+ {status()}
315
+ </Title>
316
+ <Show when={line()}>
317
+ <Description>{line()}</Description>
318
+ </Show>
319
+ </Header>
320
+ );
321
+ };
189
322
  }
190
323
 
191
324
  export type ModalDismissProps = ComponentProps<typeof KobalteButton> & {
@@ -193,15 +326,16 @@ export type ModalDismissProps = ComponentProps<typeof KobalteButton> & {
193
326
  busy?: boolean;
194
327
  };
195
328
 
196
- /* Not kobalte's own CloseButton: that one hard-defaults aria-label to its
197
- * "Dismiss" translation, and an aria-label outranks the visible text, so every
198
- * labelled button in every modal answered to "Dismiss". Here a name is set only
199
- * when the caller passes one. AlertDialog is built on the Dialog context, so
200
- * one factory serves both families. */
201
- export function createModalDismiss(slot: string): ParentComponent<ModalDismissProps> {
329
+ /* A name is set only when the caller passes one: an aria-label outranks the
330
+ * visible text, so a default label would rename every close button. Each
331
+ * family hands in the context its parts close through. */
332
+ export function createModalDismiss(
333
+ slot: string,
334
+ useCloser: () => { close(): void },
335
+ ): ParentComponent<ModalDismissProps> {
202
336
  return (props) => {
203
337
  const [local, rest] = splitProps(props, ["onClick", "busy"]);
204
- const context = useDialogContext();
338
+ const context = useCloser();
205
339
  return (
206
340
  <KobalteButton
207
341
  data-slot={slot}
@@ -216,11 +350,16 @@ export function createModalDismiss(slot: string): ParentComponent<ModalDismissPr
216
350
  };
217
351
  }
218
352
 
219
- /** Renderless. Mounted inside a portal that exists only while the modal is
220
- * open, so the refcounted page lock follows the modal's real lifetime. */
221
- export const ModalScrollLock: Component = () => {
222
- onMount(acquireScrollLock);
223
- onCleanup(releaseScrollLock);
353
+ /** Renderless, inside the modal's portal: the panel covers the page from the end of its open animation until the portal leaves. */
354
+ export const ModalCover: Component<{
355
+ panel: Accessor<Element | undefined>;
356
+ open: Accessor<boolean>;
357
+ dormant: Accessor<boolean>;
358
+ }> = (props) => {
359
+ createEffect(() => {
360
+ const panel = props.panel();
361
+ if (panel && !props.dormant()) onCleanup(coverOnceOpen(panel, props.open));
362
+ });
224
363
  return null;
225
364
  };
226
365
 
@@ -235,9 +374,9 @@ export interface ModalLabels {
235
374
 
236
375
  const ModalLabelsContext = createContext<ModalLabels>();
237
376
 
238
- /** Kobalte wires title/description ids for its own families; the hand-rolled
239
- * surfaces (BottomSheet) wire them through this. The part registers the id it
240
- * actually rendered, so a caller's own `id` still labels the panel. */
377
+ /** ModalRoot wires title/description ids for its families; BottomSheet wires
378
+ * them through this. The part registers the id it actually rendered, so a
379
+ * caller's own `id` still labels the panel. */
241
380
  export function createModalLabels(): ModalLabels {
242
381
  const titleId = createUniqueId();
243
382
  const descriptionId = createUniqueId();
@@ -1,50 +1,50 @@
1
- import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
2
1
  import { usePortalMount } from "./portal-mount.js";
3
2
  import type { VariantProps } from "cva";
4
3
  import {
5
4
  type Component,
6
5
  type ComponentProps,
7
6
  createEffect,
7
+ createMemo,
8
8
  createSignal,
9
+ type JSX,
9
10
  onCleanup,
10
11
  type ParentComponent,
11
12
  splitProps,
12
13
  } from "solid-js";
13
14
  import { overAnchor } from "../lib/anchor-placement.js";
14
- import { inShadowRoot, shadowLayer } from "../lib/shadow-layer.js";
15
+ import { ModalFrame, useDialogContext } from "../lib/behavior/modal-root.js";
16
+ import { MOTION_EXIT_MS } from "../lib/motion-classes.js";
15
17
  import { buttonVariants } from "../lib/button-variants.js";
16
18
  import { cn } from "../lib/utils.js";
17
19
  import {
18
20
  ANCHORED_PANEL,
19
21
  createModalDismiss,
22
+ createModalHead,
20
23
  createModalParts,
24
+ createModalRootSkin,
25
+ createModalTextParts,
21
26
  MODAL_ANCHOR,
22
- MODAL_DESCRIPTION,
23
27
  MODAL_PANEL,
24
28
  MODAL_SCRIM,
25
- MODAL_TITLE,
26
29
  MODAL_WIDTH,
30
+ type ModalContentProps,
27
31
  type ModalDismissProps,
28
- ModalScrollLock,
32
+ ModalCover,
29
33
  type ModalSize,
30
34
  } from "./dialog-parts.js";
31
35
 
32
- /* Kobalte's own scroll lock is off everywhere: one refcounted lock
33
- * (bottom-sheet/scroll-lock.ts) serves every modal family, so a nested modal
34
- * cannot release the page early. */
35
- const Dialog: ParentComponent<ComponentProps<typeof DialogPrimitive>> = (props) => {
36
- const mount = usePortalMount();
37
- return <DialogPrimitive modal={!inShadowRoot(mount)} {...props} preventScroll={false} />;
38
- };
36
+ const Dialog = createModalRootSkin("dialog");
39
37
 
40
- const DialogTrigger: Component<ComponentProps<typeof DialogPrimitive.Trigger>> = (props) => (
41
- <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
42
- );
38
+ const {
39
+ Trigger: DialogTrigger,
40
+ Title: DialogTitle,
41
+ Description: DialogDescription,
42
+ } = createModalTextParts("dialog");
43
43
 
44
44
  type DialogCloseProps = ModalDismissProps &
45
45
  Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
46
46
 
47
- const DialogDismiss = createModalDismiss("dialog-close");
47
+ const DialogDismiss = createModalDismiss("dialog-close", useDialogContext);
48
48
 
49
49
  /** Already the outline button, so `as` is for a non-button element (a link),
50
50
  * never for `Button`: two buttonVariants() calls leave tone knobs side by side
@@ -64,7 +64,7 @@ const DialogClose: ParentComponent<DialogCloseProps> = (props) => {
64
64
  );
65
65
  };
66
66
 
67
- type DialogContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
67
+ type DialogContentProps = ModalContentProps & {
68
68
  size?: ModalSize;
69
69
  /** Names a panel that has no `DialogTitle`. A registered Title wins. */
70
70
  ariaLabel?: string;
@@ -91,95 +91,66 @@ const DialogContent: ParentComponent<DialogContentProps> = (props) => {
91
91
  "anchor",
92
92
  "style",
93
93
  "ref",
94
- "onInteractOutside",
95
- "onCloseAutoFocus",
96
- "onOpenAutoFocus",
94
+ "onFocusOutside",
95
+ "forceMount",
97
96
  ]);
98
- const context = useDialogContext();
97
+ const ctx = useDialogContext();
99
98
  const [viewport, setViewport] = createSignal(0);
100
- const [panel, setPanel] = createSignal<HTMLElement>();
101
- const layer = shadowLayer({
102
- content: panel,
103
- open: () => context.isOpen(),
104
- dismiss: () => context.close(),
105
- trapsFocus: true,
106
- consumer: local,
107
- });
108
99
  const [height, setHeight] = createSignal<number>();
109
100
  createEffect(() => {
110
- if (!local.anchor || !context.isOpen()) return;
101
+ if (!local.anchor || !ctx.isOpen()) return;
111
102
  const measure = () => setViewport((n) => n + 1);
112
103
  window.addEventListener("resize", measure);
113
104
  onCleanup(() => window.removeEventListener("resize", measure));
114
105
  });
115
106
  createEffect(() => {
116
- const el = panel();
107
+ const el = ctx.panel();
117
108
  if (!local.anchor || !el) return;
118
109
  setHeight(el.offsetHeight);
119
110
  const observer = new ResizeObserver(() => setHeight(el.offsetHeight));
120
111
  observer.observe(el);
121
112
  onCleanup(() => observer.disconnect());
122
113
  });
123
- const placement = () => {
114
+ const placement = createMemo<JSX.CSSProperties | undefined>((last) => {
115
+ if (!ctx.isOpen()) return last;
124
116
  viewport();
125
117
  const a = local.anchor;
126
118
  return a ? overAnchor(a, ANCHORED_WIDTH[local.size ?? "lg"], height()) : undefined;
127
- };
119
+ });
128
120
  return (
129
- <DialogPrimitive.Portal mount={usePortalMount()}>
130
- <ModalScrollLock />
131
- <DialogPrimitive.Overlay data-slot="dialog-overlay" class={MODAL_SCRIM} />
132
- <DialogPrimitive.Content
133
- ref={(el: HTMLElement) => {
134
- setPanel(el);
135
- if (typeof local.ref === "function") local.ref(el);
136
- }}
137
- data-slot="dialog-content"
138
- role="dialog"
139
- aria-label={context.titleId() ? undefined : local.ariaLabel}
140
- class={cn(
121
+ <>
122
+ <ModalCover panel={ctx.panel} open={ctx.isOpen} dormant={ctx.dormant} />
123
+ <ModalFrame
124
+ slot="dialog"
125
+ mount={usePortalMount()}
126
+ exitMs={local.anchor ? MOTION_EXIT_MS.anchored : MOTION_EXIT_MS.modal}
127
+ scrimClass={MODAL_SCRIM}
128
+ panelClass={cn(
141
129
  local.anchor ? ANCHORED_PANEL : MODAL_PANEL,
142
130
  !local.anchor && MODAL_WIDTH[local.size ?? "lg"],
143
131
  !local.anchor && MODAL_ANCHOR[local.size ?? "lg"],
144
132
  local.class,
145
133
  )}
146
- style={{ ...(typeof local.style === "object" ? local.style : {}), ...placement() }}
147
- onInteractOutside={layer.onInteractOutside}
148
- onCloseAutoFocus={layer.onCloseAutoFocus}
149
- onOpenAutoFocus={layer.onOpenAutoFocus}
134
+ panelStyle={{ ...(typeof local.style === "object" ? local.style : {}), ...placement() }}
135
+ ariaLabel={local.ariaLabel}
136
+ ref={(el: HTMLElement) => {
137
+ if (typeof local.ref === "function") local.ref(el as HTMLDivElement);
138
+ }}
150
139
  {...others}
151
140
  >
152
141
  {local.children}
153
- </DialogPrimitive.Content>
154
- </DialogPrimitive.Portal>
142
+ </ModalFrame>
143
+ </>
155
144
  );
156
145
  };
157
146
 
158
147
  const { Header: DialogHeader, Body: DialogBody, Footer: DialogFooter } = createModalParts("dialog");
159
148
 
160
- const DialogTitle: Component<ComponentProps<typeof DialogPrimitive.Title>> = (props) => {
161
- const [local, others] = splitProps(props, ["class"]);
162
- return (
163
- <DialogPrimitive.Title
164
- data-slot="dialog-title"
165
- class={cn(MODAL_TITLE, local.class)}
166
- {...others}
167
- />
168
- );
169
- };
170
-
171
- const DialogDescription: Component<ComponentProps<typeof DialogPrimitive.Description>> = (
172
- props,
173
- ) => {
174
- const [local, others] = splitProps(props, ["class"]);
175
- return (
176
- <DialogPrimitive.Description
177
- data-slot="dialog-description"
178
- class={cn(MODAL_DESCRIPTION, local.class)}
179
- {...others}
180
- />
181
- );
182
- };
149
+ const DialogHead = createModalHead(
150
+ DialogHeader,
151
+ DialogTitle as Component<ComponentProps<"h2">>,
152
+ DialogDescription as Component<ComponentProps<"p">>,
153
+ );
183
154
 
184
155
  export {
185
156
  Dialog,
@@ -188,6 +159,7 @@ export {
188
159
  DialogContent,
189
160
  DialogDescription,
190
161
  DialogFooter,
162
+ DialogHead,
191
163
  DialogHeader,
192
164
  DialogTitle,
193
165
  DialogTrigger,
@@ -1,5 +1,6 @@
1
1
  import { createSignal, For, onCleanup, Show } from "solid-js";
2
2
  import { Portal } from "solid-js/web";
3
+ import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
3
4
  import { Z_CLASS } from "../lib/layers.js";
4
5
  import { cn } from "../lib/utils.js";
5
6
  import { type EdgeZone, edgeZone, moveId, slotAt } from "./dock-paging.js";
@@ -136,10 +137,10 @@ export function createDockReorder(options: ReorderOptions) {
136
137
  if (ids.indexOf(id) < 0 || to < 0 || to >= ids.length) return;
137
138
  options.onReorder(moveId(ids, id, to));
138
139
  requestAnimationFrame(() =>
139
- options
140
- .bar()
141
- ?.querySelector<HTMLElement>(`[data-dock-id="${CSS.escape(id)}"]`)
142
- ?.focus(),
140
+ focusWithoutTracking(
141
+ options.bar()?.querySelector<HTMLElement>(`[data-dock-id="${CSS.escape(id)}"]`),
142
+ { preventScroll: false },
143
+ ),
143
144
  );
144
145
  }
145
146
 
@@ -13,7 +13,7 @@ import {
13
13
  Show,
14
14
  splitProps,
15
15
  } from "solid-js";
16
- import { Dynamic } from "solid-js/web";
16
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
17
17
  import { CARD_SURFACE } from "../lib/card-classes.js";
18
18
  import { DOCK_SLOT_SHAPE } from "../lib/dock-slot-classes.js";
19
19
  import {
@@ -133,8 +133,8 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
133
133
  {isElement() ? (
134
134
  (local.icon as JSX.Element)
135
135
  ) : (
136
- <Dynamic
137
- component={local.icon as Component<{ class?: string }>}
136
+ <Polymorphic
137
+ defaultAs={local.icon as Component<{ class?: string }>}
138
138
  class="h-5 w-5 sm:h-6 sm:w-6"
139
139
  />
140
140
  )}
@@ -9,7 +9,12 @@ import {
9
9
  splitProps,
10
10
  } from "solid-js";
11
11
  import { MORPH_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 { anchorToTriggerTop } from "../lib/overlay-classes.js";
14
19
  import { cn } from "../lib/utils.js";
15
20
  import {
@@ -29,13 +34,16 @@ import {
29
34
  const DropdownMenuRoot: Component<ComponentProps<typeof DropdownMenuPrimitive>> = (props) => {
30
35
  // Modal in a shadow root, Kobalte would aria-hide the realm's host, menu included.
31
36
  const inShadow = inShadowRoot(usePortalMount());
37
+ const cover = createCoveredRoot();
32
38
  return (
33
- <DropdownMenuPrimitive
34
- gutter={0}
35
- getAnchorRect={anchorToTriggerTop}
36
- {...props}
37
- modal={inShadow ? false : props.modal}
38
- />
39
+ <ReportCovered.Provider value={cover.report}>
40
+ <DropdownMenuPrimitive
41
+ gutter={0}
42
+ getAnchorRect={anchorToTriggerTop}
43
+ {...props}
44
+ modal={inShadow || cover.covered() ? false : props.modal}
45
+ />
46
+ </ReportCovered.Provider>
39
47
  );
40
48
  };
41
49
  const DropdownMenu = Object.assign(DropdownMenuRoot, DropdownMenuPrimitive) as Component<
@@ -9,6 +9,7 @@ import {
9
9
  type ParentComponent,
10
10
  Show,
11
11
  } from "solid-js";
12
+ import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
12
13
  import { MENU_LABEL } from "../lib/menu-classes.js";
13
14
  import { PICKER_LIST } from "../lib/picker-classes.js";
14
15
  import { createIsMobile } from "../lib/use-is-mobile.js";
@@ -627,7 +628,7 @@ export function EntitySelector(props: EntitySelectorProps) {
627
628
  e.preventDefault();
628
629
  // preventScroll: the panel is portalled at (0,0) until the popper places it,
629
630
  // so a plain focus() scrolls the page to the top.
630
- inputRef?.focus({ preventScroll: true });
631
+ focusWithoutTracking(inputRef);
631
632
  }}
632
633
  onInteractOutside={() => closePicker()}
633
634
  >
@@ -16,7 +16,7 @@ import {
16
16
  useContext,
17
17
  type ValidComponent,
18
18
  } from "solid-js";
19
- import { Dynamic } from "solid-js/web";
19
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
20
20
  import { cn } from "../lib/utils.js";
21
21
  import { Field, FieldDescription, FieldError, FieldLabel } from "./field.js";
22
22
  import { Input } from "./input.js";
@@ -174,8 +174,9 @@ const FormControl = <T extends ValidComponent = typeof Input>(
174
174
  <Show
175
175
  when={wrapped()}
176
176
  fallback={
177
- <Dynamic
178
- component={local.as ?? Input}
177
+ <Polymorphic
178
+ defaultAs={Input}
179
+ as={local.as}
179
180
  id={formItemId()}
180
181
  aria-describedby={describedBy()}
181
182
  aria-invalid={error() ? true : undefined}
@@ -1,4 +1,4 @@
1
- import { HoverCard as HoverCardPrimitive } from "@kobalte/core/hover-card";
1
+ import { HoverCard as HoverCardPrimitive, useHoverCardContext } from "@kobalte/core/hover-card";
2
2
  import { usePortalMount } from "./portal-mount.js";
3
3
  import { type Component, type ComponentProps, createSignal, splitProps } from "solid-js";
4
4
  import { OVERLAY_MOTION } from "../lib/motion-classes.js";
@@ -16,7 +16,12 @@ const HoverCardContent: Component<ComponentProps<typeof HoverCardPrimitive.Conte
16
16
  const [local, rest] = splitProps(props, ["class", "ref", "onInteractOutside"]);
17
17
  const [panel, setPanel] = createSignal<HTMLElement>();
18
18
  // A hover card closes as the pointer leaves; inside a shadow root it only must not close on its own presses.
19
- const { onInteractOutside } = shadowLayer({ content: panel, open: () => true, consumer: local });
19
+ const card = useHoverCardContext();
20
+ const { onInteractOutside } = shadowLayer({
21
+ content: panel,
22
+ open: () => card.isOpen(),
23
+ consumer: local,
24
+ });
20
25
  return (
21
26
  <HoverCardPrimitive.Portal data-slot="hover-card-portal" mount={usePortalMount()}>
22
27
  <HoverCardPrimitive.Content