@vvedantb/ui 0.81.0 → 0.83.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/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.83.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";
@@ -8,11 +8,12 @@ import {
8
8
  type ReactNode,
9
9
  } from "react";
10
10
  import { AnimatePresence, domMax, LazyMotion, m, type HTMLMotionProps, type PanInfo } from "motion/react";
11
- import { IconMenu2 } from "@tabler/icons-react";
11
+ import { IconMenu2, IconPin, IconPinFilled } from "@tabler/icons-react";
12
12
  import { Button, type ButtonProps } from "../../src/ui/button";
13
13
  import { motionEase, motionTiming } from "../../src/motion/presets";
14
14
  import { cn } from "../../src/utils/cn";
15
15
  import { mobileMenuButtonClass } from "./app-shell-classes";
16
+ import { useSidebarPeek, type SidebarPeek } from "./SidebarPeek";
16
17
  import { SidebarResizeHandle, useSidebarResizeContext, type SidebarResizeHandleProps } from "./SidebarResize";
17
18
 
18
19
  type SidebarContextValue = {
@@ -20,6 +21,9 @@ type SidebarContextValue = {
20
21
  mobileOpen: boolean;
21
22
  onMobileOpenChange: (open: boolean) => void;
22
23
  collapsed: boolean;
24
+ unpinned: boolean;
25
+ peek: SidebarPeek | null;
26
+ onCollapsedChange: ((collapsed: boolean) => void) | null;
23
27
  panelHidden: boolean;
24
28
  drawerId: string;
25
29
  };
@@ -41,7 +45,12 @@ export type SidebarRootProps = {
41
45
  isDesktop: boolean;
42
46
  mobileOpen: boolean;
43
47
  onMobileOpenChange: (open: boolean) => void;
48
+ /** The panel is unpinned: the rail shows alone and the panel opens on hover. */
44
49
  collapsed?: boolean;
50
+ /** Pins or unpins the panel. Adds `Sidebar.PinButton` to `SidebarPanel`. */
51
+ onCollapsedChange?: (collapsed: boolean) => void;
52
+ /** Hover state from `useSidebarPeek`, to read the hovered item. `false` turns hover-open off. */
53
+ peek?: SidebarPeek | false;
45
54
  panelHidden?: boolean;
46
55
  id?: string;
47
56
  children?: ReactNode;
@@ -52,11 +61,16 @@ function Root({
52
61
  mobileOpen,
53
62
  onMobileOpenChange,
54
63
  collapsed = false,
64
+ onCollapsedChange,
65
+ peek: peekProp,
55
66
  panelHidden = false,
56
67
  id,
57
68
  children,
58
69
  }: SidebarRootProps) {
59
70
  const autoId = useId();
71
+ const ownPeek = useSidebarPeek();
72
+ const peek = peekProp === false ? null : (peekProp ?? ownPeek);
73
+ const peeking = collapsed && isDesktop && (peek?.peeking ?? false);
60
74
 
61
75
  useEffect(() => {
62
76
  if (isDesktop && mobileOpen) onMobileOpenChange(false);
@@ -64,7 +78,17 @@ function Root({
64
78
 
65
79
  return (
66
80
  <SidebarContext.Provider
67
- value={{ isDesktop, mobileOpen, onMobileOpenChange, collapsed, panelHidden, drawerId: id ?? autoId }}
81
+ value={{
82
+ isDesktop,
83
+ mobileOpen,
84
+ onMobileOpenChange,
85
+ collapsed: collapsed && !peeking,
86
+ unpinned: collapsed,
87
+ peek,
88
+ onCollapsedChange: onCollapsedChange ?? null,
89
+ panelHidden,
90
+ drawerId: id ?? autoId,
91
+ }}
68
92
  >
69
93
  {children}
70
94
  </SidebarContext.Provider>
@@ -198,10 +222,22 @@ function Backdrop({ label = "Close navigation", className, onClick, ...props }:
198
222
 
199
223
  export type SidebarAsideProps = HTMLMotionProps<"aside">;
200
224
 
201
- function Aside({ id, className, onKeyDown, children, ...props }: SidebarAsideProps) {
225
+ function Aside({
226
+ id,
227
+ className,
228
+ onKeyDown,
229
+ onPointerOver,
230
+ onPointerLeave,
231
+ onFocus,
232
+ onBlur,
233
+ children,
234
+ ...props
235
+ }: SidebarAsideProps) {
202
236
  const sidebar = useSidebar("Aside");
203
237
  const resize = useSidebarResizeContext();
204
- const { isDesktop, mobileOpen, collapsed, panelHidden } = sidebar;
238
+ const { isDesktop, mobileOpen, collapsed, panelHidden, peek } = sidebar;
239
+ const hover = isDesktop && sidebar.unpinned && !panelHidden ? peek : null;
240
+ const peeking = hover !== null && !collapsed;
205
241
 
206
242
  const handleDrawerDragEnd = (_event: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
207
243
  if (isDesktop || !mobileOpen) return;
@@ -217,6 +253,23 @@ function Aside({ id, className, onKeyDown, children, ...props }: SidebarAsidePro
217
253
  data-sidebar-layout={isDesktop ? "desktop" : "drawer"}
218
254
  {...props}
219
255
  inert={!isDesktop && !mobileOpen}
256
+ data-sidebar-peek={peeking ? "" : undefined}
257
+ onPointerOver={(event) => {
258
+ onPointerOver?.(event);
259
+ hover?.handlers.onPointerOver(event);
260
+ }}
261
+ onPointerLeave={(event) => {
262
+ onPointerLeave?.(event);
263
+ hover?.handlers.onPointerLeave(event);
264
+ }}
265
+ onFocus={(event) => {
266
+ onFocus?.(event);
267
+ hover?.handlers.onFocus(event);
268
+ }}
269
+ onBlur={(event) => {
270
+ onBlur?.(event);
271
+ hover?.handlers.onBlur(event);
272
+ }}
220
273
  onKeyDown={(event) => {
221
274
  onKeyDown?.(event);
222
275
  closeOnEscape(sidebar, event);
@@ -229,7 +282,13 @@ function Aside({ id, className, onKeyDown, children, ...props }: SidebarAsidePro
229
282
  collapsed || panelHidden
230
283
  ? "md:w-[var(--app-shell-rail-width)]"
231
284
  : "md:w-[var(--app-shell-sidebar-width)]",
285
+ hover !== null && "md:transition-none",
286
+ peeking &&
287
+ (sidebar.onCollapsedChange
288
+ ? "md:bg-transparent md:[&_[data-sidebar-card]]:smooth-shadow-ring-xl"
289
+ : "md:shadow-[8px_0_24px_-12px_rgb(0_0_0/0.18)]"),
232
290
  !resize?.isResizing &&
291
+ hover === null &&
233
292
  "md:transition-[width] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]",
234
293
  className,
235
294
  )}
@@ -255,11 +314,48 @@ function ResizeHandle(props: SidebarResizeHandlePartProps) {
255
314
  const resize = useSidebarResizeContext();
256
315
  const show =
257
316
  resize !== null &&
258
- (sidebar === null || (sidebar.isDesktop && !sidebar.collapsed && !sidebar.panelHidden));
317
+ (sidebar === null || (sidebar.isDesktop && !sidebar.unpinned && !sidebar.panelHidden));
259
318
  return show ? <SidebarResizeHandle {...props} /> : null;
260
319
  }
261
320
 
321
+ export type SidebarPinButtonProps = Omit<ButtonProps, "children" | "onClick">;
322
+
323
+ /**
324
+ * Pins or unpins the panel. Pinned keeps it docked beside the rail; unpinned
325
+ * shows the rail alone and opens the panel on hover. Renders nothing when
326
+ * `Sidebar.Root` has no `onCollapsedChange`, and is hidden below `md`.
327
+ */
328
+ function PinButton({ className, ...props }: SidebarPinButtonProps) {
329
+ const sidebar = useOptionalSidebar();
330
+ if (!sidebar?.onCollapsedChange) return null;
331
+ const { onCollapsedChange, peek } = sidebar;
332
+ const pinned = !sidebar.unpinned;
333
+ const label = pinned ? "Unpin sidebar" : "Pin sidebar";
334
+ const Icon = pinned ? IconPinFilled : IconPin;
335
+ return (
336
+ <Button
337
+ type="button"
338
+ variant="ghost"
339
+ size="icon-sm"
340
+ shape="rounded"
341
+ {...props}
342
+ onClick={() => {
343
+ if (pinned) peek?.hold();
344
+ else peek?.reset();
345
+ onCollapsedChange(pinned);
346
+ }}
347
+ aria-pressed={pinned}
348
+ aria-label={label}
349
+ title={label}
350
+ className={cn("size-8 shrink-0 text-muted-foreground max-md:hidden", className)}
351
+ >
352
+ <Icon size={16} />
353
+ </Button>
354
+ );
355
+ }
356
+
262
357
  export const SidebarChromeParts = {
358
+ PinButton,
263
359
  Root,
264
360
  MobileHeader,
265
361
  MobileMenuButton,
@@ -1,7 +1,8 @@
1
- import type { ComponentPropsWithoutRef, ReactElement, ReactNode } from "react";
1
+ import { useCallback, useLayoutEffect, useRef, type ComponentPropsWithoutRef, type ReactElement, type ReactNode } from "react";
2
2
  import { Slot, Slottable } from "@radix-ui/react-slot";
3
3
  import { IconX } from "@tabler/icons-react";
4
4
  import { Button, type ButtonProps } from "../../src/ui/button";
5
+ import { Card } from "../../src/ui/card";
5
6
  import { cn } from "../../src/utils/cn";
6
7
  import {
7
8
  panelCloseButtonClass,
@@ -14,7 +15,8 @@ import {
14
15
  sidebarNavItemLeadingClass,
15
16
  sidebarNavItemTrailingClass,
16
17
  } from "./app-shell-classes";
17
- import { useOptionalSidebar } from "./SidebarChrome";
18
+ import { DockArrow, useDockArrow } from "./DockArrow";
19
+ import { SidebarChromeParts, useOptionalSidebar } from "./SidebarChrome";
18
20
  import { useAppShellPanelDock } from "./shell-variant";
19
21
 
20
22
  export type SidebarPanelProps = {
@@ -39,13 +41,15 @@ export function SidebarPanel({
39
41
  className,
40
42
  children,
41
43
  }: SidebarPanelProps) {
44
+ const pin = Boolean(useOptionalSidebar()?.onCollapsedChange);
42
45
  return (
43
46
  <Panel collapsed={collapsed} panelHidden={false} className={className}>
44
47
  <PanelHeader>
45
48
  <PanelTitle>{title}</PanelTitle>
46
- {headerTrailing || onClose ? (
49
+ {headerTrailing || onClose || pin ? (
47
50
  <PanelActions>
48
51
  {headerTrailing}
52
+ <SidebarChromeParts.PinButton />
49
53
  {onClose ? (
50
54
  <PanelClose onClick={onClose} label={closeLabel} className={closeButtonClassName} />
51
55
  ) : null}
@@ -62,21 +66,87 @@ export type SidebarPanelRootProps = ComponentPropsWithoutRef<"div"> & {
62
66
  panelHidden?: boolean;
63
67
  };
64
68
 
65
- /** Panel column `<div>` beside the rail. */
66
- export function Panel({ collapsed, panelHidden, className, ...props }: SidebarPanelRootProps) {
69
+ const ACTIVE_RAIL_TILE =
70
+ '[data-rail-peek][data-active], [data-rail-peek][aria-current="page"], [data-rail-peek][data-state="active"]';
71
+
72
+ function sidebarAside(frame: HTMLElement): HTMLElement | null {
73
+ return frame.closest<HTMLElement>("aside");
74
+ }
75
+
76
+ function activeRailTile(frame: HTMLElement): HTMLElement | null {
77
+ return sidebarAside(frame)?.querySelector<HTMLElement>(ACTIVE_RAIL_TILE) ?? null;
78
+ }
79
+
80
+ function sidebarRail(frame: HTMLElement): Element | null {
81
+ return sidebarAside(frame)?.querySelector("[data-sidebar-rail]") ?? null;
82
+ }
83
+
84
+ /**
85
+ * The floating panel card and the dock arrow that points from it at its rail
86
+ * tile: the hovered tile while the panel is unpinned, else the active one.
87
+ * `useDockArrow` grows the card out of the tile when it opens.
88
+ */
89
+ function FloatingCard({ hoverTile, children }: { hoverTile: HTMLElement | null; children: ReactNode }) {
90
+ const frameRef = useRef<HTMLDivElement>(null);
91
+ const cardRef = useRef<HTMLDivElement>(null);
92
+ const arrowRef = useRef<HTMLDivElement>(null);
93
+ const hoverRef = useRef(hoverTile);
94
+ useLayoutEffect(() => {
95
+ hoverRef.current = hoverTile;
96
+ }, [hoverTile]);
97
+ const tile = useCallback((frame: HTMLElement) => hoverRef.current ?? activeRailTile(frame), []);
98
+ useDockArrow({ frameRef, cardRef, arrowRef, edge: "left", tile, watch: sidebarRail });
99
+ return (
100
+ <div ref={frameRef} className="relative flex min-h-0 flex-1 flex-col">
101
+ <DockArrow ref={arrowRef} edge="left" hairline className="z-10 bg-background" />
102
+ <Card
103
+ ref={cardRef}
104
+ data-sidebar-card=""
105
+ className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-[calc(var(--radius-lg)+0.25rem)] bg-background"
106
+ >
107
+ {children}
108
+ </Card>
109
+ </div>
110
+ );
111
+ }
112
+
113
+ /**
114
+ * Panel column `<div>` beside the rail. When `Sidebar.Root` has
115
+ * `onCollapsedChange`, it floats on desktop: a rounded `Card` inset from the
116
+ * edges, with a `DockArrow` at its rail tile.
117
+ */
118
+ export function Panel({ collapsed, panelHidden, className, children, ...props }: SidebarPanelRootProps) {
67
119
  const sidebar = useOptionalSidebar();
68
120
  const dock = useAppShellPanelDock();
69
121
  if (panelHidden ?? sidebar?.panelHidden ?? false) return null;
122
+ const peeking = sidebar !== null && sidebar.unpinned && !sidebar.collapsed;
123
+ const hidden = !peeking && (collapsed ?? sidebar?.collapsed ?? false);
124
+ if (sidebar !== null && sidebar.isDesktop && sidebar.onCollapsedChange !== null) {
125
+ return (
126
+ <div
127
+ data-shell-dock-panel={dock ? "" : undefined}
128
+ data-sidebar-panel=""
129
+ data-sidebar-floating=""
130
+ {...props}
131
+ className={cn("relative my-3 mr-2 flex min-w-0 flex-1 flex-col", hidden && "md:hidden", className)}
132
+ >
133
+ <FloatingCard hoverTile={sidebar.unpinned ? (sidebar.peek?.tile ?? null) : null}>{children}</FloatingCard>
134
+ </div>
135
+ );
136
+ }
70
137
  return (
71
138
  <div
72
139
  data-shell-dock-panel={dock ? "" : undefined}
140
+ data-sidebar-panel=""
73
141
  {...props}
74
142
  className={cn(
75
143
  "relative flex h-full min-w-0 flex-1 flex-col overflow-hidden bg-background",
76
- (collapsed ?? sidebar?.collapsed ?? false) && "md:hidden",
144
+ hidden && "md:hidden",
77
145
  className,
78
146
  )}
79
- />
147
+ >
148
+ {children}
149
+ </div>
80
150
  );
81
151
  }
82
152
 
@@ -0,0 +1,129 @@
1
+ import { useRef, useState, type FocusEvent, type PointerEvent } from "react";
2
+ import { flushSync } from "react-dom";
3
+ import { dockPopIn, dockPopOut } from "../../src/motion/dock-motion";
4
+
5
+ const OPEN_DELAY_MS = 120;
6
+ const CLOSE_DELAY_MS = 350;
7
+ const OPEN_MENU_TRIGGER = '[aria-haspopup][aria-expanded="true"]';
8
+ const PANEL_SELECTOR = "[data-sidebar-panel]";
9
+
10
+ function peekTile(target: EventTarget | null): HTMLElement | null {
11
+ if (!(target instanceof Element)) return null;
12
+ const tile = target.closest<HTMLElement>("[data-rail-peek]");
13
+ return tile && tile.closest(PANEL_SELECTOR) === null ? tile : null;
14
+ }
15
+
16
+ function inPanel(target: EventTarget | null): boolean {
17
+ return target instanceof Element && target.closest(PANEL_SELECTOR) !== null;
18
+ }
19
+
20
+ export type SidebarPeekHandlers = {
21
+ onPointerOver: (event: PointerEvent<HTMLElement>) => void;
22
+ onPointerLeave: (event: PointerEvent<HTMLElement>) => void;
23
+ onFocus: (event: FocusEvent<HTMLElement>) => void;
24
+ onBlur: (event: FocusEvent<HTMLElement>) => void;
25
+ };
26
+
27
+ export type SidebarPeek = {
28
+ /** The unpinned panel shows as an overlay. */
29
+ peeking: boolean;
30
+ /** Path of the hovered rail link, or null. */
31
+ previewPath: string | null;
32
+ /** `data-rail-peek` value of the hovered rail item (its `tabValue` or `peek` string), or null. */
33
+ previewValue: string | null;
34
+ /** The hovered rail item. */
35
+ tile: HTMLElement | null;
36
+ /** Handlers `Sidebar.Aside` spreads while the panel is unpinned. */
37
+ handlers: SidebarPeekHandlers;
38
+ /** Ends the peek at once, with no motion. */
39
+ reset: () => void;
40
+ /** Keeps the panel open as a peek until the pointer leaves it. */
41
+ hold: () => void;
42
+ };
43
+
44
+ /**
45
+ * Hover and focus state of an unpinned sidebar. The panel opens as an overlay
46
+ * when the pointer or focus is on a rail item that has `data-rail-peek` (rail
47
+ * links and tabs have it), and stays open while the pointer or focus is on a
48
+ * rail item or in the panel. It grows out of the hovered item with
49
+ * `dockPopIn` and shrinks back with `dockPopOut`. It stays open while a menu
50
+ * opened from the sidebar is open. `Sidebar.Root` makes one when none is
51
+ * passed; pass your own to read `previewPath` or `previewValue` and show the
52
+ * hovered item's panel without navigating.
53
+ */
54
+ export function useSidebarPeek(): SidebarPeek {
55
+ const [peeking, setPeeking] = useState(false);
56
+ const [tile, setTile] = useState<HTMLElement | null>(null);
57
+ const timer = useRef<number | undefined>(undefined);
58
+ const open = useRef(false);
59
+ const tileRef = useRef<HTMLElement | null>(null);
60
+
61
+ const cancelPending = () => window.clearTimeout(timer.current);
62
+
63
+ const reset = () => {
64
+ cancelPending();
65
+ open.current = false;
66
+ setPeeking(false);
67
+ setTile(null);
68
+ };
69
+
70
+ const hold = () => {
71
+ cancelPending();
72
+ open.current = true;
73
+ setPeeking(true);
74
+ };
75
+
76
+ const scheduleOpen = (aside: HTMLElement, delayMs: number) => {
77
+ cancelPending();
78
+ if (open.current) return;
79
+ timer.current = window.setTimeout(() => {
80
+ open.current = true;
81
+ flushSync(() => setPeeking(true));
82
+ const panel = aside.querySelector<HTMLElement>(PANEL_SELECTOR);
83
+ if (panel && !panel.hasAttribute("data-sidebar-floating")) dockPopIn(panel, tileRef.current, "left");
84
+ }, delayMs);
85
+ };
86
+
87
+ const scheduleClose = (aside: HTMLElement) => {
88
+ cancelPending();
89
+ if (!open.current) return;
90
+ timer.current = window.setTimeout(() => {
91
+ if (aside.querySelector(OPEN_MENU_TRIGGER)) return;
92
+ const panel = aside.querySelector<HTMLElement>(PANEL_SELECTOR);
93
+ const card = panel?.querySelector<HTMLElement>("[data-sidebar-card]") ?? panel;
94
+ const arrow = panel?.querySelector<HTMLElement>("[data-dock-arrow]");
95
+ dockPopOut(card, tileRef.current, "left", reset, arrow);
96
+ }, CLOSE_DELAY_MS);
97
+ };
98
+
99
+ const onTile = (aside: HTMLElement, next: HTMLElement, delayMs: number) => {
100
+ tileRef.current = next;
101
+ setTile(next);
102
+ scheduleOpen(aside, delayMs);
103
+ };
104
+
105
+ const handlers: SidebarPeekHandlers = {
106
+ onPointerOver: (event) => {
107
+ const next = peekTile(event.target);
108
+ if (next) onTile(event.currentTarget, next, OPEN_DELAY_MS);
109
+ else if (inPanel(event.target)) cancelPending();
110
+ else scheduleClose(event.currentTarget);
111
+ },
112
+ onPointerLeave: (event) => scheduleClose(event.currentTarget),
113
+ onFocus: (event) => {
114
+ const next = peekTile(event.target);
115
+ if (next) onTile(event.currentTarget, next, 0);
116
+ else if (inPanel(event.target)) cancelPending();
117
+ },
118
+ onBlur: (event) => {
119
+ if (peekTile(event.relatedTarget) === null && !inPanel(event.relatedTarget)) {
120
+ scheduleClose(event.currentTarget);
121
+ }
122
+ },
123
+ };
124
+
125
+ const previewPath = peeking && tile instanceof HTMLAnchorElement ? tile.pathname : null;
126
+ const previewValue = peeking && tile ? tile.dataset.railPeek || null : null;
127
+
128
+ return { peeking, previewPath, previewValue, tile, handlers, reset, hold };
129
+ }
@@ -72,6 +72,7 @@ export type SidebarRailRootProps = ComponentPropsWithoutRef<"div"> & {
72
72
  export function Rail({ showDivider = false, className, ...props }: SidebarRailRootProps) {
73
73
  return (
74
74
  <div
75
+ data-sidebar-rail=""
75
76
  {...props}
76
77
  className={cn(
77
78
  "flex h-full w-[var(--app-shell-rail-width)] shrink-0 flex-col items-center bg-background",
@@ -178,6 +179,12 @@ type SidebarRailItemBaseProps = Omit<ComponentPropsWithoutRef<"button">, "childr
178
179
  badge?: ReactNode;
179
180
  asChild?: boolean;
180
181
  tabValue?: string;
182
+ /**
183
+ * Opens the unpinned panel on hover. On by default for links (`asChild`)
184
+ * and tabs (`tabValue`). A string is the `previewValue` `useSidebarPeek`
185
+ * reports for this item (default: `tabValue`).
186
+ */
187
+ peek?: boolean | string;
181
188
  };
182
189
 
183
190
  export type SidebarRailItemProps = SidebarRailItemBaseProps &
@@ -201,12 +208,15 @@ export function RailItem({
201
208
  badge,
202
209
  asChild = false,
203
210
  tabValue,
211
+ peek,
204
212
  className,
205
213
  app,
206
214
  children,
207
215
  ...props
208
216
  }: SidebarRailItemProps) {
209
217
  const grouped = use(RailGroupContext);
218
+ const peekValue =
219
+ typeof peek === "string" ? peek : (peek ?? (asChild || tabValue !== undefined)) ? (tabValue ?? "") : undefined;
210
220
  const stateClass = railTileStateClass(active, grouped);
211
221
  const groupMarks = grouped ? { "data-rail-tile": "", "data-active": active ? "" : undefined } : undefined;
212
222
  const AppIcon = app ? APP_ICONS[app] : null;
@@ -219,6 +229,7 @@ export function RailItem({
219
229
  {...props}
220
230
  value={tabValue}
221
231
  {...groupMarks}
232
+ data-rail-peek={peekValue}
222
233
  className={cn(railTileClass, "group relative", stateClass, className)}
223
234
  >
224
235
  {content}
@@ -231,6 +242,7 @@ export function RailItem({
231
242
  aria-label={label}
232
243
  aria-current={active ? "page" : undefined}
233
244
  {...groupMarks}
245
+ data-rail-peek={peekValue}
234
246
  className={cn(railTileClass, "group", stateClass, className)}
235
247
  >
236
248
  {appIcon}
@@ -243,6 +255,7 @@ export function RailItem({
243
255
  {...props}
244
256
  aria-label={label}
245
257
  {...groupMarks}
258
+ data-rail-peek={peekValue}
246
259
  className={cn(railTileClass, "group", stateClass, className)}
247
260
  >
248
261
  {content}
@@ -255,7 +268,10 @@ export function RailItem({
255
268
 
256
269
  export type RailTileProps = SidebarRailItemProps;
257
270
 
258
- /** Legacy name of `Sidebar.RailItem`. */
271
+ /**
272
+ * Legacy name of `Sidebar.RailItem`.
273
+ * @alias
274
+ */
259
275
  export const RailTile = RailItem;
260
276
 
261
277
  export type SidebarRailSeparatorProps = ComponentPropsWithoutRef<"div">;
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 { useSidebarPeek } from "../shell/src/SidebarPeek";
240
+ export type { SidebarPeek, SidebarPeekHandlers } from "../shell/src/SidebarPeek";
239
241
  export { DockArrow, useDockArrow } from "../shell/src/DockArrow";
240
242
  export type { DockArrowProps, UseDockArrowOptions } from "../shell/src/DockArrow";
241
243
  export { AppSidebar } from "../shell/src/AppSidebar";
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 { useSidebarPeek } from "../shell/src/SidebarPeek";
243
+ export type { SidebarPeek, SidebarPeekHandlers } from "../shell/src/SidebarPeek";
242
244
  export { DockArrow, useDockArrow } from "../shell/src/DockArrow";
243
245
  export type { DockArrowProps, UseDockArrowOptions } from "../shell/src/DockArrow";
244
246
  export { AppSidebar } from "../shell/src/AppSidebar";