@buerokratt-ria/menu 0.1.7 → 0.1.8
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/CHANGELOG.md +2 -2
- package/buerokratt-ria-menu-0.1.8.tgz +0 -0
- package/package.json +1 -1
- package/src/menu/components/icons/icon/icon.tsx +3 -4
- package/src/menu/components/icons/icon.scss +0 -5
- package/src/menu/data/menu-structure.json +9 -0
- package/src/menu/index.tsx +46 -58
- package/src/menu/main-navigation.scss +3 -23
- package/buerokratt-ria-menu-0.1.7.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -12,13 +12,12 @@ import '../icon.scss';
|
|
|
12
12
|
type IconProps = StyleHTMLAttributes<CSSProperties> & {
|
|
13
13
|
label?: string | null;
|
|
14
14
|
icon: ReactNode;
|
|
15
|
-
size?: 'small' | 'medium'
|
|
16
|
-
className?: string;
|
|
15
|
+
size?: 'small' | 'medium';
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
const IconComponent = forwardRef<HTMLSpanElement, IconProps>(
|
|
20
|
-
({ label, icon,
|
|
21
|
-
const iconClasses = clsx('icon', `icon--${size}
|
|
19
|
+
({ label, icon, size = 'small', ...rest }, ref) => {
|
|
20
|
+
const iconClasses = clsx('icon', `icon--${size}`);
|
|
22
21
|
|
|
23
22
|
return (
|
|
24
23
|
<AccessibleIcon.Root label={label ?? ''}>
|
package/src/menu/index.tsx
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
1
|
+
import React, {FC, MouseEvent, useState} from 'react';
|
|
2
|
+
|
|
3
|
+
import {NavLink, useLocation} from 'react-router-dom';
|
|
3
4
|
import clsx from 'clsx';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
MdOutlineAdb,
|
|
7
|
-
MdOutlineEqualizer,
|
|
8
|
-
MdKeyboardArrowDown,
|
|
9
|
-
MdMiscellaneousServices,
|
|
10
|
-
MdSettings,
|
|
11
|
-
MdOutlineMonitorWeight,
|
|
12
|
-
MdKeyboardArrowRight,
|
|
13
|
-
MdKeyboardArrowLeft,
|
|
14
|
-
} from 'react-icons/md';
|
|
15
|
-
import Icon from './components/icons/icon/icon';
|
|
5
|
+
import { MdOutlineForum, MdOutlineAdb, MdOutlineEqualizer, MdClose, MdKeyboardArrowDown, MdMiscellaneousServices, MdSettings, MdOutlineMonitorWeight } from 'react-icons/md';
|
|
6
|
+
import Icon from './components/icons/icon/icon';
|
|
16
7
|
import './main-navigation.scss';
|
|
17
8
|
import { useQuery } from '@tanstack/react-query';
|
|
18
|
-
import {
|
|
9
|
+
import {useTranslation} from "react-i18next";
|
|
19
10
|
import menuStructure from './data/menu-structure.json';
|
|
20
11
|
|
|
21
12
|
interface MenuItem {
|
|
@@ -24,6 +15,7 @@ interface MenuItem {
|
|
|
24
15
|
path?: string;
|
|
25
16
|
target?: '_blank' | '_self';
|
|
26
17
|
children?: MenuItem[];
|
|
18
|
+
hidden?: boolean;
|
|
27
19
|
}
|
|
28
20
|
|
|
29
21
|
interface TranslatedLabel {
|
|
@@ -38,41 +30,42 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
38
30
|
const { t, i18n } = useTranslation();
|
|
39
31
|
const currentlySelectedLanguage = i18n.language;
|
|
40
32
|
const [menuItems, setMenuItems] = useState<MenuItem[]>([]);
|
|
41
|
-
|
|
42
33
|
const menuData = [
|
|
43
34
|
{
|
|
44
35
|
id: 'conversations',
|
|
45
|
-
icon: <MdOutlineForum
|
|
36
|
+
icon: <MdOutlineForum />,
|
|
46
37
|
url: import.meta.env.REACT_APP_CONVERSATIONS_BASE_URL,
|
|
47
38
|
},
|
|
48
39
|
{
|
|
49
40
|
id: 'training',
|
|
50
|
-
icon: <MdOutlineAdb
|
|
41
|
+
icon: <MdOutlineAdb />,
|
|
51
42
|
url: import.meta.env.REACT_APP_TRAINING_BASE_URL,
|
|
52
43
|
},
|
|
53
44
|
{
|
|
54
45
|
id: 'analytics',
|
|
55
|
-
icon: <MdOutlineEqualizer
|
|
46
|
+
icon: <MdOutlineEqualizer />,
|
|
56
47
|
url: import.meta.env.REACT_APP_ANALYTICS_BASE_URL,
|
|
57
48
|
},
|
|
58
49
|
{
|
|
59
50
|
id: "services",
|
|
60
|
-
icon: <MdMiscellaneousServices
|
|
51
|
+
icon: <MdMiscellaneousServices />,
|
|
61
52
|
url: import.meta.env.REACT_APP_SERVICES_BASE_URL,
|
|
62
53
|
},
|
|
63
54
|
{
|
|
64
55
|
id: 'settings',
|
|
65
|
-
icon: <MdSettings
|
|
56
|
+
icon: <MdSettings />,
|
|
66
57
|
url: import.meta.env.REACT_APP_SETTINGS_BASE_URL,
|
|
67
58
|
},
|
|
68
59
|
{
|
|
69
60
|
id: 'monitoring',
|
|
70
|
-
icon: <MdOutlineMonitorWeight
|
|
61
|
+
icon: <MdOutlineMonitorWeight />,
|
|
71
62
|
url: import.meta.env.REACT_APP_MONITORING_BASE_URL,
|
|
72
63
|
},
|
|
73
64
|
];
|
|
74
65
|
|
|
75
|
-
|
|
66
|
+
let activeMenuId;
|
|
67
|
+
|
|
68
|
+
const { data } = useQuery({
|
|
76
69
|
queryKey: ['accounts/user-role', 'prod'],
|
|
77
70
|
onSuccess: (res: any) => {
|
|
78
71
|
const filteredItems =
|
|
@@ -96,74 +89,69 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
96
89
|
},
|
|
97
90
|
});
|
|
98
91
|
|
|
92
|
+
const location = useLocation();
|
|
99
93
|
const [navCollapsed, setNavCollapsed] = useState(false);
|
|
100
94
|
|
|
101
95
|
const handleNavToggle = (event: MouseEvent) => {
|
|
102
|
-
setNavCollapsed(false);
|
|
103
96
|
const isExpanded = event.currentTarget.getAttribute('aria-expanded') === 'true';
|
|
104
97
|
event.currentTarget.setAttribute('aria-expanded', isExpanded ? 'false' : 'true');
|
|
105
98
|
};
|
|
106
99
|
|
|
107
100
|
const renderMenuTree = (menuItems: MenuItem[]) => {
|
|
108
|
-
return menuItems.map((menuItem) => (
|
|
101
|
+
return menuItems.filter(x => !x.hidden).map((menuItem) => (
|
|
109
102
|
<li key={menuItem.label[currentlySelectedLanguage]}>
|
|
110
103
|
{!!menuItem.children ? (
|
|
111
104
|
<>
|
|
112
105
|
<button
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
className={clsx('nav__toggle', { 'nav__toggle--icon': !!menuItem.id })}
|
|
107
|
+
aria-expanded={menuItem.path && (isSameRoot(menuItem)) ? 'true' : 'false'}
|
|
108
|
+
onClick={handleNavToggle}
|
|
116
109
|
>
|
|
117
|
-
{menuItem.id &&
|
|
118
|
-
|
|
110
|
+
{ menuItem.id && (
|
|
111
|
+
<Icon icon={menuData.find(dataItem => dataItem.id === menuItem.id)?.icon} />
|
|
119
112
|
)}
|
|
120
|
-
|
|
121
|
-
<
|
|
113
|
+
|
|
114
|
+
<span>{menuItem.label[currentlySelectedLanguage]}</span>
|
|
115
|
+
<Icon icon={<MdKeyboardArrowDown />} />
|
|
122
116
|
</button>
|
|
123
117
|
<ul className='nav__submenu'>
|
|
124
118
|
{renderMenuTree(menuItem.children.map((item) => ({id: menuItem.id, ...item})))}
|
|
125
119
|
</ul>
|
|
126
120
|
</>
|
|
127
121
|
) : (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
{menuItem.label[currentlySelectedLanguage]}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{menuItem.label[currentlySelectedLanguage]}
|
|
134
|
-
</a>
|
|
122
|
+
|
|
123
|
+
(serviceId.includes(menuItem.id)) ?
|
|
124
|
+
<NavLink to={menuItem.path || '#'}>{menuItem.label[currentlySelectedLanguage] }</NavLink> :
|
|
125
|
+
<a href={menuData.find(dataItem => dataItem.id === menuItem.id)?.url + menuItem.path}>{menuItem.label[currentlySelectedLanguage]}</a>
|
|
126
|
+
|
|
135
127
|
)}
|
|
136
|
-
</li>
|
|
137
|
-
),
|
|
128
|
+
</li>),
|
|
138
129
|
);
|
|
139
130
|
};
|
|
140
131
|
|
|
141
132
|
const base = window.location.pathname.split("/")[1];
|
|
142
133
|
const currentService = base === 'chat' ? serviceId : [base];
|
|
143
134
|
const isSameRoot = (menuItem) => {
|
|
144
|
-
|
|
145
|
-
|
|
135
|
+
let result = false;
|
|
136
|
+
if(currentService.includes(menuItem.id)){
|
|
137
|
+
result = menuItem.children.some((item: MenuItem) => item.path?.includes("/" + window.location.pathname.split("/")[2]));
|
|
146
138
|
}
|
|
147
|
-
return
|
|
139
|
+
return result;
|
|
148
140
|
}
|
|
149
141
|
|
|
150
142
|
if (!menuItems) return null;
|
|
151
143
|
|
|
152
144
|
return (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
</
|
|
162
|
-
<ul className='nav__menu'>
|
|
163
|
-
{renderMenuTree(menuItems)}
|
|
164
|
-
</ul>
|
|
165
|
-
</nav>
|
|
145
|
+
<nav className={clsx('nav', { 'nav--collapsed': navCollapsed })}>
|
|
146
|
+
<button className='nav__menu-toggle' onClick={() => setNavCollapsed(!navCollapsed)}>
|
|
147
|
+
<Icon icon={<MdClose />} />
|
|
148
|
+
{t('mainMenu.closeMenu')}
|
|
149
|
+
</button>
|
|
150
|
+
<ul className='nav__menu'>
|
|
151
|
+
{renderMenuTree(menuItems)}
|
|
152
|
+
</ul>
|
|
153
|
+
</nav>
|
|
166
154
|
);
|
|
167
155
|
};
|
|
168
156
|
|
|
169
|
-
export default MainNavigation;
|
|
157
|
+
export default MainNavigation;
|
|
@@ -57,6 +57,9 @@
|
|
|
57
57
|
&.active {
|
|
58
58
|
font-weight: 700;
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
&:focus {
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
&__toggle {
|
|
@@ -114,26 +117,3 @@
|
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
|
-
|
|
118
|
-
.collapsed {
|
|
119
|
-
width: 64px;
|
|
120
|
-
|
|
121
|
-
.menu-item-arrow,
|
|
122
|
-
.menu-item-title {
|
|
123
|
-
display: none !important;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.menu-item-icon {
|
|
127
|
-
height: 24px;
|
|
128
|
-
width: 24px;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.close-button-item,
|
|
132
|
-
button.nav__toggle {
|
|
133
|
-
justify-content: center;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.nav__submenu {
|
|
137
|
-
display: none !important;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
Binary file
|