@vvedantb/ui 0.80.0 → 0.82.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/README.md +2 -0
- package/dist/shell/src/AppSidebar.js +15 -9
- package/dist/shell/src/DockArrow.js +187 -0
- package/dist/shell/src/SidePanelTabs.js +65 -147
- package/dist/shell/src/SidebarChrome.js +294 -103
- package/dist/shell/src/SidebarPanel.js +24 -20
- package/dist/shell/src/SidebarPeek.js +179 -0
- package/dist/shell/src/SidebarRail.js +51 -39
- package/dist/src/client.js +2 -0
- package/dist/src/index.js +2 -0
- package/package.json +1 -1
- package/shell/src/AppSidebar.tsx +7 -0
- package/shell/src/DockArrow.tsx +125 -0
- package/shell/src/SidePanelTabs.tsx +8 -78
- package/shell/src/Sidebar.tsx +1 -0
- package/shell/src/SidebarChrome.tsx +98 -5
- package/shell/src/SidebarPanel.tsx +7 -3
- package/shell/src/SidebarPeek.ts +127 -0
- package/shell/src/SidebarRail.tsx +16 -1
- package/src/client.ts +4 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { dockPopIn, dockPopOut } from "../../src/motion/dock-motion.js";
|
|
4
|
+
const OPEN_DELAY_MS = 120;
|
|
5
|
+
const CLOSE_DELAY_MS = 350;
|
|
6
|
+
const OPEN_MENU_TRIGGER = '[aria-haspopup][aria-expanded="true"]';
|
|
7
|
+
const PANEL_SELECTOR = "[data-sidebar-panel]";
|
|
8
|
+
function peekTile(target) {
|
|
9
|
+
if (!(target instanceof Element)) return null;
|
|
10
|
+
const tile = target.closest("[data-rail-peek]");
|
|
11
|
+
return tile && tile.closest(PANEL_SELECTOR) === null ? tile : null;
|
|
12
|
+
}
|
|
13
|
+
function inPanel(target) {
|
|
14
|
+
return target instanceof Element && target.closest(PANEL_SELECTOR) !== null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hover and focus state of an unpinned sidebar. The panel opens as an overlay
|
|
18
|
+
* when the pointer or focus is on a rail item that has `data-rail-peek` (rail
|
|
19
|
+
* links and tabs have it), and stays open while the pointer or focus is on a
|
|
20
|
+
* rail item or in the panel. It grows out of the hovered item with
|
|
21
|
+
* `dockPopIn` and shrinks back with `dockPopOut`. It stays open while a menu
|
|
22
|
+
* opened from the sidebar is open. `Sidebar.Root` makes one when none is
|
|
23
|
+
* passed; pass your own to read `previewPath` or `previewValue` and show the
|
|
24
|
+
* hovered item's panel without navigating.
|
|
25
|
+
*/
|
|
26
|
+
export function useSidebarPeek() {
|
|
27
|
+
const $ = _c(12);
|
|
28
|
+
const [peeking, setPeeking] = useState(false);
|
|
29
|
+
const [tile, setTile] = useState(null);
|
|
30
|
+
const timer = useRef(undefined);
|
|
31
|
+
const open = useRef(false);
|
|
32
|
+
const tileRef = useRef(null);
|
|
33
|
+
let t0;
|
|
34
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
35
|
+
t0 = () => window.clearTimeout(timer.current);
|
|
36
|
+
$[0] = t0;
|
|
37
|
+
} else {
|
|
38
|
+
t0 = $[0];
|
|
39
|
+
}
|
|
40
|
+
const cancelPending = t0;
|
|
41
|
+
let t1;
|
|
42
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
43
|
+
t1 = () => {
|
|
44
|
+
cancelPending();
|
|
45
|
+
open.current = false;
|
|
46
|
+
setPeeking(false);
|
|
47
|
+
setTile(null);
|
|
48
|
+
};
|
|
49
|
+
$[1] = t1;
|
|
50
|
+
} else {
|
|
51
|
+
t1 = $[1];
|
|
52
|
+
}
|
|
53
|
+
const reset = t1;
|
|
54
|
+
let t2;
|
|
55
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
56
|
+
t2 = () => {
|
|
57
|
+
cancelPending();
|
|
58
|
+
open.current = true;
|
|
59
|
+
setPeeking(true);
|
|
60
|
+
};
|
|
61
|
+
$[2] = t2;
|
|
62
|
+
} else {
|
|
63
|
+
t2 = $[2];
|
|
64
|
+
}
|
|
65
|
+
const hold = t2;
|
|
66
|
+
let t3;
|
|
67
|
+
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
68
|
+
t3 = (aside, delayMs) => {
|
|
69
|
+
cancelPending();
|
|
70
|
+
if (open.current) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
timer.current = window.setTimeout(() => {
|
|
74
|
+
open.current = true;
|
|
75
|
+
setPeeking(true);
|
|
76
|
+
requestAnimationFrame(() => {
|
|
77
|
+
const panel = aside.querySelector(PANEL_SELECTOR);
|
|
78
|
+
if (panel) {
|
|
79
|
+
dockPopIn(panel, tileRef.current, "left");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}, delayMs);
|
|
83
|
+
};
|
|
84
|
+
$[3] = t3;
|
|
85
|
+
} else {
|
|
86
|
+
t3 = $[3];
|
|
87
|
+
}
|
|
88
|
+
const scheduleOpen = t3;
|
|
89
|
+
let t4;
|
|
90
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
91
|
+
t4 = aside_0 => {
|
|
92
|
+
cancelPending();
|
|
93
|
+
if (!open.current) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
timer.current = window.setTimeout(() => {
|
|
97
|
+
if (aside_0.querySelector(OPEN_MENU_TRIGGER)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
dockPopOut(aside_0.querySelector(PANEL_SELECTOR), tileRef.current, "left", reset);
|
|
101
|
+
}, CLOSE_DELAY_MS);
|
|
102
|
+
};
|
|
103
|
+
$[4] = t4;
|
|
104
|
+
} else {
|
|
105
|
+
t4 = $[4];
|
|
106
|
+
}
|
|
107
|
+
const scheduleClose = t4;
|
|
108
|
+
let t5;
|
|
109
|
+
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
110
|
+
t5 = (aside_1, next, delayMs_0) => {
|
|
111
|
+
tileRef.current = next;
|
|
112
|
+
setTile(next);
|
|
113
|
+
scheduleOpen(aside_1, delayMs_0);
|
|
114
|
+
};
|
|
115
|
+
$[5] = t5;
|
|
116
|
+
} else {
|
|
117
|
+
t5 = $[5];
|
|
118
|
+
}
|
|
119
|
+
const onTile = t5;
|
|
120
|
+
let t6;
|
|
121
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
122
|
+
t6 = {
|
|
123
|
+
onPointerOver: event => {
|
|
124
|
+
const next_0 = peekTile(event.target);
|
|
125
|
+
if (next_0) {
|
|
126
|
+
onTile(event.currentTarget, next_0, OPEN_DELAY_MS);
|
|
127
|
+
} else {
|
|
128
|
+
if (inPanel(event.target)) {
|
|
129
|
+
cancelPending();
|
|
130
|
+
} else {
|
|
131
|
+
scheduleClose(event.currentTarget);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
onPointerLeave: event_0 => scheduleClose(event_0.currentTarget),
|
|
136
|
+
onFocus: event_1 => {
|
|
137
|
+
const next_1 = peekTile(event_1.target);
|
|
138
|
+
if (next_1) {
|
|
139
|
+
onTile(event_1.currentTarget, next_1, 0);
|
|
140
|
+
} else {
|
|
141
|
+
if (inPanel(event_1.target)) {
|
|
142
|
+
cancelPending();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
onBlur: event_2 => {
|
|
147
|
+
if (peekTile(event_2.relatedTarget) === null && !inPanel(event_2.relatedTarget)) {
|
|
148
|
+
scheduleClose(event_2.currentTarget);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
$[6] = t6;
|
|
153
|
+
} else {
|
|
154
|
+
t6 = $[6];
|
|
155
|
+
}
|
|
156
|
+
const handlers = t6;
|
|
157
|
+
const previewPath = peeking && tile instanceof HTMLAnchorElement ? tile.pathname : null;
|
|
158
|
+
const previewValue = peeking && tile ? tile.dataset.railPeek || null : null;
|
|
159
|
+
let t7;
|
|
160
|
+
if ($[7] !== peeking || $[8] !== previewPath || $[9] !== previewValue || $[10] !== tile) {
|
|
161
|
+
t7 = {
|
|
162
|
+
peeking,
|
|
163
|
+
previewPath,
|
|
164
|
+
previewValue,
|
|
165
|
+
tile,
|
|
166
|
+
handlers,
|
|
167
|
+
reset,
|
|
168
|
+
hold
|
|
169
|
+
};
|
|
170
|
+
$[7] = peeking;
|
|
171
|
+
$[8] = previewPath;
|
|
172
|
+
$[9] = previewValue;
|
|
173
|
+
$[10] = tile;
|
|
174
|
+
$[11] = t7;
|
|
175
|
+
} else {
|
|
176
|
+
t7 = $[11];
|
|
177
|
+
}
|
|
178
|
+
return t7;
|
|
179
|
+
}
|
|
@@ -498,12 +498,13 @@ export function RailFooter(t0) {
|
|
|
498
498
|
}
|
|
499
499
|
/** Rail tile with a right-side tooltip. Renders a native `<button>`, its child with `asChild`, or a tabs trigger with `tabValue`. */
|
|
500
500
|
export function RailItem(t0) {
|
|
501
|
-
const $ = _c(
|
|
501
|
+
const $ = _c(32);
|
|
502
502
|
let app;
|
|
503
503
|
let badge;
|
|
504
504
|
let children;
|
|
505
505
|
let className;
|
|
506
506
|
let label;
|
|
507
|
+
let peek;
|
|
507
508
|
let props;
|
|
508
509
|
let t1;
|
|
509
510
|
let t2;
|
|
@@ -519,6 +520,7 @@ export function RailItem(t0) {
|
|
|
519
520
|
badge,
|
|
520
521
|
asChild: t3,
|
|
521
522
|
tabValue,
|
|
523
|
+
peek,
|
|
522
524
|
className,
|
|
523
525
|
app,
|
|
524
526
|
children,
|
|
@@ -530,55 +532,58 @@ export function RailItem(t0) {
|
|
|
530
532
|
$[3] = children;
|
|
531
533
|
$[4] = className;
|
|
532
534
|
$[5] = label;
|
|
533
|
-
$[6] =
|
|
534
|
-
$[7] =
|
|
535
|
-
$[8] =
|
|
536
|
-
$[9] =
|
|
537
|
-
$[10] =
|
|
538
|
-
$[11] =
|
|
535
|
+
$[6] = peek;
|
|
536
|
+
$[7] = props;
|
|
537
|
+
$[8] = t1;
|
|
538
|
+
$[9] = t2;
|
|
539
|
+
$[10] = t3;
|
|
540
|
+
$[11] = tabValue;
|
|
541
|
+
$[12] = tooltip;
|
|
539
542
|
} else {
|
|
540
543
|
app = $[1];
|
|
541
544
|
badge = $[2];
|
|
542
545
|
children = $[3];
|
|
543
546
|
className = $[4];
|
|
544
547
|
label = $[5];
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
548
|
+
peek = $[6];
|
|
549
|
+
props = $[7];
|
|
550
|
+
t1 = $[8];
|
|
551
|
+
t2 = $[9];
|
|
552
|
+
t3 = $[10];
|
|
553
|
+
tabValue = $[11];
|
|
554
|
+
tooltip = $[12];
|
|
551
555
|
}
|
|
552
556
|
const active = t1 === undefined ? false : t1;
|
|
553
557
|
const showTooltip = t2 === undefined ? true : t2;
|
|
554
558
|
const asChild = t3 === undefined ? false : t3;
|
|
555
559
|
const grouped = use(RailGroupContext);
|
|
560
|
+
const peekValue = typeof peek === "string" ? peek : peek ?? (asChild || tabValue !== undefined) ? tabValue ?? "" : undefined;
|
|
556
561
|
let t4;
|
|
557
|
-
if ($[
|
|
562
|
+
if ($[13] !== active || $[14] !== app || $[15] !== asChild || $[16] !== badge || $[17] !== children || $[18] !== className || $[19] !== grouped || $[20] !== label || $[21] !== peekValue || $[22] !== props || $[23] !== showTooltip || $[24] !== tabValue || $[25] !== tooltip) {
|
|
558
563
|
const stateClass = railTileStateClass(active, grouped);
|
|
559
564
|
let t5;
|
|
560
|
-
if ($[
|
|
565
|
+
if ($[27] !== active || $[28] !== grouped) {
|
|
561
566
|
t5 = grouped ? {
|
|
562
567
|
"data-rail-tile": "",
|
|
563
568
|
"data-active": active ? "" : undefined
|
|
564
569
|
} : undefined;
|
|
565
|
-
$[
|
|
566
|
-
$[
|
|
567
|
-
$[
|
|
570
|
+
$[27] = active;
|
|
571
|
+
$[28] = grouped;
|
|
572
|
+
$[29] = t5;
|
|
568
573
|
} else {
|
|
569
|
-
t5 = $[
|
|
574
|
+
t5 = $[29];
|
|
570
575
|
}
|
|
571
576
|
const groupMarks = t5;
|
|
572
577
|
const AppIcon = app ? APP_ICONS[app] : null;
|
|
573
578
|
let t6;
|
|
574
|
-
if ($[
|
|
579
|
+
if ($[30] !== AppIcon) {
|
|
575
580
|
t6 = AppIcon ? /*#__PURE__*/_jsx(AppIcon, {
|
|
576
581
|
size: SIDEBAR_RAIL_APP_ICON_SIZE
|
|
577
582
|
}) : null;
|
|
578
|
-
$[
|
|
579
|
-
$[
|
|
583
|
+
$[30] = AppIcon;
|
|
584
|
+
$[31] = t6;
|
|
580
585
|
} else {
|
|
581
|
-
t6 = $[
|
|
586
|
+
t6 = $[31];
|
|
582
587
|
}
|
|
583
588
|
const appIcon = t6;
|
|
584
589
|
const content = appIcon ?? children;
|
|
@@ -589,6 +594,7 @@ export function RailItem(t0) {
|
|
|
589
594
|
...props,
|
|
590
595
|
value: tabValue,
|
|
591
596
|
...groupMarks,
|
|
597
|
+
"data-rail-peek": peekValue,
|
|
592
598
|
className: cn(railTileClass, "group relative", stateClass, className),
|
|
593
599
|
children: [content, /*#__PURE__*/_jsx("span", {
|
|
594
600
|
className: "sr-only",
|
|
@@ -599,6 +605,7 @@ export function RailItem(t0) {
|
|
|
599
605
|
"aria-label": label,
|
|
600
606
|
"aria-current": active ? "page" : undefined,
|
|
601
607
|
...groupMarks,
|
|
608
|
+
"data-rail-peek": peekValue,
|
|
602
609
|
className: cn(railTileClass, "group", stateClass, className),
|
|
603
610
|
children: [appIcon, /*#__PURE__*/_jsx(Slottable, {
|
|
604
611
|
children: children
|
|
@@ -608,29 +615,34 @@ export function RailItem(t0) {
|
|
|
608
615
|
...props,
|
|
609
616
|
"aria-label": label,
|
|
610
617
|
...groupMarks,
|
|
618
|
+
"data-rail-peek": peekValue,
|
|
611
619
|
className: cn(railTileClass, "group", stateClass, className),
|
|
612
620
|
children: [content, badge]
|
|
613
621
|
})
|
|
614
622
|
});
|
|
615
|
-
$[
|
|
616
|
-
$[
|
|
617
|
-
$[
|
|
618
|
-
$[
|
|
619
|
-
$[
|
|
620
|
-
$[
|
|
621
|
-
$[
|
|
622
|
-
$[
|
|
623
|
-
$[
|
|
624
|
-
$[
|
|
625
|
-
$[
|
|
626
|
-
$[
|
|
627
|
-
$[
|
|
628
|
-
|
|
629
|
-
|
|
623
|
+
$[13] = active;
|
|
624
|
+
$[14] = app;
|
|
625
|
+
$[15] = asChild;
|
|
626
|
+
$[16] = badge;
|
|
627
|
+
$[17] = children;
|
|
628
|
+
$[18] = className;
|
|
629
|
+
$[19] = grouped;
|
|
630
|
+
$[20] = label;
|
|
631
|
+
$[21] = peekValue;
|
|
632
|
+
$[22] = props;
|
|
633
|
+
$[23] = showTooltip;
|
|
634
|
+
$[24] = tabValue;
|
|
635
|
+
$[25] = tooltip;
|
|
636
|
+
$[26] = t4;
|
|
637
|
+
} else {
|
|
638
|
+
t4 = $[26];
|
|
630
639
|
}
|
|
631
640
|
return t4;
|
|
632
641
|
}
|
|
633
|
-
/**
|
|
642
|
+
/**
|
|
643
|
+
* Legacy name of `Sidebar.RailItem`.
|
|
644
|
+
* @alias
|
|
645
|
+
*/
|
|
634
646
|
export const RailTile = RailItem;
|
|
635
647
|
/** Short horizontal rule between rail items. */
|
|
636
648
|
export function RailSeparator(t0) {
|
package/dist/src/client.js
CHANGED
|
@@ -147,6 +147,8 @@ export { useAppShellVariant } from "../shell/src/shell-variant.js";
|
|
|
147
147
|
export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "../shell/src/shell-panel-motion.js";
|
|
148
148
|
export { ButtonTrack, buttonTrackClass } from "../shell/src/ButtonTrack.js";
|
|
149
149
|
export { SidePanelTabs, popOutSidePanel, SIDE_PANEL_RAIL_WIDTH_PX, SIDE_PANEL_RAIL_LABELLED_WIDTH_PX } from "../shell/src/SidePanelTabs.js";
|
|
150
|
+
export { useSidebarPeek } from "../shell/src/SidebarPeek.js";
|
|
151
|
+
export { DockArrow, useDockArrow } from "../shell/src/DockArrow.js";
|
|
150
152
|
export { AppSidebar } from "../shell/src/AppSidebar.js";
|
|
151
153
|
export * from "../shell/src/Sidebar.js";
|
|
152
154
|
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail.js";
|
package/dist/src/index.js
CHANGED
|
@@ -148,6 +148,8 @@ export { useAppShellVariant } from "../shell/src/shell-variant.js";
|
|
|
148
148
|
export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "../shell/src/shell-panel-motion.js";
|
|
149
149
|
export { ButtonTrack, buttonTrackClass } from "../shell/src/ButtonTrack.js";
|
|
150
150
|
export { SidePanelTabs, popOutSidePanel, SIDE_PANEL_RAIL_WIDTH_PX, SIDE_PANEL_RAIL_LABELLED_WIDTH_PX } from "../shell/src/SidePanelTabs.js";
|
|
151
|
+
export { useSidebarPeek } from "../shell/src/SidebarPeek.js";
|
|
152
|
+
export { DockArrow, useDockArrow } from "../shell/src/DockArrow.js";
|
|
151
153
|
export { AppSidebar } from "../shell/src/AppSidebar.js";
|
|
152
154
|
export * from "../shell/src/Sidebar.js";
|
|
153
155
|
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.82.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
|
|
6
6
|
"type": "module",
|
package/shell/src/AppSidebar.tsx
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import type { SidebarPeek } from "./SidebarPeek";
|
|
2
3
|
import { SidebarChromeParts as Parts } from "./SidebarChrome";
|
|
3
4
|
|
|
4
5
|
export type AppSidebarProps = {
|
|
5
6
|
rail: ReactNode;
|
|
6
7
|
panel?: ReactNode;
|
|
7
8
|
collapsed?: boolean;
|
|
9
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
10
|
+
peek?: SidebarPeek | false;
|
|
8
11
|
panelHidden?: boolean;
|
|
9
12
|
isDesktop: boolean;
|
|
10
13
|
mobileOpen: boolean;
|
|
@@ -33,6 +36,8 @@ export function AppSidebar({
|
|
|
33
36
|
rail,
|
|
34
37
|
panel,
|
|
35
38
|
collapsed = false,
|
|
39
|
+
onCollapsedChange,
|
|
40
|
+
peek,
|
|
36
41
|
panelHidden = false,
|
|
37
42
|
isDesktop,
|
|
38
43
|
mobileOpen,
|
|
@@ -52,6 +57,8 @@ export function AppSidebar({
|
|
|
52
57
|
mobileOpen={mobileOpen}
|
|
53
58
|
onMobileOpenChange={onMobileOpenChange}
|
|
54
59
|
collapsed={collapsed}
|
|
60
|
+
onCollapsedChange={onCollapsedChange}
|
|
61
|
+
peek={peek}
|
|
55
62
|
panelHidden={panelHidden}
|
|
56
63
|
id={id}
|
|
57
64
|
>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { useLayoutEffect, type ComponentProps, type RefObject } from "react";
|
|
2
|
+
import { dockPopIn, dockSwitch, type DockEdge } from "../../src/motion/dock-motion";
|
|
3
|
+
import { cn } from "../../src/utils/cn";
|
|
4
|
+
|
|
5
|
+
const ARROW_HALF_PX = 8;
|
|
6
|
+
|
|
7
|
+
export type DockArrowProps = Omit<ComponentProps<"div">, "children"> & {
|
|
8
|
+
/** Which edge of the card touches the rail. The arrow points across it. Default `"right"`. */
|
|
9
|
+
edge?: DockEdge;
|
|
10
|
+
/**
|
|
11
|
+
* Draws a 0.5 px line on the two outer sides, matching `Card`'s inset ring,
|
|
12
|
+
* so the arrow shows no seam against a `Card`. Default `false`.
|
|
13
|
+
*/
|
|
14
|
+
hairline?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The 16 px rotated square a dock card draws to point at its rail tile. Place
|
|
19
|
+
* it in the same positioned parent as the card and pass its ref to
|
|
20
|
+
* `useDockArrow`, which moves it. The fill is `bg-surface`: set another with a
|
|
21
|
+
* `bg-*` class in `className`. Hide it with `className` when the card is
|
|
22
|
+
* hidden (the hook already fades it out when the card has no width).
|
|
23
|
+
*/
|
|
24
|
+
export function DockArrow({ edge = "right", hairline = false, className, ...props }: DockArrowProps) {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
aria-hidden
|
|
28
|
+
data-dock-arrow=""
|
|
29
|
+
{...props}
|
|
30
|
+
className={cn(
|
|
31
|
+
"t-side-panel-arrow pointer-events-none absolute top-0 size-4 rounded-xs bg-surface opacity-0",
|
|
32
|
+
hairline &&
|
|
33
|
+
(edge === "right"
|
|
34
|
+
? "border-t-[0.5px] border-r-[0.5px]"
|
|
35
|
+
: "border-b-[0.5px] border-l-[0.5px]"),
|
|
36
|
+
hairline && "border-black/[0.06] dark:border-white/[0.08]",
|
|
37
|
+
className,
|
|
38
|
+
)}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type UseDockArrowOptions = {
|
|
44
|
+
frameRef: RefObject<HTMLElement | null>;
|
|
45
|
+
cardRef: RefObject<HTMLElement | null>;
|
|
46
|
+
arrowRef: RefObject<HTMLElement | null>;
|
|
47
|
+
/** Returns the active rail tile inside `frame`, or null. */
|
|
48
|
+
tile: (frame: HTMLElement) => HTMLElement | null;
|
|
49
|
+
/** Which edge of the card touches the rail. Default `"right"`. */
|
|
50
|
+
edge?: DockEdge;
|
|
51
|
+
/** Returns an element whose size change moves the tiles (the tab list). */
|
|
52
|
+
watch?: (frame: HTMLElement) => Element | null;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Places `arrowRef` at the card's `edge`, level with the active tile, and
|
|
57
|
+
* slides it to the next tile in step with the tab pill (`t-side-panel-arrow`).
|
|
58
|
+
* When the card opens it runs `dockPopIn` (the card grows out of the tile and
|
|
59
|
+
* the arrow fades in once it lands); when the tile changes it runs
|
|
60
|
+
* `dockSwitch`. Close with `dockPopOut(card, tile, edge, hide, arrow)`. The
|
|
61
|
+
* arrow hides while the card has no width or the tile is outside the card's
|
|
62
|
+
* height.
|
|
63
|
+
*/
|
|
64
|
+
export function useDockArrow({ frameRef, cardRef, arrowRef, tile, edge = "right", watch }: UseDockArrowOptions) {
|
|
65
|
+
useLayoutEffect(() => {
|
|
66
|
+
const frame = frameRef.current;
|
|
67
|
+
const card = cardRef.current;
|
|
68
|
+
const arrow = arrowRef.current;
|
|
69
|
+
if (!frame || !card || !arrow) return;
|
|
70
|
+
let placed = false;
|
|
71
|
+
let wasOpen = card.getBoundingClientRect().width > 0;
|
|
72
|
+
let lastTab = tile(frame);
|
|
73
|
+
const sync = () => {
|
|
74
|
+
const tab = tile(frame);
|
|
75
|
+
const f = frame.getBoundingClientRect();
|
|
76
|
+
const c = card.getBoundingClientRect();
|
|
77
|
+
const open = c.width > 0;
|
|
78
|
+
const opened = open && !wasOpen;
|
|
79
|
+
const switched = open && wasOpen && tab !== null && tab !== lastTab;
|
|
80
|
+
const previousTab = lastTab;
|
|
81
|
+
wasOpen = open;
|
|
82
|
+
if (tab) lastTab = tab;
|
|
83
|
+
if (!tab || !open) {
|
|
84
|
+
arrow.style.opacity = "0";
|
|
85
|
+
placed = false;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const t = tab.getBoundingClientRect();
|
|
89
|
+
const centre = t.top + t.height / 2;
|
|
90
|
+
const inCard = centre > c.top + 2 * ARROW_HALF_PX && centre < c.bottom - 2 * ARROW_HALF_PX;
|
|
91
|
+
if (!inCard) {
|
|
92
|
+
arrow.style.opacity = "0";
|
|
93
|
+
} else {
|
|
94
|
+
if (!placed) arrow.style.transition = "none";
|
|
95
|
+
const x = edge === "right" ? c.right - f.left - ARROW_HALF_PX - 1 : c.left - f.left - ARROW_HALF_PX + 1;
|
|
96
|
+
arrow.style.left = `${x}px`;
|
|
97
|
+
arrow.style.transform = `translateY(${centre - f.top - ARROW_HALF_PX}px) rotate(45deg)`;
|
|
98
|
+
arrow.style.opacity = "1";
|
|
99
|
+
if (!placed) {
|
|
100
|
+
void arrow.offsetWidth;
|
|
101
|
+
arrow.style.transition = "";
|
|
102
|
+
placed = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (opened) dockPopIn(card, tab, edge, arrow);
|
|
106
|
+
else if (switched) dockSwitch(card, previousTab, tab);
|
|
107
|
+
};
|
|
108
|
+
sync();
|
|
109
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
110
|
+
const resize = new ResizeObserver(sync);
|
|
111
|
+
resize.observe(frame);
|
|
112
|
+
resize.observe(card);
|
|
113
|
+
const mutation = new MutationObserver(sync);
|
|
114
|
+
mutation.observe(frame, { subtree: true, attributes: true, attributeFilter: ["data-state", "aria-selected"] });
|
|
115
|
+
const list = watch?.(frame);
|
|
116
|
+
if (list) resize.observe(list);
|
|
117
|
+
const settle = ["scroll", "animationend", "transitionend"] as const;
|
|
118
|
+
for (const type of settle) frame.addEventListener(type, sync, true);
|
|
119
|
+
return () => {
|
|
120
|
+
resize.disconnect();
|
|
121
|
+
mutation.disconnect();
|
|
122
|
+
for (const type of settle) frame.removeEventListener(type, sync, true);
|
|
123
|
+
};
|
|
124
|
+
}, [frameRef, cardRef, arrowRef, tile, edge, watch]);
|
|
125
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
useLayoutEffect,
|
|
3
2
|
useRef,
|
|
4
3
|
type ComponentPropsWithoutRef,
|
|
5
4
|
type KeyboardEvent,
|
|
6
5
|
type MouseEvent,
|
|
7
6
|
type ReactNode,
|
|
8
|
-
type RefObject,
|
|
9
7
|
} from "react";
|
|
10
|
-
import {
|
|
8
|
+
import { dockPopOut } from "../../src/motion/dock-motion";
|
|
9
|
+
import { DockArrow, useDockArrow } from "./DockArrow";
|
|
11
10
|
import { Tabs, TabsList, TabsTrigger } from "../../src/ui/tabs";
|
|
12
11
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../../src/ui/tooltip";
|
|
13
12
|
import { cn } from "../../src/utils/cn";
|
|
@@ -17,8 +16,6 @@ export const SIDE_PANEL_RAIL_WIDTH_PX = 44;
|
|
|
17
16
|
/** Width of the rail with a label under each icon (`labelled`). */
|
|
18
17
|
export const SIDE_PANEL_RAIL_LABELLED_WIDTH_PX = 76;
|
|
19
18
|
|
|
20
|
-
const ARROW_HALF_PX = 8;
|
|
21
|
-
|
|
22
19
|
const RAIL_TABLIST_SELECTOR = ':scope > [data-side-panel-rail] [role="tablist"]';
|
|
23
20
|
const ACTIVE_TAB_SELECTOR = `${RAIL_TABLIST_SELECTOR} [role="tab"][data-state="active"]`;
|
|
24
21
|
const CARD_SELECTOR = "[data-side-panel-card]";
|
|
@@ -42,71 +39,8 @@ export function popOutSidePanel(root: HTMLElement | null, collapse: () => void)
|
|
|
42
39
|
dockPopOut(card, card ? activeTabOf(card) : null, "right", collapse, card ? arrowOf(card) : null);
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
cardRef: RefObject<HTMLDivElement | null>,
|
|
48
|
-
arrowRef: RefObject<HTMLDivElement | null>,
|
|
49
|
-
) {
|
|
50
|
-
useLayoutEffect(() => {
|
|
51
|
-
const frame = frameRef.current;
|
|
52
|
-
const card = cardRef.current;
|
|
53
|
-
const arrow = arrowRef.current;
|
|
54
|
-
if (!frame || !card || !arrow) return;
|
|
55
|
-
let placed = false;
|
|
56
|
-
let wasOpen = card.getBoundingClientRect().width > 0;
|
|
57
|
-
let lastTab = frame.querySelector(ACTIVE_TAB_SELECTOR);
|
|
58
|
-
const sync = () => {
|
|
59
|
-
const tab = frame.querySelector<HTMLElement>(ACTIVE_TAB_SELECTOR);
|
|
60
|
-
const f = frame.getBoundingClientRect();
|
|
61
|
-
const c = card.getBoundingClientRect();
|
|
62
|
-
const open = c.width > 0;
|
|
63
|
-
const opened = open && !wasOpen;
|
|
64
|
-
const switched = open && wasOpen && tab !== null && tab !== lastTab;
|
|
65
|
-
const previousTab = lastTab;
|
|
66
|
-
wasOpen = open;
|
|
67
|
-
if (tab) lastTab = tab;
|
|
68
|
-
if (!tab || !open) {
|
|
69
|
-
arrow.style.opacity = "0";
|
|
70
|
-
placed = false;
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const t = tab.getBoundingClientRect();
|
|
74
|
-
const centre = t.top + t.height / 2;
|
|
75
|
-
const inCard = centre > c.top + 2 * ARROW_HALF_PX && centre < c.bottom - 2 * ARROW_HALF_PX;
|
|
76
|
-
if (!inCard) {
|
|
77
|
-
arrow.style.opacity = "0";
|
|
78
|
-
} else {
|
|
79
|
-
if (!placed) arrow.style.transition = "none";
|
|
80
|
-
arrow.style.left = `${c.right - f.left - ARROW_HALF_PX - 1}px`;
|
|
81
|
-
arrow.style.transform = `translateY(${centre - f.top - ARROW_HALF_PX}px) rotate(45deg)`;
|
|
82
|
-
arrow.style.opacity = "1";
|
|
83
|
-
if (!placed) {
|
|
84
|
-
void arrow.offsetWidth;
|
|
85
|
-
arrow.style.transition = "";
|
|
86
|
-
placed = true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (opened) dockPopIn(card, tab, "right", arrow);
|
|
90
|
-
else if (switched) dockSwitch(card, previousTab, tab);
|
|
91
|
-
};
|
|
92
|
-
sync();
|
|
93
|
-
if (typeof ResizeObserver === "undefined") return;
|
|
94
|
-
const resize = new ResizeObserver(sync);
|
|
95
|
-
resize.observe(frame);
|
|
96
|
-
resize.observe(card);
|
|
97
|
-
const mutation = new MutationObserver(sync);
|
|
98
|
-
mutation.observe(frame, { subtree: true, attributes: true, attributeFilter: ["data-state"] });
|
|
99
|
-
const list = frame.querySelector(RAIL_TABLIST_SELECTOR);
|
|
100
|
-
if (list) resize.observe(list);
|
|
101
|
-
const settle = ["scroll", "animationend", "transitionend"] as const;
|
|
102
|
-
for (const type of settle) frame.addEventListener(type, sync, true);
|
|
103
|
-
return () => {
|
|
104
|
-
resize.disconnect();
|
|
105
|
-
mutation.disconnect();
|
|
106
|
-
for (const type of settle) frame.removeEventListener(type, sync, true);
|
|
107
|
-
};
|
|
108
|
-
}, [frameRef, cardRef, arrowRef]);
|
|
109
|
-
}
|
|
42
|
+
const activeTabIn = (frame: HTMLElement) => frame.querySelector<HTMLElement>(ACTIVE_TAB_SELECTOR);
|
|
43
|
+
const railListIn = (frame: HTMLElement) => frame.querySelector(RAIL_TABLIST_SELECTOR);
|
|
110
44
|
|
|
111
45
|
export type SidePanelTabsFrameProps = {
|
|
112
46
|
collapsed?: boolean;
|
|
@@ -121,19 +55,15 @@ function Frame({ collapsed = false, rail, children, className, cardClassName, ar
|
|
|
121
55
|
const frameRef = useRef<HTMLDivElement>(null);
|
|
122
56
|
const cardRef = useRef<HTMLDivElement>(null);
|
|
123
57
|
const arrowRef = useRef<HTMLDivElement>(null);
|
|
124
|
-
|
|
58
|
+
useDockArrow({ frameRef, cardRef, arrowRef, tile: activeTabIn, edge: "right", watch: railListIn });
|
|
125
59
|
return (
|
|
126
60
|
<div ref={frameRef} className={cn("relative flex h-full min-h-0 flex-col md:flex-row-reverse", className)}>
|
|
127
61
|
{rail}
|
|
128
|
-
<
|
|
62
|
+
<DockArrow
|
|
129
63
|
ref={arrowRef}
|
|
130
|
-
|
|
64
|
+
edge="right"
|
|
131
65
|
data-side-panel-arrow=""
|
|
132
|
-
className={cn(
|
|
133
|
-
"t-side-panel-arrow pointer-events-none absolute top-0 hidden size-4 rounded-xs bg-surface opacity-0 md:block",
|
|
134
|
-
collapsed && "md:hidden",
|
|
135
|
-
arrowClassName,
|
|
136
|
-
)}
|
|
66
|
+
className={cn("hidden md:block", collapsed && "md:hidden", arrowClassName)}
|
|
137
67
|
/>
|
|
138
68
|
<div
|
|
139
69
|
ref={cardRef}
|