@glasshome/ui 1.42.0 → 1.44.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 +8 -5
- package/dist/index.js +2 -2
- package/dist/lib/anchor-placement.d.ts +4 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +16 -3
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +6 -4
- package/dist/lib/behavior/focus-scope.d.ts +9 -1
- package/dist/lib/behavior/hide-outside.d.ts +1 -1
- package/dist/lib/behavior/layer-stack.d.ts +3 -2
- package/dist/lib/behavior/menu.d.ts +62 -0
- package/dist/lib/behavior/modal-root.d.ts +2 -0
- package/dist/lib/behavior/range.d.ts +44 -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 +2 -1
- package/dist/lib/overlay-classes.d.ts +1 -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 -45
- 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/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.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/data-table.d.ts +4 -2
- package/dist/solid/dialog-parts.d.ts +8 -8
- 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 +1 -1
- package/dist/solid/index.js +7752 -13493
- 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 +1 -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 +1 -1
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +22 -22
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CxAii-e9.js → utils-BbIeGt7o.js} +376 -314
- package/package.json +3 -6
- package/src/lib/anchor-placement.ts +10 -3
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +41 -9
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +56 -28
- package/src/lib/behavior/dismiss.ts +61 -21
- package/src/lib/behavior/focus-scope.ts +75 -9
- package/src/lib/behavior/hide-outside.ts +2 -2
- package/src/lib/behavior/layer-stack.ts +33 -8
- package/src/lib/behavior/menu.ts +462 -0
- package/src/lib/behavior/modal-root.tsx +24 -18
- package/src/lib/behavior/polymorphic.tsx +1 -1
- package/src/lib/behavior/presence.ts +1 -1
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/clipboard.ts +2 -3
- 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 +8 -9
- package/src/lib/overlay-classes.ts +1 -3
- 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 -118
- 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/area-picker.tsx +4 -4
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/bottom-sheet/arbitration.ts +4 -11
- package/src/solid/bottom-sheet/bottom-sheet.tsx +4 -5
- package/src/solid/bottom-sheet/drag-controller.ts +7 -20
- package/src/solid/button.tsx +12 -6
- 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 +285 -94
- package/src/solid/data-table.tsx +48 -22
- package/src/solid/dialog-parts.tsx +39 -17
- package/src/solid/dock.tsx +44 -43
- package/src/solid/dropdown-menu.tsx +252 -115
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +3 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +5 -6
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +287 -25
- package/src/solid/icon-picker.tsx +1 -2
- package/src/solid/image-picker.tsx +2 -2
- package/src/solid/index.ts +1 -3
- package/src/solid/input-group.tsx +2 -2
- package/src/solid/item.tsx +1 -1
- package/src/solid/menu-parts.tsx +610 -155
- package/src/solid/option-card.tsx +7 -13
- package/src/solid/picker-row.tsx +5 -1
- package/src/solid/popover.tsx +423 -80
- 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 +1 -1
- 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 +939 -95
- package/src/solid/selection.tsx +165 -74
- package/src/solid/sheet.tsx +1 -1
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +4 -16
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/tabs.tsx +12 -6
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +34 -101
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +24 -24
- package/src/styles/globals.css +61 -50
- package/src/styles/theme.css +12 -6
- package/src/tokens/material.ts +11 -2
|
@@ -1,132 +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 {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
ReportCovered,
|
|
16
|
-
shadowLayer,
|
|
17
|
-
} from "../lib/shadow-layer.js";
|
|
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";
|
|
18
18
|
import { cn } from "../lib/utils.js";
|
|
19
19
|
import {
|
|
20
|
-
|
|
20
|
+
createMenuLevel,
|
|
21
|
+
type DeprecatedMenuRootProps,
|
|
22
|
+
MenuArrow,
|
|
23
|
+
type MenuCheckboxItemProps,
|
|
21
24
|
MenuCheckboxItemPart,
|
|
22
|
-
|
|
25
|
+
MenuContentPart,
|
|
26
|
+
type MenuContentProps,
|
|
27
|
+
MenuGroup,
|
|
28
|
+
MenuItemIndicator,
|
|
29
|
+
type MenuItemProps,
|
|
23
30
|
MenuItemPart,
|
|
31
|
+
type MenuLabelProps,
|
|
24
32
|
MenuLabelPart,
|
|
33
|
+
MenuLevelProvider,
|
|
34
|
+
type MenuPlacement,
|
|
35
|
+
MenuPortal,
|
|
36
|
+
MenuRadioGroup,
|
|
37
|
+
type MenuRadioItemProps,
|
|
25
38
|
MenuRadioItemPart,
|
|
26
39
|
MenuSeparatorPart,
|
|
40
|
+
MenuSub,
|
|
27
41
|
MenuSubContentPart,
|
|
42
|
+
type MenuSubTriggerProps,
|
|
28
43
|
MenuSubTriggerPart,
|
|
44
|
+
MenuTextPart,
|
|
45
|
+
parsePlacement,
|
|
46
|
+
useMenuLevel,
|
|
29
47
|
} from "./menu-parts.js";
|
|
30
48
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
64
|
+
};
|
|
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
|
+
});
|
|
35
90
|
return (
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
</
|
|
91
|
+
<PointContext.Provider value={setPoint}>
|
|
92
|
+
<MenuLevelProvider value={level}>{props.children}</MenuLevelProvider>
|
|
93
|
+
</PointContext.Provider>
|
|
39
94
|
);
|
|
40
95
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return <ContextMenuPrimitive.Trigger data-slot="context-menu-trigger" {...props} />;
|
|
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>;
|
|
53
107
|
};
|
|
54
108
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
109
|
+
type ContextMenuTriggerProps<T extends ValidComponent = "div"> = TriggerOwnProps & {
|
|
110
|
+
as?: T;
|
|
111
|
+
} & Omit<ComponentProps<T>, "as" | keyof TriggerOwnProps>;
|
|
112
|
+
|
|
113
|
+
type Bound<E extends Event> = E & { currentTarget: HTMLElement; target: Element };
|
|
58
114
|
|
|
59
|
-
const
|
|
60
|
-
props,
|
|
61
|
-
) => <MenuSubContentPart slotName="context-menu-sub-content" {...props} />;
|
|
115
|
+
const NO_CALLOUT = "-webkit-touch-callout: none";
|
|
62
116
|
|
|
63
|
-
|
|
64
|
-
props
|
|
65
|
-
)
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
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",
|
|
69
126
|
"ref",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
127
|
+
"disabled",
|
|
128
|
+
"style",
|
|
129
|
+
"onContextMenu",
|
|
130
|
+
"onPointerDown",
|
|
131
|
+
"onPointerMove",
|
|
132
|
+
"onPointerUp",
|
|
133
|
+
"onPointerCancel",
|
|
72
134
|
]);
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
dismiss: () => menu.close(true),
|
|
79
|
-
tree: true,
|
|
80
|
-
consumer: local,
|
|
135
|
+
const fallback = createUniqueId();
|
|
136
|
+
const id = (): string => local.id ?? fallback;
|
|
137
|
+
effect(id, (value) => {
|
|
138
|
+
level.setTriggerId(value);
|
|
139
|
+
return () => level.setTriggerId(undefined);
|
|
81
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
|
+
};
|
|
193
|
+
});
|
|
194
|
+
|
|
82
195
|
return (
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
local.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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"]);
|
|
234
|
+
return (
|
|
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
|
+
/>
|
|
103
242
|
);
|
|
104
243
|
};
|
|
105
244
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
variant?: "default" | "destructive";
|
|
112
|
-
}
|
|
113
|
-
> = (props) => <MenuItemPart slotName="context-menu-item" {...props} />;
|
|
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
|
+
}
|
|
114
250
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
+
}
|
|
118
261
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
262
|
+
const ContextMenuSubContent: Component<MenuContentProps> = (props) => (
|
|
263
|
+
<MenuSubContentPart slotName="context-menu-sub-content" {...props} />
|
|
264
|
+
);
|
|
122
265
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
}
|
|
276
|
+
|
|
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
|
+
}
|
|
287
|
+
|
|
288
|
+
const ContextMenuLabel: Component<MenuLabelProps> = (props) => (
|
|
289
|
+
<MenuLabelPart slotName="context-menu-label" {...props} />
|
|
290
|
+
);
|
|
126
291
|
|
|
127
|
-
const ContextMenuSeparator: Component<ComponentProps<
|
|
128
|
-
props
|
|
129
|
-
)
|
|
292
|
+
const ContextMenuSeparator: Component<ComponentProps<"hr">> = (props) => (
|
|
293
|
+
<MenuSeparatorPart slotName="context-menu-separator" {...props} />
|
|
294
|
+
);
|
|
130
295
|
|
|
131
296
|
const ContextMenuShortcut: Component<ComponentProps<"span">> = (props) => {
|
|
132
297
|
const [local, rest] = splitProps(props, ["class"]);
|
|
@@ -139,6 +304,32 @@ const ContextMenuShortcut: Component<ComponentProps<"span">> = (props) => {
|
|
|
139
304
|
);
|
|
140
305
|
};
|
|
141
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
|
+
|
|
142
333
|
export {
|
|
143
334
|
ContextMenu,
|
|
144
335
|
ContextMenuCheckboxItem,
|
package/src/solid/data-table.tsx
CHANGED
|
@@ -60,10 +60,13 @@ export function TableFilterSelect(props: {
|
|
|
60
60
|
options: readonly string[];
|
|
61
61
|
value: string;
|
|
62
62
|
onChange: (value: string) => void;
|
|
63
|
-
label: (value: string) =>
|
|
63
|
+
label: (value: string) => JSX.Element;
|
|
64
64
|
ariaLabel: string;
|
|
65
|
+
/** Leading icon, `prefix:name`; defaults to the filter funnel. */
|
|
66
|
+
icon?: string;
|
|
65
67
|
class?: string;
|
|
66
68
|
}) {
|
|
69
|
+
const icon = createMemo(() => props.icon ?? "lucide:funnel");
|
|
67
70
|
return (
|
|
68
71
|
<Select<string>
|
|
69
72
|
options={[...props.options]}
|
|
@@ -76,12 +79,11 @@ export function TableFilterSelect(props: {
|
|
|
76
79
|
)}
|
|
77
80
|
>
|
|
78
81
|
<SelectTrigger
|
|
79
|
-
data-slot="table-filter-select"
|
|
80
82
|
class={cn("h-9 w-auto gap-1.5 text-xs", props.class)}
|
|
81
83
|
aria-label={props.ariaLabel}
|
|
82
84
|
>
|
|
83
85
|
<Icon
|
|
84
|
-
icon=
|
|
86
|
+
icon={icon()}
|
|
85
87
|
width={14}
|
|
86
88
|
height={14}
|
|
87
89
|
class="text-muted-foreground size-3.5 shrink-0"
|
|
@@ -214,6 +216,7 @@ export function TableSortHeader(props: {
|
|
|
214
216
|
align?: "start" | "end";
|
|
215
217
|
class?: string;
|
|
216
218
|
}) {
|
|
219
|
+
const label = createMemo(() => props.label);
|
|
217
220
|
return (
|
|
218
221
|
<Button
|
|
219
222
|
type="button"
|
|
@@ -226,9 +229,9 @@ export function TableSortHeader(props: {
|
|
|
226
229
|
props.align === "end" ? "justify-end" : "justify-start",
|
|
227
230
|
props.class,
|
|
228
231
|
)}
|
|
229
|
-
aria-label={`Sort by ${
|
|
232
|
+
aria-label={`Sort by ${label()}`}
|
|
230
233
|
>
|
|
231
|
-
{
|
|
234
|
+
{label()}
|
|
232
235
|
<Show
|
|
233
236
|
when={props.active}
|
|
234
237
|
fallback={
|
|
@@ -289,7 +292,27 @@ export function TableError(props: { message: JSX.Element; onRetry: () => void })
|
|
|
289
292
|
);
|
|
290
293
|
}
|
|
291
294
|
|
|
292
|
-
|
|
295
|
+
const nearEnd = new Map<Element, () => void>();
|
|
296
|
+
let endWatcher: IntersectionObserver | undefined;
|
|
297
|
+
|
|
298
|
+
// One observer serves every table's end, so a page of tables pays for one.
|
|
299
|
+
function watchNearEnd(target: Element, onNear: () => void): () => void {
|
|
300
|
+
endWatcher ??= new IntersectionObserver(
|
|
301
|
+
(entries) => {
|
|
302
|
+
for (const entry of entries) if (entry.isIntersecting) nearEnd.get(entry.target)?.();
|
|
303
|
+
},
|
|
304
|
+
{ rootMargin: "400px" },
|
|
305
|
+
);
|
|
306
|
+
const watcher = endWatcher;
|
|
307
|
+
nearEnd.set(target, onNear);
|
|
308
|
+
watcher.observe(target);
|
|
309
|
+
return () => {
|
|
310
|
+
nearEnd.delete(target);
|
|
311
|
+
watcher.unobserve(target);
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The end of a long table: once the page scrolls, asks for the next page as it nears the viewport; or on press. */
|
|
293
316
|
export function TableLoadMore(props: {
|
|
294
317
|
hasMore: boolean;
|
|
295
318
|
loading?: boolean;
|
|
@@ -299,26 +322,29 @@ export function TableLoadMore(props: {
|
|
|
299
322
|
}) {
|
|
300
323
|
let sentinel: HTMLDivElement | undefined;
|
|
301
324
|
onMount(() => {
|
|
302
|
-
if (!sentinel || typeof IntersectionObserver === "undefined") return;
|
|
303
325
|
const target = sentinel;
|
|
326
|
+
if (!target || typeof IntersectionObserver === "undefined") return;
|
|
304
327
|
let frame = 0;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
)
|
|
318
|
-
|
|
328
|
+
let unwatch: (() => void) | undefined;
|
|
329
|
+
const onNear = () => {
|
|
330
|
+
if (!props.hasMore || props.loading) return;
|
|
331
|
+
props.onLoadMore();
|
|
332
|
+
// A page too short to push the sentinel out of view never fires again on its own.
|
|
333
|
+
cancelAnimationFrame(frame);
|
|
334
|
+
frame = requestAnimationFrame(() => {
|
|
335
|
+
unwatch?.();
|
|
336
|
+
unwatch = watchNearEnd(target, onNear);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
// A table nobody scrolls never pays for an observer.
|
|
340
|
+
const arm = () => {
|
|
341
|
+
unwatch ??= watchNearEnd(target, onNear);
|
|
342
|
+
};
|
|
343
|
+
window.addEventListener("scroll", arm, { capture: true, passive: true, once: true });
|
|
319
344
|
onCleanup(() => {
|
|
345
|
+
window.removeEventListener("scroll", arm, { capture: true });
|
|
320
346
|
cancelAnimationFrame(frame);
|
|
321
|
-
|
|
347
|
+
unwatch?.();
|
|
322
348
|
});
|
|
323
349
|
});
|
|
324
350
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ButtonRoot, type ButtonRootProps } from "../lib/behavior/button-root.js";
|
|
2
2
|
import {
|
|
3
3
|
type Accessor,
|
|
4
4
|
children,
|
|
@@ -53,13 +53,13 @@ export interface ModalRootSkinProps {
|
|
|
53
53
|
modal?: boolean;
|
|
54
54
|
/** Stays mounted and dormant after it closes, so the next open shows the same nodes instead of building them. */
|
|
55
55
|
keep?: boolean;
|
|
56
|
-
/** @deprecated
|
|
56
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
57
57
|
id?: string;
|
|
58
|
-
/** @deprecated
|
|
58
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
59
59
|
forceMount?: boolean;
|
|
60
|
-
/** @deprecated
|
|
60
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
61
61
|
preventScroll?: boolean;
|
|
62
|
-
/** @deprecated
|
|
62
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
63
63
|
translations?: Record<string, string>;
|
|
64
64
|
children?: JSX.Element;
|
|
65
65
|
}
|
|
@@ -90,9 +90,9 @@ export type ModalContentProps = Omit<ComponentProps<"div">, "style" | "role"> &
|
|
|
90
90
|
onInteractOutside?: (event: InteractOutsideEvent) => void;
|
|
91
91
|
onOpenAutoFocus?: (event: Event) => void;
|
|
92
92
|
onCloseAutoFocus?: (event: Event) => void;
|
|
93
|
-
/** @deprecated
|
|
93
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
94
94
|
onFocusOutside?: (event: FocusOutsideEvent) => void;
|
|
95
|
-
/** @deprecated
|
|
95
|
+
/** @deprecated Ignored; removed in 2.0.0. */
|
|
96
96
|
forceMount?: boolean;
|
|
97
97
|
};
|
|
98
98
|
|
|
@@ -183,10 +183,13 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
|
|
|
183
183
|
* - The reserved scrollbar lives inside the right inset, so the content column
|
|
184
184
|
* ends where the Header's and Footer's do. */
|
|
185
185
|
const MODAL_BODY =
|
|
186
|
-
"gh-scroll
|
|
186
|
+
"gh-scroll relative flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-gutter,var(--scrollbar-w)))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3 in-data-[slot=bottom-sheet-content]:pl-4 in-data-[slot=bottom-sheet-content]:pr-[calc(var(--spacing)*4-var(--scrollbar-gutter,var(--scrollbar-w)))] [[data-slot=bottom-sheet-handle]+&]:pt-1";
|
|
187
|
+
|
|
188
|
+
// Out of flow, so content keeps its gap and its first child; it marks where the scroll starts.
|
|
189
|
+
const MODAL_BODY_TOP = "pointer-events-none absolute inset-x-0 top-0 h-px";
|
|
187
190
|
|
|
188
191
|
const MODAL_FOOTER =
|
|
189
|
-
"
|
|
192
|
+
"flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end in-data-[slot=bottom-sheet-content]:px-4";
|
|
190
193
|
|
|
191
194
|
export const MODAL_TITLE = "font-semibold text-foreground text-lg leading-none tracking-tight";
|
|
192
195
|
export const MODAL_DESCRIPTION = "text-muted-foreground text-sm";
|
|
@@ -238,16 +241,33 @@ export function createModalParts(slot: string): ModalParts {
|
|
|
238
241
|
);
|
|
239
242
|
};
|
|
240
243
|
|
|
241
|
-
/* data-sheet-scroll is the bottom sheet's drag arbitration marker: a Body
|
|
242
|
-
* inside a sheet must yield the gesture to its own scroll, whichever family
|
|
243
|
-
* rendered it. */
|
|
244
244
|
const Body: Component<ModalBodyProps> = (props) => {
|
|
245
|
-
const [local, rest] = splitProps(props, ["class", "as", "ref"]);
|
|
245
|
+
const [local, rest] = splitProps(props, ["class", "as", "ref", "children"]);
|
|
246
246
|
let el: HTMLElement | undefined;
|
|
247
|
+
let top: HTMLSpanElement | undefined;
|
|
247
248
|
// Overlay scrollbars reserve no gutter, so the right inset subtracts what the platform actually reserved.
|
|
248
249
|
onMount(() => {
|
|
249
250
|
if (el) el.style.setProperty("--scrollbar-gutter", `${el.offsetWidth - el.clientWidth}px`);
|
|
250
251
|
});
|
|
252
|
+
// data-scrolled comes from an observer, since a sealed widget cannot read scrollTop; made on the first scroll, as an observer costs a call to the page.
|
|
253
|
+
let observer: IntersectionObserver | undefined;
|
|
254
|
+
const watchTop = () => {
|
|
255
|
+
const box = el;
|
|
256
|
+
if (!box || !top || observer) return;
|
|
257
|
+
observer = new IntersectionObserver(
|
|
258
|
+
(entries) => {
|
|
259
|
+
const entry = entries[entries.length - 1];
|
|
260
|
+
if (entry) box.toggleAttribute("data-scrolled", entry.intersectionRatio < 0.99);
|
|
261
|
+
},
|
|
262
|
+
{ root: box, threshold: [0.99] },
|
|
263
|
+
);
|
|
264
|
+
observer.observe(top);
|
|
265
|
+
};
|
|
266
|
+
onMount(() => el?.addEventListener("scroll", watchTop, { once: true, passive: true }));
|
|
267
|
+
onCleanup(() => {
|
|
268
|
+
el?.removeEventListener("scroll", watchTop);
|
|
269
|
+
observer?.disconnect();
|
|
270
|
+
});
|
|
251
271
|
return (
|
|
252
272
|
<Polymorphic
|
|
253
273
|
defaultAs="div"
|
|
@@ -257,10 +277,12 @@ export function createModalParts(slot: string): ModalParts {
|
|
|
257
277
|
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
258
278
|
}}
|
|
259
279
|
data-slot={`${slot}-body`}
|
|
260
|
-
data-sheet-scroll=""
|
|
261
280
|
class={cn(MODAL_BODY, local.class)}
|
|
262
281
|
{...rest}
|
|
263
|
-
|
|
282
|
+
>
|
|
283
|
+
<span ref={top} aria-hidden="true" class={MODAL_BODY_TOP} />
|
|
284
|
+
{local.children}
|
|
285
|
+
</Polymorphic>
|
|
264
286
|
);
|
|
265
287
|
};
|
|
266
288
|
|
|
@@ -321,7 +343,7 @@ export function createModalHead<P extends ModalHeadProps = ModalHeadProps>(
|
|
|
321
343
|
};
|
|
322
344
|
}
|
|
323
345
|
|
|
324
|
-
export type ModalDismissProps =
|
|
346
|
+
export type ModalDismissProps = ButtonRootProps<ValidComponent> & {
|
|
325
347
|
/** Presses do nothing, the dialog stays open and focus stays put; see Button. */
|
|
326
348
|
busy?: boolean;
|
|
327
349
|
};
|
|
@@ -337,7 +359,7 @@ export function createModalDismiss(
|
|
|
337
359
|
const [local, rest] = splitProps(props, ["onClick", "busy"]);
|
|
338
360
|
const context = useCloser();
|
|
339
361
|
return (
|
|
340
|
-
<
|
|
362
|
+
<ButtonRoot
|
|
341
363
|
data-slot={slot}
|
|
342
364
|
onClick={(event: MouseEvent & { currentTarget: HTMLButtonElement; target: Element }) => {
|
|
343
365
|
callEventHandler(event, local.onClick);
|