@vvedantb/ui 0.56.0 → 0.58.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 +24 -1
- package/dist/shell/src/AppShell.js +156 -125
- package/dist/shell/src/ButtonTrack.js +57 -0
- package/dist/shell/src/SidePanelTabs.js +595 -0
- package/dist/shell/src/SidebarPanel.js +20 -15
- package/dist/shell/src/SidebarRail.js +43 -19
- package/dist/shell/src/index.js +4 -1
- package/dist/shell/src/shell-panel-motion.js +62 -0
- package/dist/shell/src/shell-variant.js +8 -0
- package/dist/src/client.js +6 -1
- package/dist/src/index.js +6 -1
- package/dist/src/motion/dock-motion.js +209 -0
- package/dist/tokens/src/css/motion.css +7 -1
- package/dist/tokens/src/css/tabs.css +4 -0
- package/dist/tokens/src/tokens.css +21 -0
- package/package.json +1 -1
- package/shell/src/AppShell.tsx +20 -15
- package/shell/src/ButtonTrack.tsx +26 -0
- package/shell/src/SidePanelTabs.tsx +380 -0
- package/shell/src/SidebarPanel.tsx +3 -0
- package/shell/src/SidebarRail.tsx +16 -3
- package/shell/src/index.ts +18 -2
- package/shell/src/shell-panel-motion.ts +64 -0
- package/shell/src/shell-variant.ts +20 -1
- package/src/client.ts +30 -1
- package/src/index.ts +30 -1
- package/src/motion/dock-motion.ts +188 -0
- package/tokens/src/css/motion.css +7 -1
- package/tokens/src/css/tabs.css +4 -0
- package/tokens/src/tokens.css +21 -0
|
@@ -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,7 +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 {
|
|
11
|
+
import { toggleShellPanel } from "./shell-panel-motion";
|
|
12
|
+
import { useAppShellPanelDock, useAppShellVariant } from "./shell-variant";
|
|
12
13
|
|
|
13
14
|
export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children" | "className"> & {
|
|
14
15
|
/** Pinned at the top, above the scroll body. */
|
|
@@ -314,16 +315,28 @@ export function RailDivider({ className }: RailDividerProps) {
|
|
|
314
315
|
return <RailSeparator className={className} />;
|
|
315
316
|
}
|
|
316
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
|
+
|
|
317
321
|
export type RailCollapseTileProps = {
|
|
318
322
|
/** Panel is collapsed: shows the expand icon and "Show sidebar". */
|
|
319
323
|
collapsed: boolean;
|
|
320
324
|
onToggle: () => void;
|
|
321
325
|
};
|
|
322
326
|
|
|
323
|
-
/**
|
|
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
|
+
*/
|
|
324
332
|
export function RailCollapseTile({ collapsed, onToggle }: RailCollapseTileProps) {
|
|
333
|
+
const dock = useAppShellPanelDock();
|
|
325
334
|
return (
|
|
326
|
-
<RailItem
|
|
335
|
+
<RailItem
|
|
336
|
+
label={collapsed ? "Show sidebar" : "Hide sidebar"}
|
|
337
|
+
onClick={dock ? () => toggleShellPanel(collapsed, onToggle) : onToggle}
|
|
338
|
+
{...(dock ? shellDockTileProps : undefined)}
|
|
339
|
+
>
|
|
327
340
|
{collapsed ? (
|
|
328
341
|
<IconLayoutSidebarLeftExpandFilled className="size-[22px]" />
|
|
329
342
|
) : (
|
package/shell/src/index.ts
CHANGED
|
@@ -22,12 +22,28 @@ export type {
|
|
|
22
22
|
AppShellSkipLinkProps,
|
|
23
23
|
} from "./AppShell.js";
|
|
24
24
|
export { useAppShellVariant } from "./shell-variant.js";
|
|
25
|
-
export type { AppShellVariant } from "./shell-variant.js";
|
|
25
|
+
export type { AppShellPanelMotion, AppShellVariant } from "./shell-variant.js";
|
|
26
|
+
export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "./shell-panel-motion.js";
|
|
27
|
+
export { ButtonTrack, buttonTrackClass } from "./ButtonTrack.js";
|
|
28
|
+
export type { ButtonTrackProps } from "./ButtonTrack.js";
|
|
29
|
+
export {
|
|
30
|
+
SidePanelTabs,
|
|
31
|
+
popOutSidePanel,
|
|
32
|
+
SIDE_PANEL_RAIL_WIDTH_PX,
|
|
33
|
+
SIDE_PANEL_RAIL_LABELLED_WIDTH_PX,
|
|
34
|
+
} from "./SidePanelTabs.js";
|
|
35
|
+
export type {
|
|
36
|
+
SidePanelTabLayout,
|
|
37
|
+
SidePanelTabsFrameProps,
|
|
38
|
+
SidePanelTabsListProps,
|
|
39
|
+
SidePanelTabsRailProps,
|
|
40
|
+
SidePanelTabsTabProps,
|
|
41
|
+
} from "./SidePanelTabs.js";
|
|
26
42
|
export { AppSidebar } from "./AppSidebar.js";
|
|
27
43
|
export type { AppSidebarProps } from "./AppSidebar.js";
|
|
28
44
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
29
45
|
export * from "./Sidebar.js";
|
|
30
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "./SidebarRail.js";
|
|
46
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "./SidebarRail.js";
|
|
31
47
|
export type { SidebarRailProps, RailTileProps, RailDividerProps, RailCollapseTileProps } from "./SidebarRail.js";
|
|
32
48
|
export { SidebarResizeHandle, useAppShellResize } from "./SidebarResize.js";
|
|
33
49
|
export type {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dock motion of the sidebar panel in an `AppShell variant="rail"`, on hide
|
|
3
|
+
* and show only: the panel shrinks into the rail's collapse tile and grows
|
|
4
|
+
* back out of it. `Sidebar.Panel` marks the panel and `RailCollapseTile` the
|
|
5
|
+
* tile (`shellDockTileProps` for a tile of your own). The main content slides
|
|
6
|
+
* its margin with the aside's width, so it does not jump.
|
|
7
|
+
*
|
|
8
|
+
* Off with `MotionProvider reducedMotion` and `PageMotionProvider disabled`
|
|
9
|
+
* (`dockMotionOff`), and outside the rail variant: the toggle runs at once.
|
|
10
|
+
*/
|
|
11
|
+
import { dockPopIn, dockPopOut, slideWith } from "../../src/motion/dock-motion";
|
|
12
|
+
|
|
13
|
+
function dockPanel(): HTMLElement | null {
|
|
14
|
+
if (typeof document === "undefined") return null;
|
|
15
|
+
return document.querySelector<HTMLElement>("[data-shell-dock-panel]");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function dockTile(): HTMLElement | null {
|
|
19
|
+
if (typeof document === "undefined") return null;
|
|
20
|
+
return document.querySelector<HTMLElement>("[data-shell-dock-tile]");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The page beside the shell aside: its left margin follows the aside. */
|
|
24
|
+
function slideMainWithAside() {
|
|
25
|
+
const tile = dockTile();
|
|
26
|
+
if (!tile) return;
|
|
27
|
+
const shell = tile.closest<HTMLElement>("[data-shell-variant]");
|
|
28
|
+
slideWith((shell ?? document).querySelector<HTMLElement>("main"), tile.closest<HTMLElement>("aside"), "margin-left");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Shrink the panel into the collapse tile, then run `hide`. */
|
|
32
|
+
export function popOutShellPanel(hide: () => void) {
|
|
33
|
+
dockPopOut(dockPanel(), dockTile(), "left", () => {
|
|
34
|
+
slideMainWithAside();
|
|
35
|
+
hide();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Call right after the state change that shows the panel. React shows it in
|
|
41
|
+
* this event's commit; the next frame runs before it paints.
|
|
42
|
+
*/
|
|
43
|
+
export function popInShellPanelNextFrame() {
|
|
44
|
+
if (typeof requestAnimationFrame !== "function") return;
|
|
45
|
+
slideMainWithAside();
|
|
46
|
+
requestAnimationFrame(() => {
|
|
47
|
+
const shown = dockPanel();
|
|
48
|
+
if (shown) dockPopIn(shown, dockTile(), "left");
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Show or hide the sidebar panel with the dock motion. `collapsed` is the
|
|
54
|
+
* state before the toggle; `toggle` flips it. For a hotkey or a context
|
|
55
|
+
* setter that does not go through `RailCollapseTile`.
|
|
56
|
+
*/
|
|
57
|
+
export function toggleShellPanel(collapsed: boolean, toggle: () => void) {
|
|
58
|
+
if (collapsed) {
|
|
59
|
+
toggle();
|
|
60
|
+
popInShellPanelNextFrame();
|
|
61
|
+
} else {
|
|
62
|
+
popOutShellPanel(toggle);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -7,6 +7,9 @@ import { createContext, use } from "react";
|
|
|
7
7
|
*/
|
|
8
8
|
export type AppShellVariant = "floating" | "rail";
|
|
9
9
|
|
|
10
|
+
/** How the sidebar panel hides and shows in the `"rail"` variant. */
|
|
11
|
+
export type AppShellPanelMotion = "dock" | "none";
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* The `variant` input of `AppShell` and `AppShell.Root`, as a union keyed on
|
|
12
15
|
* `variant`. An input that only one variant takes goes on that arm, with
|
|
@@ -16,8 +19,17 @@ export type AppShellVariantProps =
|
|
|
16
19
|
| {
|
|
17
20
|
/** Default `"floating"`. */
|
|
18
21
|
variant?: "floating";
|
|
22
|
+
panelMotion?: never;
|
|
19
23
|
}
|
|
20
|
-
| {
|
|
24
|
+
| {
|
|
25
|
+
variant: "rail";
|
|
26
|
+
/**
|
|
27
|
+
* Rail only. `"dock"` (default): `RailCollapseTile` shrinks the panel
|
|
28
|
+
* into the tile on hide and grows it back out on show. `"none"`: the
|
|
29
|
+
* panel shows and hides at once.
|
|
30
|
+
*/
|
|
31
|
+
panelMotion?: AppShellPanelMotion;
|
|
32
|
+
};
|
|
21
33
|
|
|
22
34
|
export const AppShellVariantContext = createContext<AppShellVariant>("floating");
|
|
23
35
|
|
|
@@ -25,3 +37,10 @@ export const AppShellVariantContext = createContext<AppShellVariant>("floating")
|
|
|
25
37
|
export function useAppShellVariant(): AppShellVariant {
|
|
26
38
|
return use(AppShellVariantContext);
|
|
27
39
|
}
|
|
40
|
+
|
|
41
|
+
export const AppShellPanelDockContext = createContext(false);
|
|
42
|
+
|
|
43
|
+
/** True inside an `AppShell variant="rail"` whose `panelMotion` is `"dock"`. */
|
|
44
|
+
export function useAppShellPanelDock(): boolean {
|
|
45
|
+
return use(AppShellPanelDockContext);
|
|
46
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -42,6 +42,17 @@ export type { BulkActionBarConfig, BulkActionBarProps, BulkBarAction, BulkBarLab
|
|
|
42
42
|
export { CopyLinkMenuItem } from "./ui/copy-link-menu-item";
|
|
43
43
|
export { ToggleSearch } from "./ui/toggle-search";
|
|
44
44
|
export type { ToggleSearchProps, ToggleSearchVariant } from "./ui/toggle-search";
|
|
45
|
+
export {
|
|
46
|
+
DOCK_MOTION_EVENT,
|
|
47
|
+
DockMotionEvent,
|
|
48
|
+
dockMotionOff,
|
|
49
|
+
dockNudge,
|
|
50
|
+
dockPopIn,
|
|
51
|
+
dockPopOut,
|
|
52
|
+
slideNextResize,
|
|
53
|
+
slideWith,
|
|
54
|
+
} from "./motion/dock-motion";
|
|
55
|
+
export type { DockEdge } from "./motion/dock-motion";
|
|
45
56
|
export { MotionProvider } from "./motion/motion-provider";
|
|
46
57
|
export { useReducedMotionSetting, type ReducedMotion } from "./motion/reduced-motion";
|
|
47
58
|
export { MarqueeOnHover } from "./ui/marquee-on-hover";
|
|
@@ -230,11 +241,29 @@ export type {
|
|
|
230
241
|
AppShellRootProps,
|
|
231
242
|
AppShellSkipLinkProps,
|
|
232
243
|
} from "../shell/src/AppShell";
|
|
244
|
+
export { useAppShellVariant } from "../shell/src/shell-variant";
|
|
245
|
+
export type { AppShellPanelMotion, AppShellVariant } from "../shell/src/shell-variant";
|
|
246
|
+
export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "../shell/src/shell-panel-motion";
|
|
247
|
+
export { ButtonTrack, buttonTrackClass } from "../shell/src/ButtonTrack";
|
|
248
|
+
export type { ButtonTrackProps } from "../shell/src/ButtonTrack";
|
|
249
|
+
export {
|
|
250
|
+
SidePanelTabs,
|
|
251
|
+
popOutSidePanel,
|
|
252
|
+
SIDE_PANEL_RAIL_WIDTH_PX,
|
|
253
|
+
SIDE_PANEL_RAIL_LABELLED_WIDTH_PX,
|
|
254
|
+
} from "../shell/src/SidePanelTabs";
|
|
255
|
+
export type {
|
|
256
|
+
SidePanelTabLayout,
|
|
257
|
+
SidePanelTabsFrameProps,
|
|
258
|
+
SidePanelTabsListProps,
|
|
259
|
+
SidePanelTabsRailProps,
|
|
260
|
+
SidePanelTabsTabProps,
|
|
261
|
+
} from "../shell/src/SidePanelTabs";
|
|
233
262
|
export { AppSidebar } from "../shell/src/AppSidebar";
|
|
234
263
|
export type { AppSidebarProps } from "../shell/src/AppSidebar";
|
|
235
264
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
236
265
|
export * from "../shell/src/Sidebar";
|
|
237
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail";
|
|
266
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail";
|
|
238
267
|
export type {
|
|
239
268
|
SidebarRailProps,
|
|
240
269
|
RailTileProps,
|
package/src/index.ts
CHANGED
|
@@ -38,6 +38,17 @@ export type { BulkActionBarConfig, BulkActionBarProps, BulkBarAction, BulkBarLab
|
|
|
38
38
|
export { CopyLinkMenuItem } from "./ui/copy-link-menu-item";
|
|
39
39
|
export { ToggleSearch } from "./ui/toggle-search";
|
|
40
40
|
export type { ToggleSearchProps, ToggleSearchVariant } from "./ui/toggle-search";
|
|
41
|
+
export {
|
|
42
|
+
DOCK_MOTION_EVENT,
|
|
43
|
+
DockMotionEvent,
|
|
44
|
+
dockMotionOff,
|
|
45
|
+
dockNudge,
|
|
46
|
+
dockPopIn,
|
|
47
|
+
dockPopOut,
|
|
48
|
+
slideNextResize,
|
|
49
|
+
slideWith,
|
|
50
|
+
} from "./motion/dock-motion";
|
|
51
|
+
export type { DockEdge } from "./motion/dock-motion";
|
|
41
52
|
export { MotionProvider } from "./motion/motion-provider";
|
|
42
53
|
export { useReducedMotionSetting, type ReducedMotion } from "./motion/reduced-motion";
|
|
43
54
|
export { MarqueeOnHover } from "./ui/marquee-on-hover";
|
|
@@ -231,11 +242,29 @@ export type {
|
|
|
231
242
|
AppShellScroll,
|
|
232
243
|
AppShellSkipLinkProps,
|
|
233
244
|
} from "../shell/src/AppShell";
|
|
245
|
+
export { useAppShellVariant } from "../shell/src/shell-variant";
|
|
246
|
+
export type { AppShellPanelMotion, AppShellVariant } from "../shell/src/shell-variant";
|
|
247
|
+
export { popInShellPanelNextFrame, popOutShellPanel, toggleShellPanel } from "../shell/src/shell-panel-motion";
|
|
248
|
+
export { ButtonTrack, buttonTrackClass } from "../shell/src/ButtonTrack";
|
|
249
|
+
export type { ButtonTrackProps } from "../shell/src/ButtonTrack";
|
|
250
|
+
export {
|
|
251
|
+
SidePanelTabs,
|
|
252
|
+
popOutSidePanel,
|
|
253
|
+
SIDE_PANEL_RAIL_WIDTH_PX,
|
|
254
|
+
SIDE_PANEL_RAIL_LABELLED_WIDTH_PX,
|
|
255
|
+
} from "../shell/src/SidePanelTabs";
|
|
256
|
+
export type {
|
|
257
|
+
SidePanelTabLayout,
|
|
258
|
+
SidePanelTabsFrameProps,
|
|
259
|
+
SidePanelTabsListProps,
|
|
260
|
+
SidePanelTabsRailProps,
|
|
261
|
+
SidePanelTabsTabProps,
|
|
262
|
+
} from "../shell/src/SidePanelTabs";
|
|
234
263
|
export { AppSidebar } from "../shell/src/AppSidebar";
|
|
235
264
|
export type { AppSidebarProps } from "../shell/src/AppSidebar";
|
|
236
265
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
237
266
|
export * from "../shell/src/Sidebar";
|
|
238
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail";
|
|
267
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, shellDockTileProps, useInRailGroup } from "../shell/src/SidebarRail";
|
|
239
268
|
export type {
|
|
240
269
|
SidebarRailProps,
|
|
241
270
|
RailTileProps,
|