@buerokratt-ria/menu 0.1.8 → 0.1.9

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