@ttn-shared/ui 1.2.8 → 1.4.0

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
@@ -2444,13 +2444,14 @@ var HelpModal = ({ opened, onClose }) => {
2444
2444
  var MC2 = __toESM(require("@mantine/core"), 1);
2445
2445
  var TI3 = __toESM(require("@tabler/icons-react"), 1);
2446
2446
  var import_jsx_runtime11 = require("react/jsx-runtime");
2447
+ var cloudImage = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 52 72'><path d='M-77.4698 71.426C-77.4698 71.426 -102.699 40.2305 -82.8905 21.109C-53.4064 -7.35147 -33.3402 33.0955 -21.9827 16.3565C-3.19499 -11.3325 58.2673 -4.22647 39.4625 30.2055C29.5967 48.27 62.6052 45.5705 49.1486 71.462L-77.4698 71.426Z' fill='%23EBF3FA'/></svg>`;
2447
2448
  var ChangeAccountModal = ({
2448
2449
  opened,
2449
2450
  onClose,
2450
2451
  accounts,
2451
2452
  onChangeAccount
2452
2453
  }) => {
2453
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Modal, { opened, onClose, size: 1200, title: "Cambiar cuenta", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Grid, { px: "lg", children: accounts.map((account, accountIndex) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(MC2.Menu, { position: "right", width: 210, children: [
2454
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Modal, { opened, onClose, size: 1200, title: "Seleccionar cuenta", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Grid, { px: "lg", children: accounts.map((account, accountIndex) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Grid.Col, { span: 6, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(MC2.Menu, { position: "right", width: 210, children: [
2454
2455
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MC2.Menu.Target, { "data-testid": `change-account-account-option-${accountIndex}`, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2455
2456
  MC2.Group,
2456
2457
  {
@@ -2462,7 +2463,10 @@ var ChangeAccountModal = ({
2462
2463
  border: `1px solid ${theme.colors.gray[3]}`,
2463
2464
  borderRadius: theme.radius.md,
2464
2465
  padding: "8px",
2465
- cursor: "pointer"
2466
+ cursor: "pointer",
2467
+ backgroundImage: `url("${cloudImage}")`,
2468
+ backgroundSize: "contain",
2469
+ backgroundRepeat: "no-repeat"
2466
2470
  }),
2467
2471
  children: [
2468
2472
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", {}),
@@ -2626,21 +2630,39 @@ var MC5 = __toESM(require("@mantine/core"), 1);
2626
2630
  var TI6 = __toESM(require("@tabler/icons-react"), 1);
2627
2631
 
2628
2632
  // src/components/sidebar/SidebarMenu.tsx
2633
+ var import_jsx_runtime13 = require("react/jsx-runtime");
2629
2634
  var MC4 = __toESM(require("@mantine/core"), 1);
2630
2635
  var TI5 = __toESM(require("@tabler/icons-react"), 1);
2631
- var import_jsx_runtime13 = require("react/jsx-runtime");
2632
- var import_react_router_dom = require("react-router-dom");
2633
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
+ };
2634
2649
  var SidebarMenu = ({
2635
2650
  id,
2636
2651
  label,
2637
2652
  icon,
2638
2653
  active,
2654
+ currentPathname,
2639
2655
  screens,
2640
2656
  onClickMenu,
2641
2657
  onCloseSidebar,
2642
- onClickExternalScreen
2658
+ onClickExternalScreen,
2659
+ onClickScreen
2643
2660
  }) => {
2661
+ const pathname = currentPathname || "";
2662
+ const handleClickScreen = (screen) => {
2663
+ onCloseSidebar();
2664
+ onClickScreen(screen);
2665
+ };
2644
2666
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
2645
2667
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2646
2668
  MC4.UnstyledButton,
@@ -2664,13 +2686,21 @@ var SidebarMenu = ({
2664
2686
  }
2665
2687
  ),
2666
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: [
2667
- 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
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2694
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2695
+ }
2696
+ ),
2668
2697
  !screen.external && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2669
- import_react_router_dom.NavLink,
2698
+ MC4.Box,
2670
2699
  {
2671
- to: screen.url || "#",
2672
- onClick: onCloseSidebar,
2673
- className: (isActive) => isActive ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2700
+ onClick: () => handleClickScreen(screen),
2701
+ className: isActiveScreen(screen.url || "", pathname) ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2702
+ style: { cursor: "pointer" },
2703
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2674
2704
  children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2675
2705
  }
2676
2706
  )
@@ -2680,7 +2710,12 @@ var SidebarMenu = ({
2680
2710
 
2681
2711
  // src/components/sidebar/Sidebar.tsx
2682
2712
  var import_jsx_runtime15 = require("react/jsx-runtime");
2683
- var Sidebar = ({ modules, onClickExternalScreen }) => {
2713
+ var Sidebar = ({
2714
+ modules,
2715
+ currentPathname,
2716
+ onClickExternalScreen,
2717
+ onClickScreen
2718
+ }) => {
2684
2719
  const [opened, setOpened] = (0, import_react9.useState)(false);
2685
2720
  const [activeModuleId, setActiveModuleId] = (0, import_react9.useState)(null);
2686
2721
  const handleClickMenu = (id) => {
@@ -2693,10 +2728,10 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2693
2728
  setActiveModuleId(null);
2694
2729
  setOpened(false);
2695
2730
  };
2696
- const handleClickExternalScreen = (item) => {
2731
+ const handleClickExternalScreen = (module2, screen) => {
2697
2732
  setActiveModuleId(null);
2698
2733
  setOpened(false);
2699
- onClickExternalScreen(item);
2734
+ onClickExternalScreen(module2, screen);
2700
2735
  };
2701
2736
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("aside", { className: opened ? "ttn-sidebar" : "ttn-sidebar closed", children: [
2702
2737
  /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(MC5.Flex, { direction: "column", justify: "center", h: 56, children: [
@@ -2735,10 +2770,12 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2735
2770
  label: module2.label,
2736
2771
  icon: module2.icon,
2737
2772
  active: activeModuleId === module2.id,
2773
+ currentPathname,
2738
2774
  screens: module2.screens,
2739
2775
  onClickMenu: handleClickMenu,
2740
2776
  onCloseSidebar: handleCloseSidebar,
2741
- onClickExternalScreen: handleClickExternalScreen
2777
+ onClickExternalScreen: (screen) => handleClickExternalScreen(module2, screen),
2778
+ onClickScreen: (screen) => onClickScreen(module2, screen)
2742
2779
  },
2743
2780
  module2.id
2744
2781
  )),
package/dist/index.css CHANGED
@@ -11,7 +11,6 @@
11
11
  transition: width 0.3s ease;
12
12
  &.closed {
13
13
  width: 80px;
14
- overflow: hidden;
15
14
  }
16
15
  }
17
16
  .ttn-sidebar-menu {
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
@@ -2456,13 +2456,14 @@ var HelpModal = ({ opened, onClose }) => {
2456
2456
  import * as MC2 from "@mantine/core";
2457
2457
  import * as TI3 from "@tabler/icons-react";
2458
2458
  import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
2459
+ var cloudImage = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 52 72'><path d='M-77.4698 71.426C-77.4698 71.426 -102.699 40.2305 -82.8905 21.109C-53.4064 -7.35147 -33.3402 33.0955 -21.9827 16.3565C-3.19499 -11.3325 58.2673 -4.22647 39.4625 30.2055C29.5967 48.27 62.6052 45.5705 49.1486 71.462L-77.4698 71.426Z' fill='%23EBF3FA'/></svg>`;
2459
2460
  var ChangeAccountModal = ({
2460
2461
  opened,
2461
2462
  onClose,
2462
2463
  accounts,
2463
2464
  onChangeAccount
2464
2465
  }) => {
2465
- return /* @__PURE__ */ jsx11(MC2.Modal, { opened, onClose, size: 1200, title: "Cambiar cuenta", children: /* @__PURE__ */ jsx11(MC2.Grid, { px: "lg", children: accounts.map((account, accountIndex) => /* @__PURE__ */ jsx11(MC2.Grid.Col, { span: 6, children: /* @__PURE__ */ jsxs10(MC2.Menu, { position: "right", width: 210, children: [
2466
+ return /* @__PURE__ */ jsx11(MC2.Modal, { opened, onClose, size: 1200, title: "Seleccionar cuenta", children: /* @__PURE__ */ jsx11(MC2.Grid, { px: "lg", children: accounts.map((account, accountIndex) => /* @__PURE__ */ jsx11(MC2.Grid.Col, { span: 6, children: /* @__PURE__ */ jsxs10(MC2.Menu, { position: "right", width: 210, children: [
2466
2467
  /* @__PURE__ */ jsx11(MC2.Menu.Target, { "data-testid": `change-account-account-option-${accountIndex}`, children: /* @__PURE__ */ jsxs10(
2467
2468
  MC2.Group,
2468
2469
  {
@@ -2474,7 +2475,10 @@ var ChangeAccountModal = ({
2474
2475
  border: `1px solid ${theme.colors.gray[3]}`,
2475
2476
  borderRadius: theme.radius.md,
2476
2477
  padding: "8px",
2477
- cursor: "pointer"
2478
+ cursor: "pointer",
2479
+ backgroundImage: `url("${cloudImage}")`,
2480
+ backgroundSize: "contain",
2481
+ backgroundRepeat: "no-repeat"
2478
2482
  }),
2479
2483
  children: [
2480
2484
  /* @__PURE__ */ jsx11("div", {}),
@@ -2638,21 +2642,39 @@ import * as MC5 from "@mantine/core";
2638
2642
  import * as TI6 from "@tabler/icons-react";
2639
2643
 
2640
2644
  // src/components/sidebar/SidebarMenu.tsx
2645
+ import { Fragment as Fragment4 } from "react/jsx-runtime";
2641
2646
  import * as MC4 from "@mantine/core";
2642
2647
  import * as TI5 from "@tabler/icons-react";
2643
- import { Fragment as Fragment4 } from "react/jsx-runtime";
2644
- import { NavLink } from "react-router-dom";
2645
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
+ };
2646
2661
  var SidebarMenu = ({
2647
2662
  id,
2648
2663
  label,
2649
2664
  icon,
2650
2665
  active,
2666
+ currentPathname,
2651
2667
  screens,
2652
2668
  onClickMenu,
2653
2669
  onCloseSidebar,
2654
- onClickExternalScreen
2670
+ onClickExternalScreen,
2671
+ onClickScreen
2655
2672
  }) => {
2673
+ const pathname = currentPathname || "";
2674
+ const handleClickScreen = (screen) => {
2675
+ onCloseSidebar();
2676
+ onClickScreen(screen);
2677
+ };
2656
2678
  return /* @__PURE__ */ jsxs12(Fragment5, { children: [
2657
2679
  /* @__PURE__ */ jsxs12(
2658
2680
  MC4.UnstyledButton,
@@ -2676,13 +2698,21 @@ var SidebarMenu = ({
2676
2698
  }
2677
2699
  ),
2678
2700
  Boolean(screens?.length) && /* @__PURE__ */ jsx13(MC4.Collapse, { in: active ?? false, children: screens?.map((screen) => /* @__PURE__ */ jsxs12(Fragment4, { children: [
2679
- 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
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2706
+ children: /* @__PURE__ */ jsx13(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2707
+ }
2708
+ ),
2680
2709
  !screen.external && /* @__PURE__ */ jsx13(
2681
- NavLink,
2710
+ MC4.Box,
2682
2711
  {
2683
- to: screen.url || "#",
2684
- onClick: onCloseSidebar,
2685
- className: (isActive) => isActive ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2712
+ onClick: () => handleClickScreen(screen),
2713
+ className: isActiveScreen(screen.url || "", pathname) ? "ttn-sidebar-menu-item active" : "ttn-sidebar-menu-item",
2714
+ style: { cursor: "pointer" },
2715
+ "data-testid": `sidebar-menu-${label}-screen-${screen.label}`,
2686
2716
  children: /* @__PURE__ */ jsx13(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
2687
2717
  }
2688
2718
  )
@@ -2692,7 +2722,12 @@ var SidebarMenu = ({
2692
2722
 
2693
2723
  // src/components/sidebar/Sidebar.tsx
2694
2724
  import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
2695
- var Sidebar = ({ modules, onClickExternalScreen }) => {
2725
+ var Sidebar = ({
2726
+ modules,
2727
+ currentPathname,
2728
+ onClickExternalScreen,
2729
+ onClickScreen
2730
+ }) => {
2696
2731
  const [opened, setOpened] = useState7(false);
2697
2732
  const [activeModuleId, setActiveModuleId] = useState7(null);
2698
2733
  const handleClickMenu = (id) => {
@@ -2705,10 +2740,10 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2705
2740
  setActiveModuleId(null);
2706
2741
  setOpened(false);
2707
2742
  };
2708
- const handleClickExternalScreen = (item) => {
2743
+ const handleClickExternalScreen = (module, screen) => {
2709
2744
  setActiveModuleId(null);
2710
2745
  setOpened(false);
2711
- onClickExternalScreen(item);
2746
+ onClickExternalScreen(module, screen);
2712
2747
  };
2713
2748
  return /* @__PURE__ */ jsxs13("aside", { className: opened ? "ttn-sidebar" : "ttn-sidebar closed", children: [
2714
2749
  /* @__PURE__ */ jsxs13(MC5.Flex, { direction: "column", justify: "center", h: 56, children: [
@@ -2747,10 +2782,12 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
2747
2782
  label: module.label,
2748
2783
  icon: module.icon,
2749
2784
  active: activeModuleId === module.id,
2785
+ currentPathname,
2750
2786
  screens: module.screens,
2751
2787
  onClickMenu: handleClickMenu,
2752
2788
  onCloseSidebar: handleCloseSidebar,
2753
- onClickExternalScreen: handleClickExternalScreen
2789
+ onClickExternalScreen: (screen) => handleClickExternalScreen(module, screen),
2790
+ onClickScreen: (screen) => onClickScreen(module, screen)
2754
2791
  },
2755
2792
  module.id
2756
2793
  )),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttn-shared/ui",
3
- "version": "1.2.8",
3
+ "version": "1.4.0",
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
  }
package/styles.css CHANGED
@@ -11,7 +11,6 @@
11
11
  transition: width 0.3s ease;
12
12
  &.closed {
13
13
  width: 80px;
14
- overflow: hidden;
15
14
  }
16
15
  }
17
16
  .ttn-sidebar-menu {