@ttn-shared/ui 1.3.0 → 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 +44 -11
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +44 -11
- package/package.json +2 -5
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,21 @@ 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)(
|
|
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
|
+
),
|
|
2672
2697
|
!screen.external && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2673
|
-
|
|
2698
|
+
MC4.Box,
|
|
2674
2699
|
{
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
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}`,
|
|
2678
2704
|
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
|
|
2679
2705
|
}
|
|
2680
2706
|
)
|
|
@@ -2684,7 +2710,12 @@ var SidebarMenu = ({
|
|
|
2684
2710
|
|
|
2685
2711
|
// src/components/sidebar/Sidebar.tsx
|
|
2686
2712
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2687
|
-
var Sidebar = ({
|
|
2713
|
+
var Sidebar = ({
|
|
2714
|
+
modules,
|
|
2715
|
+
currentPathname,
|
|
2716
|
+
onClickExternalScreen,
|
|
2717
|
+
onClickScreen
|
|
2718
|
+
}) => {
|
|
2688
2719
|
const [opened, setOpened] = (0, import_react9.useState)(false);
|
|
2689
2720
|
const [activeModuleId, setActiveModuleId] = (0, import_react9.useState)(null);
|
|
2690
2721
|
const handleClickMenu = (id) => {
|
|
@@ -2697,10 +2728,10 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
|
|
|
2697
2728
|
setActiveModuleId(null);
|
|
2698
2729
|
setOpened(false);
|
|
2699
2730
|
};
|
|
2700
|
-
const handleClickExternalScreen = (
|
|
2731
|
+
const handleClickExternalScreen = (module2, screen) => {
|
|
2701
2732
|
setActiveModuleId(null);
|
|
2702
2733
|
setOpened(false);
|
|
2703
|
-
onClickExternalScreen(
|
|
2734
|
+
onClickExternalScreen(module2, screen);
|
|
2704
2735
|
};
|
|
2705
2736
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("aside", { className: opened ? "ttn-sidebar" : "ttn-sidebar closed", children: [
|
|
2706
2737
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(MC5.Flex, { direction: "column", justify: "center", h: 56, children: [
|
|
@@ -2739,10 +2770,12 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
|
|
|
2739
2770
|
label: module2.label,
|
|
2740
2771
|
icon: module2.icon,
|
|
2741
2772
|
active: activeModuleId === module2.id,
|
|
2773
|
+
currentPathname,
|
|
2742
2774
|
screens: module2.screens,
|
|
2743
2775
|
onClickMenu: handleClickMenu,
|
|
2744
2776
|
onCloseSidebar: handleCloseSidebar,
|
|
2745
|
-
onClickExternalScreen: handleClickExternalScreen
|
|
2777
|
+
onClickExternalScreen: (screen) => handleClickExternalScreen(module2, screen),
|
|
2778
|
+
onClickScreen: (screen) => onClickScreen(module2, screen)
|
|
2746
2779
|
},
|
|
2747
2780
|
module2.id
|
|
2748
2781
|
)),
|
package/dist/index.d.cts
CHANGED
|
@@ -292,9 +292,11 @@ interface SidebarModule {
|
|
|
292
292
|
|
|
293
293
|
interface SidebarProps {
|
|
294
294
|
modules: SidebarModule[];
|
|
295
|
-
|
|
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
|
-
|
|
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,21 @@ 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(
|
|
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
|
+
),
|
|
2684
2709
|
!screen.external && /* @__PURE__ */ jsx13(
|
|
2685
|
-
|
|
2710
|
+
MC4.Box,
|
|
2686
2711
|
{
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
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}`,
|
|
2690
2716
|
children: /* @__PURE__ */ jsx13(MC4.Text, { size: "sm", c: "gray.7", lineClamp: 1, children: screen.label })
|
|
2691
2717
|
}
|
|
2692
2718
|
)
|
|
@@ -2696,7 +2722,12 @@ var SidebarMenu = ({
|
|
|
2696
2722
|
|
|
2697
2723
|
// src/components/sidebar/Sidebar.tsx
|
|
2698
2724
|
import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2699
|
-
var Sidebar = ({
|
|
2725
|
+
var Sidebar = ({
|
|
2726
|
+
modules,
|
|
2727
|
+
currentPathname,
|
|
2728
|
+
onClickExternalScreen,
|
|
2729
|
+
onClickScreen
|
|
2730
|
+
}) => {
|
|
2700
2731
|
const [opened, setOpened] = useState7(false);
|
|
2701
2732
|
const [activeModuleId, setActiveModuleId] = useState7(null);
|
|
2702
2733
|
const handleClickMenu = (id) => {
|
|
@@ -2709,10 +2740,10 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
|
|
|
2709
2740
|
setActiveModuleId(null);
|
|
2710
2741
|
setOpened(false);
|
|
2711
2742
|
};
|
|
2712
|
-
const handleClickExternalScreen = (
|
|
2743
|
+
const handleClickExternalScreen = (module, screen) => {
|
|
2713
2744
|
setActiveModuleId(null);
|
|
2714
2745
|
setOpened(false);
|
|
2715
|
-
onClickExternalScreen(
|
|
2746
|
+
onClickExternalScreen(module, screen);
|
|
2716
2747
|
};
|
|
2717
2748
|
return /* @__PURE__ */ jsxs13("aside", { className: opened ? "ttn-sidebar" : "ttn-sidebar closed", children: [
|
|
2718
2749
|
/* @__PURE__ */ jsxs13(MC5.Flex, { direction: "column", justify: "center", h: 56, children: [
|
|
@@ -2751,10 +2782,12 @@ var Sidebar = ({ modules, onClickExternalScreen }) => {
|
|
|
2751
2782
|
label: module.label,
|
|
2752
2783
|
icon: module.icon,
|
|
2753
2784
|
active: activeModuleId === module.id,
|
|
2785
|
+
currentPathname,
|
|
2754
2786
|
screens: module.screens,
|
|
2755
2787
|
onClickMenu: handleClickMenu,
|
|
2756
2788
|
onCloseSidebar: handleCloseSidebar,
|
|
2757
|
-
onClickExternalScreen: handleClickExternalScreen
|
|
2789
|
+
onClickExternalScreen: (screen) => handleClickExternalScreen(module, screen),
|
|
2790
|
+
onClickScreen: (screen) => onClickScreen(module, screen)
|
|
2758
2791
|
},
|
|
2759
2792
|
module.id
|
|
2760
2793
|
)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttn-shared/ui",
|
|
3
|
-
"version": "1.
|
|
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
|
}
|