@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
@@ -0,0 +1,446 @@
1
+ import {
2
+ type Accessor,
3
+ type ComponentProps,
4
+ createContext,
5
+ createRenderEffect,
6
+ createSignal,
7
+ createUniqueId,
8
+ type JSX,
9
+ onCleanup,
10
+ Show,
11
+ splitProps,
12
+ untrack,
13
+ useContext,
14
+ type ValidComponent,
15
+ } from "solid-js";
16
+ import { Portal } from "solid-js/web";
17
+ import { LAYER_ROOT } from "../overlay-classes";
18
+ import { createControllableSignal } from "./controllable";
19
+ import { createDismiss } from "./dismiss";
20
+ import { createFocusScope, focusWithoutTracking } from "./focus-scope";
21
+ import { createHideOutside } from "./hide-outside";
22
+ import { layerStack, registerLayer } from "./layer-stack";
23
+ import { Polymorphic } from "./polymorphic";
24
+ import { createPresence } from "./presence";
25
+ import { callEventHandler, effect, merge } from "./solid";
26
+
27
+ export type ModalRole = "dialog" | "alertdialog";
28
+
29
+ export interface ModalRootProps {
30
+ open?: boolean;
31
+ defaultOpen?: boolean;
32
+ onOpenChange?: (open: boolean) => void;
33
+ modal?: boolean;
34
+ keep?: boolean;
35
+ role?: ModalRole;
36
+ children?: JSX.Element;
37
+ }
38
+
39
+ export interface ModalContext {
40
+ isOpen: Accessor<boolean>;
41
+ close: () => void;
42
+ toggle: () => void;
43
+ modal: Accessor<boolean>;
44
+ keep: Accessor<boolean>;
45
+ dormant: Accessor<boolean>;
46
+ bindDormant: (source: Accessor<boolean>) => void;
47
+ readonly role: ModalRole;
48
+ titleId: Accessor<string | undefined>;
49
+ registerTitle: (id: string) => () => void;
50
+ descriptionId: Accessor<string | undefined>;
51
+ registerDescription: (id: string) => () => void;
52
+ contentId: Accessor<string | undefined>;
53
+ registerContent: (id: string) => () => void;
54
+ triggerRef: Accessor<HTMLElement | undefined>;
55
+ setTriggerRef: (el: HTMLElement | undefined) => void;
56
+ panel: Accessor<HTMLElement | undefined>;
57
+ setPanel: (el: HTMLElement | undefined) => void;
58
+ }
59
+
60
+ const ModalContextValue = createContext<ModalContext>();
61
+
62
+ export function useDialogContext(): ModalContext {
63
+ const context = useContext(ModalContextValue);
64
+ if (!context) throw new Error("Dialog parts must be used within <Dialog>");
65
+ return context;
66
+ }
67
+
68
+ /** Whether the modal around the caller is closed and kept; false outside one, so a ticker inside can pause. */
69
+ export function useDialogDormant(): Accessor<boolean> {
70
+ return useContext(ModalContextValue)?.dormant ?? (() => false);
71
+ }
72
+
73
+ function createRegistry(): [Accessor<string | undefined>, (id: string) => () => void] {
74
+ const [current, setCurrent] = createSignal<string>();
75
+ const register = (id: string) => {
76
+ setCurrent(id);
77
+ return () => {
78
+ if (untrack(current) === id) setCurrent(undefined);
79
+ };
80
+ };
81
+ return [current, register];
82
+ }
83
+
84
+ export function ModalRoot(props: ModalRootProps): JSX.Element {
85
+ const [isOpen, setOpen] = createControllableSignal<boolean>({
86
+ value: () => props.open,
87
+ defaultValue: () => props.defaultOpen ?? false,
88
+ onChange: (next) => props.onOpenChange?.(next),
89
+ });
90
+ const [titleId, registerTitle] = createRegistry();
91
+ const [descriptionId, registerDescription] = createRegistry();
92
+ const [contentId, registerContent] = createRegistry();
93
+ const [triggerRef, setTriggerRef] = createSignal<HTMLElement>();
94
+ const [panel, setPanel] = createSignal<HTMLElement>();
95
+ const [dormantSource, setDormantSource] = createSignal<Accessor<boolean>>(() => false);
96
+ const context: ModalContext = {
97
+ isOpen,
98
+ close: () => setOpen(false),
99
+ toggle: () => setOpen(!untrack(isOpen)),
100
+ modal: () => props.modal ?? true,
101
+ keep: () => props.keep ?? false,
102
+ dormant: () => dormantSource()(),
103
+ bindDormant: (source) => setDormantSource(() => source),
104
+ get role() {
105
+ return props.role ?? "dialog";
106
+ },
107
+ titleId,
108
+ registerTitle,
109
+ descriptionId,
110
+ registerDescription,
111
+ contentId,
112
+ registerContent,
113
+ triggerRef,
114
+ setTriggerRef: (el) => setTriggerRef(el),
115
+ panel,
116
+ setPanel: (el) => setPanel(el),
117
+ };
118
+ return <ModalContextValue.Provider value={context}>{props.children}</ModalContextValue.Provider>;
119
+ }
120
+
121
+ export type ModalPartProps<T extends ValidComponent> = { as?: T } & Omit<ComponentProps<T>, "as">;
122
+
123
+ export function ModalTrigger<T extends ValidComponent = "button">(
124
+ props: ModalPartProps<T>,
125
+ ): JSX.Element {
126
+ const ctx = useDialogContext();
127
+ const [local, rest] = splitProps(props as ModalPartProps<ValidComponent>, [
128
+ "as",
129
+ "ref",
130
+ "onClick",
131
+ ]);
132
+ let own: HTMLElement | undefined;
133
+ onCleanup(() => {
134
+ if (own && untrack(ctx.triggerRef) === own) ctx.setTriggerRef(undefined);
135
+ });
136
+ return (
137
+ <Polymorphic
138
+ {...merge(rest, {
139
+ as: local.as,
140
+ defaultAs: "button" as ValidComponent,
141
+ ref: (el: HTMLElement) => {
142
+ own = el;
143
+ ctx.setTriggerRef(el);
144
+ if (typeof local.ref === "function") local.ref(el);
145
+ },
146
+ "aria-haspopup": "dialog",
147
+ get "aria-expanded"() {
148
+ return ctx.isOpen();
149
+ },
150
+ get "aria-controls"() {
151
+ return ctx.isOpen() ? ctx.contentId() : undefined;
152
+ },
153
+ get "data-expanded"() {
154
+ return ctx.isOpen() ? "" : undefined;
155
+ },
156
+ get "data-closed"() {
157
+ return ctx.isOpen() ? undefined : "";
158
+ },
159
+ onClick: (event: MouseEvent & { currentTarget: HTMLElement; target: Element }) => {
160
+ callEventHandler(
161
+ event,
162
+ local.onClick as JSX.EventHandlerUnion<HTMLElement, MouseEvent> | undefined,
163
+ );
164
+ ctx.toggle();
165
+ },
166
+ })}
167
+ />
168
+ );
169
+ }
170
+
171
+ function createLabelPart(defaultAs: ValidComponent, register: (id: string) => () => void) {
172
+ return (props: ModalPartProps<ValidComponent>): JSX.Element => {
173
+ const [local, rest] = splitProps(props, ["as", "id"]);
174
+ const fallback = createUniqueId();
175
+ const id = (): string => local.id ?? fallback;
176
+ effect(id, register);
177
+ return (
178
+ <Polymorphic
179
+ {...merge(rest, {
180
+ as: local.as,
181
+ defaultAs,
182
+ get id() {
183
+ return id();
184
+ },
185
+ })}
186
+ />
187
+ );
188
+ };
189
+ }
190
+
191
+ export function ModalTitle<T extends ValidComponent = "h2">(props: ModalPartProps<T>): JSX.Element {
192
+ const ctx = useDialogContext();
193
+ return createLabelPart("h2", ctx.registerTitle)(props as ModalPartProps<ValidComponent>);
194
+ }
195
+
196
+ export function ModalDescription<T extends ValidComponent = "p">(
197
+ props: ModalPartProps<T>,
198
+ ): JSX.Element {
199
+ const ctx = useDialogContext();
200
+ return createLabelPart("p", ctx.registerDescription)(props as ModalPartProps<ValidComponent>);
201
+ }
202
+
203
+ export interface ModalFrameProps extends Omit<
204
+ JSX.HTMLAttributes<HTMLDivElement>,
205
+ "ref" | "style" | "role" | "class"
206
+ > {
207
+ slot: string;
208
+ panelClass: string;
209
+ scrimClass: string;
210
+ panelStyle?: JSX.CSSProperties;
211
+ ariaLabel?: string;
212
+ ref?: (el: HTMLElement) => void;
213
+ as?: ValidComponent;
214
+ mount?: Node;
215
+ exitMs: number;
216
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
217
+ onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
218
+ onInteractOutside?: (event: InteractOutsideEvent) => void;
219
+ onOpenAutoFocus?: (event: Event) => void;
220
+ onCloseAutoFocus?: (event: Event) => void;
221
+ }
222
+
223
+ interface OutsideDetail<T extends Event> {
224
+ originalEvent: T;
225
+ isContextMenu: boolean;
226
+ }
227
+ export type PointerDownOutsideEvent = CustomEvent<OutsideDetail<PointerEvent>>;
228
+ export type FocusOutsideEvent = CustomEvent<OutsideDetail<FocusEvent>>;
229
+ export type InteractOutsideEvent = PointerDownOutsideEvent | FocusOutsideEvent;
230
+
231
+ function vetoed<E extends Event>(handler: ((event: E) => void) | undefined, event: E): boolean {
232
+ handler?.(event);
233
+ return event.defaultPrevented;
234
+ }
235
+
236
+ const onMac = (): boolean => typeof navigator !== "undefined" && /^Mac/i.test(navigator.platform);
237
+
238
+ function isContextMenu(event: PointerEvent): boolean {
239
+ const ctrl = onMac() ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
240
+ return event.button === 2 || (ctrl && event.button === 0);
241
+ }
242
+
243
+ const OUTSIDE_EVENT = "interactoutside";
244
+
245
+ function pointerDownOutside(
246
+ original: PointerEvent,
247
+ handle: (event: PointerDownOutsideEvent) => void,
248
+ ): PointerDownOutsideEvent {
249
+ const event: PointerDownOutsideEvent = new CustomEvent(OUTSIDE_EVENT, {
250
+ cancelable: true,
251
+ detail: { originalEvent: original, isContextMenu: isContextMenu(original) },
252
+ });
253
+ const target = original.target;
254
+ // Dispatched on the pressed node so handlers read its target, as Kobalte's did.
255
+ if (!target) handle(event);
256
+ else {
257
+ target.addEventListener(OUTSIDE_EVENT, () => handle(event), { once: true });
258
+ target.dispatchEvent(event);
259
+ }
260
+ return event;
261
+ }
262
+
263
+ function inside(container: Element, node: Element | undefined): boolean {
264
+ for (
265
+ let n: Node | null | undefined = node;
266
+ n;
267
+ n = n instanceof ShadowRoot ? n.host : n.parentNode
268
+ )
269
+ if (n === container) return true;
270
+ return false;
271
+ }
272
+
273
+ // Skipped content stops ticking: an exit the timeout ended early would freeze mid-way, not at rest.
274
+ function finishMotion(root: Element): void {
275
+ for (const animation of root.getAnimations?.({ subtree: true }) ?? []) {
276
+ if (animation.playState !== "running") continue;
277
+ if (animation.effect?.getComputedTiming().iterations === Infinity) continue;
278
+ animation.finish();
279
+ }
280
+ }
281
+
282
+ export function ModalFrame(props: ModalFrameProps): JSX.Element {
283
+ const ctx = useDialogContext();
284
+ const [local, rest] = splitProps(props, [
285
+ "slot",
286
+ "panelClass",
287
+ "scrimClass",
288
+ "panelStyle",
289
+ "ariaLabel",
290
+ "ref",
291
+ "as",
292
+ "mount",
293
+ "exitMs",
294
+ "onEscapeKeyDown",
295
+ "onPointerDownOutside",
296
+ "onInteractOutside",
297
+ "onOpenAutoFocus",
298
+ "onCloseAutoFocus",
299
+ "children",
300
+ "id",
301
+ ]);
302
+ const fallbackId = createUniqueId();
303
+ const id = (): string => local.id ?? fallbackId;
304
+ effect(id, ctx.registerContent);
305
+
306
+ const presence = createPresence({
307
+ present: ctx.isOpen,
308
+ element: ctx.panel,
309
+ get exitMs() {
310
+ return local.exitMs;
311
+ },
312
+ keep: ctx.keep,
313
+ });
314
+ ctx.bindDormant(presence.dormant);
315
+ onCleanup(() => ctx.bindDormant(() => false));
316
+ const expanded = () => presence.phase() === "opening" || presence.phase() === "open";
317
+
318
+ const handle = registerLayer({
319
+ element: ctx.panel,
320
+ open: ctx.isOpen,
321
+ kind: "modal",
322
+ escape: () => true,
323
+ dismiss: () => ctx.close(),
324
+ trigger: ctx.triggerRef,
325
+ });
326
+
327
+ let closedByOutside = false;
328
+ createDismiss({
329
+ layer: handle,
330
+ escapeFrom: "document",
331
+ onDismiss: (reason, original) => {
332
+ if (reason === "escape") {
333
+ if (vetoed(local.onEscapeKeyDown, original as KeyboardEvent)) return;
334
+ } else {
335
+ const event = pointerDownOutside(original as PointerEvent, (e) => {
336
+ local.onPointerDownOutside?.(e);
337
+ if (ctx.modal() && e.detail.isContextMenu) e.preventDefault();
338
+ local.onInteractOutside?.(e);
339
+ });
340
+ if (event.defaultPrevented) return;
341
+ closedByOutside = true;
342
+ }
343
+ ctx.close();
344
+ // A controlled `open` refused the close.
345
+ if (untrack(ctx.isOpen)) closedByOutside = false;
346
+ },
347
+ });
348
+
349
+ createHideOutside({ layer: handle, active: () => ctx.isOpen() && ctx.modal() });
350
+
351
+ const [trapping, setTrapping] = createSignal(false);
352
+ const scope = createFocusScope({
353
+ container: ctx.panel,
354
+ active: trapping,
355
+ trapped: () => true,
356
+ initialFocus: (container) => {
357
+ if (!vetoed(local.onOpenAutoFocus, new Event("openautofocus", { cancelable: true })))
358
+ return null;
359
+ const active = (container.getRootNode() as Document | ShadowRoot).activeElement;
360
+ return active instanceof HTMLElement && container.contains(active) ? active : container;
361
+ },
362
+ });
363
+
364
+ effect(
365
+ () => ctx.isOpen() && ctx.panel() !== undefined,
366
+ (open) => {
367
+ if (open) {
368
+ closedByOutside = false;
369
+ setTrapping(true);
370
+ return;
371
+ }
372
+ const panel = ctx.panel();
373
+ if (panel) {
374
+ // Newest first: a list opened from inside goes before the one it came from.
375
+ for (const layer of [...layerStack.layers()].reverse()) {
376
+ if (inside(panel, layer.trigger()) || inside(panel, layer.element())) layer.dismiss?.();
377
+ }
378
+ }
379
+ if (!trapping()) return;
380
+ scope.untrap();
381
+ const kept =
382
+ vetoed(local.onCloseAutoFocus, new Event("closeautofocus", { cancelable: true })) ||
383
+ (closedByOutside && !ctx.modal());
384
+ const trigger = ctx.triggerRef();
385
+ const toTrigger = !kept && trigger?.isConnected === true;
386
+ if (kept || toTrigger) scope.skipRestore();
387
+ setTrapping(false);
388
+ if (toTrigger) queueMicrotask(() => focusWithoutTracking(trigger));
389
+ },
390
+ );
391
+
392
+ return (
393
+ <Show when={presence.mounted()}>
394
+ {(_) => {
395
+ onCleanup(() => ctx.setPanel(undefined));
396
+ return (
397
+ <Portal
398
+ mount={local.mount}
399
+ ref={(container: HTMLDivElement) => {
400
+ container.className = LAYER_ROOT;
401
+ createRenderEffect(() => {
402
+ const dormant = presence.dormant();
403
+ if (dormant) finishMotion(container);
404
+ container.toggleAttribute("data-dormant", dormant);
405
+ });
406
+ }}
407
+ >
408
+ <div
409
+ data-slot={`${local.slot}-overlay`}
410
+ class={local.scrimClass}
411
+ data-expanded={expanded() ? "" : undefined}
412
+ data-closed={expanded() ? undefined : ""}
413
+ on:pointerdown={(event) => {
414
+ // Focus stays in the panel when the scrim is pressed.
415
+ if (event.target === event.currentTarget) event.preventDefault();
416
+ }}
417
+ />
418
+ <Polymorphic
419
+ defaultAs="div"
420
+ as={local.as}
421
+ ref={(el: HTMLElement) => {
422
+ ctx.setPanel(el);
423
+ local.ref?.(el);
424
+ }}
425
+ id={id()}
426
+ role={presence.dormant() ? undefined : ctx.role}
427
+ aria-modal={ctx.modal() && !presence.dormant() ? "true" : undefined}
428
+ tabIndex={-1}
429
+ aria-labelledby={ctx.titleId()}
430
+ aria-label={ctx.titleId() ? undefined : local.ariaLabel}
431
+ aria-describedby={ctx.descriptionId()}
432
+ data-slot={`${local.slot}-content`}
433
+ data-expanded={expanded() ? "" : undefined}
434
+ data-closed={expanded() ? undefined : ""}
435
+ class={local.panelClass}
436
+ style={local.panelStyle}
437
+ {...rest}
438
+ >
439
+ {local.children}
440
+ </Polymorphic>
441
+ </Portal>
442
+ );
443
+ }}
444
+ </Show>
445
+ );
446
+ }
@@ -0,0 +1,30 @@
1
+ import { type ComponentProps, type JSX, type ValidComponent } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
3
+ import { merge, omit } from "./solid";
4
+
5
+ export type PolymorphicProps<D extends ValidComponent> = {
6
+ as?: ValidComponent;
7
+ defaultAs: D;
8
+ } & ComponentProps<D>;
9
+
10
+ export function Polymorphic<D extends ValidComponent>(props: PolymorphicProps<D>): JSX.Element {
11
+ const component = () => props.as ?? props.defaultAs;
12
+ const rest = omit(props as PolymorphicProps<ValidComponent>, "as", "defaultAs");
13
+ return (
14
+ <Dynamic
15
+ {...merge(
16
+ {
17
+ get type() {
18
+ return component() === "button" ? "button" : undefined;
19
+ },
20
+ },
21
+ rest,
22
+ {
23
+ get component() {
24
+ return component();
25
+ },
26
+ },
27
+ )}
28
+ />
29
+ );
30
+ }
@@ -0,0 +1,89 @@
1
+ import { type Accessor, createMemo, createSignal } from "solid-js";
2
+ import { effect } from "./solid";
3
+
4
+ export type PresencePhase = "opening" | "open" | "closing" | "closed";
5
+ export type MotionEvent = AnimationEvent | TransitionEvent;
6
+
7
+ export interface PresenceOptions {
8
+ present: Accessor<boolean>;
9
+ element: Accessor<Element | undefined>;
10
+ exitMs: number;
11
+ accept?: (e: MotionEvent) => boolean;
12
+ keep?: Accessor<boolean>;
13
+ }
14
+
15
+ export interface Presence {
16
+ mounted: Accessor<boolean>;
17
+ phase: Accessor<PresencePhase>;
18
+ dormant: Accessor<boolean>;
19
+ }
20
+
21
+ export const PRESENCE_TIMEOUT_MS = 1000;
22
+
23
+ const END_EVENTS = [
24
+ "animationend",
25
+ "animationcancel",
26
+ "transitionend",
27
+ "transitioncancel",
28
+ ] as const;
29
+
30
+ export function watchMotion(
31
+ el: Element,
32
+ exitMs: number,
33
+ done: () => void,
34
+ accept?: (e: MotionEvent) => boolean,
35
+ ): () => void {
36
+ let timer: ReturnType<typeof setTimeout> | undefined;
37
+ const stop = () => {
38
+ clearTimeout(timer);
39
+ for (const type of END_EVENTS) el.removeEventListener(type, onEnd as EventListener);
40
+ };
41
+ const finish = () => {
42
+ stop();
43
+ done();
44
+ };
45
+ const onEnd = (e: MotionEvent) => {
46
+ if (e.target !== el || e.pseudoElement) return;
47
+ if (accept && !accept(e)) return;
48
+ finish();
49
+ };
50
+ for (const type of END_EVENTS) el.addEventListener(type, onEnd as EventListener);
51
+ timer = setTimeout(finish, Math.min(exitMs, PRESENCE_TIMEOUT_MS));
52
+ return stop;
53
+ }
54
+
55
+ export function createPresence(options: PresenceOptions): Presence {
56
+ const [phase, setPhase] = createSignal<PresencePhase>(options.present() ? "opening" : "closed");
57
+
58
+ effect(
59
+ () => options.present(),
60
+ (present) => {
61
+ setPhase((current) => {
62
+ if (present)
63
+ return current === "closing" ? "open" : current === "closed" ? "opening" : current;
64
+ return current === "closed" ? current : "closing";
65
+ });
66
+ },
67
+ );
68
+
69
+ effect(
70
+ () => [phase(), options.element()] as const,
71
+ ([current, el]) => {
72
+ if (current !== "opening" && current !== "closing") return;
73
+ if (!el) {
74
+ if (current === "closing") setPhase("closed");
75
+ return;
76
+ }
77
+ return watchMotion(
78
+ el,
79
+ options.exitMs,
80
+ () => setPhase(current === "opening" ? "open" : "closed"),
81
+ options.accept,
82
+ );
83
+ },
84
+ );
85
+
86
+ const mounted = createMemo(() => phase() !== "closed" || (options.keep?.() ?? false));
87
+ const dormant = createMemo(() => phase() === "closed" && mounted());
88
+ return { mounted, phase, dormant };
89
+ }
@@ -0,0 +1,30 @@
1
+ import { createEffect, type JSX, mergeProps, onCleanup, splitProps, untrack } from "solid-js";
2
+
3
+ export function effect<T>(compute: () => T, apply: (value: T) => (() => void) | void): void {
4
+ createEffect(() => {
5
+ const value = compute();
6
+ const cleanup = untrack(() => apply(value));
7
+ if (cleanup) onCleanup(cleanup);
8
+ });
9
+ }
10
+
11
+ export const merge = mergeProps;
12
+
13
+ export function omit<T extends object, K extends keyof T>(
14
+ props: T,
15
+ ...keys: K[]
16
+ ): { [P in keyof T as Exclude<P, K>]: T[P] } {
17
+ return splitProps(props, keys)[1];
18
+ }
19
+
20
+ /** Solid's handler prop is a union: a plain function, or the bound
21
+ * `[handler, data]` form that calls `handler(data, event)`. A wrapper that
22
+ * only checks for a function silently drops the bound one. */
23
+ export function callEventHandler<T, E extends Event>(
24
+ event: E & { currentTarget: T; target: Element },
25
+ handler: JSX.EventHandlerUnion<T, E> | undefined,
26
+ ): void {
27
+ if (!handler) return;
28
+ if (typeof handler === "function") handler(event);
29
+ else handler[0](handler[1], event);
30
+ }
@@ -1,3 +1,4 @@
1
+ import { focusWithoutTracking } from "./behavior/focus-scope.js";
1
2
  /** The one door to the clipboard. Call it from the click: browsers refuse a
2
3
  * copy more than a few seconds after it. Text still loading goes in as a
3
4
  * promise so a ClipboardItem write keeps the gesture (Safari). */
