@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
|
@@ -1,122 +1,297 @@
|
|
|
1
|
-
import { ContextMenu as ContextMenuPrimitive } from "@kobalte/core/context-menu";
|
|
2
|
-
import { usePortalMount } from "./portal-mount.js";
|
|
3
|
-
import { useMenuContext } from "@kobalte/core/menu";
|
|
4
1
|
import {
|
|
5
2
|
type Component,
|
|
6
3
|
type ComponentProps,
|
|
4
|
+
createContext,
|
|
7
5
|
createSignal,
|
|
8
|
-
|
|
6
|
+
createUniqueId,
|
|
7
|
+
type JSX,
|
|
8
|
+
onCleanup,
|
|
9
9
|
splitProps,
|
|
10
|
+
untrack,
|
|
11
|
+
useContext,
|
|
12
|
+
type ValidComponent,
|
|
10
13
|
} from "solid-js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
14
|
+
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
15
|
+
import { callEventHandler, effect, merge } from "../lib/behavior/solid.js";
|
|
16
|
+
import { createHold } from "../lib/hold.js";
|
|
17
|
+
import { MOTION_EXIT_MS, OVERLAY_MOTION } from "../lib/motion-classes.js";
|
|
13
18
|
import { cn } from "../lib/utils.js";
|
|
14
19
|
import {
|
|
15
|
-
|
|
20
|
+
createMenuLevel,
|
|
21
|
+
type DeprecatedMenuRootProps,
|
|
22
|
+
MenuArrow,
|
|
23
|
+
type MenuCheckboxItemProps,
|
|
16
24
|
MenuCheckboxItemPart,
|
|
17
|
-
|
|
25
|
+
MenuContentPart,
|
|
26
|
+
type MenuContentProps,
|
|
27
|
+
MenuGroup,
|
|
28
|
+
MenuItemIndicator,
|
|
29
|
+
type MenuItemProps,
|
|
18
30
|
MenuItemPart,
|
|
31
|
+
type MenuLabelProps,
|
|
19
32
|
MenuLabelPart,
|
|
33
|
+
MenuLevelProvider,
|
|
34
|
+
type MenuPlacement,
|
|
35
|
+
MenuPortal,
|
|
36
|
+
MenuRadioGroup,
|
|
37
|
+
type MenuRadioItemProps,
|
|
20
38
|
MenuRadioItemPart,
|
|
21
39
|
MenuSeparatorPart,
|
|
40
|
+
MenuSub,
|
|
22
41
|
MenuSubContentPart,
|
|
42
|
+
type MenuSubTriggerProps,
|
|
23
43
|
MenuSubTriggerPart,
|
|
44
|
+
MenuTextPart,
|
|
45
|
+
parsePlacement,
|
|
46
|
+
useMenuLevel,
|
|
24
47
|
} from "./menu-parts.js";
|
|
25
48
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
interface ContextMenuRootProps extends DeprecatedMenuRootProps {
|
|
50
|
+
onOpenChange?: (open: boolean) => void;
|
|
51
|
+
placement?: MenuPlacement;
|
|
52
|
+
gutter?: number;
|
|
53
|
+
children?: JSX.Element;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type Point = { x: number; y: number };
|
|
57
|
+
|
|
58
|
+
const PointContext = createContext<(point: Point) => void>();
|
|
59
|
+
|
|
60
|
+
const usePoint = (): ((point: Point) => void) => {
|
|
61
|
+
const setPoint = useContext(PointContext);
|
|
62
|
+
if (!setPoint) throw new Error("ContextMenuTrigger renders inside a ContextMenu");
|
|
63
|
+
return setPoint;
|
|
30
64
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
props
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
|
|
66
|
+
const ContextMenuRoot: Component<ContextMenuRootProps> = (props) => {
|
|
67
|
+
const [isOpen, setIsOpen] = createSignal(false);
|
|
68
|
+
const setOpen = (next: boolean) => {
|
|
69
|
+
if (next === untrack(isOpen)) return;
|
|
70
|
+
setIsOpen(next);
|
|
71
|
+
props.onOpenChange?.(next);
|
|
72
|
+
};
|
|
73
|
+
const [point, setPoint] = createSignal<Point>({ x: 0, y: 0 });
|
|
74
|
+
const placement = () => parsePlacement(props.placement ?? "right-start");
|
|
75
|
+
const level = createMenuLevel({
|
|
76
|
+
open: isOpen,
|
|
77
|
+
onOpenChange: setOpen,
|
|
78
|
+
anchor: (trigger) => {
|
|
79
|
+
const at = point();
|
|
80
|
+
return {
|
|
81
|
+
getBoundingClientRect: () => ({ left: at.x, top: at.y, width: 0, height: 0 }),
|
|
82
|
+
getRootNode: () => trigger?.getRootNode() ?? document,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
side: () => placement()[0],
|
|
86
|
+
align: () => placement()[1],
|
|
87
|
+
offset: untrack(() => props.gutter ?? 2),
|
|
88
|
+
triggerIsArea: true,
|
|
89
|
+
});
|
|
90
|
+
return (
|
|
91
|
+
<PointContext.Provider value={setPoint}>
|
|
92
|
+
<MenuLevelProvider value={level}>{props.children}</MenuLevelProvider>
|
|
93
|
+
</PointContext.Provider>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
type TriggerOwnProps = {
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
id?: string;
|
|
100
|
+
ref?: unknown;
|
|
101
|
+
style?: JSX.CSSProperties | string;
|
|
102
|
+
onContextMenu?: JSX.EventHandlerUnion<HTMLElement, MouseEvent>;
|
|
103
|
+
onPointerDown?: JSX.EventHandlerUnion<HTMLElement, PointerEvent>;
|
|
104
|
+
onPointerMove?: JSX.EventHandlerUnion<HTMLElement, PointerEvent>;
|
|
105
|
+
onPointerUp?: JSX.EventHandlerUnion<HTMLElement, PointerEvent>;
|
|
106
|
+
onPointerCancel?: JSX.EventHandlerUnion<HTMLElement, PointerEvent>;
|
|
43
107
|
};
|
|
44
108
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
109
|
+
type ContextMenuTriggerProps<T extends ValidComponent = "div"> = TriggerOwnProps & {
|
|
110
|
+
as?: T;
|
|
111
|
+
} & Omit<ComponentProps<T>, "as" | keyof TriggerOwnProps>;
|
|
48
112
|
|
|
49
|
-
|
|
50
|
-
props,
|
|
51
|
-
) => <MenuSubContentPart slotName="context-menu-sub-content" {...props} />;
|
|
113
|
+
type Bound<E extends Event> = E & { currentTarget: HTMLElement; target: Element };
|
|
52
114
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
115
|
+
const NO_CALLOUT = "-webkit-touch-callout: none";
|
|
116
|
+
|
|
117
|
+
function ContextMenuTrigger<T extends ValidComponent = "div">(
|
|
118
|
+
props: ContextMenuTriggerProps<T>,
|
|
119
|
+
): JSX.Element {
|
|
120
|
+
const level = useMenuLevel();
|
|
121
|
+
const menu = level.menu;
|
|
122
|
+
const setPoint = usePoint();
|
|
123
|
+
const [local, rest] = splitProps(props as ContextMenuTriggerProps<ValidComponent>, [
|
|
124
|
+
"as",
|
|
125
|
+
"id",
|
|
59
126
|
"ref",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
127
|
+
"disabled",
|
|
128
|
+
"style",
|
|
129
|
+
"onContextMenu",
|
|
130
|
+
"onPointerDown",
|
|
131
|
+
"onPointerMove",
|
|
132
|
+
"onPointerUp",
|
|
133
|
+
"onPointerCancel",
|
|
62
134
|
]);
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
135
|
+
const fallback = createUniqueId();
|
|
136
|
+
const id = (): string => local.id ?? fallback;
|
|
137
|
+
effect(id, (value) => {
|
|
138
|
+
level.setTriggerId(value);
|
|
139
|
+
return () => level.setTriggerId(undefined);
|
|
140
|
+
});
|
|
141
|
+
const disabled = () => local.disabled ?? false;
|
|
142
|
+
const openAt = (point: Point) => {
|
|
143
|
+
setPoint(point);
|
|
144
|
+
menu.show("content");
|
|
145
|
+
};
|
|
146
|
+
let pressedAt: Point = { x: 0, y: 0 };
|
|
147
|
+
const hold = createHold({ onHold: () => openAt(pressedAt) });
|
|
148
|
+
onCleanup(hold.cancel);
|
|
149
|
+
const [el, setEl] = createSignal<HTMLElement>();
|
|
150
|
+
|
|
151
|
+
// Bound on the element, since Solid's delegated handlers never reach inside a closed shadow root.
|
|
152
|
+
effect(el, (node) => {
|
|
153
|
+
if (!node) return;
|
|
154
|
+
const onMenu = (event: MouseEvent) => {
|
|
155
|
+
callEventHandler(event as Bound<MouseEvent>, local.onContextMenu);
|
|
156
|
+
// A fired hold already opened the menu and spent this press.
|
|
157
|
+
if (disabled() || event.defaultPrevented) return;
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
openAt({ x: event.clientX, y: event.clientY });
|
|
161
|
+
};
|
|
162
|
+
const onDown = (event: PointerEvent) => {
|
|
163
|
+
callEventHandler(event as Bound<PointerEvent>, local.onPointerDown);
|
|
164
|
+
if (disabled() || event.pointerType === "mouse") return;
|
|
165
|
+
pressedAt = { x: event.clientX, y: event.clientY };
|
|
166
|
+
hold.down(event);
|
|
167
|
+
};
|
|
168
|
+
const onMove = (event: PointerEvent) => {
|
|
169
|
+
callEventHandler(event as Bound<PointerEvent>, local.onPointerMove);
|
|
170
|
+
hold.move(event);
|
|
171
|
+
};
|
|
172
|
+
const onUp = (event: PointerEvent) => {
|
|
173
|
+
callEventHandler(event as Bound<PointerEvent>, local.onPointerUp);
|
|
174
|
+
hold.up();
|
|
175
|
+
};
|
|
176
|
+
const onCancel = (event: PointerEvent) => {
|
|
177
|
+
callEventHandler(event as Bound<PointerEvent>, local.onPointerCancel);
|
|
178
|
+
hold.cancel();
|
|
179
|
+
};
|
|
180
|
+
node.addEventListener("contextmenu", onMenu);
|
|
181
|
+
node.addEventListener("pointerdown", onDown);
|
|
182
|
+
node.addEventListener("pointermove", onMove);
|
|
183
|
+
node.addEventListener("pointerup", onUp);
|
|
184
|
+
node.addEventListener("pointercancel", onCancel);
|
|
185
|
+
return () => {
|
|
186
|
+
node.removeEventListener("contextmenu", onMenu);
|
|
187
|
+
node.removeEventListener("pointerdown", onDown);
|
|
188
|
+
node.removeEventListener("pointermove", onMove);
|
|
189
|
+
node.removeEventListener("pointerup", onUp);
|
|
190
|
+
node.removeEventListener("pointercancel", onCancel);
|
|
191
|
+
if (untrack(menu.trigger) === node) menu.setTrigger(undefined);
|
|
192
|
+
};
|
|
71
193
|
});
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<Polymorphic
|
|
197
|
+
{...merge({ "data-slot": "context-menu-trigger" }, rest, {
|
|
198
|
+
as: local.as,
|
|
199
|
+
defaultAs: "div" as ValidComponent,
|
|
200
|
+
get id() {
|
|
201
|
+
return id();
|
|
202
|
+
},
|
|
203
|
+
ref: (node: HTMLElement) => {
|
|
204
|
+
setEl(node);
|
|
205
|
+
menu.setTrigger(node);
|
|
206
|
+
if (typeof local.ref === "function") local.ref(node);
|
|
207
|
+
},
|
|
208
|
+
get style() {
|
|
209
|
+
const own = local.style;
|
|
210
|
+
return typeof own === "string"
|
|
211
|
+
? `${NO_CALLOUT}; ${own}`
|
|
212
|
+
: { "-webkit-touch-callout": "none", ...own };
|
|
213
|
+
},
|
|
214
|
+
get "data-disabled"() {
|
|
215
|
+
return disabled() ? "" : undefined;
|
|
216
|
+
},
|
|
217
|
+
get "data-expanded"() {
|
|
218
|
+
return menu.open() ? "" : undefined;
|
|
219
|
+
},
|
|
220
|
+
get "data-closed"() {
|
|
221
|
+
return menu.open() ? undefined : "";
|
|
222
|
+
},
|
|
223
|
+
})}
|
|
224
|
+
/>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// The panel opens at the pointer with its start corner there, so it unfolds from that corner.
|
|
229
|
+
const ORIGIN_AT_POINTER =
|
|
230
|
+
"data-[side=right]:origin-top-left data-[side=left]:origin-top-right data-[side=bottom]:origin-top-left data-[side=top]:origin-bottom-left";
|
|
231
|
+
|
|
232
|
+
const ContextMenuContent: Component<MenuContentProps> = (props) => {
|
|
233
|
+
const [local, rest] = splitProps(props, ["class"]);
|
|
72
234
|
return (
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
onCloseAutoFocus={layer.onCloseAutoFocus}
|
|
81
|
-
data-slot="context-menu-content"
|
|
82
|
-
class={cn(
|
|
83
|
-
MENU_CONTENT_CLASS,
|
|
84
|
-
OVERLAY_MOTION,
|
|
85
|
-
"overflow-x-hidden overflow-y-auto",
|
|
86
|
-
local.class,
|
|
87
|
-
)}
|
|
88
|
-
{...rest}
|
|
89
|
-
>
|
|
90
|
-
<MenuContentIndicator>{local.children}</MenuContentIndicator>
|
|
91
|
-
</ContextMenuPrimitive.Content>
|
|
92
|
-
</ContextMenuPrimitive.Portal>
|
|
235
|
+
<MenuContentPart
|
|
236
|
+
slotName="context-menu-content"
|
|
237
|
+
motionClass={cn(OVERLAY_MOTION, ORIGIN_AT_POINTER, "overflow-x-hidden overflow-y-auto")}
|
|
238
|
+
exitMs={MOTION_EXIT_MS.overlay}
|
|
239
|
+
class={local.class}
|
|
240
|
+
{...rest}
|
|
241
|
+
/>
|
|
93
242
|
);
|
|
94
243
|
};
|
|
95
244
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
245
|
+
function ContextMenuItem<T extends ValidComponent = "div">(props: MenuItemProps<T>): JSX.Element {
|
|
246
|
+
return (
|
|
247
|
+
<MenuItemPart slotName="context-menu-item" {...(props as MenuItemProps<ValidComponent>)} />
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function ContextMenuSubTrigger<T extends ValidComponent = "div">(
|
|
252
|
+
props: MenuSubTriggerProps<T>,
|
|
253
|
+
): JSX.Element {
|
|
254
|
+
return (
|
|
255
|
+
<MenuSubTriggerPart
|
|
256
|
+
slotName="context-menu-sub-trigger"
|
|
257
|
+
{...(props as MenuSubTriggerProps<ValidComponent>)}
|
|
258
|
+
/>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const ContextMenuSubContent: Component<MenuContentProps> = (props) => (
|
|
263
|
+
<MenuSubContentPart slotName="context-menu-sub-content" {...props} />
|
|
264
|
+
);
|
|
104
265
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
266
|
+
function ContextMenuCheckboxItem<T extends ValidComponent = "div">(
|
|
267
|
+
props: MenuCheckboxItemProps<T>,
|
|
268
|
+
): JSX.Element {
|
|
269
|
+
return (
|
|
270
|
+
<MenuCheckboxItemPart
|
|
271
|
+
slotName="context-menu-checkbox-item"
|
|
272
|
+
{...(props as MenuCheckboxItemProps<ValidComponent>)}
|
|
273
|
+
/>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
108
276
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
277
|
+
function ContextMenuRadioItem<T extends ValidComponent = "div">(
|
|
278
|
+
props: MenuRadioItemProps<T>,
|
|
279
|
+
): JSX.Element {
|
|
280
|
+
return (
|
|
281
|
+
<MenuRadioItemPart
|
|
282
|
+
slotName="context-menu-radio-item"
|
|
283
|
+
{...(props as MenuRadioItemProps<ValidComponent>)}
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
112
287
|
|
|
113
|
-
const ContextMenuLabel: Component<
|
|
114
|
-
|
|
115
|
-
|
|
288
|
+
const ContextMenuLabel: Component<MenuLabelProps> = (props) => (
|
|
289
|
+
<MenuLabelPart slotName="context-menu-label" {...props} />
|
|
290
|
+
);
|
|
116
291
|
|
|
117
|
-
const ContextMenuSeparator: Component<ComponentProps<
|
|
118
|
-
props
|
|
119
|
-
)
|
|
292
|
+
const ContextMenuSeparator: Component<ComponentProps<"hr">> = (props) => (
|
|
293
|
+
<MenuSeparatorPart slotName="context-menu-separator" {...props} />
|
|
294
|
+
);
|
|
120
295
|
|
|
121
296
|
const ContextMenuShortcut: Component<ComponentProps<"span">> = (props) => {
|
|
122
297
|
const [local, rest] = splitProps(props, ["class"]);
|
|
@@ -129,6 +304,32 @@ const ContextMenuShortcut: Component<ComponentProps<"span">> = (props) => {
|
|
|
129
304
|
);
|
|
130
305
|
};
|
|
131
306
|
|
|
307
|
+
const ContextMenuGroup = MenuGroup;
|
|
308
|
+
const ContextMenuSub = MenuSub;
|
|
309
|
+
const ContextMenuRadioGroup = MenuRadioGroup;
|
|
310
|
+
|
|
311
|
+
const ContextMenu = Object.assign(ContextMenuRoot, {
|
|
312
|
+
Root: ContextMenuRoot,
|
|
313
|
+
Trigger: ContextMenuTrigger,
|
|
314
|
+
Portal: MenuPortal,
|
|
315
|
+
Content: ContextMenuContent,
|
|
316
|
+
Arrow: MenuArrow,
|
|
317
|
+
Item: ContextMenuItem,
|
|
318
|
+
CheckboxItem: ContextMenuCheckboxItem,
|
|
319
|
+
RadioGroup: ContextMenuRadioGroup,
|
|
320
|
+
RadioItem: ContextMenuRadioItem,
|
|
321
|
+
Group: ContextMenuGroup,
|
|
322
|
+
GroupLabel: ContextMenuLabel,
|
|
323
|
+
Separator: ContextMenuSeparator,
|
|
324
|
+
Sub: ContextMenuSub,
|
|
325
|
+
SubTrigger: ContextMenuSubTrigger,
|
|
326
|
+
SubContent: ContextMenuSubContent,
|
|
327
|
+
ItemIndicator: MenuItemIndicator,
|
|
328
|
+
Icon: MenuTextPart,
|
|
329
|
+
ItemLabel: MenuTextPart,
|
|
330
|
+
ItemDescription: MenuTextPart,
|
|
331
|
+
});
|
|
332
|
+
|
|
132
333
|
export {
|
|
133
334
|
ContextMenu,
|
|
134
335
|
ContextMenuCheckboxItem,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useDialogContext } from "@kobalte/core/dialog";
|
|
1
|
+
import { ButtonRoot, type ButtonRootProps } from "../lib/behavior/button-root.js";
|
|
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,19 +17,114 @@ import {
|
|
|
17
17
|
useContext,
|
|
18
18
|
type ValidComponent,
|
|
19
19
|
} from "solid-js";
|
|
20
|
-
import {
|
|
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 {
|
|
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 {
|
|
45
|
+
import { usePortalMount } from "./portal-mount.js";
|
|
27
46
|
import { SectionIcon } from "./section-card.js";
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 Ignored; removed in 2.0.0. */
|
|
57
|
+
id?: string;
|
|
58
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
59
|
+
forceMount?: boolean;
|
|
60
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
61
|
+
preventScroll?: boolean;
|
|
62
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
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 Ignored; removed in 2.0.0. */
|
|
94
|
+
onFocusOutside?: (event: FocusOutsideEvent) => void;
|
|
95
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
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
|
+
}
|
|
33
128
|
|
|
34
129
|
export type ModalSize = "sm" | "md" | "lg" | "xl" | "full";
|
|
35
130
|
|
|
@@ -62,13 +157,13 @@ export const MODAL_ANCHOR: Record<ModalSize, string> = {
|
|
|
62
157
|
/* The panel: it clips, it never scrolls, and it carries no padding. Every inset
|
|
63
158
|
* belongs to Header, Body or Footer, so the Body scrollbar rides inside the
|
|
64
159
|
* panel edge instead of under the header. */
|
|
65
|
-
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}`;
|
|
66
161
|
|
|
67
162
|
/* A panel anchored on the element that opened it: placed and sized inline (lib/anchor-placement),
|
|
68
163
|
* so it drops the centring, and it unrolls out of that element instead of rising in. */
|
|
69
|
-
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}`;
|
|
70
165
|
|
|
71
|
-
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}`;
|
|
72
167
|
|
|
73
168
|
const MODAL_HEADER =
|
|
74
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";
|
|
@@ -81,9 +176,8 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
|
|
|
81
176
|
|
|
82
177
|
/* The only scroll container.
|
|
83
178
|
* - The inset is the full one and a Header or Footer sibling shortens it, keyed
|
|
84
|
-
* on data-slot rather than on position:
|
|
85
|
-
*
|
|
86
|
-
* 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.
|
|
87
181
|
* - `pan-y pinch-zoom` leaves the single-finger vertical gesture to the sheet's
|
|
88
182
|
* drag arbitration without taking two-finger zoom away.
|
|
89
183
|
* - The reserved scrollbar lives inside the right inset, so the content column
|
|
@@ -155,8 +249,9 @@ export function createModalParts(slot: string): ModalParts {
|
|
|
155
249
|
if (el) el.style.setProperty("--scrollbar-gutter", `${el.offsetWidth - el.clientWidth}px`);
|
|
156
250
|
});
|
|
157
251
|
return (
|
|
158
|
-
<
|
|
159
|
-
|
|
252
|
+
<Polymorphic
|
|
253
|
+
defaultAs="div"
|
|
254
|
+
as={local.as}
|
|
160
255
|
ref={(node: HTMLElement) => {
|
|
161
256
|
el = node;
|
|
162
257
|
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
@@ -226,34 +321,23 @@ export function createModalHead<P extends ModalHeadProps = ModalHeadProps>(
|
|
|
226
321
|
};
|
|
227
322
|
}
|
|
228
323
|
|
|
229
|
-
|
|
230
|
-
* `[handler, data]` form that calls `handler(data, event)`. A wrapper that
|
|
231
|
-
* only checks for a function silently drops the bound one. */
|
|
232
|
-
export function callEventHandler<T, E extends Event>(
|
|
233
|
-
event: E & { currentTarget: T; target: Element },
|
|
234
|
-
handler: JSX.EventHandlerUnion<T, E> | undefined,
|
|
235
|
-
): void {
|
|
236
|
-
if (!handler) return;
|
|
237
|
-
if (typeof handler === "function") handler(event);
|
|
238
|
-
else handler[0](handler[1], event);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export type ModalDismissProps = ComponentProps<typeof KobalteButton> & {
|
|
324
|
+
export type ModalDismissProps = ButtonRootProps<ValidComponent> & {
|
|
242
325
|
/** Presses do nothing, the dialog stays open and focus stays put; see Button. */
|
|
243
326
|
busy?: boolean;
|
|
244
327
|
};
|
|
245
328
|
|
|
246
|
-
/*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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> {
|
|
252
336
|
return (props) => {
|
|
253
337
|
const [local, rest] = splitProps(props, ["onClick", "busy"]);
|
|
254
|
-
const context =
|
|
338
|
+
const context = useCloser();
|
|
255
339
|
return (
|
|
256
|
-
<
|
|
340
|
+
<ButtonRoot
|
|
257
341
|
data-slot={slot}
|
|
258
342
|
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
259
343
|
callEventHandler(event, local.onClick);
|
|
@@ -266,11 +350,16 @@ export function createModalDismiss(slot: string): ParentComponent<ModalDismissPr
|
|
|
266
350
|
};
|
|
267
351
|
}
|
|
268
352
|
|
|
269
|
-
/** Renderless
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
+
});
|
|
274
363
|
return null;
|
|
275
364
|
};
|
|
276
365
|
|
|
@@ -285,9 +374,9 @@ export interface ModalLabels {
|
|
|
285
374
|
|
|
286
375
|
const ModalLabelsContext = createContext<ModalLabels>();
|
|
287
376
|
|
|
288
|
-
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
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. */
|
|
291
380
|
export function createModalLabels(): ModalLabels {
|
|
292
381
|
const titleId = createUniqueId();
|
|
293
382
|
const descriptionId = createUniqueId();
|