@vvedantb/ui 0.81.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.
@@ -4,12 +4,12 @@ import { IconX } from "@tabler/icons-react";
4
4
  import { Button } from "../../src/ui/button.js";
5
5
  import { cn } from "../../src/utils/cn.js";
6
6
  import { panelCloseButtonClass, sidebarHeaderRowClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemTrailingClass } from "./app-shell-classes.js";
7
- import { useOptionalSidebar } from "./SidebarChrome.js";
7
+ import { SidebarChromeParts, useOptionalSidebar } from "./SidebarChrome.js";
8
8
  import { useAppShellPanelDock } from "./shell-variant.js";
9
9
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
10
  /** Sidebar panel column beside the rail: a header and the app's body. Composed from `Sidebar.Panel` parts. */
11
11
  export function SidebarPanel(t0) {
12
- const $ = _c(15);
12
+ const $ = _c(16);
13
13
  const {
14
14
  title,
15
15
  headerTrailing,
@@ -21,6 +21,7 @@ export function SidebarPanel(t0) {
21
21
  children
22
22
  } = t0;
23
23
  const collapsed = t1 === undefined ? false : t1;
24
+ const pin = Boolean(useOptionalSidebar()?.onCollapsedChange);
24
25
  let t2;
25
26
  if ($[0] !== title) {
26
27
  t2 = /*#__PURE__*/_jsx(PanelTitle, {
@@ -32,9 +33,9 @@ export function SidebarPanel(t0) {
32
33
  t2 = $[1];
33
34
  }
34
35
  let t3;
35
- if ($[2] !== closeButtonClassName || $[3] !== closeLabel || $[4] !== headerTrailing || $[5] !== onClose) {
36
- t3 = headerTrailing || onClose ? /*#__PURE__*/_jsxs(PanelActions, {
37
- children: [headerTrailing, onClose ? /*#__PURE__*/_jsx(PanelClose, {
36
+ if ($[2] !== closeButtonClassName || $[3] !== closeLabel || $[4] !== headerTrailing || $[5] !== onClose || $[6] !== pin) {
37
+ t3 = headerTrailing || onClose || pin ? /*#__PURE__*/_jsxs(PanelActions, {
38
+ children: [headerTrailing, /*#__PURE__*/_jsx(SidebarChromeParts.PinButton, {}), onClose ? /*#__PURE__*/_jsx(PanelClose, {
38
39
  onClick: onClose,
39
40
  label: closeLabel,
40
41
  className: closeButtonClassName
@@ -44,36 +45,37 @@ export function SidebarPanel(t0) {
44
45
  $[3] = closeLabel;
45
46
  $[4] = headerTrailing;
46
47
  $[5] = onClose;
47
- $[6] = t3;
48
+ $[6] = pin;
49
+ $[7] = t3;
48
50
  } else {
49
- t3 = $[6];
51
+ t3 = $[7];
50
52
  }
51
53
  let t4;
52
- if ($[7] !== t2 || $[8] !== t3) {
54
+ if ($[8] !== t2 || $[9] !== t3) {
53
55
  t4 = /*#__PURE__*/_jsxs(PanelHeader, {
54
56
  children: [t2, t3]
55
57
  });
56
- $[7] = t2;
57
- $[8] = t3;
58
- $[9] = t4;
58
+ $[8] = t2;
59
+ $[9] = t3;
60
+ $[10] = t4;
59
61
  } else {
60
- t4 = $[9];
62
+ t4 = $[10];
61
63
  }
62
64
  let t5;
63
- if ($[10] !== children || $[11] !== className || $[12] !== collapsed || $[13] !== t4) {
65
+ if ($[11] !== children || $[12] !== className || $[13] !== collapsed || $[14] !== t4) {
64
66
  t5 = /*#__PURE__*/_jsxs(Panel, {
65
67
  collapsed: collapsed,
66
68
  panelHidden: false,
67
69
  className: className,
68
70
  children: [t4, children]
69
71
  });
70
- $[10] = children;
71
- $[11] = className;
72
- $[12] = collapsed;
73
- $[13] = t4;
74
- $[14] = t5;
72
+ $[11] = children;
73
+ $[12] = className;
74
+ $[13] = collapsed;
75
+ $[14] = t4;
76
+ $[15] = t5;
75
77
  } else {
76
- t5 = $[14];
78
+ t5 = $[15];
77
79
  }
78
80
  return t5;
79
81
  }
@@ -107,8 +109,9 @@ export function Panel(t0) {
107
109
  if (panelHidden ?? sidebar?.panelHidden ?? false) {
108
110
  return null;
109
111
  }
112
+ const peeking = sidebar !== null && sidebar.unpinned && !sidebar.collapsed;
110
113
  const t1 = dock ? "" : undefined;
111
- const t2 = (collapsed ?? sidebar?.collapsed ?? false) && "md:hidden";
114
+ const t2 = !peeking && (collapsed ?? sidebar?.collapsed ?? false) && "md:hidden";
112
115
  let t3;
113
116
  if ($[5] !== className || $[6] !== t2) {
114
117
  t3 = cn("relative flex h-full min-w-0 flex-1 flex-col overflow-hidden bg-background", t2, className);
@@ -122,6 +125,7 @@ export function Panel(t0) {
122
125
  if ($[8] !== props || $[9] !== t1 || $[10] !== t3) {
123
126
  t4 = /*#__PURE__*/_jsx("div", {
124
127
  "data-shell-dock-panel": t1,
128
+ "data-sidebar-panel": "",
125
129
  ...props,
126
130
  className: t3
127
131
  });
@@ -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(30);
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] = props;
534
- $[7] = t1;
535
- $[8] = t2;
536
- $[9] = t3;
537
- $[10] = tabValue;
538
- $[11] = tooltip;
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
- props = $[6];
546
- t1 = $[7];
547
- t2 = $[8];
548
- t3 = $[9];
549
- tabValue = $[10];
550
- tooltip = $[11];
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 ($[12] !== active || $[13] !== app || $[14] !== asChild || $[15] !== badge || $[16] !== children || $[17] !== className || $[18] !== grouped || $[19] !== label || $[20] !== props || $[21] !== showTooltip || $[22] !== tabValue || $[23] !== tooltip) {
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 ($[25] !== active || $[26] !== grouped) {
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
- $[25] = active;
566
- $[26] = grouped;
567
- $[27] = t5;
570
+ $[27] = active;
571
+ $[28] = grouped;
572
+ $[29] = t5;
568
573
  } else {
569
- t5 = $[27];
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 ($[28] !== AppIcon) {
579
+ if ($[30] !== AppIcon) {
575
580
  t6 = AppIcon ? /*#__PURE__*/_jsx(AppIcon, {
576
581
  size: SIDEBAR_RAIL_APP_ICON_SIZE
577
582
  }) : null;
578
- $[28] = AppIcon;
579
- $[29] = t6;
583
+ $[30] = AppIcon;
584
+ $[31] = t6;
580
585
  } else {
581
- t6 = $[29];
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
- $[12] = active;
616
- $[13] = app;
617
- $[14] = asChild;
618
- $[15] = badge;
619
- $[16] = children;
620
- $[17] = className;
621
- $[18] = grouped;
622
- $[19] = label;
623
- $[20] = props;
624
- $[21] = showTooltip;
625
- $[22] = tabValue;
626
- $[23] = tooltip;
627
- $[24] = t4;
628
- } else {
629
- t4 = $[24];
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
- /** Legacy name of `Sidebar.RailItem`. */
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) {
@@ -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 { useSidebarPeek } from "../shell/src/SidebarPeek.js";
150
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";
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 { useSidebarPeek } from "../shell/src/SidebarPeek.js";
151
152
  export { DockArrow, useDockArrow } from "../shell/src/DockArrow.js";
152
153
  export { AppSidebar } from "../shell/src/AppSidebar.js";
153
154
  export * from "../shell/src/Sidebar.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.81.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",
@@ -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
  >
@@ -30,6 +30,7 @@ export type {
30
30
  SidebarMobileHeaderProps,
31
31
  SidebarMobileMenuButtonProps,
32
32
  SidebarMobileTitleProps,
33
+ SidebarPinButtonProps,
33
34
  SidebarResizeHandlePartProps,
34
35
  SidebarRootProps,
35
36
  } from "./SidebarChrome";