@buerokratt-ria/menu 0.1.16 → 0.2.1

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.
@@ -1,64 +1,77 @@
1
- import React, { FC, MouseEvent } from "react";
2
- import { NavLink } from 'react-router-dom';
3
- import { MdKeyboardArrowDown } from 'react-icons/md';
4
- import { MenuItem } from "../../types/menuItem";
5
- import { useTranslation } from "react-i18next";
6
- import { menuData } from './menuData';
7
- import Icon from "../icons/icon/icon";
8
- import { isSameRoot } from "./isSameRoot";
9
- import clsx from 'clsx';
10
- import '../../main-navigation.scss';
11
-
12
- interface MenuTreeProps {
13
- menuItems: MenuItem[];
14
- serviceId: string[];
15
- handleNavToggle: (event: MouseEvent) => void;
16
- }
17
-
18
- const MenuTree: FC<MenuTreeProps> = ({
19
- menuItems,
20
- serviceId,
21
- handleNavToggle,
22
- }) => {
23
- const currentlySelectedLanguage = useTranslation().i18n.language;
24
-
25
- return menuItems
26
- .filter(x => !x.hidden)
27
- .map((menuItem) => (
28
- <li key={menuItem.label[currentlySelectedLanguage]}>
29
- {!!menuItem.children ? (
30
- <>
31
- <button
32
- className={clsx('nav__toggle', { 'nav__toggle--icon': !!menuItem.id })}
33
- aria-expanded={menuItem.path && (isSameRoot(menuItem, serviceId)) ? 'true' : 'false'}
34
- onClick={handleNavToggle}
35
- >
36
- {menuItem.id && (
37
- <Icon icon={menuData.find(dataItem => dataItem.id === menuItem.id)?.icon} size='large' />
38
- )}
39
- <span className='menu-item-title'>{menuItem.label[currentlySelectedLanguage]}</span>
40
- <Icon icon={<MdKeyboardArrowDown />} className='menu-item-arrow' />
41
- </button>
42
- <ul className='nav__submenu'>
43
- <MenuTree
44
- menuItems={menuItem.children.map((item) => ({id: menuItem.id, ...item}))}
45
- serviceId={serviceId}
46
- handleNavToggle={handleNavToggle}
47
- />
48
- </ul>
49
- </>
50
- ) : (
51
- serviceId.includes(menuItem.id!)
52
- ? <NavLink to={menuItem.path || '#'}>
53
- {menuItem.label[currentlySelectedLanguage]}
54
- </NavLink>
55
- : <a href={(menuData.find(dataItem => dataItem.id === menuItem.id)?.url ?? '') + menuItem.path}>
56
- {menuItem.label[currentlySelectedLanguage]}
57
- </a>
58
- )}
59
- </li>
60
- ),
61
- );
62
- }
63
-
64
- export default MenuTree;
1
+ import React, { FC, MouseEvent } from "react";
2
+ import { NavLink } from 'react-router-dom';
3
+ import { MdKeyboardArrowDown } from 'react-icons/md';
4
+ import { MenuItem } from "../../types/menuItem";
5
+ import { useTranslation } from "react-i18next";
6
+ import { menuData } from './menuData';
7
+ import Icon from "../icons/icon/icon";
8
+ import { isSameRoot } from "./isSameRoot";
9
+ import clsx from 'clsx';
10
+ import '../../main-navigation.scss';
11
+
12
+ interface MenuTreeProps {
13
+ menuItems: MenuItem[];
14
+ serviceId: string[];
15
+ handleNavToggle: (event: MouseEvent) => void;
16
+ }
17
+
18
+ interface MenuItemLabelProps {
19
+ menuItem: MenuItem
20
+ currentlySelectedLanguage: string
21
+ }
22
+
23
+ const MenuItemLabel: React.FC<MenuItemLabelProps> = ({ menuItem, currentlySelectedLanguage }) => {
24
+ return (
25
+ <>
26
+ {menuItem.label[currentlySelectedLanguage]} {menuItem.count != null ? `(${menuItem.count})` : ''}
27
+ </>
28
+ );
29
+ };
30
+
31
+ const MenuTree: FC<MenuTreeProps> = ({
32
+ menuItems,
33
+ serviceId,
34
+ handleNavToggle,
35
+ }) => {
36
+ const currentlySelectedLanguage = useTranslation().i18n.language;
37
+
38
+ return menuItems
39
+ .filter(x => !x.hidden)
40
+ .map((menuItem) => (
41
+ <li key={menuItem.label[currentlySelectedLanguage]}>
42
+ {!!menuItem.children ? (
43
+ <>
44
+ <button
45
+ className={clsx('nav__toggle', { 'nav__toggle--icon': !!menuItem.id })}
46
+ aria-expanded={menuItem.path && (isSameRoot(menuItem, serviceId)) ? 'true' : 'false'}
47
+ onClick={handleNavToggle}
48
+ >
49
+ {menuItem.id && (
50
+ <Icon icon={menuData.find(dataItem => dataItem.id === menuItem.id)?.icon} size='large' />
51
+ )}
52
+ <span className='menu-item-title'>{menuItem.label[currentlySelectedLanguage]}</span>
53
+ <Icon icon={<MdKeyboardArrowDown />} className='menu-item-arrow' />
54
+ </button>
55
+ <ul className='nav__submenu'>
56
+ <MenuTree
57
+ menuItems={menuItem.children.map((item) => ({id: menuItem.id, ...item}))}
58
+ serviceId={serviceId}
59
+ handleNavToggle={handleNavToggle}
60
+ />
61
+ </ul>
62
+ </>
63
+ ) : (
64
+ serviceId.includes(menuItem.id!)
65
+ ? <NavLink to={menuItem.path || '#'}>
66
+ <MenuItemLabel menuItem={menuItem} currentlySelectedLanguage={currentlySelectedLanguage} />
67
+ </NavLink>
68
+ : <a href={(menuData.find(dataItem => dataItem.id === menuItem.id)?.url ?? '') + menuItem.path}>
69
+ <MenuItemLabel menuItem={menuItem} currentlySelectedLanguage={currentlySelectedLanguage} />
70
+ </a>
71
+ )}
72
+ </li>
73
+ ),
74
+ );
75
+ }
76
+
77
+ export default MenuTree;
@@ -1,10 +1,10 @@
1
- import { MenuItem } from "../../types/menuItem";
2
-
3
- export const isSameRoot = (menuItem, serviceId) => {
4
- const base = window.location.pathname.split("/")[1];
5
- const currentService = base === 'chat' ? serviceId : [base];
6
- if(currentService.includes(menuItem.id)) {
7
- return menuItem.children.some((item: MenuItem) => item.path?.includes("/" + window.location.pathname.split("/")[2]));
8
- }
9
- return false;
10
- }
1
+ import { MenuItem } from "../../types/menuItem";
2
+
3
+ export const isSameRoot = (menuItem, serviceId) => {
4
+ const base = window.location.pathname.split("/")[1];
5
+ const currentService = base === 'chat' ? serviceId : [base];
6
+ if(currentService.includes(menuItem.id)) {
7
+ return menuItem.children.some((item: MenuItem) => item.path?.includes("/" + window.location.pathname.split("/")[2]));
8
+ }
9
+ return false;
10
+ }
@@ -1,42 +1,42 @@
1
- import React from 'react';
2
- import {
3
- MdOutlineForum,
4
- MdOutlineAdb,
5
- MdOutlineEqualizer,
6
- MdMiscellaneousServices,
7
- MdSettings,
8
- MdOutlineMonitorWeight,
9
- } from 'react-icons/md';
10
-
11
- export const menuData = [
12
- {
13
- id: 'conversations',
14
- icon: <MdOutlineForum className='menu-item-icon' />,
15
- url: import.meta.env.REACT_APP_CONVERSATIONS_BASE_URL,
16
- },
17
- {
18
- id: 'training',
19
- icon: <MdOutlineAdb className='menu-item-icon' />,
20
- url: import.meta.env.REACT_APP_TRAINING_BASE_URL,
21
- },
22
- {
23
- id: 'analytics',
24
- icon: <MdOutlineEqualizer className='menu-item-icon' />,
25
- url: import.meta.env.REACT_APP_ANALYTICS_BASE_URL,
26
- },
27
- {
28
- id: "services",
29
- icon: <MdMiscellaneousServices className='menu-item-icon' />,
30
- url: import.meta.env.REACT_APP_SERVICES_BASE_URL,
31
- },
32
- {
33
- id: 'settings',
34
- icon: <MdSettings className='menu-item-icon' />,
35
- url: import.meta.env.REACT_APP_SETTINGS_BASE_URL,
36
- },
37
- {
38
- id: 'monitoring',
39
- icon: <MdOutlineMonitorWeight className='menu-item-icon' />,
40
- url: import.meta.env.REACT_APP_MONITORING_BASE_URL,
41
- },
42
- ];
1
+ import React from 'react';
2
+ import {
3
+ MdOutlineForum,
4
+ MdOutlineAdb,
5
+ MdOutlineEqualizer,
6
+ MdMiscellaneousServices,
7
+ MdSettings,
8
+ MdOutlineMonitorWeight,
9
+ } from 'react-icons/md';
10
+
11
+ export const menuData = [
12
+ {
13
+ id: 'conversations',
14
+ icon: <MdOutlineForum className='menu-item-icon' />,
15
+ url: import.meta.env.REACT_APP_CONVERSATIONS_BASE_URL,
16
+ },
17
+ {
18
+ id: 'training',
19
+ icon: <MdOutlineAdb className='menu-item-icon' />,
20
+ url: import.meta.env.REACT_APP_TRAINING_BASE_URL,
21
+ },
22
+ {
23
+ id: 'analytics',
24
+ icon: <MdOutlineEqualizer className='menu-item-icon' />,
25
+ url: import.meta.env.REACT_APP_ANALYTICS_BASE_URL,
26
+ },
27
+ {
28
+ id: "services",
29
+ icon: <MdMiscellaneousServices className='menu-item-icon' />,
30
+ url: import.meta.env.REACT_APP_SERVICES_BASE_URL,
31
+ },
32
+ {
33
+ id: 'settings',
34
+ icon: <MdSettings className='menu-item-icon' />,
35
+ url: import.meta.env.REACT_APP_SETTINGS_BASE_URL,
36
+ },
37
+ {
38
+ id: 'monitoring',
39
+ icon: <MdOutlineMonitorWeight className='menu-item-icon' />,
40
+ url: import.meta.env.REACT_APP_MONITORING_BASE_URL,
41
+ },
42
+ ];