@eztrak/shared 0.16.1 → 0.16.2

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.
@@ -1295,7 +1295,7 @@ function Breadcrumbs({
1295
1295
  }
1296
1296
 
1297
1297
  // src/components/sidebar/Sidebar.tsx
1298
- import { useEffect as useEffect5, useState as useState3 } from "react";
1298
+ import { useEffect as useEffect5, useRef as useRef5, useState as useState3 } from "react";
1299
1299
  import { Link as Link2, useLocation as useLocation2 } from "react-router-dom";
1300
1300
 
1301
1301
  // src/components/tooltip/ToolTip.tsx
@@ -1358,15 +1358,49 @@ function ToolTip({
1358
1358
 
1359
1359
  // src/components/sidebar/Sidebar.tsx
1360
1360
  import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
1361
+ function getItemTooltip(item) {
1362
+ return item.tooltip || item.name;
1363
+ }
1364
+ function getTooltipPlacement(item, collapsed) {
1365
+ return item.tooltipPlacement || (collapsed ? "right" : "top");
1366
+ }
1367
+ function isItemActive(pathname, link) {
1368
+ if (!link || link === "#") return false;
1369
+ return pathname === link || pathname.startsWith(`${link}/`);
1370
+ }
1371
+ function SidebarItemLabel({
1372
+ name,
1373
+ collapsed,
1374
+ className
1375
+ }) {
1376
+ return /* @__PURE__ */ jsx13(
1377
+ "span",
1378
+ {
1379
+ className: cn(
1380
+ className,
1381
+ collapsed && "block w-full text-center text-[10px] font-medium leading-tight line-clamp-2 wrap-break-word"
1382
+ ),
1383
+ children: name
1384
+ }
1385
+ );
1386
+ }
1387
+ function SidebarItemIcon({
1388
+ icon,
1389
+ className
1390
+ }) {
1391
+ if (!icon) return null;
1392
+ return /* @__PURE__ */ jsx13("span", { className: cn("inline-flex shrink-0", className), "aria-hidden": "true", children: icon });
1393
+ }
1361
1394
  function Sidebar({
1362
1395
  className,
1363
- sideCollapseWidth = "w-20",
1396
+ sideCollapseWidth = "w-24",
1364
1397
  sidebarWidth = "w-48",
1365
1398
  header,
1366
1399
  children,
1367
1400
  footer,
1368
1401
  items = [],
1369
1402
  logoUrl = "",
1403
+ logoRouteUrl = "",
1370
1404
  logoAltText = "Logo",
1371
1405
  collapseButtonText = "\u2B05\uFE0F Collapse",
1372
1406
  expandButtonText = "\u27A1\uFE0F",
@@ -1379,29 +1413,68 @@ function Sidebar({
1379
1413
  }) {
1380
1414
  const location = useLocation2();
1381
1415
  const [collapsed, setCollapsed] = useState3(isCollapsed);
1382
- const [, setActiveLink] = useState3(location.pathname);
1383
- const [subItemsCollapsed, setSubItemsCollapsed] = useState3({});
1416
+ const [openGroups, setOpenGroups] = useState3({});
1417
+ const onCollapseChangeRef = useRef5(onCollapseChange);
1418
+ onCollapseChangeRef.current = onCollapseChange;
1384
1419
  useEffect5(() => {
1385
- if (onCollapseChange) {
1386
- onCollapseChange(collapsed);
1387
- }
1388
- }, [collapsed, onCollapseChange]);
1420
+ setCollapsed(isCollapsed);
1421
+ }, [isCollapsed]);
1389
1422
  useEffect5(() => {
1390
- setActiveLink(location.pathname);
1391
- }, [location]);
1423
+ onCollapseChangeRef.current?.(collapsed);
1424
+ }, [collapsed]);
1392
1425
  const toggleGroup = (group) => {
1393
- setSubItemsCollapsed((prevState) => ({
1426
+ setOpenGroups((prevState) => ({
1394
1427
  ...prevState,
1395
1428
  [group]: !prevState[group]
1396
1429
  }));
1397
1430
  };
1398
- const isActive = (link) => {
1399
- return location.pathname.startsWith(link);
1431
+ const itemLayoutClass = (active, itemClassName) => cn(
1432
+ "flex cursor-pointer",
1433
+ classNames?.navItem,
1434
+ collapsed && "w-full flex-col items-center justify-center gap-0.5 px-1 py-2 my-1 !mx-0 max-w-full min-w-0 box-border text-center min-h-11",
1435
+ active && "active",
1436
+ itemClassName
1437
+ );
1438
+ const renderLink = (item, key) => {
1439
+ const active = isItemActive(location.pathname, item.link);
1440
+ return /* @__PURE__ */ jsx13("div", { className: "max-w-full min-w-0", "data-sidebar-item": item.name, children: /* @__PURE__ */ jsx13(
1441
+ ToolTip,
1442
+ {
1443
+ text: getItemTooltip(item),
1444
+ placement: getTooltipPlacement(item, collapsed),
1445
+ delayShow: 150,
1446
+ className: "block max-w-full min-w-0",
1447
+ children: /* @__PURE__ */ jsxs10(
1448
+ Link2,
1449
+ {
1450
+ to: item.link || "#",
1451
+ className: itemLayoutClass(active, item.itemClassName),
1452
+ "aria-current": active ? "page" : void 0,
1453
+ children: [
1454
+ /* @__PURE__ */ jsx13(SidebarItemIcon, { icon: item.icon, className: classNames?.navItemText }),
1455
+ /* @__PURE__ */ jsx13(
1456
+ SidebarItemLabel,
1457
+ {
1458
+ name: item.name,
1459
+ collapsed,
1460
+ className: classNames?.navItemText
1461
+ }
1462
+ )
1463
+ ]
1464
+ }
1465
+ )
1466
+ }
1467
+ ) }, key);
1400
1468
  };
1401
1469
  return /* @__PURE__ */ jsxs10(
1402
1470
  "div",
1403
1471
  {
1404
- className: `flex flex-col h-screen overflow-hidden ${collapsed ? `${sideCollapseWidth} justify-center items-center collapsed` : `${sidebarWidth}`} transition-all duration-100 ${className ?? ""}`,
1472
+ className: cn(
1473
+ "flex flex-col h-screen overflow-hidden",
1474
+ collapsed ? `${sideCollapseWidth} items-stretch collapsed` : sidebarWidth,
1475
+ "transition-[width] duration-200 ease-in-out motion-reduce:transition-none",
1476
+ className
1477
+ ),
1405
1478
  ...rest,
1406
1479
  children: [
1407
1480
  logoUrl && /* @__PURE__ */ jsx13(
@@ -1411,134 +1484,205 @@ function Sidebar({
1411
1484
  "flex items-center justify-center h-16 border-b border-gray-300",
1412
1485
  classNames.logoSection
1413
1486
  ),
1414
- children: /* @__PURE__ */ jsx13("img", { src: logoUrl, alt: logoAltText, className: "h-10" })
1487
+ children: logoRouteUrl ? /* @__PURE__ */ jsx13(
1488
+ Link2,
1489
+ {
1490
+ to: logoRouteUrl,
1491
+ className: "sidebar-logo-link inline-flex items-center justify-center",
1492
+ children: /* @__PURE__ */ jsx13("img", { src: logoUrl, alt: logoAltText, className: "h-10" })
1493
+ }
1494
+ ) : /* @__PURE__ */ jsx13("img", { src: logoUrl, alt: logoAltText, className: "h-10" })
1415
1495
  }
1416
1496
  ),
1417
- header && /* @__PURE__ */ jsx13("div", { className: "flex items-center justify-between p-4 border-b border-gray-300", children: header }),
1418
- /* @__PURE__ */ jsx13("nav", { className: cn("flex-grow", classNames.navSection), children: items.map((item, index) => {
1419
- if (item.subItems) {
1420
- return /* @__PURE__ */ jsxs10(
1421
- "div",
1422
- {
1423
- className: `my-2 ${item?.subItems && "has-sub-items"}`,
1424
- children: [
1425
- /* @__PURE__ */ jsxs10(
1426
- "div",
1427
- {
1428
- onClick: () => toggleGroup(item.name),
1429
- "data-sidebar-item": item.name,
1430
- "data-tooltip-id": item.name,
1431
- className: `flex cursor-pointer dropdown-title-wrapper ${classNames?.navItem ?? ""}`,
1432
- children: [
1433
- /* @__PURE__ */ jsx13(
1434
- ToolTip,
1435
- {
1436
- text: item.tooltip || item.name,
1437
- placement: item.tooltipPlacement || "top",
1438
- children: /* @__PURE__ */ jsxs10("div", { className: "flex items-center space-x-2", children: [
1439
- /* @__PURE__ */ jsx13("span", { className: classNames?.navItemText, children: item.icon }),
1440
- !collapsed && /* @__PURE__ */ jsx13("span", { className: classNames?.navItemText, children: item.name })
1441
- ] })
1442
- }
1443
- ),
1444
- !collapsed && /* @__PURE__ */ jsx13(
1445
- "span",
1446
- {
1447
- className: `transform transition-transform ${subItemsCollapsed[item.name] ? "rotate-180" : "rotate-0"}`,
1448
- children: itemDropdownIcon
1449
- }
1450
- )
1451
- ]
1452
- }
1453
- ),
1454
- subItemsCollapsed[item.name] && /* @__PURE__ */ jsx13("div", { className: cn("collapse-btn-wrapper", classNames.subItem), children: item.subItems.map((subItem, subIndex) => {
1455
- if (subItem.component) {
1456
- const SubItemComponent = subItem.component;
1457
- return /* @__PURE__ */ jsx13(SubItemComponent, {}, `${index}-${subIndex}`);
1458
- }
1459
- return /* @__PURE__ */ jsx13(
1460
- "div",
1461
- {
1462
- className: "w-full",
1463
- "data-sidebar-item": subItem.name,
1464
- "data-tooltip-id": subItem.name,
1465
- children: /* @__PURE__ */ jsx13(
1466
- ToolTip,
1467
- {
1468
- text: item.tooltip || item.name,
1469
- placement: item.tooltipPlacement || "top",
1470
- className: "block w-full",
1471
- children: /* @__PURE__ */ jsxs10(
1472
- Link2,
1473
- {
1474
- to: subItem.link || "#",
1475
- className: `flex ${classNames?.navItem ?? ""} ${isActive(subItem?.link ?? "") ? "active" : ""} ${item?.itemClassName}`,
1476
- onClick: () => subItem.link && setActiveLink(subItem.link || ""),
1477
- title: subItem.tooltip || subItem.name,
1478
- children: [
1479
- /* @__PURE__ */ jsx13(
1480
- "span",
1481
- {
1482
- className: classNames.navItemText ?? "text-orange-600",
1483
- children: subItem.icon
1484
- }
1497
+ header && /* @__PURE__ */ jsx13("div", { className: "flex items-center justify-between p-4 border-b border-gray-300 shrink-0", children: header }),
1498
+ /* @__PURE__ */ jsx13(
1499
+ "nav",
1500
+ {
1501
+ "aria-label": "Sidebar",
1502
+ className: cn(
1503
+ "grow min-h-0 min-w-0 w-full",
1504
+ classNames.navSection
1505
+ ),
1506
+ children: items.map((item, index) => {
1507
+ if (item.subItems) {
1508
+ const groupOpen = Boolean(openGroups[item.name]);
1509
+ const groupId = `sidebar-group-${index}`;
1510
+ return /* @__PURE__ */ jsxs10(
1511
+ "div",
1512
+ {
1513
+ className: cn(
1514
+ "has-sub-items max-w-full min-w-0 flex flex-col",
1515
+ collapsed ? "my-1" : "my-2"
1516
+ ),
1517
+ children: [
1518
+ /* @__PURE__ */ jsx13(
1519
+ ToolTip,
1520
+ {
1521
+ text: getItemTooltip(item),
1522
+ placement: getTooltipPlacement(item, collapsed),
1523
+ delayShow: 150,
1524
+ className: "flex flex-col w-full max-w-full min-w-0",
1525
+ children: /* @__PURE__ */ jsxs10(
1526
+ "button",
1527
+ {
1528
+ type: "button",
1529
+ onClick: () => toggleGroup(item.name),
1530
+ "data-sidebar-item": item.name,
1531
+ "aria-expanded": groupOpen,
1532
+ "aria-controls": groupId,
1533
+ className: cn(
1534
+ itemLayoutClass(false, item.itemClassName),
1535
+ !collapsed && "dropdown-title-wrapper",
1536
+ "relative appearance-none border-0 bg-transparent [font:inherit]"
1537
+ ),
1538
+ children: [
1539
+ /* @__PURE__ */ jsxs10(
1540
+ "span",
1541
+ {
1542
+ className: cn(
1543
+ "flex items-center min-w-0",
1544
+ collapsed ? "flex-col gap-0.5 w-full" : "space-x-2 flex-1"
1545
+ ),
1546
+ children: [
1547
+ collapsed ? /* @__PURE__ */ jsx13("span", { className: "flex w-full items-center justify-center", children: /* @__PURE__ */ jsxs10("span", { className: "inline-flex items-center gap-2", children: [
1548
+ /* @__PURE__ */ jsx13("span", { className: "inline-flex w-3 shrink-0", "aria-hidden": "true" }),
1549
+ /* @__PURE__ */ jsx13(
1550
+ SidebarItemIcon,
1551
+ {
1552
+ icon: item.icon,
1553
+ className: classNames?.navItemText
1554
+ }
1555
+ ),
1556
+ /* @__PURE__ */ jsx13(
1557
+ "span",
1558
+ {
1559
+ className: cn(
1560
+ "sidebar-group-caret inline-flex w-3 shrink-0 items-center justify-center text-current [&>svg]:h-3 [&>svg]:w-3 transition-transform duration-200 motion-reduce:transition-none",
1561
+ groupOpen ? "rotate-180" : "rotate-0"
1562
+ ),
1563
+ "aria-hidden": "true",
1564
+ children: itemDropdownIcon
1565
+ }
1566
+ )
1567
+ ] }) }) : /* @__PURE__ */ jsxs10("span", { className: "flex items-center space-x-2 min-w-0 flex-1", children: [
1568
+ /* @__PURE__ */ jsx13(
1569
+ SidebarItemIcon,
1570
+ {
1571
+ icon: item.icon,
1572
+ className: classNames?.navItemText
1573
+ }
1574
+ ),
1575
+ /* @__PURE__ */ jsx13(
1576
+ SidebarItemLabel,
1577
+ {
1578
+ name: item.name,
1579
+ collapsed: false,
1580
+ className: classNames?.navItemText
1581
+ }
1582
+ )
1583
+ ] }),
1584
+ collapsed && /* @__PURE__ */ jsx13(
1585
+ SidebarItemLabel,
1586
+ {
1587
+ name: item.name,
1588
+ collapsed: true,
1589
+ className: classNames?.navItemText
1590
+ }
1591
+ )
1592
+ ]
1593
+ }
1594
+ ),
1595
+ !collapsed && /* @__PURE__ */ jsx13(
1596
+ "span",
1597
+ {
1598
+ className: cn(
1599
+ "transform transition-transform duration-200 motion-reduce:transition-none",
1600
+ groupOpen ? "rotate-180" : "rotate-0"
1601
+ ),
1602
+ "aria-hidden": "true",
1603
+ children: itemDropdownIcon
1604
+ }
1605
+ )
1606
+ ]
1607
+ }
1608
+ )
1609
+ }
1610
+ ),
1611
+ groupOpen && /* @__PURE__ */ jsx13(
1612
+ "div",
1613
+ {
1614
+ id: groupId,
1615
+ role: "group",
1616
+ "aria-label": item.name,
1617
+ className: cn(
1618
+ collapsed ? "sidebar-sub-panel flex flex-col items-center max-w-full min-w-0 box-border" : "collapse-btn-wrapper",
1619
+ classNames.subItem
1620
+ ),
1621
+ children: item.subItems.map((subItem, subIndex) => {
1622
+ if (subItem.component) {
1623
+ const SubItemComponent = subItem.component;
1624
+ return /* @__PURE__ */ jsxs10(
1625
+ "div",
1626
+ {
1627
+ className: cn(
1628
+ "min-w-0 max-w-full",
1629
+ collapsed && "flex flex-col items-center text-center"
1485
1630
  ),
1486
- !collapsed && /* @__PURE__ */ jsx13("span", { className: classNames.navItemText, children: subItem.name })
1487
- ]
1488
- }
1489
- )
1490
- }
1491
- )
1492
- },
1493
- `${index}-${subIndex}`
1494
- );
1495
- }) })
1496
- ]
1497
- },
1498
- index
1499
- );
1631
+ "data-sidebar-item": subItem.name,
1632
+ children: [
1633
+ /* @__PURE__ */ jsx13(SubItemComponent, {}),
1634
+ collapsed && /* @__PURE__ */ jsx13(
1635
+ SidebarItemLabel,
1636
+ {
1637
+ name: subItem.name,
1638
+ collapsed: true,
1639
+ className: classNames?.navItemText
1640
+ }
1641
+ )
1642
+ ]
1643
+ },
1644
+ `${index}-${subIndex}`
1645
+ );
1646
+ }
1647
+ return renderLink(subItem, `${index}-${subIndex}`);
1648
+ })
1649
+ }
1650
+ )
1651
+ ]
1652
+ },
1653
+ index
1654
+ );
1655
+ }
1656
+ if (item.component) {
1657
+ const ItemComponent = item.component;
1658
+ return /* @__PURE__ */ jsx13(ItemComponent, {}, index);
1659
+ }
1660
+ return renderLink(item, String(index));
1661
+ })
1500
1662
  }
1501
- if (item.component) {
1502
- const ItemComponent = item.component;
1503
- return /* @__PURE__ */ jsx13(ItemComponent, {}, index);
1663
+ ),
1664
+ children != null && /* @__PURE__ */ jsx13(
1665
+ "div",
1666
+ {
1667
+ className: cn(
1668
+ "sidebar-chrome w-full shrink-0",
1669
+ collapsed && "flex flex-col items-center"
1670
+ ),
1671
+ children
1504
1672
  }
1505
- return /* @__PURE__ */ jsx13(
1506
- "div",
1507
- {
1508
- className: "w-full",
1509
- "data-sidebar-item": item.name,
1510
- "data-tooltip-id": item.name,
1511
- children: /* @__PURE__ */ jsx13(
1512
- ToolTip,
1513
- {
1514
- text: item.tooltip || item.name,
1515
- placement: item.tooltipPlacement || "top",
1516
- className: "block w-full",
1517
- children: /* @__PURE__ */ jsxs10(
1518
- Link2,
1519
- {
1520
- to: item.link || "#",
1521
- className: `flex ${classNames?.navItem ?? ""} ${isActive(item.link || "") ? "active" : ""} ${item?.itemClassName}`,
1522
- onClick: () => setActiveLink(item.link || ""),
1523
- title: item.tooltip || item.name,
1524
- children: [
1525
- /* @__PURE__ */ jsx13("span", { className: classNames.navItemText ?? "text-orange-600", children: item.icon }),
1526
- !collapsed && /* @__PURE__ */ jsx13("span", { className: classNames.navItemText, children: item.name })
1527
- ]
1528
- }
1529
- )
1530
- }
1531
- )
1532
- },
1533
- index
1534
- );
1535
- }) }),
1536
- children,
1673
+ ),
1537
1674
  /* @__PURE__ */ jsx13(
1538
1675
  "button",
1539
1676
  {
1677
+ type: "button",
1540
1678
  onClick: () => setCollapsed(!collapsed),
1541
- className: cn("", classNames.collapseButton) ?? "p-4 border-t border-gray-300",
1679
+ "aria-expanded": !collapsed,
1680
+ "aria-label": collapsed ? "Expand sidebar" : "Collapse sidebar",
1681
+ className: cn(
1682
+ "shrink-0 border-t border-gray-300",
1683
+ classNames.collapseButton,
1684
+ collapsed && "flex items-center justify-center"
1685
+ ),
1542
1686
  children: collapsed ? expandButtonText : collapseButtonText
1543
1687
  }
1544
1688
  ),
@@ -1688,7 +1832,7 @@ import {
1688
1832
  useEffect as useEffect6,
1689
1833
  useImperativeHandle,
1690
1834
  useMemo,
1691
- useRef as useRef5,
1835
+ useRef as useRef6,
1692
1836
  useState as useState4
1693
1837
  } from "react";
1694
1838
  import toast from "react-hot-toast";
@@ -1764,8 +1908,8 @@ var CustomCellEditor = forwardRef2(
1764
1908
  const normalizedInitial = normalizeInitialValue(initialValue, inputType);
1765
1909
  const [value, setValue] = useState4(normalizedInitial);
1766
1910
  const [isLoading, setIsLoading] = useState4(false);
1767
- const inputRef = useRef5(null);
1768
- const selectRef = useRef5(null);
1911
+ const inputRef = useRef6(null);
1912
+ const selectRef = useRef6(null);
1769
1913
  const normalizedOptions = useMemo(() => {
1770
1914
  if (customOptions && customOptions.length > 0) {
1771
1915
  return customOptions.map((opt) => ({
@@ -1919,7 +2063,7 @@ var CustomCellEditor = forwardRef2(
1919
2063
  CustomCellEditor.displayName = "CustomCellEditor";
1920
2064
 
1921
2065
  // src/components/popup-cell-renderer/PopupCellRenderer.tsx
1922
- import { useRef as useRef6, useState as useState5 } from "react";
2066
+ import { useRef as useRef7, useState as useState5 } from "react";
1923
2067
  import Tippy from "@tippyjs/react";
1924
2068
  import { BiDotsVerticalRounded } from "react-icons/bi";
1925
2069
  import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
@@ -1937,7 +2081,7 @@ function PopupCellRenderer({
1937
2081
  openOnHover = false
1938
2082
  }) {
1939
2083
  const [visible, setVisible] = useState5(false);
1940
- const instanceRef = useRef6(null);
2084
+ const instanceRef = useRef7(null);
1941
2085
  const show = () => setVisible(true);
1942
2086
  const hide = () => {
1943
2087
  setVisible(false);
@@ -2408,4 +2552,4 @@ export {
2408
2552
  RowActions,
2409
2553
  TableErrorBoundary
2410
2554
  };
2411
- //# sourceMappingURL=chunk-DFGYKOJF.mjs.map
2555
+ //# sourceMappingURL=chunk-MJWHQ24F.mjs.map