@ttn-shared/ui 1.3.0 → 1.4.1

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.cjs CHANGED
@@ -2631,20 +2631,38 @@ var TI6 = __toESM(require("@tabler/icons-react"), 1);
2631
2631
 
2632
2632
  // src/components/sidebar/SidebarMenu.tsx
2633
2633
  var import_jsx_runtime13 = require("react/jsx-runtime");
2634
- var import_react_router_dom = require("react-router-dom");
2635
2634
  var MC4 = __toESM(require("@mantine/core"), 1);
2636
2635
  var TI5 = __toESM(require("@tabler/icons-react"), 1);
2637
2636
  var import_jsx_runtime14 = require("react/jsx-runtime");
2637
+ var normalizePath = (path) => {
2638
+ if (!path) {
2639
+ return "/";
2640
+ }
2641
+ const normalized = path.replace(/\/+$/, "");
2642
+ return normalized || "/";
2643
+ };
2644
+ var isActiveScreen = (screenUrl, pathname) => {
2645
+ const currentPath = normalizePath(pathname);
2646
+ const targetPath = normalizePath(screenUrl);
2647
+ return currentPath === targetPath || currentPath.startsWith(`${targetPath}/`);
2648
+ };
2638
2649
  var SidebarMenu = ({
2639
2650
  id,
2640
2651
  label,
2641
2652
  icon,
2642
2653
  active,
2654
+ currentPathname,
2643
2655
  screens,
2644
2656
  onClickMenu,
2645
2657
  onCloseSidebar,
2646
- onClickExternalScreen
2658
+ onClickExternalScreen,
2659
+ onClickScreen
2647
2660
  }) => {
2661
+ const pathname = currentPathname || "";
2662
+ const handleClickScreen = (screen) => {
2663
+ onCloseSidebar();
2664
+ onClickScreen(screen);
2665
+ };
2648
2666
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2649
2667
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2650
2668
  MC4.UnstyledButton,
@@ -2668,13 +2686,22 @@ var SidebarMenu = ({
2668
2686
  }
2669
2687
  ),
2670
2688
  Boolean(screens?.length) && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Collapse, { in: active ?? false, children: screens?.map((screen) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime13.Fragment, { children: [
2671
- screen.external && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Box, { onClick: () => onClickExternalScreen(screen), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label }) }),
2689
+ screen.external && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2690
+ MC4.Box,
2691
+ {
2692
+ onClick: () => onClickExternalScreen(screen),
2693
+ className: "ttn-sidebar-menu-item",
2694
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2695
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2696
+ }
2697
+ ),
2672
2698
  !screen.external && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2673
- import_react_router_dom.NavLink,
2699
+ MC4.Box,
2674
2700
  {
2675
- to: screen.url || "#",
2676
- onClick: onCloseSidebar,
2677
- className: (isActive) => isActive ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2701
+ onClick: () => handleClickScreen(screen),
2702
+ className: isActiveScreen(screen.url || "", pathname) ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2703
+ style: { cursor: "pointer" },
2704
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2678
2705
  children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2679
2706
  }
2680
2707
  )
