@lovett/ui 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1330,7 +1330,11 @@ var Ctx = createContext({ collapsed: false, nested: false });
1330
1330
  function SidebarNavRoot({ collapsed = false, className, children, ...rest }) {
1331
1331
  return /* @__PURE__ */ jsx(Ctx.Provider, { value: { collapsed, nested: false }, children: /* @__PURE__ */ jsx("nav", { className: cn("flex flex-col gap-0.5", className), ...rest, children }) });
1332
1332
  }
1333
- var ROW_BASE = "relative flex h-9 w-full items-center gap-3 rounded-[var(--radius-md)] px-2.5 text-left text-sm font-medium outline-none transition-colors focus-visible:[box-shadow:var(--ring-focus)]";
1333
+ var ROW_BASE = "relative flex h-9 w-full items-center gap-3 overflow-hidden whitespace-nowrap rounded-[var(--radius-md)] px-3 text-left text-sm font-medium outline-none transition-colors focus-visible:[box-shadow:var(--ring-focus)]";
1334
+ var FADE = "transition-opacity duration-[var(--dur-fast)] ease-[var(--ease-out)] motion-reduce:transition-none";
1335
+ function fadeClass(collapsed) {
1336
+ return cn(FADE, collapsed ? "opacity-0" : "opacity-100");
1337
+ }
1334
1338
  var ROW_REST = "text-[rgb(var(--sidebar-text))] hover:bg-[rgb(var(--sidebar-surface-hover))] hover:text-[rgb(var(--sidebar-text-bright))]";
1335
1339
  var ROW_ACTIVE = "bg-[rgb(var(--sidebar-surface-active))] text-[rgb(var(--sidebar-text-bright))]";
1336
1340
  function ActiveBar() {
@@ -1362,28 +1366,17 @@ function SidebarNavItem({
1362
1366
  const rowClass = cn(
1363
1367
  ROW_BASE,
1364
1368
  active ? ROW_ACTIVE : ROW_REST,
1365
- collapsed && "justify-center px-0",
1366
- nested && !collapsed && "h-8 pl-[2.375rem] text-[13px]",
1369
+ // A nested row is a step shorter and a step smaller; it keeps its icon.
1370
+ nested && "h-8 gap-2.5 px-2 text-[13px]",
1367
1371
  className
1368
1372
  );
1369
1373
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
1370
1374
  active && !nested && /* @__PURE__ */ jsx(ActiveBar, {}),
1371
- (!nested || collapsed) && /* @__PURE__ */ jsx(RowIcon, { icon }),
1372
- nested && !collapsed && // The connector: a dot on the group's rail, filled when active.
1373
- /* @__PURE__ */ jsx(
1374
- "span",
1375
- {
1376
- "aria-hidden": "true",
1377
- className: cn(
1378
- "absolute left-[1.0625rem] top-1/2 h-1.5 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full transition-colors",
1379
- active ? "bg-[rgb(var(--accent))]" : "bg-[rgb(var(--sidebar-rail))]"
1380
- )
1381
- }
1382
- ),
1383
- !collapsed && /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: label }),
1384
- !collapsed && badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1375
+ /* @__PURE__ */ jsx(RowIcon, { icon }),
1376
+ /* @__PURE__ */ jsx("span", { className: cn("flex-1 truncate", fadeClass(collapsed)), children: label }),
1377
+ badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1385
1378
  " ",
1386
- /* @__PURE__ */ jsx(RowBadge, { children: badge })
1379
+ /* @__PURE__ */ jsx("span", { className: fadeClass(collapsed), children: /* @__PURE__ */ jsx(RowBadge, { children: badge }) })
1387
1380
  ] })
1388
1381
  ] });
