@eztrak/shared 0.16.0 → 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.
@@ -883,6 +883,9 @@ import { createPortal } from "react-dom";
883
883
  import { FaFileExport, FaPrint } from "react-icons/fa";
884
884
  import { IoCloseCircleOutline } from "react-icons/io5";
885
885
 
886
+ // src/components/Loader/Loader.css
887
+ import "@eztrak/shared/components/loader.css";
888
+
886
889
  // src/components/Loader/Loader.tsx
887
890
  import { jsx as jsx6 } from "react/jsx-runtime";
888
891
  var Loader = ({ className, color = "#F54C00", size = "50px", speed = "1s" }) => {
@@ -1292,7 +1295,7 @@ function Breadcrumbs({
1292
1295
  }
1293
1296
 
1294
1297
  // src/components/sidebar/Sidebar.tsx
1295
- import { useEffect as useEffect5, useState as useState3 } from "react";
1298
+ import { useEffect as useEffect5, useRef as useRef5, useState as useState3 } from "react";
1296
1299
  import { Link as Link2, useLocation as useLocation2 } from "react-router-dom";
1297
1300
 
1298
1301
  // src/components/tooltip/ToolTip.tsx
@@ -1355,15 +1358,49 @@ function ToolTip({
1355
1358
 
1356
1359
  // src/components/sidebar/Sidebar.tsx
1357
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
+ }
1358
1394
  function Sidebar({
1359
1395
  className,
1360
- sideCollapseWidth = "w-20",
1396
+ sideCollapseWidth = "w-24",
1361
1397
  sidebarWidth = "w-48",
1362
1398
  header,
1363
1399
  children,
1364
1400
  footer,
1365
1401
  items = [],
1366
1402
  logoUrl = "",
1403
+ logoRouteUrl = "",
1367
1404
  logoAltText = "Logo",
1368
1405
  collapseButtonText = "\u2B05\uFE0F Collapse",
1369
1406
  expandButtonText = "\u27A1\uFE0F",
@@ -1376,29 +1413,68 @@ function Sidebar({
1376
1413
  }) {
1377
1414
  const location = useLocation2();
1378
1415
  const [collapsed, setCollapsed] = useState3(isCollapsed);
1379
- const [, setActiveLink] = useState3(location.pathname);
1380
- const [subItemsCollapsed, setSubItemsCollapsed] = useState3({});
1416
+ const [openGroups, setOpenGroups] = useState3({});
1417
+ const onCollapseChangeRef = useRef5(onCollapseChange);
1418
+ onCollapseChangeRef.current = onCollapseChange;
1381
1419
  useEffect5(() => {
1382
- if (onCollapseChange) {
1383
- onCollapseChange(collapsed);
1384
- }
1385
- }, [collapsed, onCollapseChange]);
1420
+ setCollapsed(isCollapsed);
1421
+ }, [isCollapsed]);
1386
1422
  useEffect5(() => {
1387
- setActiveLink(location.pathname);
1388
- }, [location]);
1423
+ onCollapseChangeRef.current?.(collapsed);
1424
+ }, [collapsed]);
1389
1425
  const toggleGroup = (group) => {
1390
- setSubItemsCollapsed((prevState) => ({
1426
+ setOpenGroups((prevState) => ({
1391
1427
  ...prevState,
1392
1428
  [group]: !prevState[group]
1393
1429
  }));
1394
1430
  };
1395
- const isActive = (link) => {
1396
- 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);
1397
1468
  };
1398
1469
  return /* @__PURE__ */ jsxs10(
1399
1470
  "div",
1400
1471
  {
1401
- 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
+ ),
1402
1478
  ...rest,
1403
1479
  children: [
1404
1480
  logoUrl && /* @__PURE__ */ jsx13(
@@ -1408,134 +1484,205 @@ function Sidebar({
1408
1484
  "flex items-center justify-center h-16 border-b border-gray-300",
1409
1485
  classNames.logoSection
1410
1486
  ),
1411
- 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" })
1412
1495
  }
1413
1496
  ),
1414
- header && /* @__PURE__ */ jsx13("div", { className: "flex items-center justify-between p-4 border-b border-gray-300", children: header }),
1415
- /* @__PURE__ */ jsx13("nav", { className: cn("flex-grow", classNames.navSection), children: items.map((item, index) => {
1416
- if (item.subItems) {
1417
- return /* @__PURE__ */ jsxs10(
1418
- "div",
1419
- {
1420
- className: `my-2 ${item?.subItems && "has-sub-items"}`,
1421
- children: [
1422
- /* @__PURE__ */ jsxs10(
1423
- "div",
1424
- {
1425
- onClick: () => toggleGroup(item.name),
1426
- "data-sidebar-item": item.name,
1427
- "data-tooltip-id": item.name,
1428
- className: `flex cursor-pointer dropdown-title-wrapper ${classNames?.navItem ?? ""}`,
1429
- children: [
1430
- /* @__PURE__ */ jsx13(
1431
- ToolTip,
1432
- {
1433
- text: item.tooltip || item.name,
1434
- placement: item.tooltipPlacement || "top",
1435
- children: /* @__PURE__ */ jsxs10("div", { className: "flex items-center space-x-2", children: [
1436
- /* @__PURE__ */ jsx13("span", { className: classNames?.navItemText, children: item.icon }),
1437
- !collapsed && /* @__PURE__ */ jsx13("span", { className: classNames?.navItemText, children: item.name })
1438
- ] })
1439
- }
1440
- ),
1441
- !collapsed && /* @__PURE__ */ jsx13(
1442
- "span",
1443
- {
1444
- className: `transform transition-transform ${subItemsCollapsed[item.name] ? "rotate-180" : "rotate-0"}`,
1445
- children: itemDropdownIcon
1446
- }
1447
- )
1448
- ]
1449
- }
1450
- ),
1451
- subItemsCollapsed[item.name] && /* @__PURE__ */ jsx13("div", { className: cn("collapse-btn-wrapper", classNames.subItem), children: item.subItems.map((subItem, subIndex) => {
1452
- if (subItem.component) {
1453
- const SubItemComponent = subItem.component;
1454
- return /* @__PURE__ */ jsx13(SubItemComponent, {}, `${index}-${subIndex}`);
1455
- }
1456
- return /* @__PURE__ */ jsx13(
1457
- "div",
1458
- {
1459
- className: "w-full",
1460
- "data-sidebar-item": subItem.name,
1461
- "data-tooltip-id": subItem.name,
1462
- children: /* @__PURE__ */ jsx13(
1463
- ToolTip,
1464
- {
1465
- text: item.tooltip || item.name,
1466
- placement: item.tooltipPlacement || "top",
1467
- className: "block w-full",
1468
- children: /* @__PURE__ */ jsxs10(
1469
- Link2,
1470
- {
1471
- to: subItem.link || "#",
1472
- className: `flex ${classNames?.navItem ?? ""} ${isActive(subItem?.link ?? "") ? "active" : ""} ${item?.itemClassName}`,
1473
- onClick: () => subItem.link && setActiveLink(subItem.link || ""),
1474
- title: subItem.tooltip || subItem.name,
1475
- children: [
1476
- /* @__PURE__ */ jsx13(
1477
- "span",
1478
- {
1479
- className: classNames.navItemText ?? "text-orange-600",
1480
- children: subItem.icon
1481
- }
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"
1482
1630
  ),
1483
- !collapsed && /* @__PURE__ */ jsx13("span", { className: classNames.navItemText, children: subItem.name })
1484
- ]
1485
- }
1486
- )
1487
- }
1488
- )
1489
- },
1490
- `${index}-${subIndex}`
1491
- );
1492
- }) })
1493
- ]
1494
- },
1495
- index
1496
- );
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
+ })
1497
1662
  }
1498
- if (item.component) {
1499
- const ItemComponent = item.component;
1500
- 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
1501
1672
  }
1502
- return /* @__PURE__ */ jsx13(
1503
- "div",
1504
- {
1505
- className: "w-full",
1506
- "data-sidebar-item": item.name,
1507
- "data-tooltip-id": item.name,
1508
- children: /* @__PURE__ */ jsx13(
1509
- ToolTip,
1510
- {
1511
- text: item.tooltip || item.name,
1512
- placement: item.tooltipPlacement || "top",
1513
- className: "block w-full",
1514
- children: /* @__PURE__ */ jsxs10(
1515
- Link2,
1516
- {
1517
- to: item.link || "#",
1518
- className: `flex ${classNames?.navItem ?? ""} ${isActive(item.link || "") ? "active" : ""} ${item?.itemClassName}`,
1519
- onClick: () => setActiveLink(item.link || ""),
1520
- title: item.tooltip || item.name,
1521
- children: [
1522
- /* @__PURE__ */ jsx13("span", { className: classNames.navItemText ?? "text-orange-600", children: item.icon }),
1523
- !collapsed && /* @__PURE__ */ jsx13("span", { className: classNames.navItemText, children: item.name })
1524
- ]
1525
- }
1526
- )
1527
- }
1528
- )
1529
- },
1530
- index
1531
- );
1532
- }) }),
1533
- children,
1673
+ ),
1534
1674
  /* @__PURE__ */ jsx13(
1535
1675
  "button",
1536
1676
  {
1677
+ type: "button",
1537
1678
  onClick: () => setCollapsed(!collapsed),
1538
- 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
+ ),
1539
1686
  children: collapsed ? expandButtonText : collapseButtonText
1540
1687
  }
1541
1688
  ),
@@ -1685,7 +1832,7 @@ import {
1685
1832
  useEffect as useEffect6,
1686
1833
  useImperativeHandle,
1687
1834
  useMemo,
1688
- useRef as useRef5,
1835
+ useRef as useRef6,
1689
1836
  useState as useState4
1690
1837
  } from "react";
1691
1838
  import toast from "react-hot-toast";
@@ -1761,8 +1908,8 @@ var CustomCellEditor = forwardRef2(
1761
1908
  const normalizedInitial = normalizeInitialValue(initialValue, inputType);
1762
1909
  const [value, setValue] = useState4(normalizedInitial);
1763
1910
  const [isLoading, setIsLoading] = useState4(false);
1764
- const inputRef = useRef5(null);
1765
- const selectRef = useRef5(null);
1911
+ const inputRef = useRef6(null);
1912
+ const selectRef = useRef6(null);
1766
1913
  const normalizedOptions = useMemo(() => {
1767
1914
  if (customOptions && customOptions.length > 0) {
1768
1915
  return customOptions.map((opt) => ({
@@ -1916,7 +2063,7 @@ var CustomCellEditor = forwardRef2(
1916
2063
  CustomCellEditor.displayName = "CustomCellEditor";
1917
2064
 
1918
2065
  // src/components/popup-cell-renderer/PopupCellRenderer.tsx
1919
- import { useRef as useRef6, useState as useState5 } from "react";
2066
+ import { useRef as useRef7, useState as useState5 } from "react";
1920
2067
  import Tippy from "@tippyjs/react";
1921
2068
  import { BiDotsVerticalRounded } from "react-icons/bi";
1922
2069
  import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
@@ -1934,7 +2081,7 @@ function PopupCellRenderer({
1934
2081
  openOnHover = false
1935
2082
  }) {
1936
2083
  const [visible, setVisible] = useState5(false);
1937
- const instanceRef = useRef6(null);
2084
+ const instanceRef = useRef7(null);
1938
2085
  const show = () => setVisible(true);
1939
2086
  const hide = () => {
1940
2087
  setVisible(false);
@@ -2405,4 +2552,4 @@ export {
2405
2552
  RowActions,
2406
2553
  TableErrorBoundary
2407
2554
  };
2408
- //# sourceMappingURL=chunk-PE7NNAX6.mjs.map
2555
+ //# sourceMappingURL=chunk-MJWHQ24F.mjs.map