@lovett/ui 0.2.9 → 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,18 +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
1369
  // A nested row is a step shorter and a step smaller; it keeps its icon.
1367
- nested && !collapsed && "h-8 gap-2.5 px-2 text-[13px]",
1370
+ nested && "h-8 gap-2.5 px-2 text-[13px]",
1368
1371
  className
1369
1372
  );
1370
1373
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
1371
1374
  active && !nested && /* @__PURE__ */ jsx(ActiveBar, {}),
1372
1375
  /* @__PURE__ */ jsx(RowIcon, { icon }),
1373
- !collapsed && /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: label }),
1374
- !collapsed && badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1376
+ /* @__PURE__ */ jsx("span", { className: cn("flex-1 truncate", fadeClass(collapsed)), children: label }),
1377
+ badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1375
1378
  " ",
1376
- /* @__PURE__ */ jsx(RowBadge, { children: badge })
1379
+ /* @__PURE__ */ jsx("span", { className: fadeClass(collapsed), children: /* @__PURE__ */ jsx(RowBadge, { children: badge }) })
1377
1380
  ] })
1378
1381
  ] });
1379
1382
  const shared = {
@@ -1394,6 +1397,15 @@ function SidebarNavItem({
1394
1397
  }
1395
1398
  return /* @__PURE__ */ jsx("a", { ...rest, ...shared, children: content });
1396
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
+ });
1397
1409
  function SidebarNavGroup({
1398
1410
  id,
1399
1411
  icon,
@@ -1415,71 +1427,73 @@ function SidebarNavGroup({
1415
1427
  const reactId = useId();
1416
1428
  const bodyId = `sidebar-group-${id}-${reactId}`;
1417
1429
  const labelId = `${bodyId}-label`;
1418
- if (collapsed) {
1419
- return /* @__PURE__ */ jsxs(Popover, { children: [
1420
- /* @__PURE__ */ jsx(Popover.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs(
1421
- "button",
1422
- {
1423
- type: "button",
1424
- title: label,
1425
- className: cn(ROW_BASE, "justify-center px-0", active ? ROW_ACTIVE : ROW_REST),
1426
- children: [
1427
- active && /* @__PURE__ */ jsx(ActiveBar, {}),
1428
- /* @__PURE__ */ jsx(RowIcon, { icon })
1429
- ]
1430
- }
1431
- ) }),
1432
- /* @__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
+ ] }),
1433
1456
  /* @__PURE__ */ jsx(
1434
- "p",
1457
+ ChevronDown,
1435
1458
  {
1436
- id: labelId,
1437
- className: "px-2.5 pb-1 pt-1 text-[11px] font-semibold text-[rgb(var(--text-tertiary))]",
1438
- 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)" }
1439
1465
  }
1440
- ),
1441
- /* @__PURE__ */ jsx("div", { role: "group", "aria-labelledby": labelId, className: "flex flex-col gap-0.5", children })
1442
- ] }) })
1443
- ] });
1444
- }
1466
+ )
1467
+ ]
1468
+ }
1469
+ );
1445
1470
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
1446
- /* @__PURE__ */ jsxs(
1447
- "button",
1448
- {
1449
- type: "button",
1450
- onClick: () => setOpen(!open),
1451
- "aria-expanded": open,
1452
- "aria-controls": bodyId,
1453
- id: labelId,
1454
- className: cn(ROW_BASE, active && !open ? ROW_ACTIVE : ROW_REST),
1455
- children: [
1456
- active && !open && /* @__PURE__ */ jsx(ActiveBar, {}),
1457
- /* @__PURE__ */ jsx(RowIcon, { icon }),
1458
- /* @__PURE__ */ jsx("span", { id: `${labelId}-text`, className: "flex-1 truncate", children: label }),
1459
- badge !== void 0 && badge !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
1460
- " ",
1461
- /* @__PURE__ */ jsx(RowBadge, { children: badge })
1462
- ] }),
1463
- /* @__PURE__ */ jsx(
1464
- ChevronDown,
1465
- {
1466
- "aria-hidden": "true",
1467
- 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",
1468
- style: { transform: open ? "rotate(180deg)" : "rotate(0deg)" }
1469
- }
1470
- )
1471
- ]
1472
- }
1473
- ),
1474
- /* @__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(
1475
1489
  "div",
1476
1490
  {
1477
1491
  id: bodyId,
1478
1492
  role: "group",
1479
1493
  "aria-labelledby": `${labelId}-text`,
1480
- className: "ml-[calc(1.0625rem-0.5px)] flex flex-col gap-0.5 border-l border-[rgb(var(--sidebar-rail))] py-1 pl-2",
1481
- inert: !open,
1482
- "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,
1483
1497
  children
1484
1498
  }
1485
1499
  ) }) }) })