1389
1382
  const shared = {
@@ -1404,6 +1397,15 @@ function SidebarNavItem({
1404
1397
  }
1405
1398
  return /* @__PURE__ */ jsx("a", { ...rest, ...shared, children: content });
1406
1399
  }
1400
+ var GroupHeader = forwardRef(function GroupHeader2({ collapsed, disclosureOpen, disclosureControls, ...props }, ref) {
1401
+ const disclosure = collapsed ? {} : {
1402
+ "aria-haspopup": void 0,
1403
+ "data-state": void 0,
1404
+ "aria-expanded": disclosureOpen,
1405
+ "aria-controls": disclosureControls
1406
+ };
1407
+ return /* @__PURE__ */ jsx("button", { ref, type: "button", ...props, ...disclosure });
1408
+ });
1407
1409
  function SidebarNavGroup({
1408
1410
  id,
1409
1411
  icon,
@@ -1425,71 +1427,73 @@ function SidebarNavGroup({
1425
1427
  const reactId = useId();
1426
1428
  const bodyId = `sidebar-group-${id}-${reactId}`;
1427
1429
  const labelId = `${bodyId}-label`;
1428
- if (collapsed) {
1429
- return /* @__PURE__ */ jsxs(Popover, { children: [
1430
- /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1431
- "button",
1432
- {
1433
- type: "button",
1434
- title: label,
1435
- className: cn(ROW_BASE, "justify-center px-0", active ? ROW_ACTIVE : ROW_REST),
1436
- children: [
1437
- active && /* @__PURE__ */ jsx(ActiveBar, {}),
1438
- /* @__PURE__ */ jsx(RowIcon, { icon })
1439
- ]
1440
- }
1441
- ) }),
1442
- /* @__PURE__ */ jsx(Popover.Content, { side: "right", align: "start", offset: 8, "aria-label": label, className: "min-w-[13rem] p-1.5", children: /* @__PURE__ */ jsxs(Ctx.Provider, { value: { collapsed: false, nested: false }, children: [
1430
+ const [flyoutOpen, setFlyoutOpen] = useState(false);
1431
+ useEffect(() => {
1432
+ if (!collapsed) setFlyoutOpen(false);
1433
+ }, [collapsed]);
1434
+ const header = /* @__PURE__ */ jsxs(
1435
+ GroupHeader,
1436
+ {
1437
+ collapsed,
1438
+ disclosureOpen: open,
1439
+ disclosureControls: bodyId,
1440
+ onClick: (event) => {
1441
+ if (collapsed) return;
1442
+ event.preventDefault();
1443
+ setOpen(!open);
1444
+ },
1445
+ id: labelId,
1446
+ title: collapsed ? label : void 0,
1447
+ className: cn(ROW_BASE, active && (!open || collapsed) ? ROW_ACTIVE : ROW_REST),
1448
+ children: [
1449
+ active && (!open || collapsed) && /* @__PURE__ */ jsx(ActiveBar, {}),
1450
+ /* @__PURE__ */ jsx(RowIcon, { icon }),
1451
+ /* @__PURE__ */ jsx("span", { id: `${labelId}-text`, className: cn("flex-1 truncate", fadeClass(collapsed)), children: label }),
1452
+ badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1453
+ " ",
1454
+ /* @__PURE__ */ jsx("span", { className: fadeClass(collapsed), children: /* @__PURE__ */ jsx(RowBadge, { children: badge }) })
1455
+ ] }),
1443
1456
  /* @__PURE__ */ jsx(
1444
- "p",
1457
+ ChevronDown,
1445
1458
  {
1446
- id: labelId,
1447
- className: "px-2.5 pb-1 pt-1 text-[11px] font-semibold text-[rgb(var(--text-tertiary))]",
1448
- children: label
1459
+ "aria-hidden": "true",
1460
+ className: cn(
1461
+ "h-3.5 w-3.5 shrink-0 text-[rgb(var(--sidebar-text-dim))] transition-[transform,opacity] duration-[var(--dur-fast)] ease-[var(--ease-out)] motion-reduce:transition-none",
1462
+ collapsed ? "opacity-0" : "opacity-100"
1463
+ ),
1464
+ style: { transform: open && !collapsed ? "rotate(180deg)" : "rotate(0deg)" }
1449
1465
  }
1450
- ),
1451
- /* @__PURE__ */ jsx("div", { role: "group", "aria-labelledby": labelId, className: "flex flex-col gap-0.5", children })
1452
- ] }) })
1453
- ] });
1454
- }
1466
+ )
1467
+ ]
1468
+ }
1469
+ );
1455
1470
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
1456
- /* @__PURE__ */ jsxs(
1457
- "button",
1458
- {
1459
- type: "button",
1460
- onClick: () => setOpen(!open),
1461
- "aria-expanded": open,
1462
- "aria-controls": bodyId,
1463
- id: labelId,
1464
- className: cn(ROW_BASE, active && !open ? ROW_ACTIVE : ROW_REST),
1465
- children: [
1466
- active && !open && /* @__PURE__ */ jsx(ActiveBar, {}),
1467
- /* @__PURE__ */ jsx(RowIcon, { icon }),
1468
- /* @__PURE__ */ jsx("span", { id: `${labelId}-text`, className: "flex-1 truncate", children: label }),
1469
- badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1470
- " ",
1471
- /* @__PURE__ */ jsx(RowBadge, { children: badge })
1472
- ] }),
1473
- /* @__PURE__ */ jsx(
1474
- ChevronDown,
1475
- {
1476
- "aria-hidden": "true",
1477
- className: "h-3.5 w-3.5 shrink-0 text-[rgb(var(--sidebar-text-dim))] transition-transform duration-150 ease-out motion-reduce:transition-none",
1478
- style: { transform: open ? "rotate(180deg)" : "rotate(0deg)" }
1479
- }
1480
- )
1481
- ]
1482
- }
1483
- ),
1484
- /* @__PURE__ */ jsx("div", { className: "ds-sidebar-group-body", "data-open": open ? "true" : "false", children: /* @__PURE__ */ jsx("div", { className: "min-h-0 overflow-hidden", children: /* @__PURE__ */ jsx(Ctx.Provider, { value: { collapsed: false, nested: true }, children: /* @__PURE__ */ jsx(
1471
+ /* @__PURE__ */ jsxs(Popover, { open: collapsed && flyoutOpen, onOpenChange: setFlyoutOpen, children: [
1472
+ /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: header }),
1473
+ /* @__PURE__ */ jsx(
1474
+ Popover.Content,
1475
+ {
1476
+ side: "right",
1477
+ align: "start",
1478
+ offset: 8,
1479
+ "aria-label": label,
1480
+ className: "min-w-[13rem] p-1.5",
1481
+ children: /* @__PURE__ */ jsxs(Ctx.Provider, { value: { collapsed: false, nested: false }, children: [
1482
+ /* @__PURE__ */ jsx("p", { className: "px-2.5 pb-1 pt-1 text-[11px] font-semibold text-[rgb(var(--text-tertiary))]", children: label }),
1483
+ /* @__PURE__ */ jsx("div", { role: "group", "aria-label": label, className: "flex flex-col gap-0.5", children })
1484
+ ] })
1485
+ }
1486
+ )
1487
+ ] }),
1488
+ /* @__PURE__ */ jsx("div", { className: "ds-sidebar-group-body", "data-open": open && !collapsed ? "true" : "false", children: /* @__PURE__ */ jsx("div", { className: "min-h-0 overflow-hidden", children: /* @__PURE__ */ jsx(Ctx.Provider, { value: { collapsed: false, nested: true }, children: /* @__PURE__ */ jsx(
1485
1489
  "div",
1486
1490
  {
1487
1491
  id: bodyId,
1488
1492
  role: "group",
1489
1493
  "aria-labelledby": `${labelId}-text`,
1490
- className: "relative flex flex-col gap-0.5 py-0.5 before:absolute before:bottom-1 before:left-[1.0625rem] before:top-1 before:w-px before:-translate-x-1/2 before:bg-[rgb(var(--sidebar-rail))]",
1491
- inert: !open,
1492
- "aria-hidden": !open,
1494
+ className: "ml-[calc(1.25rem-0.5px)] flex flex-col gap-0.5 border-l border-[rgb(var(--sidebar-rail))] py-1 pl-2",
1495
+ inert: !open || collapsed,
1496
+ "aria-hidden": !open || collapsed,
1493
1497
  children
1494
1498
  }
1495
1499
  ) }) }) })