@vvedantb/ui 0.80.0 → 0.81.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 CHANGED
@@ -1289,6 +1289,7 @@ Rail-variant pieces (all work without the rail variant too, except the first):
1289
1289
  - **Dock motion of the sidebar panel.** In `variant="rail"` the panel shrinks into the `RailCollapseTile` on hide and grows back out on show, and the main content slides with the sidebar width. `panelMotion="none"` on `AppShell` turns it off (a rail-only input: a type error on `"floating"`). For a toggle of your own (a hotkey, a context setter) call `toggleShellPanel(collapsed, toggle)`, or `popOutShellPanel(hide)` and `popInShellPanelNextFrame()`. For a tile of your own, spread `shellDockTileProps` on it.
1290
1290
  - **`dockPopIn`, `dockNudge`, `dockPopOut`, `slideWith`, `slideNextResize`** (`DockEdge`, `DOCK_MOTION_EVENT`, `DockMotionEvent`, `dockMotionOff`): the same motion for any panel that docks into a tile. All of it stops with `MotionProvider reducedMotion` and `PageMotionProvider disabled`: a show is instant and a hide runs at once.
1291
1291
  - **`ButtonTrack`** (`buttonTrackClass`): a trough for a group of flat buttons, for page header actions (`direction="row"`, default) or tools under a side rail (`direction="column"`). It renders nothing visible when empty.
1292
+ - **`DockArrow`** and **`useDockArrow`**: the arrow `SidePanelTabs.Frame` draws, for any dock card. `<DockArrow ref={arrowRef} edge="left" hairline />` renders the 16 px rotated square (`bg-surface` fill; set another with a `bg-*` class). `hairline` adds a 0.5 px line on the two outer sides, matching `Card`'s inset ring, so it shows no seam on a `Card`. `useDockArrow({ frameRef, cardRef, arrowRef, tile, edge, watch })` puts it on the card's `edge` (`"left"` or `"right"`, the edge that touches the rail), level with the tile `tile(frame)` returns, and slides it in step with the tab pill. It runs `dockPopIn` when the card opens (the arrow fades in once the card lands) and `dockSwitch` when the tile changes. Close with `dockPopOut(card, tile, edge, hide, arrow)`. Motion stops under page motion off and reduced motion.
1292
1293
  - **`SidePanelTabs`**: tabs on a rail beside a content card, for a side panel. `SidePanelTabs.Frame({ collapsed, rail })` holds a `SidePanelTabs.Rail` with a `SidePanelTabs.List({ value, onValueChange })` of `SidePanelTabs.Tab({ value, label, icon, activeIcon, layout, count, indicator, onReselect })`. From `md` up the rail is on the right edge and an arrow on the card points at the active tab; below `md` the tabs are a strip on top. `collapsed` hides the card and leaves the rail (`SIDE_PANEL_RAIL_WIDTH_PX`, 44; `SIDE_PANEL_RAIL_LABELLED_WIDTH_PX`, 76). Close it with `popOutSidePanel(root, collapse)`. It does not depend on the `AppShell` variant. The rail is on the right only. The card is `bg-surface md:rounded-surface`. The tab trough is `bg-default`, and in dark (and `.dark.neutral`) it takes the card tone (`dark:bg-surface`) so the `bg-segment` pill stands out; `Sidebar.RailGroup` and `ButtonTrack` troughs do the same.
1293
1294
 
