@vvedantb/ui 0.83.0 → 0.84.1
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/dist/shell/src/DockArrow.js +37 -5
- package/dist/shell/src/SidebarChrome.js +135 -117
- package/dist/shell/src/SidebarPanel.js +14 -12
- package/dist/shell/src/SidebarPeek.js +274 -98
- package/dist/shell/src/app-shell-classes.js +3 -2
- package/package.json +1 -1
- package/shell/src/DockArrow.tsx +36 -6
- package/shell/src/SidebarChrome.tsx +7 -2
- package/shell/src/SidebarPanel.tsx +1 -1
- package/shell/src/SidebarPeek.ts +131 -24
- package/shell/src/app-shell-classes.ts +5 -2
- package/src/client.ts +1 -1
- package/src/index.ts +1 -1
package/shell/src/SidebarPeek.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { useRef, useState, type FocusEvent, type PointerEvent } from "react";
|
|
1
|
+
import { useRef, useState, type FocusEvent, type MouseEvent, type PointerEvent } from "react";
|
|
2
2
|
import { flushSync } from "react-dom";
|
|
3
3
|
import { dockPopIn, dockPopOut } from "../../src/motion/dock-motion";
|
|
4
4
|
|
|
5
5
|
const OPEN_DELAY_MS = 120;
|
|
6
6
|
const CLOSE_DELAY_MS = 350;
|
|
7
|
+
const MENU_CLOSE_DELAY_MS = 2000;
|
|
7
8
|
const OPEN_MENU_TRIGGER = '[aria-haspopup][aria-expanded="true"]';
|
|
8
9
|
const PANEL_SELECTOR = "[data-sidebar-panel]";
|
|
10
|
+
const PORTAL_MENU = '[role="menu"]';
|
|
9
11
|
|
|
10
12
|
function peekTile(target: EventTarget | null): HTMLElement | null {
|
|
11
13
|
if (!(target instanceof Element)) return null;
|
|
@@ -17,11 +19,31 @@ function inPanel(target: EventTarget | null): boolean {
|
|
|
17
19
|
return target instanceof Element && target.closest(PANEL_SELECTOR) !== null;
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
function inPortal(aside: HTMLElement, target: EventTarget | null): boolean {
|
|
23
|
+
return target instanceof Node && !aside.contains(target);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function inPortalMenu(aside: HTMLElement, target: EventTarget | null): boolean {
|
|
27
|
+
return target instanceof Element && target.closest(PORTAL_MENU) !== null && !aside.contains(target);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function openPortalMenu(aside: HTMLElement): boolean {
|
|
31
|
+
return Array.from(document.querySelectorAll(PORTAL_MENU)).some(
|
|
32
|
+
(menu) => !aside.contains(menu) && menu.getAttribute("data-state") !== "closed",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type SidebarPeekOptions = {
|
|
37
|
+
/** Delay before the peek closes after a menu opened from it closes with the pointer outside. Default 2000 ms. */
|
|
38
|
+
menuCloseDelay?: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
20
41
|
export type SidebarPeekHandlers = {
|
|
21
42
|
onPointerOver: (event: PointerEvent<HTMLElement>) => void;
|
|
22
43
|
onPointerLeave: (event: PointerEvent<HTMLElement>) => void;
|
|
23
44
|
onFocus: (event: FocusEvent<HTMLElement>) => void;
|
|
24
45
|
onBlur: (event: FocusEvent<HTMLElement>) => void;
|
|
46
|
+
onContextMenu: (event: MouseEvent<HTMLElement>) => void;
|
|
25
47
|
};
|
|
26
48
|
|
|
27
49
|
export type SidebarPeek = {
|
|
@@ -47,21 +69,33 @@ export type SidebarPeek = {
|
|
|
47
69
|
* links and tabs have it), and stays open while the pointer or focus is on a
|
|
48
70
|
* rail item or in the panel. It grows out of the hovered item with
|
|
49
71
|
* `dockPopIn` and shrinks back with `dockPopOut`. It stays open while a menu
|
|
50
|
-
* opened from the sidebar is open
|
|
72
|
+
* opened from the sidebar is open, a right-click menu included, and closes
|
|
73
|
+
* `menuCloseDelay` after that menu closes with the pointer outside. A rail item
|
|
74
|
+
* whose page has no panel closes it, like empty rail. `Sidebar.Root` makes one when none is
|
|
51
75
|
* passed; pass your own to read `previewPath` or `previewValue` and show the
|
|
52
76
|
* hovered item's panel without navigating.
|
|
53
77
|
*/
|
|
54
|
-
export function useSidebarPeek(): SidebarPeek {
|
|
78
|
+
export function useSidebarPeek({ menuCloseDelay = MENU_CLOSE_DELAY_MS }: SidebarPeekOptions = {}): SidebarPeek {
|
|
55
79
|
const [peeking, setPeeking] = useState(false);
|
|
56
80
|
const [tile, setTile] = useState<HTMLElement | null>(null);
|
|
57
81
|
const timer = useRef<number | undefined>(undefined);
|
|
58
82
|
const open = useRef(false);
|
|
59
83
|
const tileRef = useRef<HTMLElement | null>(null);
|
|
84
|
+
const noPanelTile = useRef<HTMLElement | null>(null);
|
|
85
|
+
const contextMenu = useRef(false);
|
|
86
|
+
const stopWatch = useRef<(() => void) | null>(null);
|
|
60
87
|
|
|
61
88
|
const cancelPending = () => window.clearTimeout(timer.current);
|
|
62
89
|
|
|
90
|
+
const endMenuWatch = () => {
|
|
91
|
+
stopWatch.current?.();
|
|
92
|
+
stopWatch.current = null;
|
|
93
|
+
contextMenu.current = false;
|
|
94
|
+
};
|
|
95
|
+
|
|
63
96
|
const reset = () => {
|
|
64
97
|
cancelPending();
|
|
98
|
+
endMenuWatch();
|
|
65
99
|
open.current = false;
|
|
66
100
|
setPeeking(false);
|
|
67
101
|
setTile(null);
|
|
@@ -73,52 +107,125 @@ export function useSidebarPeek(): SidebarPeek {
|
|
|
73
107
|
setPeeking(true);
|
|
74
108
|
};
|
|
75
109
|
|
|
76
|
-
const
|
|
110
|
+
const menuHeld = (aside: HTMLElement) =>
|
|
111
|
+
aside.querySelector(OPEN_MENU_TRIGGER) !== null || (contextMenu.current && openPortalMenu(aside));
|
|
112
|
+
|
|
113
|
+
const closeWithoutPanel = () => {
|
|
114
|
+
noPanelTile.current = tileRef.current;
|
|
115
|
+
reset();
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const scheduleClose = (aside: HTMLElement, delayMs = CLOSE_DELAY_MS) => {
|
|
77
119
|
cancelPending();
|
|
78
|
-
if (open.current) return;
|
|
120
|
+
if (!open.current) return;
|
|
79
121
|
timer.current = window.setTimeout(() => {
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
if (menuHeld(aside)) {
|
|
123
|
+
watchMenu(aside, true);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
82
126
|
const panel = aside.querySelector<HTMLElement>(PANEL_SELECTOR);
|
|
83
|
-
if (
|
|
127
|
+
if (!panel) {
|
|
128
|
+
reset();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const card = panel.querySelector<HTMLElement>("[data-sidebar-card]") ?? panel;
|
|
132
|
+
const arrow = panel.querySelector<HTMLElement>("[data-dock-arrow]");
|
|
133
|
+
dockPopOut(card, tileRef.current, "left", reset, arrow);
|
|
84
134
|
}, delayMs);
|
|
85
135
|
};
|
|
86
136
|
|
|
87
|
-
const
|
|
137
|
+
const watchMenu = (aside: HTMLElement, alreadyOpen: boolean) => {
|
|
138
|
+
if (stopWatch.current) return;
|
|
139
|
+
let seenOpen = alreadyOpen;
|
|
140
|
+
let pointerInside = aside.matches(":hover");
|
|
141
|
+
const enter = () => {
|
|
142
|
+
pointerInside = true;
|
|
143
|
+
};
|
|
144
|
+
const leave = () => {
|
|
145
|
+
pointerInside = false;
|
|
146
|
+
};
|
|
147
|
+
const observer = new MutationObserver(() => {
|
|
148
|
+
if (!aside.isConnected) return endMenuWatch();
|
|
149
|
+
if (menuHeld(aside)) {
|
|
150
|
+
seenOpen = true;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!seenOpen) return;
|
|
154
|
+
endMenuWatch();
|
|
155
|
+
if (!pointerInside) scheduleClose(aside, menuCloseDelay);
|
|
156
|
+
});
|
|
157
|
+
observer.observe(document.body, {
|
|
158
|
+
childList: true,
|
|
159
|
+
subtree: true,
|
|
160
|
+
attributes: true,
|
|
161
|
+
attributeFilter: ["aria-expanded", "data-state"],
|
|
162
|
+
});
|
|
163
|
+
aside.addEventListener("pointerenter", enter);
|
|
164
|
+
aside.addEventListener("pointerleave", leave);
|
|
165
|
+
stopWatch.current = () => {
|
|
166
|
+
observer.disconnect();
|
|
167
|
+
aside.removeEventListener("pointerenter", enter);
|
|
168
|
+
aside.removeEventListener("pointerleave", leave);
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const scheduleOpen = (aside: HTMLElement, delayMs: number) => {
|
|
88
173
|
cancelPending();
|
|
89
|
-
if (
|
|
174
|
+
if (open.current) return;
|
|
90
175
|
timer.current = window.setTimeout(() => {
|
|
91
|
-
|
|
176
|
+
open.current = true;
|
|
177
|
+
flushSync(() => setPeeking(true));
|
|
92
178
|
const panel = aside.querySelector<HTMLElement>(PANEL_SELECTOR);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}, CLOSE_DELAY_MS);
|
|
179
|
+
if (!panel) return closeWithoutPanel();
|
|
180
|
+
if (!panel.hasAttribute("data-sidebar-floating")) dockPopIn(panel, tileRef.current, "left");
|
|
181
|
+
}, delayMs);
|
|
97
182
|
};
|
|
98
183
|
|
|
99
184
|
const onTile = (aside: HTMLElement, next: HTMLElement, delayMs: number) => {
|
|
185
|
+
if (next === noPanelTile.current && !open.current) return;
|
|
186
|
+
noPanelTile.current = null;
|
|
187
|
+
const changed = next !== tileRef.current;
|
|
100
188
|
tileRef.current = next;
|
|
189
|
+
if (open.current && changed) {
|
|
190
|
+
cancelPending();
|
|
191
|
+
flushSync(() => setTile(next));
|
|
192
|
+
if (!aside.querySelector(PANEL_SELECTOR)) closeWithoutPanel();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
101
195
|
setTile(next);
|
|
102
196
|
scheduleOpen(aside, delayMs);
|
|
103
197
|
};
|
|
104
198
|
|
|
105
199
|
const handlers: SidebarPeekHandlers = {
|
|
106
200
|
onPointerOver: (event) => {
|
|
201
|
+
const aside = event.currentTarget;
|
|
107
202
|
const next = peekTile(event.target);
|
|
108
|
-
if (next) onTile(
|
|
109
|
-
|
|
110
|
-
|
|
203
|
+
if (next) return onTile(aside, next, OPEN_DELAY_MS);
|
|
204
|
+
noPanelTile.current = null;
|
|
205
|
+
if (inPanel(event.target) || inPortal(aside, event.target)) cancelPending();
|
|
206
|
+
else scheduleClose(aside);
|
|
207
|
+
},
|
|
208
|
+
onPointerLeave: (event) => {
|
|
209
|
+
noPanelTile.current = null;
|
|
210
|
+
scheduleClose(event.currentTarget);
|
|
111
211
|
},
|
|
112
|
-
onPointerLeave: (event) => scheduleClose(event.currentTarget),
|
|
113
212
|
onFocus: (event) => {
|
|
213
|
+
const aside = event.currentTarget;
|
|
114
214
|
const next = peekTile(event.target);
|
|
115
|
-
if (next) onTile(
|
|
116
|
-
else if (inPanel(event.target)) cancelPending();
|
|
215
|
+
if (next) onTile(aside, next, 0);
|
|
216
|
+
else if (inPanel(event.target) || inPortal(aside, event.target)) cancelPending();
|
|
117
217
|
},
|
|
118
218
|
onBlur: (event) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
219
|
+
const aside = event.currentTarget;
|
|
220
|
+
const to = event.relatedTarget;
|
|
221
|
+
if (peekTile(to) !== null || inPanel(to) || inPortalMenu(aside, to)) return;
|
|
222
|
+
scheduleClose(aside);
|
|
223
|
+
},
|
|
224
|
+
onContextMenu: (event) => {
|
|
225
|
+
if (!open.current) return;
|
|
226
|
+
cancelPending();
|
|
227
|
+
contextMenu.current = true;
|
|
228
|
+
watchMenu(event.currentTarget, false);
|
|
122
229
|
},
|
|
123
230
|
};
|
|
124
231
|
|
|
@@ -7,7 +7,10 @@ export const SIDEBAR_RAIL_APP_ICON_SIZE = 24;
|
|
|
7
7
|
export const railTileClass =
|
|
8
8
|
"relative flex size-11 md:size-10 items-center justify-center rounded-lg border active:scale-[0.96] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring";
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const railGlassClass =
|
|
11
|
+
"shadow-[inset_0_0_0_0.5px_rgb(0_0_0/0.08),inset_1.5px_1.5px_1px_-1px_rgb(255_255_255/0.5),0_1px_1px_rgb(0_0_0/0.08)] dark:shadow-[inset_0_0_0_0.5px_rgb(255_255_255/0.1),inset_1.5px_1.5px_1px_-1px_rgb(255_255_255/0.12),0_1px_1px_rgb(0_0_0/0.3)]";
|
|
12
|
+
|
|
13
|
+
const railTileActiveClass = `border-transparent bg-surface-tertiary text-foreground ${railGlassClass}`;
|
|
11
14
|
const railTileIdleClass = "border-transparent text-muted opacity-75 hover:bg-surface-tertiary/50 hover:opacity-100 hover:text-foreground"; // check-tokens-allow: text-muted
|
|
12
15
|
|
|
13
16
|
const railTileGroupActiveClass = "z-1 border-transparent bg-transparent text-segment-foreground";
|
|
@@ -29,7 +32,7 @@ export const railGroupClass =
|
|
|
29
32
|
"relative isolate flex flex-col items-center gap-1 rounded-[calc(var(--radius-lg)+0.25rem)] bg-default p-1 dark:bg-surface";
|
|
30
33
|
|
|
31
34
|
/** The `RailGroup` sliding pill: the segmented tabs pill, with the tile radius. */
|
|
32
|
-
export const railGroupPillClass =
|
|
35
|
+
export const railGroupPillClass = `t-tabs-pill rounded-lg bg-segment ${railGlassClass}`;
|
|
33
36
|
|
|
34
37
|
/** Count badge pinned to the bottom-right of a rail tile. */
|
|
35
38
|
export const railBadgeClass = "absolute -bottom-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-accent px-1 text-[10px] font-medium leading-none text-accent-foreground"; // check-tokens-allow: accent
|
package/src/client.ts
CHANGED
|
@@ -237,7 +237,7 @@ export type {
|
|
|
237
237
|
SidePanelTabsTabProps,
|
|
238
238
|
} from "../shell/src/SidePanelTabs";
|
|
239
239
|
export { useSidebarPeek } from "../shell/src/SidebarPeek";
|
|
240
|
-
export type { SidebarPeek, SidebarPeekHandlers } from "../shell/src/SidebarPeek";
|
|
240
|
+
export type { SidebarPeek, SidebarPeekHandlers, SidebarPeekOptions } from "../shell/src/SidebarPeek";
|
|
241
241
|
export { DockArrow, useDockArrow } from "../shell/src/DockArrow";
|
|
242
242
|
export type { DockArrowProps, UseDockArrowOptions } from "../shell/src/DockArrow";
|
|
243
243
|
export { AppSidebar } from "../shell/src/AppSidebar";
|
package/src/index.ts
CHANGED
|
@@ -240,7 +240,7 @@ export type {
|
|
|
240
240
|
SidePanelTabsTabProps,
|
|
241
241
|
} from "../shell/src/SidePanelTabs";
|
|
242
242
|
export { useSidebarPeek } from "../shell/src/SidebarPeek";
|
|
243
|
-
export type { SidebarPeek, SidebarPeekHandlers } from "../shell/src/SidebarPeek";
|
|
243
|
+
export type { SidebarPeek, SidebarPeekHandlers, SidebarPeekOptions } from "../shell/src/SidebarPeek";
|
|
244
244
|
export { DockArrow, useDockArrow } from "../shell/src/DockArrow";
|
|
245
245
|
export type { DockArrowProps, UseDockArrowOptions } from "../shell/src/DockArrow";
|
|
246
246
|
export { AppSidebar } from "../shell/src/AppSidebar";
|