@glasshome/ui 1.41.0 → 1.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SPEC.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/anchor-placement.d.ts +34 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +26 -0
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +32 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +13 -0
- package/dist/lib/behavior/focus-scope.d.ts +24 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +34 -0
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +68 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/behavior/solid.d.ts +13 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +5 -2
- package/dist/lib/overlay-classes.d.ts +4 -0
- package/dist/lib/page-cover.d.ts +8 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -43
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/alert-dialog.d.ts +5 -8
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
- package/dist/solid/bottom-sheet/constants.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/dialog-parts.d.ts +53 -16
- package/dist/solid/dialog.d.ts +7 -10
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +5 -2
- package/dist/solid/index.js +8671 -14317
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +3 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +6 -9
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/stale-veil.d.ts +7 -0
- package/dist/solid/tabs.d.ts +28 -9
- package/dist/solid/toggle-group.d.ts +30 -5
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
- package/package.json +6 -7
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +77 -4
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +106 -0
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +218 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +185 -0
- package/src/lib/behavior/focus-scope.ts +227 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +150 -0
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +452 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +4 -4
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +33 -8
- package/src/lib/overlay-classes.ts +8 -3
- package/src/lib/page-cover.ts +47 -0
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -136
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +5 -3
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
- package/src/solid/bottom-sheet/constants.ts +3 -1
- package/src/solid/bottom-sheet/drag-controller.ts +11 -0
- package/src/solid/breadcrumb.tsx +4 -4
- package/src/solid/button-group.tsx +4 -4
- package/src/solid/button.tsx +12 -6
- package/src/solid/card.tsx +5 -4
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +287 -86
- package/src/solid/dialog-parts.tsx +135 -46
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +6 -5
- package/src/solid/dropdown-menu.tsx +252 -107
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +5 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +9 -9
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +288 -21
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +6 -5
- package/src/solid/index.ts +5 -4
- package/src/solid/input-group.tsx +7 -5
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +5 -5
- package/src/solid/logo.tsx +5 -4
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +10 -5
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +424 -71
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +10 -10
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +950 -95
- package/src/solid/selection.tsx +142 -66
- package/src/solid/sheet.tsx +48 -80
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +1 -1
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/spotlight.tsx +23 -11
- package/src/solid/stale-veil.tsx +20 -0
- package/src/solid/switch.tsx +8 -6
- package/src/solid/tabs.tsx +377 -52
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +237 -95
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +64 -10
- package/src/styles/theme.css +12 -4
- package/src/tokens/material.ts +11 -2
- package/dist/lib/when-animations-settle.d.ts +0 -4
- package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
- package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
- package/src/lib/when-animations-settle.ts +0 -12
- package/src/solid/bottom-sheet/focus-trap.ts +0 -63
- package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
- package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
|
@@ -0,0 +1,452 @@
|
|
|
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.js";
|
|
18
|
+
import { createControllableSignal } from "./controllable.js";
|
|
19
|
+
import { createDismiss } from "./dismiss.js";
|
|
20
|
+
import { activeOf, createFocusScope, focusWithoutTracking } from "./focus-scope.js";
|
|
21
|
+
import { createHideOutside } from "./hide-outside.js";
|
|
22
|
+
import { layerStack, registerLayer } from "./layer-stack.js";
|
|
23
|
+
import { Polymorphic } from "./polymorphic.js";
|
|
24
|
+
import { createPresence } from "./presence.js";
|
|
25
|
+
import { callEventHandler, effect, merge } from "./solid.js";
|
|
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
|
+
export function vetoed<E extends Event>(
|
|
232
|
+
handler: ((event: E) => void) | undefined,
|
|
233
|
+
event: E,
|
|
234
|
+
): boolean {
|
|
235
|
+
handler?.(event);
|
|
236
|
+
return event.defaultPrevented;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const onMac = (): boolean => typeof navigator !== "undefined" && /^Mac/i.test(navigator.platform);
|
|
240
|
+
|
|
241
|
+
function isContextMenu(event: PointerEvent): boolean {
|
|
242
|
+
const ctrl = onMac() ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
|
|
243
|
+
return event.button === 2 || (ctrl && event.button === 0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const OUTSIDE_EVENT = "interactoutside";
|
|
247
|
+
|
|
248
|
+
export function interactOutside<T extends PointerEvent | FocusEvent>(
|
|
249
|
+
original: T,
|
|
250
|
+
handle: (event: CustomEvent<OutsideDetail<T>>) => void,
|
|
251
|
+
): CustomEvent<OutsideDetail<T>> {
|
|
252
|
+
const event = new CustomEvent<OutsideDetail<T>>(OUTSIDE_EVENT, {
|
|
253
|
+
cancelable: true,
|
|
254
|
+
detail: {
|
|
255
|
+
originalEvent: original,
|
|
256
|
+
isContextMenu: original.type === "pointerdown" && isContextMenu(original as PointerEvent),
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
const target = original.target;
|
|
260
|
+
// Dispatched on the pressed node so handlers read its target, as Kobalte's did.
|
|
261
|
+
if (!target) handle(event);
|
|
262
|
+
else {
|
|
263
|
+
target.addEventListener(OUTSIDE_EVENT, () => handle(event), { once: true });
|
|
264
|
+
target.dispatchEvent(event);
|
|
265
|
+
}
|
|
266
|
+
return event;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function inside(container: Element, node: Element | undefined): boolean {
|
|
270
|
+
for (
|
|
271
|
+
let n: Node | null | undefined = node;
|
|
272
|
+
n;
|
|
273
|
+
n = n instanceof ShadowRoot ? n.host : n.parentNode
|
|
274
|
+
)
|
|
275
|
+
if (n === container) return true;
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Skipped content stops ticking: an exit the timeout ended early would freeze mid-way, not at rest.
|
|
280
|
+
function finishMotion(root: Element): void {
|
|
281
|
+
for (const animation of root.getAnimations?.({ subtree: true }) ?? []) {
|
|
282
|
+
if (animation.playState !== "running") continue;
|
|
283
|
+
if (animation.effect?.getComputedTiming().iterations === Infinity) continue;
|
|
284
|
+
animation.finish();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function ModalFrame(props: ModalFrameProps): JSX.Element {
|
|
289
|
+
const ctx = useDialogContext();
|
|
290
|
+
const [local, rest] = splitProps(props, [
|
|
291
|
+
"slot",
|
|
292
|
+
"panelClass",
|
|
293
|
+
"scrimClass",
|
|
294
|
+
"panelStyle",
|
|
295
|
+
"ariaLabel",
|
|
296
|
+
"ref",
|
|
297
|
+
"as",
|
|
298
|
+
"mount",
|
|
299
|
+
"exitMs",
|
|
300
|
+
"onEscapeKeyDown",
|
|
301
|
+
"onPointerDownOutside",
|
|
302
|
+
"onInteractOutside",
|
|
303
|
+
"onOpenAutoFocus",
|
|
304
|
+
"onCloseAutoFocus",
|
|
305
|
+
"children",
|
|
306
|
+
"id",
|
|
307
|
+
]);
|
|
308
|
+
const fallbackId = createUniqueId();
|
|
309
|
+
const id = (): string => local.id ?? fallbackId;
|
|
310
|
+
effect(id, ctx.registerContent);
|
|
311
|
+
|
|
312
|
+
const presence = createPresence({
|
|
313
|
+
present: ctx.isOpen,
|
|
314
|
+
element: ctx.panel,
|
|
315
|
+
get exitMs() {
|
|
316
|
+
return local.exitMs;
|
|
317
|
+
},
|
|
318
|
+
keep: ctx.keep,
|
|
319
|
+
});
|
|
320
|
+
ctx.bindDormant(presence.dormant);
|
|
321
|
+
onCleanup(() => ctx.bindDormant(() => false));
|
|
322
|
+
const expanded = () => presence.phase() === "opening" || presence.phase() === "open";
|
|
323
|
+
|
|
324
|
+
const handle = registerLayer({
|
|
325
|
+
element: ctx.panel,
|
|
326
|
+
open: ctx.isOpen,
|
|
327
|
+
kind: "modal",
|
|
328
|
+
escape: () => true,
|
|
329
|
+
dismiss: () => ctx.close(),
|
|
330
|
+
trigger: ctx.triggerRef,
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
let closedByOutside = false;
|
|
334
|
+
createDismiss({
|
|
335
|
+
layer: handle,
|
|
336
|
+
escapeFrom: "document",
|
|
337
|
+
onDismiss: (reason, original) => {
|
|
338
|
+
if (reason === "escape") {
|
|
339
|
+
if (vetoed(local.onEscapeKeyDown, original as KeyboardEvent)) return;
|
|
340
|
+
} else {
|
|
341
|
+
const event = interactOutside(original as PointerEvent, (e) => {
|
|
342
|
+
local.onPointerDownOutside?.(e);
|
|
343
|
+
if (ctx.modal() && e.detail.isContextMenu) e.preventDefault();
|
|
344
|
+
local.onInteractOutside?.(e);
|
|
345
|
+
});
|
|
346
|
+
if (event.defaultPrevented) return;
|
|
347
|
+
closedByOutside = true;
|
|
348
|
+
}
|
|
349
|
+
ctx.close();
|
|
350
|
+
// A controlled `open` refused the close.
|
|
351
|
+
if (untrack(ctx.isOpen)) closedByOutside = false;
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
createHideOutside({ layer: handle, active: () => ctx.isOpen() && ctx.modal() });
|
|
356
|
+
|
|
357
|
+
const [trapping, setTrapping] = createSignal(false);
|
|
358
|
+
const scope = createFocusScope({
|
|
359
|
+
container: ctx.panel,
|
|
360
|
+
active: trapping,
|
|
361
|
+
trapped: () => true,
|
|
362
|
+
initialFocus: (container) => {
|
|
363
|
+
if (!vetoed(local.onOpenAutoFocus, new Event("openautofocus", { cancelable: true })))
|
|
364
|
+
return null;
|
|
365
|
+
const active = activeOf(container);
|
|
366
|
+
return active instanceof HTMLElement && container.contains(active) ? active : container;
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
effect(
|
|
371
|
+
() => ctx.isOpen() && ctx.panel() !== undefined,
|
|
372
|
+
(open) => {
|
|
373
|
+
if (open) {
|
|
374
|
+
closedByOutside = false;
|
|
375
|
+
setTrapping(true);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const panel = ctx.panel();
|
|
379
|
+
if (panel) {
|
|
380
|
+
// Newest first: a list opened from inside goes before the one it came from.
|
|
381
|
+
for (const layer of [...layerStack.layers()].reverse()) {
|
|
382
|
+
if (inside(panel, layer.trigger()) || inside(panel, layer.element())) layer.dismiss?.();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (!trapping()) return;
|
|
386
|
+
scope.untrap();
|
|
387
|
+
const kept =
|
|
388
|
+
vetoed(local.onCloseAutoFocus, new Event("closeautofocus", { cancelable: true })) ||
|
|
389
|
+
(closedByOutside && !ctx.modal());
|
|
390
|
+
const trigger = ctx.triggerRef();
|
|
391
|
+
const toTrigger = !kept && trigger?.isConnected === true;
|
|
392
|
+
if (kept || toTrigger) scope.skipRestore();
|
|
393
|
+
setTrapping(false);
|
|
394
|
+
if (toTrigger) queueMicrotask(() => focusWithoutTracking(trigger));
|
|
395
|
+
},
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
return (
|
|
399
|
+
<Show when={presence.mounted()}>
|
|
400
|
+
{(_) => {
|
|
401
|
+
onCleanup(() => ctx.setPanel(undefined));
|
|
402
|
+
return (
|
|
403
|
+
<Portal
|
|
404
|
+
mount={local.mount}
|
|
405
|
+
ref={(container: HTMLDivElement) => {
|
|
406
|
+
container.className = LAYER_ROOT;
|
|
407
|
+
createRenderEffect(() => {
|
|
408
|
+
const dormant = presence.dormant();
|
|
409
|
+
if (dormant) finishMotion(container);
|
|
410
|
+
container.toggleAttribute("data-dormant", dormant);
|
|
411
|
+
});
|
|
412
|
+
}}
|
|
413
|
+
>
|
|
414
|
+
<div
|
|
415
|
+
data-slot={`${local.slot}-overlay`}
|
|
416
|
+
class={local.scrimClass}
|
|
417
|
+
data-expanded={expanded() ? "" : undefined}
|
|
418
|
+
data-closed={expanded() ? undefined : ""}
|
|
419
|
+
on:pointerdown={(event) => {
|
|
420
|
+
// Focus stays in the panel when the scrim is pressed.
|
|
421
|
+
if (event.target === event.currentTarget) event.preventDefault();
|
|
422
|
+
}}
|
|
423
|
+
/>
|
|
424
|
+
<Polymorphic
|
|
425
|
+
defaultAs="div"
|
|
426
|
+
as={local.as}
|
|
427
|
+
ref={(el: HTMLElement) => {
|
|
428
|
+
ctx.setPanel(el);
|
|
429
|
+
local.ref?.(el);
|
|
430
|
+
}}
|
|
431
|
+
id={id()}
|
|
432
|
+
role={presence.dormant() ? undefined : ctx.role}
|
|
433
|
+
aria-modal={ctx.modal() && !presence.dormant() ? "true" : undefined}
|
|
434
|
+
tabIndex={-1}
|
|
435
|
+
aria-labelledby={ctx.titleId()}
|
|
436
|
+
aria-label={ctx.titleId() ? undefined : local.ariaLabel}
|
|
437
|
+
aria-describedby={ctx.descriptionId()}
|
|
438
|
+
data-slot={`${local.slot}-content`}
|
|
439
|
+
data-expanded={expanded() ? "" : undefined}
|
|
440
|
+
data-closed={expanded() ? undefined : ""}
|
|
441
|
+
class={local.panelClass}
|
|
442
|
+
style={local.panelStyle}
|
|
443
|
+
{...rest}
|
|
444
|
+
>
|
|
445
|
+
{local.children}
|
|
446
|
+
</Polymorphic>
|
|
447
|
+
</Portal>
|
|
448
|
+
);
|
|
449
|
+
}}
|
|
450
|
+
</Show>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
@@ -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.js";
|
|
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.js";
|
|
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
|
+
}
|