@vvedantb/ui 0.50.2 → 0.51.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 +1 -0
- package/dist/shell/src/Sidebar.js +2 -1
- package/dist/shell/src/SidebarAccountMenu.js +23 -20
- package/dist/shell/src/SidebarRail.js +213 -65
- package/dist/shell/src/app-shell-classes.js +19 -1
- package/dist/shell/src/index.js +2 -2
- package/dist/src/client.js +2 -2
- package/dist/src/index.js +2 -2
- package/dist/src/ui/tabsSliding.js +2 -1
- package/package.json +4 -4
- package/shell/src/Sidebar.tsx +3 -1
- package/shell/src/SidebarAccountMenu.tsx +3 -1
- package/shell/src/SidebarRail.tsx +82 -5
- package/shell/src/app-shell-classes.ts +19 -1
- package/shell/src/index.ts +2 -1
- package/src/client.ts +2 -1
- package/src/index.ts +2 -1
- package/src/ui/tabsSliding.ts +2 -1
package/README.md
CHANGED
|
@@ -347,6 +347,7 @@ import {
|
|
|
347
347
|
- `RailTile`: `label` (`aria-label` and tooltip), `active`, `tooltip`, `showTooltip` (default `true`), `badge` (inside the tile, after the children; style it with `railBadgeClass`), `asChild`, `app`, `className`. Without `asChild` it is a native `<button type="button">` (0.5.3), so icons keep their authored size; other props go to it. With `asChild` the child (for example a router link) gets the tile classes and `aria-current="page"` when active.
|
|
348
348
|
- Rail app icon: the home `RailTile` icon is 24px across the apps (26px before 0.49.0), enforced by the tile. Pass `app="vmem"` (any `ProductAppName`) and the tile renders `APP_ICONS[app]` at `SIDEBAR_RAIL_APP_ICON_SIZE` (`24`). With `asChild` it goes inside the child (`<Link to="/" />`); without it, `children` are ignored. Tiles without `app` are unchanged: the tile renders the icon you pass, at its size. `Sidebar.MobileHeader` is the standard mobile bar: 56px plus safe-area, solid `bg-surface`, centred `text-base font-semibold tracking-tight` title, 20px menu icon.
|
|
349
349
|
- `RailDivider`, `SidebarIconTooltip` (`label`, `enabled`, `side` `"right"`, `sideOffset` 8).
|
|
350
|
+
- `Sidebar.RailGroup`: a trough (`railGroupClass`, `bg-default`) that holds rail tiles like segmented tabs; one `bg-segment` pill slides to the active tile (`data-active`) and hides when none is active. The gaps between groups divide them, so skip `RailSeparator` and `showDivider`. Centre a body group with `justify-center-safe` on `RailBody`. Custom tiles read `useInRailGroup()` and pass it to `railTileStateClass(active, grouped)`.
|
|
350
351
|
- `SidebarPanel`: legacy (still supported) `headerTrailing`, `onClose`, `closeLabel` and `closeButtonClassName`; compose `Sidebar.Panel` parts instead. `title`, `headerTrailing`, `onClose` (adds the close button; pass it on the mobile drawer only), `closeLabel`, `closeButtonClassName`, `collapsed` (`md:hidden`), `className`, `children`.
|
|
351
352
|
- `SidebarAccountMenu`: legacy (still supported) `badge`, `triggerProps`, `contentProps` and `stackedLabel`; compose `Sidebar.Account*` parts instead. `name`, `email` (two-line label when set), `stackedLabel` (two-line layout even without `email`, default `false`), `imageUrl` (initials without it), `align` (`"center"`), `side` (`"right"`), `sideOffset` (8), `collisionPadding`, `contentClassName`, `children` (menu items). 0.5.2 adds `badge` (unread dot beside the trigger, in a `relative` wrapper around the menu, so the trigger's dimming and press scale skip it: `true` shows it, `false` fades it out, omitted renders no wrapper and no dot), `triggerProps` (spread onto the trigger `Button` after the defaults; `className` merges last) and `contentProps` (spread onto `DropdownMenuContent`, for example `fitViewport` or `aria-label`; no `className`, use `contentClassName`). `SidebarAccountMenuPlaceholder` is the tile-sized loading box.
|
|
352
353
|
- `SignOutDialog`: legacy (still supported) `question` and `title`; compose `ConfirmDialog` parts with `alert={false}` for other copy. `open`, `onOpenChange` (not called with `false` while `pending`), `pending`, `onConfirm`, `description`, `contentClassName`, `title` (`"Sign out"`), `question` (`"Sign out of your account?"`).
|
|
@@ -2,7 +2,7 @@ import { SidebarChromeParts } from "./SidebarChrome.js";
|
|
|
2
2
|
import { SidebarIconTooltip } from "./SidebarIconTooltip.js";
|
|
3
3
|
import { AccountAvatar, AccountBadge, AccountContent, AccountLabel, AccountMenu, AccountSeparator, AccountTrigger } from "./SidebarAccountMenu.js";
|
|
4
4
|
import { NavItem, NavItemActions, NavItemLabel, NavItemLeading, NavItemTrailing, Panel, PanelActions, PanelClose, PanelHeader, PanelTitle } from "./SidebarPanel.js";
|
|
5
|
-
import { Rail, RailBody, RailFooter, RailHeader, RailItem, RailSeparator } from "./SidebarRail.js";
|
|
5
|
+
import { Rail, RailBody, RailFooter, RailGroup, RailHeader, RailItem, RailSeparator } from "./SidebarRail.js";
|
|
6
6
|
/**
|
|
7
7
|
* Composable sidebar parts. `Sidebar.Root` holds the drawer and layout state;
|
|
8
8
|
* the chrome, rail, panel and account parts read it. See the README
|
|
@@ -17,6 +17,7 @@ export const Sidebar = {
|
|
|
17
17
|
/** Alias of `RailFooter`. */
|
|
18
18
|
Footer: RailFooter,
|
|
19
19
|
RailItem,
|
|
20
|
+
RailGroup,
|
|
20
21
|
RailSeparator,
|
|
21
22
|
Tooltip: SidebarIconTooltip,
|
|
22
23
|
Panel,
|
|
@@ -7,6 +7,7 @@ import { Button } from "../../src/ui/button.js";
|
|
|
7
7
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "../../src/ui/dropdown-menu.js";
|
|
8
8
|
import { cn } from "../../src/utils/cn.js";
|
|
9
9
|
import { accountEmailClass, railTileClass, railTileStateClass } from "./app-shell-classes.js";
|
|
10
|
+
import { useInRailGroup } from "./SidebarRail.js";
|
|
10
11
|
import { SignOutDialog } from "./SignOutDialog.js";
|
|
11
12
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
12
13
|
/** Account menu on a rail tile: avatar trigger, identity label, then the app's items. Composed from `Sidebar.Account*` parts. */
|
|
@@ -380,7 +381,7 @@ function _temp(part) {
|
|
|
380
381
|
* A rail tile (`rounded-lg`), so `shape="rounded"`; change the radius with `className`.
|
|
381
382
|
*/
|
|
382
383
|
export function AccountTrigger(t0) {
|
|
383
|
-
const $ = _c(
|
|
384
|
+
const $ = _c(19);
|
|
384
385
|
let children;
|
|
385
386
|
let className;
|
|
386
387
|
let imageUrl;
|
|
@@ -407,31 +408,33 @@ export function AccountTrigger(t0) {
|
|
|
407
408
|
props = $[4];
|
|
408
409
|
userName = $[5];
|
|
409
410
|
}
|
|
411
|
+
const grouped = useInRailGroup();
|
|
410
412
|
const t1 = `Account menu for ${userName}`;
|
|
411
413
|
let t2;
|
|
412
|
-
if ($[6] !== className) {
|
|
413
|
-
t2 = cn(railTileClass, "h-11 w-11 p-0 md:h-10 md:w-10", railTileStateClass(false), className);
|
|
414
|
+
if ($[6] !== className || $[7] !== grouped) {
|
|
415
|
+
t2 = cn(railTileClass, "h-11 w-11 p-0 md:h-10 md:w-10", railTileStateClass(false, grouped), className);
|
|
414
416
|
$[6] = className;
|
|
415
|
-
$[7] =
|
|
417
|
+
$[7] = grouped;
|
|
418
|
+
$[8] = t2;
|
|
416
419
|
} else {
|
|
417
|
-
t2 = $[
|
|
420
|
+
t2 = $[8];
|
|
418
421
|
}
|
|
419
422
|
let t3;
|
|
420
|
-
if ($[
|
|
423
|
+
if ($[9] !== children || $[10] !== imageUrl || $[11] !== userName) {
|
|
421
424
|
t3 = children ?? /*#__PURE__*/_jsx(AccountAvatar, {
|
|
422
425
|
imageUrl: imageUrl,
|
|
423
426
|
userName: userName,
|
|
424
427
|
className: "h-7 w-7"
|
|
425
428
|
});
|
|
426
|
-
$[
|
|
427
|
-
$[
|
|
428
|
-
$[
|
|
429
|
-
$[
|
|
429
|
+
$[9] = children;
|
|
430
|
+
$[10] = imageUrl;
|
|
431
|
+
$[11] = userName;
|
|
432
|
+
$[12] = t3;
|
|
430
433
|
} else {
|
|
431
|
-
t3 = $[
|
|
434
|
+
t3 = $[12];
|
|
432
435
|
}
|
|
433
436
|
let t4;
|
|
434
|
-
if ($[
|
|
437
|
+
if ($[13] !== props || $[14] !== t1 || $[15] !== t2 || $[16] !== t3 || $[17] !== userName) {
|
|
435
438
|
t4 = /*#__PURE__*/_jsx(DropdownMenuTrigger, {
|
|
436
439
|
asChild: true,
|
|
437
440
|
children: /*#__PURE__*/_jsx(Button, {
|
|
@@ -445,14 +448,14 @@ export function AccountTrigger(t0) {
|
|
|
445
448
|
children: t3
|
|
446
449
|
})
|
|
447
450
|
});
|
|
448
|
-
$[
|
|
449
|
-
$[
|
|
450
|
-
$[
|
|
451
|
-
$[
|
|
452
|
-
$[
|
|
453
|
-
$[
|
|
454
|
-
} else {
|
|
455
|
-
t4 = $[
|
|
451
|
+
$[13] = props;
|
|
452
|
+
$[14] = t1;
|
|
453
|
+
$[15] = t2;
|
|
454
|
+
$[16] = t3;
|
|
455
|
+
$[17] = userName;
|
|
456
|
+
$[18] = t4;
|
|
457
|
+
} else {
|
|
458
|
+
t4 = $[18];
|
|
456
459
|
}
|
|
457
460
|
return t4;
|
|
458
461
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { createContext, use, useLayoutEffect, useRef } from "react";
|
|
2
3
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
3
4
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
5
|
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpandFilled } from "@tabler/icons-react";
|
|
5
6
|
import { cn } from "../../src/utils/cn.js";
|
|
6
7
|
import { APP_ICONS } from "../../src/brand/AppIcons.js";
|
|
7
|
-
import {
|
|
8
|
+
import { moveTabsPillXY } from "../../src/ui/tabsSliding.js";
|
|
9
|
+
import { SIDEBAR_RAIL_APP_ICON_SIZE, railGroupClass, railGroupPillClass, railTileClass, railTileStateClass } from "./app-shell-classes.js";
|
|
8
10
|
import { SidebarIconTooltip } from "./SidebarIconTooltip.js";
|
|
9
11
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
12
|
/**
|
|
@@ -283,6 +285,143 @@ export function RailBody(t0) {
|
|
|
283
285
|
}
|
|
284
286
|
return t4;
|
|
285
287
|
}
|
|
288
|
+
|
|
289
|
+
/** True inside a `RailGroup`: its tiles take the segmented fills. */
|
|
290
|
+
const RailGroupContext = /*#__PURE__*/createContext(false);
|
|
291
|
+
|
|
292
|
+
/** Whether the caller sits in a `Sidebar.RailGroup`. Custom rail tiles pass it to `railTileStateClass`. */
|
|
293
|
+
export function useInRailGroup() {
|
|
294
|
+
return use(RailGroupContext);
|
|
295
|
+
}
|
|
296
|
+
/** Marks the active `RailItem`, so its group's pill can find it. */
|
|
297
|
+
const ACTIVE_TILE_SELECTOR = "[data-rail-tile][data-active]";
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Keeps the group's pill under its active tile. The first placement and any
|
|
301
|
+
* resize snap; a change of active tile slides, as `TabsList` does. With no
|
|
302
|
+
* active tile the pill hides, and the next one snaps in rather than sliding
|
|
303
|
+
* from where the pill was last.
|
|
304
|
+
*/
|
|
305
|
+
function useRailGroupPill(groupRef, pillRef) {
|
|
306
|
+
const $ = _c(4);
|
|
307
|
+
let t0;
|
|
308
|
+
let t1;
|
|
309
|
+
if ($[0] !== groupRef || $[1] !== pillRef) {
|
|
310
|
+
t0 = () => {
|
|
311
|
+
const group = groupRef.current;
|
|
312
|
+
const pill = pillRef.current;
|
|
313
|
+
if (!group || !pill) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
let shown = false;
|
|
317
|
+
const sync = animate => {
|
|
318
|
+
const tile = group.querySelector(ACTIVE_TILE_SELECTOR);
|
|
319
|
+
if (!tile) {
|
|
320
|
+
pill.style.opacity = "0";
|
|
321
|
+
shown = false;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
moveTabsPillXY(pill, tile, animate && shown);
|
|
325
|
+
pill.style.opacity = "1";
|
|
326
|
+
shown = true;
|
|
327
|
+
};
|
|
328
|
+
sync(false);
|
|
329
|
+
const resizeObserver = new ResizeObserver(() => sync(false));
|
|
330
|
+
resizeObserver.observe(group);
|
|
331
|
+
const mutationObserver = new MutationObserver(() => sync(true));
|
|
332
|
+
mutationObserver.observe(group, {
|
|
333
|
+
subtree: true,
|
|
334
|
+
childList: true,
|
|
335
|
+
attributes: true,
|
|
336
|
+
attributeFilter: ["data-active"]
|
|
337
|
+
});
|
|
338
|
+
return () => {
|
|
339
|
+
resizeObserver.disconnect();
|
|
340
|
+
mutationObserver.disconnect();
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
t1 = [groupRef, pillRef];
|
|
344
|
+
$[0] = groupRef;
|
|
345
|
+
$[1] = pillRef;
|
|
346
|
+
$[2] = t0;
|
|
347
|
+
$[3] = t1;
|
|
348
|
+
} else {
|
|
349
|
+
t0 = $[2];
|
|
350
|
+
t1 = $[3];
|
|
351
|
+
}
|
|
352
|
+
useLayoutEffect(t0, t1);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A group of rail tiles on one shared trough, like segmented tabs: one pill
|
|
357
|
+
* slides to the active tile. Put groups in `RailHeader`, `RailBody` and
|
|
358
|
+
* `RailFooter`; the space between troughs divides them, so drop
|
|
359
|
+
* `RailSeparator` and `showDivider`. Centre a body group with
|
|
360
|
+
* `className="justify-center-safe"` on `RailBody`.
|
|
361
|
+
*/
|
|
362
|
+
export function RailGroup(t0) {
|
|
363
|
+
const $ = _c(11);
|
|
364
|
+
let children;
|
|
365
|
+
let className;
|
|
366
|
+
let props;
|
|
367
|
+
if ($[0] !== t0) {
|
|
368
|
+
({
|
|
369
|
+
className,
|
|
370
|
+
children,
|
|
371
|
+
...props
|
|
372
|
+
} = t0);
|
|
373
|
+
$[0] = t0;
|
|
374
|
+
$[1] = children;
|
|
375
|
+
$[2] = className;
|
|
376
|
+
$[3] = props;
|
|
377
|
+
} else {
|
|
378
|
+
children = $[1];
|
|
379
|
+
className = $[2];
|
|
380
|
+
props = $[3];
|
|
381
|
+
}
|
|
382
|
+
const groupRef = useRef(null);
|
|
383
|
+
const pillRef = useRef(null);
|
|
384
|
+
useRailGroupPill(groupRef, pillRef);
|
|
385
|
+
let t1;
|
|
386
|
+
if ($[4] !== className) {
|
|
387
|
+
t1 = cn(railGroupClass, className);
|
|
388
|
+
$[4] = className;
|
|
389
|
+
$[5] = t1;
|
|
390
|
+
} else {
|
|
391
|
+
t1 = $[5];
|
|
392
|
+
}
|
|
393
|
+
let t2;
|
|
394
|
+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
395
|
+
t2 = /*#__PURE__*/_jsx("span", {
|
|
396
|
+
ref: pillRef,
|
|
397
|
+
"aria-hidden": true,
|
|
398
|
+
className: railGroupPillClass
|
|
399
|
+
});
|
|
400
|
+
$[6] = t2;
|
|
401
|
+
} else {
|
|
402
|
+
t2 = $[6];
|
|
403
|
+
}
|
|
404
|
+
let t3;
|
|
405
|
+
if ($[7] !== children || $[8] !== props || $[9] !== t1) {
|
|
406
|
+
t3 = /*#__PURE__*/_jsx(RailGroupContext, {
|
|
407
|
+
value: true,
|
|
408
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
409
|
+
...props,
|
|
410
|
+
ref: groupRef,
|
|
411
|
+
role: "group",
|
|
412
|
+
className: t1,
|
|
413
|
+
children: [t2, children]
|
|
414
|
+
})
|
|
415
|
+
});
|
|
416
|
+
$[7] = children;
|
|
417
|
+
$[8] = props;
|
|
418
|
+
$[9] = t1;
|
|
419
|
+
$[10] = t3;
|
|
420
|
+
} else {
|
|
421
|
+
t3 = $[10];
|
|
422
|
+
}
|
|
423
|
+
return t3;
|
|
424
|
+
}
|
|
286
425
|
/** Block pinned at the bottom of the rail. */
|
|
287
426
|
export function RailFooter(t0) {
|
|
288
427
|
const $ = _c(8);
|
|
@@ -324,7 +463,7 @@ export function RailFooter(t0) {
|
|
|
324
463
|
}
|
|
325
464
|
/** Rail tile with a right-side tooltip. Renders a native `<button>`, its child with `asChild`, or a tabs trigger with `tabValue`. */
|
|
326
465
|
export function RailItem(t0) {
|
|
327
|
-
const $ = _c(
|
|
466
|
+
const $ = _c(30);
|
|
328
467
|
let app;
|
|
329
468
|
let badge;
|
|
330
469
|
let children;
|
|
@@ -378,74 +517,83 @@ export function RailItem(t0) {
|
|
|
378
517
|
const active = t1 === undefined ? false : t1;
|
|
379
518
|
const showTooltip = t2 === undefined ? true : t2;
|
|
380
519
|
const asChild = t3 === undefined ? false : t3;
|
|
381
|
-
const
|
|
520
|
+
const grouped = use(RailGroupContext);
|
|
382
521
|
let t4;
|
|
383
|
-
if ($[12] !==
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}) : /*#__PURE__*/_jsxs("button", {
|
|
414
|
-
type: "button",
|
|
415
|
-
...props,
|
|
416
|
-
"aria-label": label,
|
|
417
|
-
className: cn(railTileClass, "group", railTileStateClass(active), className),
|
|
418
|
-
children: [content, badge]
|
|
419
|
-
});
|
|
420
|
-
$[14] = active;
|
|
421
|
-
$[15] = appIcon;
|
|
422
|
-
$[16] = asChild;
|
|
423
|
-
$[17] = badge;
|
|
424
|
-
$[18] = children;
|
|
425
|
-
$[19] = className;
|
|
426
|
-
$[20] = content;
|
|
427
|
-
$[21] = label;
|
|
428
|
-
$[22] = props;
|
|
429
|
-
$[23] = tabValue;
|
|
430
|
-
$[24] = t6;
|
|
431
|
-
} else {
|
|
432
|
-
t6 = $[24];
|
|
433
|
-
}
|
|
434
|
-
let t7;
|
|
435
|
-
if ($[25] !== showTooltip || $[26] !== t5 || $[27] !== t6) {
|
|
436
|
-
t7 = /*#__PURE__*/_jsx(SidebarIconTooltip, {
|
|
437
|
-
label: t5,
|
|
522
|
+
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) {
|
|
523
|
+
const stateClass = railTileStateClass(active, grouped);
|
|
524
|
+
let t5;
|
|
525
|
+
if ($[25] !== active || $[26] !== grouped) {
|
|
526
|
+
t5 = grouped ? {
|
|
527
|
+
"data-rail-tile": "",
|
|
528
|
+
"data-active": active ? "" : undefined
|
|
529
|
+
} : undefined;
|
|
530
|
+
$[25] = active;
|
|
531
|
+
$[26] = grouped;
|
|
532
|
+
$[27] = t5;
|
|
533
|
+
} else {
|
|
534
|
+
t5 = $[27];
|
|
535
|
+
}
|
|
536
|
+
const groupMarks = t5;
|
|
537
|
+
const AppIcon = app ? APP_ICONS[app] : null;
|
|
538
|
+
let t6;
|
|
539
|
+
if ($[28] !== AppIcon) {
|
|
540
|
+
t6 = AppIcon ? /*#__PURE__*/_jsx(AppIcon, {
|
|
541
|
+
size: SIDEBAR_RAIL_APP_ICON_SIZE
|
|
542
|
+
}) : null;
|
|
543
|
+
$[28] = AppIcon;
|
|
544
|
+
$[29] = t6;
|
|
545
|
+
} else {
|
|
546
|
+
t6 = $[29];
|
|
547
|
+
}
|
|
548
|
+
const appIcon = t6;
|
|
549
|
+
const content = appIcon ?? children;
|
|
550
|
+
t4 = /*#__PURE__*/_jsx(SidebarIconTooltip, {
|
|
551
|
+
label: tooltip ?? label,
|
|
438
552
|
enabled: showTooltip,
|
|
439
|
-
children:
|
|
553
|
+
children: tabValue !== undefined ? /*#__PURE__*/_jsxs(TabsPrimitive.Trigger, {
|
|
554
|
+
...props,
|
|
555
|
+
value: tabValue,
|
|
556
|
+
...groupMarks,
|
|
557
|
+
className: cn(railTileClass, "group relative", stateClass, className),
|
|
558
|
+
children: [content, /*#__PURE__*/_jsx("span", {
|
|
559
|
+
className: "sr-only",
|
|
560
|
+
children: label
|
|
561
|
+
}), badge]
|
|
562
|
+
}) : asChild ? /*#__PURE__*/_jsxs(Slot, {
|
|
563
|
+
...props,
|
|
564
|
+
"aria-label": label,
|
|
565
|
+
"aria-current": active ? "page" : undefined,
|
|
566
|
+
...groupMarks,
|
|
567
|
+
className: cn(railTileClass, "group", stateClass, className),
|
|
568
|
+
children: [appIcon, /*#__PURE__*/_jsx(Slottable, {
|
|
569
|
+
children: children
|
|
570
|
+
}), badge]
|
|
571
|
+
}) : /*#__PURE__*/_jsxs("button", {
|
|
572
|
+
type: "button",
|
|
573
|
+
...props,
|
|
574
|
+
"aria-label": label,
|
|
575
|
+
...groupMarks,
|
|
576
|
+
className: cn(railTileClass, "group", stateClass, className),
|
|
577
|
+
children: [content, badge]
|
|
578
|
+
})
|
|
440
579
|
});
|
|
441
|
-
$[
|
|
442
|
-
$[
|
|
443
|
-
$[
|
|
444
|
-
$[
|
|
580
|
+
$[12] = active;
|
|
581
|
+
$[13] = app;
|
|
582
|
+
$[14] = asChild;
|
|
583
|
+
$[15] = badge;
|
|
584
|
+
$[16] = children;
|
|
585
|
+
$[17] = className;
|
|
586
|
+
$[18] = grouped;
|
|
587
|
+
$[19] = label;
|
|
588
|
+
$[20] = props;
|
|
589
|
+
$[21] = showTooltip;
|
|
590
|
+
$[22] = tabValue;
|
|
591
|
+
$[23] = tooltip;
|
|
592
|
+
$[24] = t4;
|
|
445
593
|
} else {
|
|
446
|
-
|
|
594
|
+
t4 = $[24];
|
|
447
595
|
}
|
|
448
|
-
return
|
|
596
|
+
return t4;
|
|
449
597
|
}
|
|
450
598
|
/** Legacy name of `Sidebar.RailItem`. */
|
|
451
599
|
export const RailTile = RailItem;
|
|
@@ -13,10 +13,28 @@ export const railTileClass = "relative flex size-11 md:size-10 items-center just
|
|
|
13
13
|
const railTileActiveClass = "border-transparent bg-surface-tertiary text-foreground";
|
|
14
14
|
const railTileIdleClass = "border-transparent text-muted opacity-75 hover:bg-surface-tertiary/50 hover:opacity-100 hover:text-foreground"; // check-tokens-allow: text-muted
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// Inside a `RailGroup` the tiles read as segmented tabs: the trough is
|
|
17
|
+
// `--default` (the segmented bar) and the group's sliding `--segment` pill sits
|
|
18
|
+
// under the active tile, so the tile itself has no fill. Hover is the pill at
|
|
19
|
+
// half strength, as on `.t-tabs--pills`. `z-1` lifts tiles over the pill.
|
|
20
|
+
const railTileGroupActiveClass = "z-1 border-transparent bg-transparent text-segment-foreground";
|
|
21
|
+
const railTileGroupIdleClass = "z-1 border-transparent text-muted opacity-75 hover:bg-segment/50 hover:opacity-100 hover:text-foreground"; // check-tokens-allow: text-muted
|
|
22
|
+
|
|
23
|
+
/** Tile fill for its state. `grouped`: the tile sits in a `Sidebar.RailGroup` trough. */
|
|
24
|
+
export function railTileStateClass(active, grouped = false) {
|
|
25
|
+
if (grouped) return active ? railTileGroupActiveClass : railTileGroupIdleClass;
|
|
17
26
|
return active ? railTileActiveClass : railTileIdleClass;
|
|
18
27
|
}
|
|
19
28
|
|
|
29
|
+
/**
|
|
30
|
+
* `Sidebar.RailGroup` trough: the segmented tabs bar (`bg-default`) as a column.
|
|
31
|
+
* 4px padding and a 12px radius sit concentric with the 8px tile corners.
|
|
32
|
+
*/
|
|
33
|
+
export const railGroupClass = "relative isolate flex flex-col items-center gap-1 rounded-xl bg-default p-1";
|
|
34
|
+
|
|
35
|
+
/** The `RailGroup` sliding pill: the segmented tabs pill, with the tile radius. */
|
|
36
|
+
export const railGroupPillClass = "t-tabs-pill rounded-lg bg-segment";
|
|
37
|
+
|
|
20
38
|
/** Count badge pinned to the bottom-right of a rail tile. */
|
|
21
39
|
export const railBadgeClass = "absolute -bottom-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-accent px-1 text-[10px] font-semibold leading-none text-accent-foreground"; // check-tokens-allow: accent
|
|
22
40
|
|
package/dist/shell/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { AppShell } from "./AppShell.js";
|
|
|
7
7
|
export { AppSidebar } from "./AppSidebar.js";
|
|
8
8
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
9
9
|
export * from "./Sidebar.js";
|
|
10
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "./SidebarRail.js";
|
|
10
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "./SidebarRail.js";
|
|
11
11
|
export { SidebarResizeHandle, useAppShellResize } from "./SidebarResize.js";
|
|
12
12
|
export { SidebarIconTooltip } from "./SidebarIconTooltip.js";
|
|
13
13
|
export { SidebarPanel } from "./SidebarPanel.js";
|
|
@@ -15,4 +15,4 @@ export { SidebarAccountMenu, SidebarAccountMenuPlaceholder } from "./SidebarAcco
|
|
|
15
15
|
export { SignOutDialog } from "./SignOutDialog.js";
|
|
16
16
|
export { PageHeaderBar } from "./PageHeaderBar.js";
|
|
17
17
|
export { PageWrapper } from "./PageWrapper.js";
|
|
18
|
-
export { railBadgeClass, railTileClass, SIDEBAR_RAIL_APP_ICON_SIZE, railTileStateClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemSubtitleClass, sidebarNavItemTrailingClass, sidebarNavLinkTextClass, sidebarNavRowClass, sidebarSectionLabelClass } from "./app-shell-classes.js";
|
|
18
|
+
export { railBadgeClass, railTileClass, SIDEBAR_RAIL_APP_ICON_SIZE, railTileStateClass, railGroupClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemSubtitleClass, sidebarNavItemTrailingClass, sidebarNavLinkTextClass, sidebarNavRowClass, sidebarSectionLabelClass } from "./app-shell-classes.js";
|
package/dist/src/client.js
CHANGED
|
@@ -173,7 +173,7 @@ export { AppShell } from "../shell/src/AppShell.js";
|
|
|
173
173
|
export { AppSidebar } from "../shell/src/AppSidebar.js";
|
|
174
174
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
175
175
|
export * from "../shell/src/Sidebar.js";
|
|
176
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "../shell/src/SidebarRail.js";
|
|
176
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail.js";
|
|
177
177
|
export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize.js";
|
|
178
178
|
export { SidebarIconTooltip } from "../shell/src/SidebarIconTooltip.js";
|
|
179
179
|
export { SidebarPanel } from "../shell/src/SidebarPanel.js";
|
|
@@ -181,7 +181,7 @@ export { SidebarAccountMenu, SidebarAccountMenuPlaceholder } from "../shell/src/
|
|
|
181
181
|
export { SignOutDialog } from "../shell/src/SignOutDialog.js";
|
|
182
182
|
export { PageHeaderBar } from "../shell/src/PageHeaderBar.js";
|
|
183
183
|
export { PageWrapper } from "../shell/src/PageWrapper.js";
|
|
184
|
-
export { railBadgeClass, railTileClass, SIDEBAR_RAIL_APP_ICON_SIZE, railTileStateClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemSubtitleClass, sidebarNavItemTrailingClass, sidebarNavLinkTextClass, sidebarNavRowClass, sidebarSectionLabelClass } from "../shell/src/app-shell-classes.js";
|
|
184
|
+
export { railBadgeClass, railTileClass, SIDEBAR_RAIL_APP_ICON_SIZE, railTileStateClass, railGroupClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemSubtitleClass, sidebarNavItemTrailingClass, sidebarNavLinkTextClass, sidebarNavRowClass, sidebarSectionLabelClass } from "../shell/src/app-shell-classes.js";
|
|
185
185
|
// Marketing: landing kit, site footer and pricing dialog. Router- and Motion-free;
|
|
186
186
|
// `createLandingKit` takes the app's `motion`. Styles: `@vvedantb/ui/landing.css`.
|
|
187
187
|
export { LandingFeatureCard, LandingFooter, LandingLattice, LandingNavMenu, LandingPageLayout, LandingSection, LandingSectionHeading, landingItemVariants } from "./marketing/landing.js";
|
package/dist/src/index.js
CHANGED
|
@@ -173,7 +173,7 @@ export { AppShell } from "../shell/src/AppShell.js";
|
|
|
173
173
|
export { AppSidebar } from "../shell/src/AppSidebar.js";
|
|
174
174
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
175
175
|
export * from "../shell/src/Sidebar.js";
|
|
176
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "../shell/src/SidebarRail.js";
|
|
176
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail.js";
|
|
177
177
|
export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize.js";
|
|
178
178
|
export { SidebarIconTooltip } from "../shell/src/SidebarIconTooltip.js";
|
|
179
179
|
export { SidebarPanel } from "../shell/src/SidebarPanel.js";
|
|
@@ -181,7 +181,7 @@ export { SidebarAccountMenu, SidebarAccountMenuPlaceholder } from "../shell/src/
|
|
|
181
181
|
export { SignOutDialog } from "../shell/src/SignOutDialog.js";
|
|
182
182
|
export { PageHeaderBar } from "../shell/src/PageHeaderBar.js";
|
|
183
183
|
export { PageWrapper } from "../shell/src/PageWrapper.js";
|
|
184
|
-
export { railBadgeClass, railTileClass, SIDEBAR_RAIL_APP_ICON_SIZE, railTileStateClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemSubtitleClass, sidebarNavItemTrailingClass, sidebarNavLinkTextClass, sidebarNavRowClass, sidebarSectionLabelClass } from "../shell/src/app-shell-classes.js";
|
|
184
|
+
export { railBadgeClass, railTileClass, SIDEBAR_RAIL_APP_ICON_SIZE, railTileStateClass, railGroupClass, sidebarNavIconClass, sidebarNavItemActionsClass, sidebarNavItemClass, sidebarNavItemIndentStyle, sidebarNavItemLabelClass, sidebarNavItemLeadingClass, sidebarNavItemSubtitleClass, sidebarNavItemTrailingClass, sidebarNavLinkTextClass, sidebarNavRowClass, sidebarSectionLabelClass } from "../shell/src/app-shell-classes.js";
|
|
185
185
|
// Marketing: landing kit, site footer and pricing dialog. Router- and Motion-free;
|
|
186
186
|
// `createLandingKit` takes the app's `motion`. Styles: `@vvedantb/ui/landing.css`.
|
|
187
187
|
export { LandingFeatureCard, LandingFooter, LandingLattice, LandingNavMenu, LandingPageLayout, LandingSection, LandingSectionHeading, landingItemVariants } from "./marketing/landing.js";
|
|
@@ -15,7 +15,8 @@ function findActiveTab(list) {
|
|
|
15
15
|
|
|
16
16
|
// `xy`: both axes on transform (top pinned to 0), so a column list slides the
|
|
17
17
|
// same way a row does; `top` is a layout property and does not tween.
|
|
18
|
-
|
|
18
|
+
// Exported for other sliding pills (`Sidebar.RailGroup`).
|
|
19
|
+
export function moveTabsPillXY(pill, tab, animate) {
|
|
19
20
|
const transform = `translate(${tab.offsetLeft}px, ${tab.offsetTop}px)`;
|
|
20
21
|
const width = `${tab.offsetWidth}px`;
|
|
21
22
|
const height = `${tab.offsetHeight}px`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.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",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"@streamdown/mermaid": "*",
|
|
137
137
|
"@tabler/icons-react": "^3.35.0",
|
|
138
138
|
"@tanstack/react-hotkeys": "*",
|
|
139
|
-
"@vvedantb/server": ">=0.17.
|
|
139
|
+
"@vvedantb/server": ">=0.17.1",
|
|
140
140
|
"ai": ">=5.0.0",
|
|
141
141
|
"class-variance-authority": "^0.7.1",
|
|
142
142
|
"clsx": "^2.1.1",
|
|
@@ -214,7 +214,7 @@
|
|
|
214
214
|
"vitest": "^3.2.0",
|
|
215
215
|
"zod": "^4.0.0",
|
|
216
216
|
"zod3": "npm:zod@^3.25.76",
|
|
217
|
-
"@vvedantb/server": "0.17.
|
|
217
|
+
"@vvedantb/server": "0.17.1"
|
|
218
218
|
},
|
|
219
219
|
"peerDependenciesMeta": {
|
|
220
220
|
"@clerk/clerk-react": {
|
|
@@ -246,7 +246,7 @@
|
|
|
246
246
|
"check:client-graph": "node scripts/check-client-graph.mjs",
|
|
247
247
|
"check:tokens": "node tokens/scripts/check-component-tokens.mjs",
|
|
248
248
|
"build": "node scripts/build-dist.mjs && node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
|
|
249
|
-
"typecheck": "
|
|
249
|
+
"typecheck": "tsrs --noEmit --fast -p tsconfig.json && tsrs --noEmit --fast -p tsconfig.consumer.json && tsrs --noEmit --fast -p tsconfig.consumer-speech.json && tsrs --noEmit --fast -p tokens/tsconfig.json",
|
|
250
250
|
"test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
|
|
251
251
|
"verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
|
|
252
252
|
"analyze": "node tokens/verify/analyze.mjs",
|
package/shell/src/Sidebar.tsx
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
PanelHeader,
|
|
22
22
|
PanelTitle,
|
|
23
23
|
} from "./SidebarPanel";
|
|
24
|
-
import { Rail, RailBody, RailFooter, RailHeader, RailItem, RailSeparator } from "./SidebarRail";
|
|
24
|
+
import { Rail, RailBody, RailFooter, RailGroup, RailHeader, RailItem, RailSeparator } from "./SidebarRail";
|
|
25
25
|
|
|
26
26
|
export type {
|
|
27
27
|
SidebarAsideProps,
|
|
@@ -36,6 +36,7 @@ export type {
|
|
|
36
36
|
export type {
|
|
37
37
|
SidebarRailBodyProps,
|
|
38
38
|
SidebarRailFooterProps,
|
|
39
|
+
SidebarRailGroupProps,
|
|
39
40
|
SidebarRailHeaderProps,
|
|
40
41
|
SidebarRailItemProps,
|
|
41
42
|
SidebarRailRootProps,
|
|
@@ -74,6 +75,7 @@ export const Sidebar = {
|
|
|
74
75
|
/** Alias of `RailFooter`. */
|
|
75
76
|
Footer: RailFooter,
|
|
76
77
|
RailItem,
|
|
78
|
+
RailGroup,
|
|
77
79
|
RailSeparator,
|
|
78
80
|
Tooltip: SidebarIconTooltip,
|
|
79
81
|
Panel,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "../../src/ui/dropdown-menu";
|
|
14
14
|
import { cn } from "../../src/utils/cn";
|
|
15
15
|
import { accountEmailClass, railTileClass, railTileStateClass } from "./app-shell-classes";
|
|
16
|
+
import { useInRailGroup } from "./SidebarRail";
|
|
16
17
|
import { SignOutDialog } from "./SignOutDialog";
|
|
17
18
|
|
|
18
19
|
type ContentProps = ComponentPropsWithoutRef<typeof DropdownMenuContent>;
|
|
@@ -249,6 +250,7 @@ export type SidebarAccountTriggerProps = Omit<ButtonProps, "asChild" | "shape">
|
|
|
249
250
|
* A rail tile (`rounded-lg`), so `shape="rounded"`; change the radius with `className`.
|
|
250
251
|
*/
|
|
251
252
|
export function AccountTrigger({ userName, imageUrl, className, children, ...props }: SidebarAccountTriggerProps) {
|
|
253
|
+
const grouped = useInRailGroup();
|
|
252
254
|
return (
|
|
253
255
|
<DropdownMenuTrigger asChild>
|
|
254
256
|
<Button
|
|
@@ -258,7 +260,7 @@ export function AccountTrigger({ userName, imageUrl, className, children, ...pro
|
|
|
258
260
|
title={userName}
|
|
259
261
|
aria-label={`Account menu for ${userName}`}
|
|
260
262
|
{...props}
|
|
261
|
-
className={cn(railTileClass, "h-11 w-11 p-0 md:h-10 md:w-10", railTileStateClass(false), className)}
|
|
263
|
+
className={cn(railTileClass, "h-11 w-11 p-0 md:h-10 md:w-10", railTileStateClass(false, grouped), className)}
|
|
262
264
|
>
|
|
263
265
|
{children ?? <AccountAvatar imageUrl={imageUrl} userName={userName} className="h-7 w-7" />}
|
|
264
266
|
</Button>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { createContext, use, useLayoutEffect, useRef, type ComponentPropsWithoutRef, type ReactNode, type RefObject } from "react";
|
|
2
2
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
3
3
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
4
|
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpandFilled } from "@tabler/icons-react";
|
|
5
5
|
import { cn } from "../../src/utils/cn";
|
|
6
6
|
import { APP_ICONS } from "../../src/brand/AppIcons";
|
|
7
7
|
import type { ProductAppName } from "../../src/brand/AppWordmark";
|
|
8
|
-
import {
|
|
8
|
+
import { moveTabsPillXY } from "../../src/ui/tabsSliding";
|
|
9
|
+
import { SIDEBAR_RAIL_APP_ICON_SIZE, railGroupClass, railGroupPillClass, railTileClass, railTileStateClass } from "./app-shell-classes";
|
|
9
10
|
import { SidebarIconTooltip } from "./SidebarIconTooltip";
|
|
10
11
|
|
|
11
12
|
export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children" | "className"> & {
|
|
@@ -106,6 +107,75 @@ export function RailBody({ asChild = false, tabs = false, className, ...props }:
|
|
|
106
107
|
return <Body {...props} className={bodyClass} />;
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
/** True inside a `RailGroup`: its tiles take the segmented fills. */
|
|
111
|
+
const RailGroupContext = createContext(false);
|
|
112
|
+
|
|
113
|
+
/** Whether the caller sits in a `Sidebar.RailGroup`. Custom rail tiles pass it to `railTileStateClass`. */
|
|
114
|
+
export function useInRailGroup(): boolean {
|
|
115
|
+
return use(RailGroupContext);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type SidebarRailGroupProps = ComponentPropsWithoutRef<"div">;
|
|
119
|
+
|
|
120
|
+
/** Marks the active `RailItem`, so its group's pill can find it. */
|
|
121
|
+
const ACTIVE_TILE_SELECTOR = "[data-rail-tile][data-active]";
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Keeps the group's pill under its active tile. The first placement and any
|
|
125
|
+
* resize snap; a change of active tile slides, as `TabsList` does. With no
|
|
126
|
+
* active tile the pill hides, and the next one snaps in rather than sliding
|
|
127
|
+
* from where the pill was last.
|
|
128
|
+
*/
|
|
129
|
+
function useRailGroupPill(groupRef: RefObject<HTMLDivElement | null>, pillRef: RefObject<HTMLSpanElement | null>) {
|
|
130
|
+
useLayoutEffect(() => {
|
|
131
|
+
const group = groupRef.current;
|
|
132
|
+
const pill = pillRef.current;
|
|
133
|
+
if (!group || !pill) return;
|
|
134
|
+
let shown = false;
|
|
135
|
+
const sync = (animate: boolean) => {
|
|
136
|
+
const tile = group.querySelector<HTMLElement>(ACTIVE_TILE_SELECTOR);
|
|
137
|
+
if (!tile) {
|
|
138
|
+
pill.style.opacity = "0";
|
|
139
|
+
shown = false;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
moveTabsPillXY(pill, tile, animate && shown);
|
|
143
|
+
pill.style.opacity = "1";
|
|
144
|
+
shown = true;
|
|
145
|
+
};
|
|
146
|
+
sync(false);
|
|
147
|
+
const resizeObserver = new ResizeObserver(() => sync(false));
|
|
148
|
+
resizeObserver.observe(group);
|
|
149
|
+
const mutationObserver = new MutationObserver(() => sync(true));
|
|
150
|
+
mutationObserver.observe(group, { subtree: true, childList: true, attributes: true, attributeFilter: ["data-active"] });
|
|
151
|
+
return () => {
|
|
152
|
+
resizeObserver.disconnect();
|
|
153
|
+
mutationObserver.disconnect();
|
|
154
|
+
};
|
|
155
|
+
}, [groupRef, pillRef]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A group of rail tiles on one shared trough, like segmented tabs: one pill
|
|
160
|
+
* slides to the active tile. Put groups in `RailHeader`, `RailBody` and
|
|
161
|
+
* `RailFooter`; the space between troughs divides them, so drop
|
|
162
|
+
* `RailSeparator` and `showDivider`. Centre a body group with
|
|
163
|
+
* `className="justify-center-safe"` on `RailBody`.
|
|
164
|
+
*/
|
|
165
|
+
export function RailGroup({ className, children, ...props }: SidebarRailGroupProps) {
|
|
166
|
+
const groupRef = useRef<HTMLDivElement>(null);
|
|
167
|
+
const pillRef = useRef<HTMLSpanElement>(null);
|
|
168
|
+
useRailGroupPill(groupRef, pillRef);
|
|
169
|
+
return (
|
|
170
|
+
<RailGroupContext value>
|
|
171
|
+
<div {...props} ref={groupRef} role="group" className={cn(railGroupClass, className)}>
|
|
172
|
+
<span ref={pillRef} aria-hidden className={railGroupPillClass} />
|
|
173
|
+
{children}
|
|
174
|
+
</div>
|
|
175
|
+
</RailGroupContext>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
109
179
|
export type SidebarRailFooterProps = ComponentPropsWithoutRef<"div">;
|
|
110
180
|
|
|
111
181
|
/** Block pinned at the bottom of the rail. */
|
|
@@ -166,6 +236,10 @@ export function RailItem({
|
|
|
166
236
|
children,
|
|
167
237
|
...props
|
|
168
238
|
}: SidebarRailItemProps) {
|
|
239
|
+
const grouped = use(RailGroupContext);
|
|
240
|
+
const stateClass = railTileStateClass(active, grouped);
|
|
241
|
+
// Markers for the group's pill; ungrouped tiles keep their old DOM.
|
|
242
|
+
const groupMarks = grouped ? { "data-rail-tile": "", "data-active": active ? "" : undefined } : undefined;
|
|
169
243
|
const AppIcon = app ? APP_ICONS[app] : null;
|
|
170
244
|
const appIcon = AppIcon ? <AppIcon size={SIDEBAR_RAIL_APP_ICON_SIZE} /> : null;
|
|
171
245
|
const content = appIcon ?? children;
|
|
@@ -175,7 +249,8 @@ export function RailItem({
|
|
|
175
249
|
<TabsPrimitive.Trigger
|
|
176
250
|
{...props}
|
|
177
251
|
value={tabValue}
|
|
178
|
-
|
|
252
|
+
{...groupMarks}
|
|
253
|
+
className={cn(railTileClass, "group relative", stateClass, className)}
|
|
179
254
|
>
|
|
180
255
|
{content}
|
|
181
256
|
<span className="sr-only">{label}</span>
|
|
@@ -186,7 +261,8 @@ export function RailItem({
|
|
|
186
261
|
{...props}
|
|
187
262
|
aria-label={label}
|
|
188
263
|
aria-current={active ? "page" : undefined}
|
|
189
|
-
|
|
264
|
+
{...groupMarks}
|
|
265
|
+
className={cn(railTileClass, "group", stateClass, className)}
|
|
190
266
|
>
|
|
191
267
|
{appIcon}
|
|
192
268
|
<Slottable>{children}</Slottable>
|
|
@@ -197,7 +273,8 @@ export function RailItem({
|
|
|
197
273
|
type="button"
|
|
198
274
|
{...props}
|
|
199
275
|
aria-label={label}
|
|
200
|
-
|
|
276
|
+
{...groupMarks}
|
|
277
|
+
className={cn(railTileClass, "group", stateClass, className)}
|
|
201
278
|
>
|
|
202
279
|
{content}
|
|
203
280
|
{badge}
|
|
@@ -15,10 +15,28 @@ export const railTileClass =
|
|
|
15
15
|
const railTileActiveClass = "border-transparent bg-surface-tertiary text-foreground";
|
|
16
16
|
const railTileIdleClass = "border-transparent text-muted opacity-75 hover:bg-surface-tertiary/50 hover:opacity-100 hover:text-foreground"; // check-tokens-allow: text-muted
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// Inside a `RailGroup` the tiles read as segmented tabs: the trough is
|
|
19
|
+
// `--default` (the segmented bar) and the group's sliding `--segment` pill sits
|
|
20
|
+
// under the active tile, so the tile itself has no fill. Hover is the pill at
|
|
21
|
+
// half strength, as on `.t-tabs--pills`. `z-1` lifts tiles over the pill.
|
|
22
|
+
const railTileGroupActiveClass = "z-1 border-transparent bg-transparent text-segment-foreground";
|
|
23
|
+
const railTileGroupIdleClass = "z-1 border-transparent text-muted opacity-75 hover:bg-segment/50 hover:opacity-100 hover:text-foreground"; // check-tokens-allow: text-muted
|
|
24
|
+
|
|
25
|
+
/** Tile fill for its state. `grouped`: the tile sits in a `Sidebar.RailGroup` trough. */
|
|
26
|
+
export function railTileStateClass(active: boolean, grouped = false): string {
|
|
27
|
+
if (grouped) return active ? railTileGroupActiveClass : railTileGroupIdleClass;
|
|
19
28
|
return active ? railTileActiveClass : railTileIdleClass;
|
|
20
29
|
}
|
|
21
30
|
|
|
31
|
+
/**
|
|
32
|
+
* `Sidebar.RailGroup` trough: the segmented tabs bar (`bg-default`) as a column.
|
|
33
|
+
* 4px padding and a 12px radius sit concentric with the 8px tile corners.
|
|
34
|
+
*/
|
|
35
|
+
export const railGroupClass = "relative isolate flex flex-col items-center gap-1 rounded-xl bg-default p-1";
|
|
36
|
+
|
|
37
|
+
/** The `RailGroup` sliding pill: the segmented tabs pill, with the tile radius. */
|
|
38
|
+
export const railGroupPillClass = "t-tabs-pill rounded-lg bg-segment";
|
|
39
|
+
|
|
22
40
|
/** Count badge pinned to the bottom-right of a rail tile. */
|
|
23
41
|
export const railBadgeClass = "absolute -bottom-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-accent px-1 text-[10px] font-semibold leading-none text-accent-foreground"; // check-tokens-allow: accent
|
|
24
42
|
|
package/shell/src/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { AppSidebar } from "./AppSidebar.js";
|
|
|
25
25
|
export type { AppSidebarProps } from "./AppSidebar.js";
|
|
26
26
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
27
27
|
export * from "./Sidebar.js";
|
|
28
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "./SidebarRail.js";
|
|
28
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "./SidebarRail.js";
|
|
29
29
|
export type { SidebarRailProps, RailTileProps, RailDividerProps, RailCollapseTileProps } from "./SidebarRail.js";
|
|
30
30
|
export { SidebarResizeHandle, useAppShellResize } from "./SidebarResize.js";
|
|
31
31
|
export type {
|
|
@@ -53,6 +53,7 @@ export {
|
|
|
53
53
|
railTileClass,
|
|
54
54
|
SIDEBAR_RAIL_APP_ICON_SIZE,
|
|
55
55
|
railTileStateClass,
|
|
56
|
+
railGroupClass,
|
|
56
57
|
sidebarNavIconClass,
|
|
57
58
|
sidebarNavItemActionsClass,
|
|
58
59
|
sidebarNavItemClass,
|
package/src/client.ts
CHANGED
|
@@ -233,7 +233,7 @@ export { AppSidebar } from "../shell/src/AppSidebar";
|
|
|
233
233
|
export type { AppSidebarProps } from "../shell/src/AppSidebar";
|
|
234
234
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
235
235
|
export * from "../shell/src/Sidebar";
|
|
236
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "../shell/src/SidebarRail";
|
|
236
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail";
|
|
237
237
|
export type {
|
|
238
238
|
SidebarRailProps,
|
|
239
239
|
RailTileProps,
|
|
@@ -266,6 +266,7 @@ export {
|
|
|
266
266
|
railTileClass,
|
|
267
267
|
SIDEBAR_RAIL_APP_ICON_SIZE,
|
|
268
268
|
railTileStateClass,
|
|
269
|
+
railGroupClass,
|
|
269
270
|
sidebarNavIconClass,
|
|
270
271
|
sidebarNavItemActionsClass,
|
|
271
272
|
sidebarNavItemClass,
|
package/src/index.ts
CHANGED
|
@@ -234,7 +234,7 @@ export { AppSidebar } from "../shell/src/AppSidebar";
|
|
|
234
234
|
export type { AppSidebarProps } from "../shell/src/AppSidebar";
|
|
235
235
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
236
236
|
export * from "../shell/src/Sidebar";
|
|
237
|
-
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "../shell/src/SidebarRail";
|
|
237
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile, useInRailGroup } from "../shell/src/SidebarRail";
|
|
238
238
|
export type {
|
|
239
239
|
SidebarRailProps,
|
|
240
240
|
RailTileProps,
|
|
@@ -267,6 +267,7 @@ export {
|
|
|
267
267
|
railTileClass,
|
|
268
268
|
SIDEBAR_RAIL_APP_ICON_SIZE,
|
|
269
269
|
railTileStateClass,
|
|
270
|
+
railGroupClass,
|
|
270
271
|
sidebarNavIconClass,
|
|
271
272
|
sidebarNavItemActionsClass,
|
|
272
273
|
sidebarNavItemClass,
|
package/src/ui/tabsSliding.ts
CHANGED
|
@@ -18,7 +18,8 @@ function findActiveTab(list: HTMLElement): HTMLElement | null {
|
|
|
18
18
|
|
|
19
19
|
// `xy`: both axes on transform (top pinned to 0), so a column list slides the
|
|
20
20
|
// same way a row does; `top` is a layout property and does not tween.
|
|
21
|
-
|
|
21
|
+
// Exported for other sliding pills (`Sidebar.RailGroup`).
|
|
22
|
+
export function moveTabsPillXY(
|
|
22
23
|
pill: HTMLElement,
|
|
23
24
|
tab: HTMLElement,
|
|
24
25
|
animate: boolean,
|