@vvedantb/ui 0.55.0 → 0.57.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.
@@ -6,8 +6,9 @@ import {
6
6
  useSidebarResizeState,
7
7
  type SidebarResizeOptions,
8
8
  } from "./SidebarResize";
9
+ import { AppShellPanelDockContext, AppShellVariantContext, useAppShellVariant, type AppShellVariantProps } from "./shell-variant";
9
10
 
10
- export type AppShellProps = {
11
+ type AppShellBaseProps = {
11
12
  /** Rendered between the skip link and `<main>`, usually an `AppSidebar`. */
12
13
  sidebar?: ReactNode;
13
14
  children?: ReactNode;
@@ -45,6 +46,13 @@ export type AppShellProps = {
45
46
  contentClassName?: string;
46
47
  };
47
48
 
49
+ /**
50
+ * `variant` picks the layout: `"floating"` (default) or `"rail"`. Both take
51
+ * the same inputs, so an app switches with this one prop. The sidebar pieces
52
+ * inside (`SidebarRail`, `RailDivider`) read it from the shell.
53
+ */
54
+ export type AppShellProps = AppShellBaseProps & AppShellVariantProps;
55
+
48
56
  export type AppShellScroll = "contained" | "document";
49
57
 
50
58
  type ShellVars = CSSProperties & Record<`--app-shell-${string}`, string>;
@@ -58,7 +66,8 @@ const AppShellContext = createContext<AppShellContextValue>({
58
66
  });
59
67
 
60
68
  export type AppShellRootProps = ComponentProps<"div"> &
61
- Pick<AppShellProps, "panelHidden" | "railWidth" | "sidebarWidth" | "resizable" | "scroll" | "mobileHeaderHeight" | "mainId">;
69
+ Pick<AppShellBaseProps, "panelHidden" | "railWidth" | "sidebarWidth" | "resizable" | "scroll" | "mobileHeaderHeight" | "mainId"> &
70
+ AppShellVariantProps;
62
71
 
63
72
  /** Frame `<div>`: sets the `--app-shell-*` variables and owns the resize state. `style` merges over the variables. */
64
73
  function Root({
@@ -69,6 +78,8 @@ function Root({
69
78
  scroll = "contained",
70
79
  mobileHeaderHeight = "calc(3.5rem + env(safe-area-inset-top, 0px))",
71
80
  mainId = "main-content",
81
+ variant = "floating",
82
+ panelMotion,
72
83
  className,
73
84
  style,
74
85
  ...props
@@ -81,18 +92,23 @@ function Root({
81
92
  };
82
93
  return (
83
94
  <AppShellContext.Provider value={{ mainId, panelHidden, scroll }}>
84
- <SidebarResizeProvider value={resize}>
85
- <div
86
- {...props}
87
- className={cn(
88
- scroll === "document"
89
- ? "relative min-h-dvh bg-background"
90
- : "relative h-dvh overflow-hidden bg-background",
91
- className,
92
- )}
93
- style={{ ...vars, ...style }}
94
- />
95
- </SidebarResizeProvider>
95
+ <AppShellVariantContext value={variant}>
96
+ <AppShellPanelDockContext value={variant === "rail" && panelMotion !== "none"}>
97
+ <SidebarResizeProvider value={resize}>
98
+ <div
99
+ {...props}
100
+ data-shell-variant={variant === "rail" ? "rail" : undefined}
101
+ className={cn(
102
+ scroll === "document"
103
+ ? "relative min-h-dvh bg-background"
104
+ : "relative h-dvh overflow-hidden bg-background",
105
+ className,
106
+ )}
107
+ style={{ ...vars, ...style }}
108
+ />
109
+ </SidebarResizeProvider>
110
+ </AppShellPanelDockContext>
111
+ </AppShellVariantContext>
96
112
  </AppShellContext.Provider>
97
113
  );
98
114
  }
@@ -128,6 +144,7 @@ function Main({ id, className, ...props }: AppShellMainProps) {
128
144
  const { mainId, panelHidden, scroll } = useContext(AppShellContext);
129
145
  const pageScrolls = scroll === "document";
130
146
  const resize = useSidebarResizeContext();
147
+ const rail = useAppShellVariant() === "rail";
131
148
  return (
132
149
  <main
133
150
  id={id ?? mainId}
@@ -136,7 +153,7 @@ function Main({ id, className, ...props }: AppShellMainProps) {
136
153
  className={cn(
137
154
  pageScrolls
138
155
  ? "relative z-10 flex min-h-dvh outline-none"
139
- : "relative z-10 flex h-full min-h-0 outline-none md:p-2",
156
+ : cn("relative z-10 flex h-full min-h-0 outline-none", !rail && "md:p-2"),
140
157
  panelHidden ? "md:ml-[var(--app-shell-rail-width)]" : "md:ml-[var(--app-shell-sidebar-width)]",
141
158
  !pageScrolls &&
142
159
  !resize?.isResizing &&
@@ -149,16 +166,23 @@ function Main({ id, className, ...props }: AppShellMainProps) {
149
166
 
150
167
  export type AppShellContentProps = ComponentProps<"div">;
151
168
 
152
- /** Content card inside `<main>` (a plain column while the Root `scroll` is `"document"`). Pads for the mobile header below `md`. */
169
+ /**
170
+ * Content card inside `<main>`. A plain column, with no card, while the Root
171
+ * `scroll` is `"document"` or its `variant` is `"rail"`. Pads for the mobile
172
+ * header below `md`.
173
+ */
153
174
  function Content({ className, ...props }: AppShellContentProps) {
154
175
  const { scroll } = useContext(AppShellContext);
176
+ const rail = useAppShellVariant() === "rail";
155
177
  return (
156
178
  <div
157
179
  {...props}
158
180
  className={cn(
159
181
  scroll === "document"
160
182
  ? "flex min-w-0 flex-1 flex-col pt-[var(--app-shell-mobile-header-height)] md:pt-0"
161
- : "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface pt-[var(--app-shell-mobile-header-height)] md:rounded-lg md:pt-0",
183
+ : rail
184
+ ? "flex min-h-0 flex-1 flex-col overflow-hidden pt-[var(--app-shell-mobile-header-height)] md:pt-0"
185
+ : "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface pt-[var(--app-shell-mobile-header-height)] md:rounded-lg md:pt-0",
162
186
  className,
163
187
  )}
164
188
  />
@@ -181,10 +205,13 @@ function LegacyAppShell({
181
205
  mobileHeaderHeight,
182
206
  skipLinkLabel,
183
207
  mainId = "main-content",
208
+ variant = "floating",
209
+ panelMotion,
184
210
  className,
185
211
  mainClassName,
186
212
  contentClassName,
187
213
  }: AppShellProps) {
214
+ const layout: AppShellVariantProps = variant === "rail" ? { variant: "rail", panelMotion } : {};
188
215
  return (
189
216
  <Root
190
217
  panelHidden={panelHidden}
@@ -194,6 +221,7 @@ function LegacyAppShell({
194
221
  scroll={scroll}
195
222
  mobileHeaderHeight={mobileHeaderHeight}
196
223
  mainId={mainId}
224
+ {...layout}
197
225
  className={className}
198
226
  >
199
227
  <SkipLink label={skipLinkLabel} targetId={mainId} />
@@ -0,0 +1,26 @@
1
+ import type { ComponentPropsWithoutRef } from "react";
2
+ import { cn } from "../../src/utils/cn";
3
+
4
+ /**
5
+ * The trough of a `ButtonTrack`: the `Sidebar.RailGroup` tone as a row.
6
+ * Buttons on it are flat (the trough is their surface) and hover at half the
7
+ * pill tone. Empty, it takes no space.
8
+ */
9
+ export const buttonTrackClass =
10
+ "flex shrink-0 items-center gap-0.5 rounded-xl bg-default p-0.5 empty:hidden [&_button]:bg-transparent [&_button:not([data-active]):not(:disabled):hover]:bg-segment/50";
11
+
12
+ export type ButtonTrackProps = ComponentPropsWithoutRef<"div"> & {
13
+ /** `"column"` stacks the buttons from `md` up (a side rail). Default `"row"`. */
14
+ direction?: "row" | "column";
15
+ };
16
+
17
+ /** A group of icon buttons on one trough, for example the actions of a page header. */
18
+ export function ButtonTrack({ direction = "row", className, ...props }: ButtonTrackProps) {
19
+ return (
20
+ <div
21
+ role="group"
22
+ {...props}
23
+ className={cn(buttonTrackClass, direction === "column" ? "gap-1 md:flex-col" : "flex-wrap justify-end", className)}
24
+ />
25
+ );
26
+ }
@@ -0,0 +1,380 @@
1
+ import {
2
+ useLayoutEffect,
3
+ useRef,
4
+ type ComponentPropsWithoutRef,
5
+ type KeyboardEvent,
6
+ type MouseEvent,
7
+ type ReactNode,
8
+ type RefObject,
9
+ } from "react";
10
+ import { dockNudge, dockPopIn, dockPopOut } from "../../src/motion/dock-motion";
11
+ import { Tabs, TabsList, TabsTrigger } from "../../src/ui/tabs";
12
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../../src/ui/tooltip";
13
+ import { cn } from "../../src/utils/cn";
14
+
15
+ /** Width of the icon rail from `md` up. A collapsed side panel is this wide, not 0. */
16
+ export const SIDE_PANEL_RAIL_WIDTH_PX = 44;
17
+ /** Width of the rail with a label under each icon (`labelled`). */
18
+ export const SIDE_PANEL_RAIL_LABELLED_WIDTH_PX = 76;
19
+
20
+ /** Half the arrow's side (`size-4`), so its centre lands on the tab centre. */
21
+ const ARROW_HALF_PX = 8;
22
+
23
+ /* Relative to the frame, and scoped to its rail: content inside the card can
24
+ have tab lists of its own. */
25
+ const RAIL_TABLIST_SELECTOR = ':scope > [data-side-panel-rail] [role="tablist"]';
26
+ const ACTIVE_TAB_SELECTOR = `${RAIL_TABLIST_SELECTOR} [role="tab"][data-state="active"]`;
27
+ const CARD_SELECTOR = "[data-side-panel-card]";
28
+ const ARROW_SELECTOR = ":scope > [data-side-panel-arrow]";
29
+
30
+ function activeTabOf(card: HTMLElement): HTMLElement | null {
31
+ return card.parentElement?.querySelector<HTMLElement>(ACTIVE_TAB_SELECTOR) ?? null;
32
+ }
33
+
34
+ function arrowOf(card: HTMLElement): HTMLElement | null {
35
+ return card.parentElement?.querySelector<HTMLElement>(ARROW_SELECTOR) ?? null;
36
+ }
37
+
38
+ /**
39
+ * Closing a side panel: shrink the visible card in `root` back into its
40
+ * active tab, then run `collapse`. With no visible card, or motion off
41
+ * (`dockMotionOff`), it collapses at once.
42
+ */
43
+ export function popOutSidePanel(root: HTMLElement | null, collapse: () => void) {
44
+ const card = root?.querySelector<HTMLElement>(CARD_SELECTOR) ?? null;
45
+ dockPopOut(card, card ? activeTabOf(card) : null, "right", collapse, card ? arrowOf(card) : null);
46
+ }
47
+
48
+ /**
49
+ * Keeps the card's arrow level with the active rail tab, and plays the card's
50
+ * dock motion: pop in when the card appears, a settle when the active tab
51
+ * changes. It writes the transform straight to the node (no React state), as
52
+ * the tab pill does: the first placement snaps, later moves slide. The arrow
53
+ * hides when the active tab is scrolled out of the card's height. Measure
54
+ * before animating: a scaled card reports a scaled rect.
55
+ */
56
+ function useActiveTabArrow(
57
+ frameRef: RefObject<HTMLDivElement | null>,
58
+ cardRef: RefObject<HTMLDivElement | null>,
59
+ arrowRef: RefObject<HTMLDivElement | null>,
60
+ ) {
61
+ useLayoutEffect(() => {
62
+ const frame = frameRef.current;
63
+ const card = cardRef.current;
64
+ const arrow = arrowRef.current;
65
+ if (!frame || !card || !arrow) return;
66
+ let placed = false;
67
+ // Start from what is on screen, so a mount does not pop.
68
+ let wasOpen = card.getBoundingClientRect().width > 0;
69
+ let lastTab = frame.querySelector(ACTIVE_TAB_SELECTOR);
70
+ const sync = () => {
71
+ const tab = frame.querySelector<HTMLElement>(ACTIVE_TAB_SELECTOR);
72
+ const f = frame.getBoundingClientRect();
73
+ const c = card.getBoundingClientRect();
74
+ const open = c.width > 0;
75
+ const opened = open && !wasOpen;
76
+ const switched = open && wasOpen && tab !== null && tab !== lastTab;
77
+ wasOpen = open;
78
+ if (tab) lastTab = tab;
79
+ if (!tab || !open) {
80
+ arrow.style.opacity = "0";
81
+ placed = false;
82
+ return;
83
+ }
84
+ const t = tab.getBoundingClientRect();
85
+ const centre = t.top + t.height / 2;
86
+ const inCard = centre > c.top + 2 * ARROW_HALF_PX && centre < c.bottom - 2 * ARROW_HALF_PX;
87
+ if (!inCard) {
88
+ arrow.style.opacity = "0";
89
+ } else {
90
+ if (!placed) arrow.style.transition = "none";
91
+ arrow.style.left = `${c.right - f.left - ARROW_HALF_PX - 1}px`;
92
+ arrow.style.transform = `translateY(${centre - f.top - ARROW_HALF_PX}px) rotate(45deg)`;
93
+ arrow.style.opacity = "1";
94
+ if (!placed) {
95
+ void arrow.offsetWidth;
96
+ arrow.style.transition = "";
97
+ placed = true;
98
+ }
99
+ }
100
+ if (opened) dockPopIn(card, tab, "right", arrow);
101
+ else if (switched) dockNudge(card, tab, "right");
102
+ };
103
+ sync();
104
+ if (typeof ResizeObserver === "undefined") return;
105
+ const resize = new ResizeObserver(sync);
106
+ resize.observe(frame);
107
+ // The card un-hides without the frame changing size.
108
+ resize.observe(card);
109
+ const mutation = new MutationObserver(sync);
110
+ mutation.observe(frame, { subtree: true, attributes: true, attributeFilter: ["data-state"] });
111
+ const list = frame.querySelector(RAIL_TABLIST_SELECTOR);
112
+ if (list) resize.observe(list);
113
+ // Tabs can enter with a short slide and the list re-centres as tabs come
114
+ // and go, so measure again once each motion settles.
115
+ const settle = ["scroll", "animationend", "transitionend"] as const;
116
+ for (const type of settle) frame.addEventListener(type, sync, true);
117
+ return () => {
118
+ resize.disconnect();
119
+ mutation.disconnect();
120
+ for (const type of settle) frame.removeEventListener(type, sync, true);
121
+ };
122
+ }, [frameRef, cardRef, arrowRef]);
123
+ }
124
+
125
+ export type SidePanelTabsFrameProps = {
126
+ /** From `md` up: hides the card and leaves the rail. */
127
+ collapsed?: boolean;
128
+ /** The tab rail: a `SidePanelTabs.Rail`. */
129
+ rail: ReactNode;
130
+ /** The content of the active tab. */
131
+ children?: ReactNode;
132
+ className?: string;
133
+ /** Merged onto the content card (tone, radius, margins). */
134
+ cardClassName?: string;
135
+ /** Merged onto the arrow. Give it the card's tone when `cardClassName` changes it. */
136
+ arrowClassName?: string;
137
+ };
138
+
139
+ /**
140
+ * A side panel with its tabs on a rail. From `md` up: the rail on the right
141
+ * edge, the content a rounded card beside it with an arrow that points at the
142
+ * active tab; `collapsed` hides the card and the rail stays. Below `md`: a
143
+ * column, the tab strip on top and the content edge to edge. The card pops
144
+ * out of the active tab when it opens and settles on a tab switch; close it
145
+ * through `popOutSidePanel`.
146
+ */
147
+ function Frame({ collapsed = false, rail, children, className, cardClassName, arrowClassName }: SidePanelTabsFrameProps) {
148
+ const frameRef = useRef<HTMLDivElement>(null);
149
+ const cardRef = useRef<HTMLDivElement>(null);
150
+ const arrowRef = useRef<HTMLDivElement>(null);
151
+ useActiveTabArrow(frameRef, cardRef, arrowRef);
152
+ return (
153
+ <div ref={frameRef} className={cn("relative flex h-full min-h-0 flex-col md:flex-row-reverse", className)}>
154
+ {rail}
155
+ {/* The arrow comes before the card, and the card is positioned, so the
156
+ card paints over the arrow's inner half: only the tip shows. */}
157
+ <div
158
+ ref={arrowRef}
159
+ aria-hidden
160
+ data-side-panel-arrow=""
161
+ className={cn(
162
+ "t-side-panel-arrow pointer-events-none absolute top-0 hidden size-4 rounded-xs bg-surface opacity-0 md:block",
163
+ collapsed && "md:hidden",
164
+ arrowClassName,
165
+ )}
166
+ />
167
+ <div
168
+ ref={cardRef}
169
+ data-side-panel-card=""
170
+ className={cn(
171
+ "relative min-h-0 min-w-0 flex-1 overflow-hidden bg-surface md:my-2 md:mr-1.5 md:rounded-lg",
172
+ collapsed && "md:hidden",
173
+ cardClassName,
174
+ )}
175
+ >
176
+ {children}
177
+ </div>
178
+ </div>
179
+ );
180
+ }
181
+
182
+ export type SidePanelTabsRailProps = ComponentPropsWithoutRef<"div"> & {
183
+ /** The wider rail, for tabs with `layout="stacked"`. Default `false`. */
184
+ labelled?: boolean;
185
+ };
186
+
187
+ /** The rail column: holds a `SidePanelTabs.List`, and any `ButtonTrack` of tools after it. */
188
+ function Rail({ labelled = false, className, ...props }: SidePanelTabsRailProps) {
189
+ return (
190
+ <div
191
+ data-side-panel-rail=""
192
+ {...props}
193
+ className={cn(
194
+ "flex shrink-0 items-center gap-1 px-1.5 py-1 md:relative md:z-20 md:h-full md:w-11 md:flex-col md:items-center md:overflow-hidden md:px-1 md:pb-1.5 md:pt-3",
195
+ labelled && "md:w-[76px]",
196
+ className,
197
+ )}
198
+ />
199
+ );
200
+ }
201
+
202
+ export type SidePanelTabsListProps = {
203
+ value: string;
204
+ onValueChange: (value: string) => void;
205
+ /** Fills the wider rail, for tabs with `layout="stacked"`. Default `false`. */
206
+ labelled?: boolean;
207
+ /** Accessible name of the tab list. */
208
+ "aria-label"?: string;
209
+ /** Merged onto the tabs root. */
210
+ className?: string;
211
+ /** Merged onto the tab list (the trough). */
212
+ listClassName?: string;
213
+ /** `SidePanelTabs.Tab` items. */
214
+ children?: ReactNode;
215
+ };
216
+
217
+ /**
218
+ * The tabs of the rail on one trough with a sliding pill. Activation is
219
+ * manual: a tab selects on press, not on focus, so a press on the selected
220
+ * tab can mean something else (`onReselect`).
221
+ */
222
+ function List({ value, onValueChange, labelled = false, className, listClassName, children, ...props }: SidePanelTabsListProps) {
223
+ return (
224
+ <Tabs
225
+ activationMode="manual"
226
+ value={value}
227
+ onValueChange={onValueChange}
228
+ className={cn("min-w-0 flex-1 md:flex md:min-h-0 md:w-full md:flex-col md:items-center md:justify-center-safe", className)}
229
+ >
230
+ <TabsList
231
+ aria-label={props["aria-label"]}
232
+ className={cn(
233
+ "scrollbar-none h-auto max-w-full justify-start gap-1 overflow-x-auto rounded-xl border-0 bg-default p-0.5 shadow-none md:max-w-none md:flex-col md:overflow-x-hidden md:overflow-y-auto [&>.t-tabs-pill]:bg-segment",
234
+ labelled && "md:w-full",
235
+ listClassName,
236
+ )}
237
+ >
238
+ {children}
239
+ </TabsList>
240
+ </Tabs>
241
+ );
242
+ }
243
+
244
+ /**
245
+ * How one tab is arranged. `"icon"` (default): icon only from `md` up, the
246
+ * label in a tooltip. `"stacked"`: icon over label, for a `labelled` rail.
247
+ * `"row"`: icon beside label, for a phone strip.
248
+ */
249
+ export type SidePanelTabLayout = "row" | "icon" | "stacked";
250
+
251
+ const TAB_LAYOUT_CLASS: Record<SidePanelTabLayout, string> = {
252
+ row: "",
253
+ icon: "md:w-8 md:justify-center md:px-0",
254
+ stacked: "md:h-auto md:w-full md:flex-col md:justify-center md:gap-0.5 md:px-1 md:py-1.5",
255
+ };
256
+
257
+ /* Selection is Radix's `data-state` on the trigger, so the idle and active
258
+ icons swap in CSS. */
259
+ const ICON_SLOT_CLASS = "contents [&_svg]:size-4 [&_svg]:shrink-0";
260
+
261
+ export type SidePanelTabsTabProps = {
262
+ value: string;
263
+ label: string;
264
+ /** The icon. Without `activeIcon` its stroke thickens while the tab is selected. */
265
+ icon: ReactNode;
266
+ /** Shown in place of `icon` while the tab is selected (a filled variant). */
267
+ activeIcon?: ReactNode;
268
+ /** Default `"icon"`. */
269
+ layout?: SidePanelTabLayout;
270
+ /** How many items the tab holds. Above 0 it shows as a badge, in place of the `indicator` dot. */
271
+ count?: number;
272
+ /** A dot on the tab. `"activity"` pulses (something is live); `"content"` is still (something waits for the reader). */
273
+ indicator?: "activity" | "content";
274
+ /** Accessible name of the count badge or the dot. */
275
+ indicatorLabel?: string;
276
+ /** A press on this tab while it is selected (for example to show or hide the card). Radix skips `onValueChange` then. */
277
+ onReselect?: () => void;
278
+ /** Second tooltip line: what a press on the selected tab does. */
279
+ reselectHint?: string;
280
+ className?: string;
281
+ };
282
+
283
+ /* Radix selects a tab on mouse down (or Enter / Space key down), so read the
284
+ state there: by `click` a newly picked tab is already active. */
285
+ function isReselectPress(event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>) {
286
+ const press =
287
+ "button" in event
288
+ ? event.button === 0 && !event.ctrlKey
289
+ : !event.repeat && (event.key === "Enter" || event.key === " ");
290
+ return press && event.currentTarget.dataset.state === "active";
291
+ }
292
+
293
+ /** One tab of a `SidePanelTabs.List`. */
294
+ function Tab({
295
+ value,
296
+ label,
297
+ icon,
298
+ activeIcon,
299
+ layout = "icon",
300
+ count,
301
+ indicator,
302
+ indicatorLabel,
303
+ onReselect,
304
+ reselectHint,
305
+ className,
306
+ }: SidePanelTabsTabProps) {
307
+ const labelHidden = layout === "icon";
308
+ const shownCount = count !== undefined && count > 0 ? count : undefined;
309
+ const trigger = (
310
+ <TabsTrigger
311
+ value={value}
312
+ aria-label={labelHidden ? label : undefined}
313
+ className={cn(
314
+ "group/tab h-8 shrink-0 gap-1.5 px-2.5 text-xs data-[state=inactive]:text-muted-foreground data-[state=inactive]:hover:bg-segment/50 data-[state=inactive]:hover:text-foreground max-sm:h-10",
315
+ TAB_LAYOUT_CLASS[layout],
316
+ className,
317
+ )}
318
+ onMouseDown={(event) => {
319
+ if (isReselectPress(event)) onReselect?.();
320
+ }}
321
+ onKeyDown={(event) => {
322
+ if (isReselectPress(event)) onReselect?.();
323
+ }}
324
+ >
325
+ {activeIcon === undefined ? (
326
+ <span className={cn(ICON_SLOT_CLASS, "group-data-[state=active]/tab:[&_svg]:stroke-[2.75]")}>{icon}</span>
327
+ ) : (
328
+ <>
329
+ <span className={cn(ICON_SLOT_CLASS, "group-data-[state=active]/tab:hidden")}>{icon}</span>
330
+ <span className={cn(ICON_SLOT_CLASS, "hidden group-data-[state=active]/tab:contents")}>{activeIcon}</span>
331
+ </>
332
+ )}
333
+ {layout === "row" ? label : null}
334
+ {layout === "stacked" ? <span className="w-full truncate text-3xs leading-3">{label}</span> : null}
335
+ {shownCount !== undefined ? (
336
+ <span
337
+ aria-label={indicatorLabel}
338
+ className={cn(
339
+ "inline-flex h-3.5 min-w-3.5 shrink-0 items-center justify-center rounded-full bg-primary px-1 text-[9px] font-medium leading-none text-primary-foreground tabular-nums",
340
+ layout !== "row" && "absolute right-0 top-0",
341
+ )}
342
+ >
343
+ {shownCount > 99 ? "99+" : shownCount}
344
+ </span>
345
+ ) : indicator ? (
346
+ <span
347
+ aria-label={indicatorLabel}
348
+ className={cn(
349
+ "size-1.5 shrink-0 rounded-full bg-primary",
350
+ layout !== "row" && "absolute right-0.5 top-0.5",
351
+ indicator === "activity" && "animate-pulse ring-2 ring-primary/30",
352
+ )}
353
+ />
354
+ ) : null}
355
+ </TabsTrigger>
356
+ );
357
+ // A visible label needs no tooltip that repeats it.
358
+ if (!labelHidden) return trigger;
359
+ return (
360
+ <Tooltip>
361
+ <TooltipTrigger asChild>
362
+ {/* The span keeps the Tooltip `data-state` off the trigger: Radix
363
+ Tabs uses `data-state` for active and inactive. */}
364
+ <span className="inline-flex">{trigger}</span>
365
+ </TooltipTrigger>
366
+ <TooltipContent side="left" className="text-xs">
367
+ {label}
368
+ {reselectHint ? <span className="block opacity-70">{reselectHint}</span> : null}
369
+ </TooltipContent>
370
+ </Tooltip>
371
+ );
372
+ }
373
+
374
+ /**
375
+ * Tabs on a rail beside a content card, for a side panel: `SidePanelTabs.Frame`
376
+ * holds a `SidePanelTabs.Rail` (a `SidePanelTabs.List` of `SidePanelTabs.Tab`,
377
+ * then any `ButtonTrack direction="column"` of tools) and the content.
378
+ * It does not depend on the `AppShell` variant.
379
+ */
380
+ export const SidePanelTabs = { Frame, Rail, List, Tab };
@@ -15,6 +15,7 @@ import {
15
15
  sidebarNavItemTrailingClass,
16
16
  } from "./app-shell-classes";
17
17
  import { useOptionalSidebar } from "./SidebarChrome";
18
+ import { useAppShellPanelDock } from "./shell-variant";
18
19
 
19
20
  export type SidebarPanelProps = {
20
21
  title: string;
@@ -72,9 +73,11 @@ export type SidebarPanelRootProps = ComponentPropsWithoutRef<"div"> & {
72
73
  /** Panel column `<div>` beside the rail. */
73
74
  export function Panel({ collapsed, panelHidden, className, ...props }: SidebarPanelRootProps) {
74
75
  const sidebar = useOptionalSidebar();
76
+ const dock = useAppShellPanelDock();
75
77
  if (panelHidden ?? sidebar?.panelHidden ?? false) return null;
76
78
  return (
77
79
  <div
80
+ data-shell-dock-panel={dock ? "" : undefined}
78
81
  {...props}
79
82
  className={cn(
80
83
  // No border-r: the main content card floats beside this panel, so a
@@ -8,6 +8,8 @@ import type { ProductAppName } from "../../src/brand/AppWordmark";
8
8
  import { moveTabsPillXY } from "../../src/ui/tabsSliding";
9
9
  import { SIDEBAR_RAIL_APP_ICON_SIZE, railGroupClass, railGroupPillClass, railTileClass, railTileStateClass } from "./app-shell-classes";
10
10
  import { SidebarIconTooltip } from "./SidebarIconTooltip";
11
+ import { toggleShellPanel } from "./shell-panel-motion";
12
+ import { useAppShellPanelDock, useAppShellVariant } from "./shell-variant";
11
13
 
12
14
  export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children" | "className"> & {
13
15
  /** Pinned at the top, above the scroll body. */
@@ -16,7 +18,7 @@ export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children"
16
18
  children?: ReactNode;
17
19
  /** Pinned at the bottom. */
18
20
  footer?: ReactNode;
19
- /** Adds a right border between the rail and the panel. Default `false`. */
21
+ /** Adds a right border between the rail and the panel. Default `false`. No effect in an `AppShell variant="rail"`. */
20
22
  showDivider?: boolean;
21
23
  /** Render the body as its single child element (for example a tabs list), with the body classes merged. */
22
24
  bodyAsChild?: boolean;
@@ -38,6 +40,10 @@ export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children"
38
40
  * Legacy (still supported): the `top`, `footer`, `bodyAsChild`, `tabs` and
39
41
  * `*ClassName` props. Compose `Sidebar.Rail`, `.RailHeader`, `.RailBody` and
40
42
  * `.RailFooter` instead.
43
+ *
44
+ * In an `AppShell variant="rail"` each of `top`, the body and `footer` sits on
45
+ * its own `RailGroup` trough, and `showDivider` and `RailDivider` draw nothing.
46
+ * A `bodyAsChild` body is left as it is.
41
47
  */
42
48
  export function SidebarRail({
43
49
  top,
@@ -52,17 +58,22 @@ export function SidebarRail({
52
58
  footerClassName,
53
59
  ...props
54
60
  }: SidebarRailProps) {
61
+ const rail = useAppShellVariant() === "rail";
62
+ const slot = (node: ReactNode) => (rail ? <RailGroup className={railSlotGroupClass}>{node}</RailGroup> : node);
55
63
  return (
56
- <Rail {...props} showDivider={showDivider} className={className}>
57
- {top == null ? null : <RailHeader className={topClassName}>{top}</RailHeader>}
64
+ <Rail {...props} showDivider={showDivider && !rail} className={className}>
65
+ {top == null ? null : <RailHeader className={topClassName}>{slot(top)}</RailHeader>}
58
66
  <RailBody asChild={bodyAsChild} tabs={tabs} className={bodyClassName}>
59
- {children}
67
+ {bodyAsChild ? children : slot(children)}
60
68
  </RailBody>
61
- {footer == null ? null : <RailFooter className={footerClassName}>{footer}</RailFooter>}
69
+ {footer == null ? null : <RailFooter className={footerClassName}>{slot(footer)}</RailFooter>}
62
70
  </Rail>
63
71
  );
64
72
  }
65
73
 
74
+ /** A slot's trough hides while the slot renders nothing (the pill is then its only child). */
75
+ const railSlotGroupClass = "[&:not(:has(>:not([data-rail-pill])))]:hidden";
76
+
66
77
  export type SidebarRailRootProps = ComponentPropsWithoutRef<"div"> & {
67
78
  /** Adds a right border between the rail and the panel. Default `false`. */
68
79
  showDivider?: boolean;
@@ -169,7 +180,7 @@ export function RailGroup({ className, children, ...props }: SidebarRailGroupPro
169
180
  return (
170
181
  <RailGroupContext value>
171
182
  <div {...props} ref={groupRef} role="group" className={cn(railGroupClass, className)}>
172
- <span ref={pillRef} aria-hidden className={railGroupPillClass} />
183
+ <span ref={pillRef} aria-hidden data-rail-pill="" className={railGroupPillClass} />
173
184
  {children}
174
185
  </div>
175
186
  </RailGroupContext>
@@ -298,21 +309,34 @@ export function RailSeparator({ className, ...props }: SidebarRailSeparatorProps
298
309
 
299
310
  export type RailDividerProps = { className?: string };
300
311
 
301
- /** Legacy name of `Sidebar.RailSeparator`. */
312
+ /** Legacy name of `Sidebar.RailSeparator`. Draws nothing in an `AppShell variant="rail"`: the gap between troughs divides. */
302
313
  export function RailDivider({ className }: RailDividerProps) {
314
+ if (useAppShellVariant() === "rail") return null;
303
315
  return <RailSeparator className={className} />;
304
316
  }
305
317
 
318
+ /** Spread on the rail tile that the panel docks into, when it is not a `RailCollapseTile`. */
319
+ export const shellDockTileProps = { "data-shell-dock-tile": "" } as const;
320
+
306
321
  export type RailCollapseTileProps = {
307
322
  /** Panel is collapsed: shows the expand icon and "Show sidebar". */
308
323
  collapsed: boolean;
309
324
  onToggle: () => void;
310
325
  };
311
326
 
312
- /** Rail tile that shows or hides the sidebar panel. */
327
+ /**
328
+ * Rail tile that shows or hides the sidebar panel. In an `AppShell
329
+ * variant="rail"` (unless `panelMotion="none"`) the panel shrinks into this
330
+ * tile and grows back out of it (`toggleShellPanel`).
331
+ */
313
332
  export function RailCollapseTile({ collapsed, onToggle }: RailCollapseTileProps) {
333
+ const dock = useAppShellPanelDock();
314
334
  return (
315
- <RailItem label={collapsed ? "Show sidebar" : "Hide sidebar"} onClick={onToggle}>
335
+ <RailItem
336
+ label={collapsed ? "Show sidebar" : "Hide sidebar"}
337
+ onClick={dock ? () => toggleShellPanel(collapsed, onToggle) : onToggle}
338
+ {...(dock ? shellDockTileProps : undefined)}
339
+ >
316
340
  {collapsed ? (
317
341
  <IconLayoutSidebarLeftExpandFilled className="size-[22px]" />
318
342
  ) : (