@campxdev/react-blueprint 2.2.0 → 2.2.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.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/types/src/components/Layout/AppLayout/components/Sidebar/interfaces.d.ts +2 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/types/src/components/Layout/AppLayout/components/Sidebar/interfaces.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/DataDisplay/Card/Card.tsx +2 -1
- package/src/components/Layout/AppLayout/components/SideDrawer.tsx +1 -0
- package/src/components/Layout/AppLayout/components/Sidebar/MenuBar.tsx +2 -2
- package/src/components/Layout/AppLayout/components/Sidebar/MenuItem.tsx +28 -3
- package/src/components/Layout/AppLayout/components/Sidebar/interfaces.ts +2 -0
- package/src/components/Layout/AppLayout/components/Sidebar/useSidebarNavigation.ts +62 -13
|
@@ -39,6 +39,7 @@ export interface MenuItemProps {
|
|
|
39
39
|
menuItem: SideMenuItemProps;
|
|
40
40
|
currentMenuPath: string | null;
|
|
41
41
|
internalMenuClickHandler: (params: InternalMenuClickHandlerProps) => void;
|
|
42
|
+
onClose?: () => void;
|
|
42
43
|
}
|
|
43
44
|
export interface SubMenuItemProps {
|
|
44
45
|
index: number;
|
|
@@ -50,4 +51,5 @@ export interface MenuBarProps {
|
|
|
50
51
|
menuPosition: number;
|
|
51
52
|
internalMenuClickHandler: (params: InternalMenuClickHandlerProps) => void;
|
|
52
53
|
previousMenuClickHandler: () => void;
|
|
54
|
+
onClose?: () => void;
|
|
53
55
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
} from '@mui/material';
|
|
10
10
|
import { TypographyVariant as Variant } from '@mui/material/styles';
|
|
11
11
|
import { ReactNode } from 'react';
|
|
12
|
-
import { DropDownIcon
|
|
12
|
+
import { DropDownIcon } from '../../Navigation/DropDownMenu/DropDownIcon';
|
|
13
|
+
import { DropdownMenu } from '../../Navigation/DropDownMenu/DropDownMenu';
|
|
13
14
|
import {
|
|
14
15
|
StyledButton,
|
|
15
16
|
StyledCardActions,
|
|
@@ -95,6 +95,7 @@ export const SideDrawer: React.FC<SideDrawerProps> = ({
|
|
|
95
95
|
menuPosition={navigation.menuPosition}
|
|
96
96
|
internalMenuClickHandler={navigation.internalMenuClickHandler}
|
|
97
97
|
previousMenuClickHandler={navigation.previousMenuClickHandler}
|
|
98
|
+
onClose={onClose}
|
|
98
99
|
/>
|
|
99
100
|
</motion.div>
|
|
100
101
|
</Drawer>
|
|
@@ -22,10 +22,10 @@ export const MenuBar: React.FC<MenuBarProps> = ({
|
|
|
22
22
|
menuPosition,
|
|
23
23
|
internalMenuClickHandler,
|
|
24
24
|
previousMenuClickHandler,
|
|
25
|
+
onClose,
|
|
25
26
|
}) => {
|
|
26
27
|
return (
|
|
27
28
|
<MenuBarContainer>
|
|
28
|
-
{/* Menu Header with Back Button */}
|
|
29
29
|
{currentMenuState.title && (
|
|
30
30
|
<MenuHeaderContainer
|
|
31
31
|
direction="row"
|
|
@@ -39,7 +39,6 @@ export const MenuBar: React.FC<MenuBarProps> = ({
|
|
|
39
39
|
</MenuHeaderContainer>
|
|
40
40
|
)}
|
|
41
41
|
|
|
42
|
-
{/* Menu Items */}
|
|
43
42
|
{currentMenuState.menu && currentMenuState.menu.length > 0 && (
|
|
44
43
|
<motion.div
|
|
45
44
|
variants={containerVariants}
|
|
@@ -53,6 +52,7 @@ export const MenuBar: React.FC<MenuBarProps> = ({
|
|
|
53
52
|
menuItem={item}
|
|
54
53
|
currentMenuPath={currentMenuState.path}
|
|
55
54
|
internalMenuClickHandler={internalMenuClickHandler}
|
|
55
|
+
onClose={onClose}
|
|
56
56
|
/>
|
|
57
57
|
))}
|
|
58
58
|
</motion.div>
|
|
@@ -20,6 +20,7 @@ export const MenuItem: React.FC<MenuItemProps> = ({
|
|
|
20
20
|
menuItem,
|
|
21
21
|
currentMenuPath,
|
|
22
22
|
internalMenuClickHandler,
|
|
23
|
+
onClose,
|
|
23
24
|
}) => {
|
|
24
25
|
const { name, path, icon, menu: internalMenu, subMenu } = menuItem;
|
|
25
26
|
const newPath = currentMenuPath ? `${currentMenuPath}${path}` : path;
|
|
@@ -38,6 +39,21 @@ export const MenuItem: React.FC<MenuItemProps> = ({
|
|
|
38
39
|
});
|
|
39
40
|
};
|
|
40
41
|
|
|
42
|
+
// Smart drawer closing logic
|
|
43
|
+
const shouldCloseDrawer = (item: typeof menuItem) => {
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// For desktop, only close if it's a leaf node (no children)
|
|
48
|
+
return !item.menu && !item.subMenu;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const handleNavigationClick = () => {
|
|
52
|
+
if (shouldCloseDrawer(menuItem) && onClose) {
|
|
53
|
+
onClose();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
41
57
|
// Internal menu item (has nested menu)
|
|
42
58
|
if (internalMenu && internalMenu.length > 0) {
|
|
43
59
|
return (
|
|
@@ -110,6 +126,7 @@ export const MenuItem: React.FC<MenuItemProps> = ({
|
|
|
110
126
|
index={subIndex}
|
|
111
127
|
subMenuItem={item}
|
|
112
128
|
subMenuButtonPath={newPath}
|
|
129
|
+
onClose={onClose}
|
|
113
130
|
/>
|
|
114
131
|
))}
|
|
115
132
|
</SubMenuItemContainer>
|
|
@@ -128,7 +145,7 @@ export const MenuItem: React.FC<MenuItemProps> = ({
|
|
|
128
145
|
transition={{ duration: 1 }}
|
|
129
146
|
>
|
|
130
147
|
<MenuItemContainer disablePadding>
|
|
131
|
-
<MenuLink to={newPath} match={match}>
|
|
148
|
+
<MenuLink to={newPath} match={match} onClick={handleNavigationClick}>
|
|
132
149
|
<MenuItemButton>
|
|
133
150
|
<MenuItemIcon>{icon}</MenuItemIcon>
|
|
134
151
|
<Typography variant="button1">{name}</Typography>
|
|
@@ -144,16 +161,24 @@ const SubMenuItem: React.FC<{
|
|
|
144
161
|
index: number;
|
|
145
162
|
subMenuItem: { name: string; path: string };
|
|
146
163
|
subMenuButtonPath: string;
|
|
147
|
-
|
|
164
|
+
onClose?: () => void;
|
|
165
|
+
}> = ({ index, subMenuItem, subMenuButtonPath, onClose }) => {
|
|
148
166
|
const { name, path } = subMenuItem;
|
|
149
167
|
const newPath = `${subMenuButtonPath}${path}`;
|
|
150
168
|
|
|
151
169
|
const resolved = useResolvedPath(newPath);
|
|
152
170
|
const match = useMatch({ path: resolved.pathname, end: false });
|
|
153
171
|
|
|
172
|
+
const handleSubMenuNavigationClick = () => {
|
|
173
|
+
// Always close drawer for submenu items (they are leaf nodes)
|
|
174
|
+
if (onClose) {
|
|
175
|
+
onClose();
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
154
179
|
return (
|
|
155
180
|
<MenuItemContainer key={index} disablePadding>
|
|
156
|
-
<MenuLink to={newPath} match={match} sx={{ margin: '5px 8px 5px 16px' }}>
|
|
181
|
+
<MenuLink to={newPath} match={match} sx={{ margin: '5px 8px 5px 16px' }} onClick={handleSubMenuNavigationClick}>
|
|
157
182
|
<MenuItemButton>
|
|
158
183
|
<Typography variant="button1">{name}</Typography>
|
|
159
184
|
</MenuItemButton>
|
|
@@ -47,6 +47,7 @@ export interface MenuItemProps {
|
|
|
47
47
|
menuItem: SideMenuItemProps;
|
|
48
48
|
currentMenuPath: string | null;
|
|
49
49
|
internalMenuClickHandler: (params: InternalMenuClickHandlerProps) => void;
|
|
50
|
+
onClose?: () => void; // Optional callback to close the drawer
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export interface SubMenuItemProps {
|
|
@@ -60,4 +61,5 @@ export interface MenuBarProps {
|
|
|
60
61
|
menuPosition: number;
|
|
61
62
|
internalMenuClickHandler: (params: InternalMenuClickHandlerProps) => void;
|
|
62
63
|
previousMenuClickHandler: () => void;
|
|
64
|
+
onClose?: () => void; // Optional callback to close the drawer
|
|
63
65
|
}
|
|
@@ -123,21 +123,70 @@ export const useSidebarNavigation = (
|
|
|
123
123
|
const currentPathArray = window.location.pathname.split('/');
|
|
124
124
|
|
|
125
125
|
if (currentPathArray.length > 3) {
|
|
126
|
-
currentPathArray.splice(0, 3);
|
|
127
|
-
|
|
126
|
+
currentPathArray.splice(0, 3); // Remove ['', 'aupulse', 'common-workspace']
|
|
127
|
+
// Remove the pop() - we need all remaining segments for navigation
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
// Build history stack while traversing to the active menu
|
|
131
|
+
const historyStack: MenuState[] = [];
|
|
132
|
+
let currentMenu = menu;
|
|
133
|
+
let currentPath = '';
|
|
134
|
+
let currentTitle: string | null = null;
|
|
135
|
+
|
|
136
|
+
// Traverse the path array to build history and find final menu state
|
|
137
|
+
for (let i = 0; i < currentPathArray.length; i++) {
|
|
138
|
+
const pathSegment = `/${currentPathArray[i]}`;
|
|
139
|
+
const item = currentMenu.find(
|
|
140
|
+
(item: SideMenuItemProps) => item.path === pathSegment,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
if (item && item.menu) {
|
|
144
|
+
if (i < currentPathArray.length - 1) {
|
|
145
|
+
// This is an intermediate level - add current level to history before moving deeper
|
|
146
|
+
historyStack.push({
|
|
147
|
+
title: currentTitle,
|
|
148
|
+
path: currentPath || null,
|
|
149
|
+
menu: currentMenu,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Move to next level
|
|
154
|
+
currentMenu = item.menu;
|
|
155
|
+
currentPath += item.path;
|
|
156
|
+
currentTitle = item.name;
|
|
157
|
+
} else {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Set the final menu state if we found nested menus
|
|
163
|
+
let finalMenuState: MenuState = currentMenuState;
|
|
164
|
+
if (currentPath) {
|
|
165
|
+
finalMenuState = {
|
|
166
|
+
title: currentTitle,
|
|
167
|
+
path: currentPath,
|
|
168
|
+
menu: currentMenu,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// If we have history, it means we're in a nested menu
|
|
173
|
+
if (historyStack.length > 0) {
|
|
174
|
+
setHistory(historyStack);
|
|
175
|
+
setCurrentMenuState(finalMenuState);
|
|
176
|
+
} else {
|
|
177
|
+
// Fallback to the original logic for non-nested menus
|
|
178
|
+
const activeMenu = getActiveMenu({
|
|
179
|
+
menu: currentMenuState.menu,
|
|
180
|
+
pathArray: currentPathArray,
|
|
181
|
+
previousMenuState: currentMenuState,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
setCurrentMenuState({
|
|
185
|
+
title: activeMenu?.title,
|
|
186
|
+
path: activeMenu.path,
|
|
187
|
+
menu: activeMenu?.menu,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
141
190
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
142
191
|
}, []);
|
|
143
192
|
|