@@ -65,7 +66,7 @@ function copyViaSelection(text: string): boolean {
65
66
  // copied nothing.
66
67
  (previous?.parentElement ?? document.body).append(area);
67
68
  try {
68
- area.focus();
69
+ focusWithoutTracking(area);
69
70
  area.select();
70
71
  area.setSelectionRange(0, text.length);
71
72
  const root = area.getRootNode() as Document | ShadowRoot;
@@ -75,7 +76,7 @@ function copyViaSelection(text: string): boolean {
75
76
  return false;
76
77
  } finally {
77
78
  area.remove();
78
- previous?.focus();
79
+ focusWithoutTracking(previous);
79
80
  }
80
81
  }
81
82
 
@@ -32,15 +32,26 @@ export const ANCHORED_MOTION =
32
32
  * (globals.css): one door, no per-row index, mount-only. */
33
33
  export const STAGGER = "gh-stagger";
34
34
 
35
+ /* An exit that holds its last frame: a closed surface still mounted (kept, or waiting
36
+ * for its unmount) rests invisible instead of snapping back. */
37
+ const REST_CLOSED = "data-[closed]:fill-mode-forwards";
38
+
35
39
  /* Modals: rise into place. Sheets keep their slide. */
36
- export const MODAL_MOTION = `${ARRIVE} data-[expanded]:fade-in-0 data-[expanded]:zoom-in-[0.94] data-[expanded]:slide-in-from-bottom-2 ${LEAVE} data-[closed]:fade-out-0 data-[closed]:zoom-out-[0.96]`;
40
+ export const MODAL_MOTION = `${ARRIVE} data-[expanded]:fade-in-0 data-[expanded]:zoom-in-[0.94] data-[expanded]:slide-in-from-bottom-2 ${LEAVE} ${REST_CLOSED} data-[closed]:fade-out-0 data-[closed]:zoom-out-[0.96]`;
37
41
 
38
- export const SCRIM_MOTION = `${ARRIVE} data-[expanded]:fade-in-0 ${LEAVE} data-[closed]:fade-out-0`;
42
+ export const SCRIM_MOTION = `${ARRIVE} data-[expanded]:fade-in-0 ${LEAVE} ${REST_CLOSED} data-[closed]:fade-out-0`;
39
43
 
40
44
  /* Content that swaps in place (tab panel, a row added to a list). */
41
45
  export const SETTLE_MOTION =
42
46
  "animate-in fade-in-0 slide-in-from-bottom-1 duration-(--duration-state) ease-(--ease-expand)";
43
47
 
48
+ /* A cover that fades in once and rests; the animation ends, nothing runs after. */
49
+ export const VEIL_MOTION =
50
+ "animate-in fade-in-0 duration-(--duration-state) ease-(--ease-emphasis) motion-reduce:animate-none in-[.reduce-motion]:animate-none";
51
+
52
+ /* The content a StaleVeil covers: black and white for as long as it is stale, no transition. */
53
+ export const STALE_CONTENT = "grayscale";
54
+
44
55
  /* Every pressable dips the same amount. */
45
56
  export const PRESS_DIP = "active:scale-[0.97]";
46
57
 
@@ -70,3 +81,17 @@ export const RISE_MOTION =
70
81
  * spotlight's hole and bubble). */
71
82
  export const TRAVEL_MOTION =
72
83
  "transition-[translate,clip-path] duration-(--duration-morph) ease-(--ease-expand)";
84
+
85
+ /* The longest exit (delay plus duration) each door's data-[closed] classes run;
86
+ * tests/lib/motion-exit.test.tsx holds these to the computed styles. */
87
+ export const MOTION_EXIT_MS: Record<
88
+ "overlay" | "modal" | "anchored" | "scrim" | "field" | "sheet",
89
+ number
90
+ > = {
91
+ overlay: 120,
92
+ modal: 120,
93
+ anchored: 150,
94
+ scrim: 120,
95
+ field: 120,
96
+ sheet: 500,
97
+ };
@@ -22,10 +22,12 @@ export const OVERLAY_SURFACE = `${OVERLAY_SURFACE_BASE} ${OVERLAY_BLUR}`;
22
22
  * behind it would just be see-through. */
23
23
  export const OVERLAY_SURFACE_OPAQUE = `${OVERLAY_KNOBS} [--glass-base:var(--popover)]`;
24
24
 
25
- /* Modal scrim behind dialogs/sheets, from the theme's own --scrim so light can
26
- * darken while dark keeps its background wash. BottomSheet keeps its own
27
- * unblurred scrim (backdrop-blur is too slow on mobile). */
28
- export const SCRIM_CLASS = "bg-scrim backdrop-blur-md";
25
+ /* Touch screens only dim: a full-screen blur over moving widgets re-blurs every frame on a tablet GPU. */
26
+ export const SCRIM_CLASS = "bg-scrim backdrop-blur-md pointer-coarse:backdrop-blur-none";
27
+
28
+ /* overflow-hidden makes the scrim a scroll container, so overscroll-behavior applies to it. */
29
+ export const SCROLL_CONTAIN = "overscroll-contain";
30
+ export const SCRIM_CONTAIN = `${SCROLL_CONTAIN} overflow-hidden`;
29
31
 
30
32
  export const PANEL_TAIL = `${Z_CLASS.overlay} rounded-md text-popover-foreground outline-hidden`;
31
33
 
@@ -47,3 +49,6 @@ export const anchorToTriggerTop = (anchor?: HTMLElement) => {
47
49
  ? { x: r.left, y: r.top, width: r.width, height: 0 }
48
50
  : { x: 0, y: 0, width: 0, height: 0 };
49
51
  };
52
+
53
+ /* The modal layer's own root. Its box, containment and stacking never change, so going dormant only adds skipping. */
54
+ export const LAYER_ROOT = `pointer-events-none fixed inset-0 ${Z_CLASS.overlay} [contain:layout_paint_style] *:pointer-events-auto data-[dormant]:[content-visibility:hidden] not-supports-[content-visibility:hidden]:data-[dormant]:hidden`;