@@ -2684,7 +2711,12 @@ var SidebarMenu = ({
2684
2711
 
2685
2712
  // src/components/sidebar/Sidebar.tsx
2686
2713
  var import_jsx_runtime15 = require("react/jsx-runtime");
2687
- var Sidebar = ({ modules, onClickExternalScreen }) => {
2714
+ var Sidebar = ({
2715
+ modules,
2716
+ currentPathname,
2717
+ onClickExternalScreen,
2718
+ onClickScreen
2719
+ }) => {
2688
2720
  const [opened, setOpened] = (0, import_react9.useState)(false);
2689
2721
  const [activeModuleId, setActiveModuleId] = (0, import_react9.useState)(null);
2690
2722
  const handleClickMenu = (id) => {
@@ -2697,10 +2729,10 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2697
2729
  setActiveModuleId(null);
2698
2730
  setOpened(false);
2699
2731
  };
2700
- const handleClickExternalScreen = (item) => {
2732
+ const handleClickExternalScreen = (module2, screen) => {
2701
2733
  setActiveModuleId(null);
2702
2734
  setOpened(false);
2703
- onClickExternalScreen(item);
2735
+ onClickExternalScreen(module2, screen);
2704
2736
  };
2705
2737
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("aside", { className: opened ? "ttn-sidebar" : "ttn-sidebar closed", children: [
2706
2738
  /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(MC5.Flex, { direction: "column", justify: "center", h: 56, children: [
@@ -2739,10 +2771,12 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2739
2771
  label: module2.label,
2740
2772
  icon: module2.icon,
2741
2773
  active: activeModuleId === module2.id,
2774
+ currentPathname,
2742
2775
  screens: module2.screens,
2743
2776
  onClickMenu: handleClickMenu,
2744
2777
  onCloseSidebar: handleCloseSidebar,
2745
- onClickExternalScreen: handleClickExternalScreen
2778
+ onClickExternalScreen: (screen) => handleClickExternalScreen(module2, screen),
2779
+ onClickScreen: (screen) => onClickScreen(module2, screen)
2746
2780
  },
2747
2781
  module2.id
2748
2782
  )),
package/dist/index.d.cts CHANGED
@@ -292,9 +292,11 @@ interface SidebarModule {
292
292
 
293
293
  interface SidebarProps {
294
294
  modules: SidebarModule[];
295
- onClickExternalScreen: (item: SidebarModuleScreen) => void;
295
+ currentPathname: string;
296
+ onClickExternalScreen: (module: SidebarModule, screen: SidebarModuleScreen) => void;
297
+ onClickScreen: (module: SidebarModule, screen: SidebarModuleScreen) => void;
296
298
  }
297
- declare const Sidebar: ({ modules, onClickExternalScreen }: SidebarProps) => react_jsx_runtime.JSX.Element;
299
+ declare const Sidebar: ({ modules, currentPathname, onClickExternalScreen, onClickScreen, }: SidebarProps) => react_jsx_runtime.JSX.Element;
298
300
 
299
301
  interface TTNSharedProviderProps {
300
302
  token: string;
package/dist/index.d.ts CHANGED
@@ -292,9 +292,11 @@ interface SidebarModule {
292
292
 
293
293
  interface SidebarProps {
294
294
  modules: SidebarModule[];
295
- onClickExternalScreen: (item: SidebarModuleScreen) => void;
295
+ currentPathname: string;
296
+ onClickExternalScreen: (module: SidebarModule, screen: SidebarModuleScreen) => void;
297
+ onClickScreen: (module: SidebarModule, screen: SidebarModuleScreen) => void;
296
298
  }
297
- declare const Sidebar: ({ modules, onClickExternalScreen }: SidebarProps) => react_jsx_runtime.JSX.Element;
299
+ declare const Sidebar: ({ modules, currentPathname, onClickExternalScreen, onClickScreen, }: SidebarProps) => react_jsx_runtime.JSX.Element;
298
300
 
299
301
  interface TTNSharedProviderProps {
300
302
  token: string;
package/dist/index.js CHANGED
@@ -2643,20 +2643,38 @@ import * as TI6 from "@tabler/icons-react";
2643
2643
 
2644
2644
  // src/components/sidebar/SidebarMenu.tsx
2645
2645
  import { Fragment as Fragment4 } from "react/jsx-runtime";
2646
- import { NavLink } from "react-router-dom";
2647
2646
  import * as MC4 from "@mantine/core";
2648
2647
  import * as TI5 from "@tabler/icons-react";
2649
2648
  import { Fragment as Fragment5, jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
2649
+ var normalizePath = (path) => {
2650
+ if (!path) {
2651
+ return "/";
2652
+ }
2653
+ const normalized = path.replace(/\/+$/, "");
2654
+ return normalized || "/";
2655
+ };
2656
+ var isActiveScreen = (screenUrl, pathname) => {
2657
+ const currentPath = normalizePath(pathname);
2658
+ const targetPath = normalizePath(screenUrl);
2659
+ return currentPath === targetPath || currentPath.startsWith(`${targetPath}/`);
2660
+ };
2650
2661
  var SidebarMenu = ({
2651
2662
  id,
2652
2663
  label,
2653
2664
  icon,
2654
2665
  active,
2666
+ currentPathname,
2655
2667
  screens,
2656
2668
  onClickMenu,
2657
2669
  onCloseSidebar,
2658
- onClickExternalScreen
2670
+ onClickExternalScreen,
2671
+ onClickScreen
2659
2672
  }) => {
2673
+ const pathname = currentPathname || "";
2674
+ const handleClickScreen = (screen) => {
2675
+ onCloseSidebar();
2676
+ onClickScreen(screen);
2677
+ };
2660
2678
  return /* @__PURE__ */ jsxs12(Fragment5, { children: [
2661
2679
  /* @__PURE__ */ jsxs12(
2662
2680
  MC4.UnstyledButton,
@@ -2680,13 +2698,22 @@ var SidebarMenu = ({
2680
2698
  }
2681
2699
  ),
2682
2700
  Boolean(screens?.length) && /* @__PURE__ */ jsx13(MC4.Collapse, { in: active ?? false, children: screens?.map((screen) => /* @__PURE__ */ jsxs12(Fragment4, { children: [
2683
- screen.external && /* @__PURE__ */ jsx13(MC4.Box, { onClick: () => onClickExternalScreen(screen), children: /* @__PURE__ */ jsx13(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label }) }),
2701
+ screen.external && /* @__PURE__ */ jsx13(
2702
+ MC4.Box,
2703
+ {
2704
+ onClick: () => onClickExternalScreen(screen),
2705
+ className: "ttn-sidebar-menu-item",
2706
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2707
+ children: /* @__PURE__ */ jsx13(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2708
+ }
2709
+ ),
2684
2710
  !screen.external && /* @__PURE__ */ jsx13(
2685
- NavLink,
2711
+ MC4.Box,
2686
2712
  {
2687
- to: screen.url || "#",
2688
- onClick: onCloseSidebar,
2689
- className: (isActive) => isActive ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2713
+ onClick: () => handleClickScreen(screen),
2714
+ className: isActiveScreen(screen.url || "", pathname) ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2715
+ style: { cursor: "pointer" },
2716
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2690
2717
  children: /* @__PURE__ */ jsx13(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2691
2718
  }
2692
2719
  )
@@ -2696,7 +2723,12 @@ var SidebarMenu = ({
2696
2723
 
2697
2724
  // src/components/sidebar/Sidebar.tsx
2698
2725
  import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
2699
- var Sidebar = ({ modules, onClickExternalScreen }) => {
2726
+ var Sidebar = ({
2727
+ modules,
2728
+ currentPathname,
2729
+ onClickExternalScreen,
2730
+ onClickScreen
2731
+ }) => {
2700
2732
  const [opened, setOpened] = useState7(false);
2701
2733
  const [activeModuleId, setActiveModuleId] = useState7(null);
2702
2734
  const handleClickMenu = (id) => {
@@ -2709,10 +2741,10 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2709
2741
  setActiveModuleId(null);
2710
2742
  setOpened(false);
2711
2743
  };
2712
- const handleClickExternalScreen = (item) => {
2744
+ const handleClickExternalScreen = (module, screen) => {
2713
2745
  setActiveModuleId(null);
2714
2746
  setOpened(false);
2715
- onClickExternalScreen(item);
2747
+ onClickExternalScreen(module, screen);
2716
2748
  };
2717
2749
  return /* @__PURE__ */ jsxs13("aside", { className: opened ? "ttn-sidebar" : "ttn-sidebar closed", children: [
2718
2750
  /* @__PURE__ */ jsxs13(MC5.Flex, { direction: "column", justify: "center", h: 56, children: [
@@ -2751,10 +2783,12 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2751
2783
  label: module.label,
2752
2784
  icon: module.icon,
2753
2785
  active: activeModuleId === module.id,
2786
+ currentPathname,
2754
2787
  screens: module.screens,
2755
2788
  onClickMenu: handleClickMenu,
2756
2789
  onCloseSidebar: handleCloseSidebar,
2757
- onClickExternalScreen: handleClickExternalScreen
2790
+ onClickExternalScreen: (screen) => handleClickExternalScreen(module, screen),
2791
+ onClickScreen: (screen) => onClickScreen(module, screen)
2758
2792
  },
2759
2793
  module.id
2760
2794
  )),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttn-shared/ui",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [
@@ -49,10 +49,8 @@
49
49
  "@types/node": "18.19.130",
50
50
  "@types/react": "18.3.27",
51
51
  "@types/react-dom": "18.3.7",
52
- "@types/react-router-dom": "^5.3.3",
53
52
  "react": "^18.3.1",
54
53
  "react-dom": "^18.3.1",
55
- "react-router-dom": "^5.3.4",
56
54
  "tsup": "8.5.1",
57
55
  "typescript": "5.9.3"
58
56
  },
@@ -62,7 +60,6 @@
62
60
  "@tabler/icons-react": ">=3.0.0",
63
61
  "@tanstack/react-query": ">=5.0.0",
64
62
  "react": ">=18.0.0",
65
- "react-dom": ">=18.0.0",
66
- "react-router-dom": ">=5.0.0"
63
+ "react-dom": ">=18.0.0"
67
64
  }
68
65
  }