1294
1295
  ```tsx
@@ -0,0 +1,187 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useLayoutEffect } from "react";
3
+ import { dockPopIn, dockSwitch } from "../../src/motion/dock-motion.js";
4
+ import { cn } from "../../src/utils/cn.js";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const ARROW_HALF_PX = 8;
7
+ /**
8
+ * The 16 px rotated square a dock card draws to point at its rail tile. Place
9
+ * it in the same positioned parent as the card and pass its ref to
10
+ * `useDockArrow`, which moves it. The fill is `bg-surface`: set another with a
11
+ * `bg-*` class in `className`. Hide it with `className` when the card is
12
+ * hidden (the hook already fades it out when the card has no width).
13
+ */
14
+ export function DockArrow(t0) {
15
+ const $ = _c(12);
16
+ let className;
17
+ let props;
18
+ let t1;
19
+ let t2;
20
+ if ($[0] !== t0) {
21
+ ({
22
+ edge: t1,
23
+ hairline: t2,
24
+ className,
25
+ ...props
26
+ } = t0);
27
+ $[0] = t0;
28
+ $[1] = className;
29
+ $[2] = props;
30
+ $[3] = t1;
31
+ $[4] = t2;
32
+ } else {
33
+ className = $[1];
34
+ props = $[2];
35
+ t1 = $[3];
36
+ t2 = $[4];
37
+ }
38
+ const edge = t1 === undefined ? "right" : t1;
39
+ const hairline = t2 === undefined ? false : t2;
40
+ const t3 = hairline && (edge === "right" ? "border-t-[0.5px] border-r-[0.5px]" : "border-b-[0.5px] border-l-[0.5px]");
41
+ const t4 = hairline && "border-black/[0.06] dark:border-white/[0.08]";
42
+ let t5;
43
+ if ($[5] !== className || $[6] !== t3 || $[7] !== t4) {
44
+ t5 = cn("t-side-panel-arrow pointer-events-none absolute top-0 size-4 rounded-xs bg-surface opacity-0", t3, t4, className);
45
+ $[5] = className;
46
+ $[6] = t3;
47
+ $[7] = t4;
48
+ $[8] = t5;
49
+ } else {
50
+ t5 = $[8];
51
+ }
52
+ let t6;
53
+ if ($[9] !== props || $[10] !== t5) {
54
+ t6 = /*#__PURE__*/_jsx("div", {
55
+ "aria-hidden": true,
56
+ "data-dock-arrow": "",
57
+ ...props,
58
+ className: t5
59
+ });
60
+ $[9] = props;
61
+ $[10] = t5;
62
+ $[11] = t6;
63
+ } else {
64
+ t6 = $[11];
65
+ }
66
+ return t6;
67
+ }
68
+ /**
69
+ * Places `arrowRef` at the card's `edge`, level with the active tile, and
70
+ * slides it to the next tile in step with the tab pill (`t-side-panel-arrow`).
71
+ * When the card opens it runs `dockPopIn` (the card grows out of the tile and
72
+ * the arrow fades in once it lands); when the tile changes it runs
73
+ * `dockSwitch`. Close with `dockPopOut(card, tile, edge, hide, arrow)`. The
74
+ * arrow hides while the card has no width or the tile is outside the card's
75
+ * height.
76
+ */
77
+ export function useDockArrow(t0) {
78
+ const $ = _c(8);
79
+ const {
80
+ frameRef,
81
+ cardRef,
82
+ arrowRef,
83
+ tile,
84
+ edge: t1,
85
+ watch
86
+ } = t0;
87
+ const edge = t1 === undefined ? "right" : t1;
88
+ let t2;
89
+ let t3;
90
+ if ($[0] !== arrowRef || $[1] !== cardRef || $[2] !== edge || $[3] !== frameRef || $[4] !== tile || $[5] !== watch) {
91
+ t2 = () => {
92
+ const frame = frameRef.current;
93
+ const card = cardRef.current;
94
+ const arrow = arrowRef.current;
95
+ if (!frame || !card || !arrow) {
96
+ return;
97
+ }
98
+ let placed = false;
99
+ let wasOpen = card.getBoundingClientRect().width > 0;
100
+ let lastTab = tile(frame);
101
+ const sync = () => {
102
+ const tab = tile(frame);
103
+ const f = frame.getBoundingClientRect();
104
+ const c = card.getBoundingClientRect();
105
+ const open = c.width > 0;
106
+ const opened = open && !wasOpen;
107
+ const switched = open && wasOpen && tab !== null && tab !== lastTab;
108
+ const previousTab = lastTab;
109
+ wasOpen = open;
110
+ if (tab) {
111
+ lastTab = tab;
112
+ }
113
+ if (!tab || !open) {
114
+ arrow.style.opacity = "0";
115
+ placed = false;
116
+ return;
117
+ }
118
+ const t = tab.getBoundingClientRect();
119
+ const centre = t.top + t.height / 2;
120
+ const inCard = centre > c.top + 2 * ARROW_HALF_PX && centre < c.bottom - 2 * ARROW_HALF_PX;
121
+ if (!inCard) {
122
+ arrow.style.opacity = "0";
123
+ } else {
124
+ if (!placed) {
125
+ arrow.style.transition = "none";
126
+ }
127
+ const x = edge === "right" ? c.right - f.left - ARROW_HALF_PX - 1 : c.left - f.left - ARROW_HALF_PX + 1;
128
+ arrow.style.left = `${x}px`;
129
+ arrow.style.transform = `translateY(${centre - f.top - ARROW_HALF_PX}px) rotate(45deg)`;
130
+ arrow.style.opacity = "1";
131
+ if (!placed) {
132
+ arrow.style.transition = "";
133
+ placed = true;
134
+ }
135
+ }
136
+ if (opened) {
137
+ dockPopIn(card, tab, edge, arrow);
138
+ } else {
139
+ if (switched) {
140
+ dockSwitch(card, previousTab, tab);
141
+ }
142
+ }
143
+ };
144
+ sync();
145
+ if (typeof ResizeObserver === "undefined") {
146
+ return;
147
+ }
148
+ const resize = new ResizeObserver(sync);
149
+ resize.observe(frame);
150
+ resize.observe(card);
151
+ const mutation = new MutationObserver(sync);
152
+ mutation.observe(frame, {
153
+ subtree: true,
154
+ attributes: true,
155
+ attributeFilter: ["data-state", "aria-selected"]
156
+ });
157
+ const list = watch?.(frame);
158
+ if (list) {
159
+ resize.observe(list);
160
+ }
161
+ const settle = ["scroll", "animationend", "transitionend"];
162
+ for (const type of settle) {
163
+ frame.addEventListener(type, sync, true);
164
+ }
165
+ return () => {
166
+ resize.disconnect();
167
+ mutation.disconnect();
168
+ for (const type_0 of settle) {
169
+ frame.removeEventListener(type_0, sync, true);
170
+ }
171
+ };
172
+ };
173
+ t3 = [frameRef, cardRef, arrowRef, tile, edge, watch];
174
+ $[0] = arrowRef;
175
+ $[1] = cardRef;
176
+ $[2] = edge;
177
+ $[3] = frameRef;
178
+ $[4] = tile;
179
+ $[5] = watch;
180
+ $[6] = t2;
181
+ $[7] = t3;
182
+ } else {
183
+ t2 = $[6];
184
+ t3 = $[7];
185
+ }
186
+ useLayoutEffect(t2, t3);
187
+ }
@@ -1,6 +1,7 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
- import { useLayoutEffect, useRef } from "react";
3
- import { dockPopIn, dockPopOut, dockSwitch } from "../../src/motion/dock-motion.js";
2
+ import { useRef } from "react";
3
+ import { dockPopOut } from "../../src/motion/dock-motion.js";
4
+ import { DockArrow, useDockArrow } from "./DockArrow.js";
4
5
  import { Tabs, TabsList, TabsTrigger } from "../../src/ui/tabs.js";
5
6
  import { Tooltip, TooltipContent, TooltipTrigger } from "../../src/ui/tooltip.js";
6
7
  import { cn } from "../../src/utils/cn.js";
@@ -10,7 +11,6 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
10
11
  export const SIDE_PANEL_RAIL_WIDTH_PX = 44;
11
12
  /** Width of the rail with a label under each icon (`labelled`). */
12
13
  export const SIDE_PANEL_RAIL_LABELLED_WIDTH_PX = 76;
13
- const ARROW_HALF_PX = 8;
14
14
  const RAIL_TABLIST_SELECTOR = ':scope > [data-side-panel-rail] [role="tablist"]';
15
15
  const ACTIVE_TAB_SELECTOR = `${RAIL_TABLIST_SELECTOR} [role="tab"][data-state="active"]`;
16
16
  const CARD_SELECTOR = "[data-side-panel-card]";
@@ -31,106 +31,10 @@ export function popOutSidePanel(root, collapse) {
31
31
  const card = root?.querySelector(CARD_SELECTOR) ?? null;
32
32
  dockPopOut(card, card ? activeTabOf(card) : null, "right", collapse, card ? arrowOf(card) : null);
33
33
  }
34
- function useActiveTabArrow(frameRef, cardRef, arrowRef) {
35
- const $ = _c(5);
36
- let t0;
37
- let t1;
38
- if ($[0] !== arrowRef || $[1] !== cardRef || $[2] !== frameRef) {
39
- t0 = () => {
40
- const frame = frameRef.current;
41
- const card = cardRef.current;
42
- const arrow = arrowRef.current;
43
- if (!frame || !card || !arrow) {
44
- return;
45
- }
46
- let placed = false;
47
- let wasOpen = card.getBoundingClientRect().width > 0;
48
- let lastTab = frame.querySelector(ACTIVE_TAB_SELECTOR);
49
- const sync = () => {
50
- const tab = frame.querySelector(ACTIVE_TAB_SELECTOR);
51
- const f = frame.getBoundingClientRect();
52
- const c = card.getBoundingClientRect();
53
- const open = c.width > 0;
54
- const opened = open && !wasOpen;
55
- const switched = open && wasOpen && tab !== null && tab !== lastTab;
56
- const previousTab = lastTab;
57
- wasOpen = open;
58
- if (tab) {
59
- lastTab = tab;
60
- }
61
- if (!tab || !open) {
62
- arrow.style.opacity = "0";
63
- placed = false;
64
- return;
65
- }
66
- const t = tab.getBoundingClientRect();
67
- const centre = t.top + t.height / 2;
68
- const inCard = centre > c.top + 2 * ARROW_HALF_PX && centre < c.bottom - 2 * ARROW_HALF_PX;
69
- if (!inCard) {
70
- arrow.style.opacity = "0";
71
- } else {
72
- if (!placed) {
73
- arrow.style.transition = "none";
74
- }
75
- arrow.style.left = `${c.right - f.left - ARROW_HALF_PX - 1}px`;
76
- arrow.style.transform = `translateY(${centre - f.top - ARROW_HALF_PX}px) rotate(45deg)`;
77
- arrow.style.opacity = "1";
78
- if (!placed) {
79
- arrow.style.transition = "";
80
- placed = true;
81
- }
82
- }
83
- if (opened) {
84
- dockPopIn(card, tab, "right", arrow);
85
- } else {
86
- if (switched) {
87
- dockSwitch(card, previousTab, tab);
88
- }
89
- }
90
- };
91
- sync();
92
- if (typeof ResizeObserver === "undefined") {
93
- return;
94
- }
95
- const resize = new ResizeObserver(sync);
96
- resize.observe(frame);
97
- resize.observe(card);
98
- const mutation = new MutationObserver(sync);
99
- mutation.observe(frame, {
100
- subtree: true,
101
- attributes: true,
102
- attributeFilter: ["data-state"]
103
- });
104
- const list = frame.querySelector(RAIL_TABLIST_SELECTOR);
105
- if (list) {
106
- resize.observe(list);
107
- }
108
- const settle = ["scroll", "animationend", "transitionend"];
109
- for (const type of settle) {
110
- frame.addEventListener(type, sync, true);
111
- }
112
- return () => {
113
- resize.disconnect();
114
- mutation.disconnect();
115
- for (const type_0 of settle) {
116
- frame.removeEventListener(type_0, sync, true);
117
- }
118
- };
119
- };
120
- t1 = [frameRef, cardRef, arrowRef];
121
- $[0] = arrowRef;
122
- $[1] = cardRef;
123
- $[2] = frameRef;
124
- $[3] = t0;
125
- $[4] = t1;
126
- } else {
127
- t0 = $[3];
128
- t1 = $[4];
129
- }
130
- useLayoutEffect(t0, t1);
131
- }
34
+ const activeTabIn = frame => frame.querySelector(ACTIVE_TAB_SELECTOR);
35
+ const railListIn = frame => frame.querySelector(RAIL_TABLIST_SELECTOR);
132
36
  function Frame(t0) {
133
- const $ = _c(18);
37
+ const $ = _c(19);
134
38
  const {
135
39
  collapsed: t1,
136
40
  rail,
@@ -143,78 +47,92 @@ function Frame(t0) {
143
47
  const frameRef = useRef(null);
144
48
  const cardRef = useRef(null);
145
49
  const arrowRef = useRef(null);
146
- useActiveTabArrow(frameRef, cardRef, arrowRef);
147
50
  let t2;
148
- if ($[0] !== className) {
149
- t2 = cn("relative flex h-full min-h-0 flex-col md:flex-row-reverse", className);
150
- $[0] = className;
151
- $[1] = t2;
51
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
52
+ t2 = {
53
+ frameRef,
54
+ cardRef,
55
+ arrowRef,
56
+ tile: activeTabIn,
57
+ edge: "right",
58
+ watch: railListIn
59
+ };
60
+ $[0] = t2;
152
61
  } else {
153
- t2 = $[1];
62
+ t2 = $[0];
154
63
  }
155
- const t3 = collapsed && "md:hidden";
156
- let t4;
157
- if ($[2] !== arrowClassName || $[3] !== t3) {
158
- t4 = cn("t-side-panel-arrow pointer-events-none absolute top-0 hidden size-4 rounded-xs bg-surface opacity-0 md:block", t3, arrowClassName);
159
- $[2] = arrowClassName;
160
- $[3] = t3;
161
- $[4] = t4;
64
+ useDockArrow(t2);
65
+ let t3;
66
+ if ($[1] !== className) {
67
+ t3 = cn("relative flex h-full min-h-0 flex-col md:flex-row-reverse", className);
68
+ $[1] = className;
69
+ $[2] = t3;
162
70
  } else {
163
- t4 = $[4];
71
+ t3 = $[2];
164
72
  }
73
+ const t4 = collapsed && "md:hidden";
165
74
  let t5;
166
- if ($[5] !== t4) {
167
- t5 = /*#__PURE__*/_jsx("div", {
75
+ if ($[3] !== arrowClassName || $[4] !== t4) {
76
+ t5 = cn("hidden md:block", t4, arrowClassName);
77
+ $[3] = arrowClassName;
78
+ $[4] = t4;
79
+ $[5] = t5;
80
+ } else {
81
+ t5 = $[5];
82
+ }
83
+ let t6;
84
+ if ($[6] !== t5) {
85
+ t6 = /*#__PURE__*/_jsx(DockArrow, {
168
86
  ref: arrowRef,
169
- "aria-hidden": true,
87
+ edge: "right",
170
88
  "data-side-panel-arrow": "",
171
- className: t4
89
+ className: t5
172
90
  });
173
- $[5] = t4;
174
91
  $[6] = t5;
92
+ $[7] = t6;
175
93
  } else {
176
- t5 = $[6];
94
+ t6 = $[7];
177
95
  }
178
- const t6 = collapsed && "md:hidden";
179
- let t7;
180
- if ($[7] !== cardClassName || $[8] !== t6) {
181
- t7 = cn("relative min-h-0 min-w-0 flex-1 overflow-hidden bg-surface md:my-2 md:mr-1.5 md:rounded-surface", t6, cardClassName);
182
- $[7] = cardClassName;
183
- $[8] = t6;
96
+ const t7 = collapsed && "md:hidden";
97
+ let t8;
98
+ if ($[8] !== cardClassName || $[9] !== t7) {
99
+ t8 = cn("relative min-h-0 min-w-0 flex-1 overflow-hidden bg-surface md:my-2 md:mr-1.5 md:rounded-surface", t7, cardClassName);
100
+ $[8] = cardClassName;
184
101
  $[9] = t7;
102
+ $[10] = t8;
185
103
  } else {
186
- t7 = $[9];
104
+ t8 = $[10];
187
105
  }
188
- let t8;
189
- if ($[10] !== children || $[11] !== t7) {
190
- t8 = /*#__PURE__*/_jsx("div", {
106
+ let t9;
107
+ if ($[11] !== children || $[12] !== t8) {
108
+ t9 = /*#__PURE__*/_jsx("div", {
191
109
  ref: cardRef,
192
110
  "data-side-panel-card": "",
193
- className: t7,
111
+ className: t8,
194
112
  children: children
195
113
  });
196
- $[10] = children;
197
- $[11] = t7;
114
+ $[11] = children;
198
115
  $[12] = t8;
116
+ $[13] = t9;
199
117
  } else {
200
- t8 = $[12];
118
+ t9 = $[13];
201
119
  }
202
- let t9;
203
- if ($[13] !== rail || $[14] !== t2 || $[15] !== t5 || $[16] !== t8) {
204
- t9 = /*#__PURE__*/_jsxs("div", {
120
+ let t10;
121
+ if ($[14] !== rail || $[15] !== t3 || $[16] !== t6 || $[17] !== t9) {
122
+ t10 = /*#__PURE__*/_jsxs("div", {
205
123
  ref: frameRef,
206
- className: t2,
207
- children: [rail, t5, t8]
124
+ className: t3,
125
+ children: [rail, t6, t9]
208
126
  });
209
- $[13] = rail;
210
- $[14] = t2;
211
- $[15] = t5;
212
- $[16] = t8;
127
+ $[14] = rail;
128
+ $[15] = t3;
129
+ $[16] = t6;
213
130
  $[17] = t9;
131
+ $[18] = t10;
214
132
  } else {
215
- t9 = $[17];
133
+ t10 = $[18];
216
134
  }
217
- return t9;
135
+ return t10;
218
136
  }
219
137
  function Rail(t0) {
220
138
  const $ = _c(10);
@@ -147,6 +147,7 @@ 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 { DockArrow, useDockArrow } from "../shell/src/DockArrow.js";
150
151
  export { AppSidebar } from "../shell/src/AppSidebar.js";
151
152
  export * from "../shell/src/Sidebar.js";
152
153
  export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail.js";
package/dist/src/index.js CHANGED
@@ -148,6 +148,7 @@ 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 { DockArrow, useDockArrow } from "../shell/src/DockArrow.js";
151
152
  export { AppSidebar } from "../shell/src/AppSidebar.js";
152
153
  export * from "../shell/src/Sidebar.js";
153
154
  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.80.0",
3
+ "version": "0.81.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",
@@ -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 { dockPopIn, dockPopOut, dockSwitch } from "../../src/motion/dock-motion";
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
- function useActiveTabArrow(
46
- frameRef: RefObject<HTMLDivElement | null>,
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
- useActiveTabArrow(frameRef, cardRef, arrowRef);
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
- <div
62
+ <DockArrow
129
63
  ref={arrowRef}
130
- aria-hidden
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}
package/src/client.ts CHANGED
@@ -236,6 +236,8 @@ export type {
236
236
  SidePanelTabsRailProps,
237
237
  SidePanelTabsTabProps,
238
238
  } from "../shell/src/SidePanelTabs";
239
+ export { DockArrow, useDockArrow } from "../shell/src/DockArrow";
240
+ export type { DockArrowProps, UseDockArrowOptions } from "../shell/src/DockArrow";
239
241
  export { AppSidebar } from "../shell/src/AppSidebar";
240
242
  export type { AppSidebarProps } from "../shell/src/AppSidebar";
241
243
  export * from "../shell/src/Sidebar";
package/src/index.ts CHANGED
@@ -239,6 +239,8 @@ export type {
239
239
  SidePanelTabsRailProps,
240
240
  SidePanelTabsTabProps,
241
241
  } from "../shell/src/SidePanelTabs";
242
+ export { DockArrow, useDockArrow } from "../shell/src/DockArrow";
243
+ export type { DockArrowProps, UseDockArrowOptions } from "../shell/src/DockArrow";
242
244
  export { AppSidebar } from "../shell/src/AppSidebar";
243
245
  export type { AppSidebarProps } from "../shell/src/AppSidebar";
244
246
  export * from "../shell/src/Sidebar";