@laerdal/life-react-components 2.2.1-dev.9 → 2.3.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.
Files changed (227) hide show
  1. package/dist/Accordion/AccordionItem.cjs +17 -8
  2. package/dist/Accordion/AccordionItem.cjs.map +1 -1
  3. package/dist/Accordion/AccordionItem.d.ts +0 -2
  4. package/dist/Accordion/AccordionItem.js +18 -9
  5. package/dist/Accordion/AccordionItem.js.map +1 -1
  6. package/dist/Accordion/AccordionMenu.cjs +2 -6
  7. package/dist/Accordion/AccordionMenu.cjs.map +1 -1
  8. package/dist/Accordion/AccordionMenu.d.ts +0 -3
  9. package/dist/Accordion/AccordionMenu.js +2 -6
  10. package/dist/Accordion/AccordionMenu.js.map +1 -1
  11. package/dist/Accordion/styles.cjs +11 -7
  12. package/dist/Accordion/styles.cjs.map +1 -1
  13. package/dist/Accordion/styles.d.ts +4 -1
  14. package/dist/Accordion/styles.js +9 -6
  15. package/dist/Accordion/styles.js.map +1 -1
  16. package/dist/AuthPage/AuthPage.js +1 -1
  17. package/dist/Banners/Banner.cjs.map +1 -1
  18. package/dist/Banners/Banner.js.map +1 -1
  19. package/dist/Button/Button.cjs +1 -1
  20. package/dist/Button/Button.cjs.map +1 -1
  21. package/dist/Button/Button.js +2 -2
  22. package/dist/Button/Button.js.map +1 -1
  23. package/dist/Button/Iconbutton.cjs.map +1 -1
  24. package/dist/Button/Iconbutton.d.ts +1 -1
  25. package/dist/Button/Iconbutton.js.map +1 -1
  26. package/dist/Card/HorizontalCard/HorizontalCard.cjs +9 -12
  27. package/dist/Card/HorizontalCard/HorizontalCard.cjs.map +1 -1
  28. package/dist/Card/HorizontalCard/HorizontalCard.d.ts +0 -2
  29. package/dist/Card/HorizontalCard/HorizontalCard.js +8 -9
  30. package/dist/Card/HorizontalCard/HorizontalCard.js.map +1 -1
  31. package/dist/Card/HorizontalCard/HorizontalCardBody.cjs +9 -13
  32. package/dist/Card/HorizontalCard/HorizontalCardBody.cjs.map +1 -1
  33. package/dist/Card/HorizontalCard/HorizontalCardBody.d.ts +0 -4
  34. package/dist/Card/HorizontalCard/HorizontalCardBody.js +8 -8
  35. package/dist/Card/HorizontalCard/HorizontalCardBody.js.map +1 -1
  36. package/dist/Card/HorizontalCard/HorizontalCardThumbnail.cjs +5 -7
  37. package/dist/Card/HorizontalCard/HorizontalCardThumbnail.cjs.map +1 -1
  38. package/dist/Card/HorizontalCard/HorizontalCardThumbnail.d.ts +0 -2
  39. package/dist/Card/HorizontalCard/HorizontalCardThumbnail.js +5 -5
  40. package/dist/Card/HorizontalCard/HorizontalCardThumbnail.js.map +1 -1
  41. package/dist/Card/HorizontalCard/index.cjs +12 -33
  42. package/dist/Card/HorizontalCard/index.cjs.map +1 -1
  43. package/dist/Card/HorizontalCard/index.d.ts +1 -3
  44. package/dist/Card/HorizontalCard/index.js +1 -3
  45. package/dist/Card/HorizontalCard/index.js.map +1 -1
  46. package/dist/Card/HorizontalCard/types.cjs.map +1 -1
  47. package/dist/Card/HorizontalCard/types.d.ts +1 -1
  48. package/dist/Card/HorizontalCard/types.js.map +1 -1
  49. package/dist/ChipsInput/ChipInputField.cjs +1 -1
  50. package/dist/ChipsInput/ChipInputField.cjs.map +1 -1
  51. package/dist/ChipsInput/ChipInputField.js +1 -1
  52. package/dist/ChipsInput/ChipInputField.js.map +1 -1
  53. package/dist/Dropdown/BasicDropdown.cjs +21 -6
  54. package/dist/Dropdown/BasicDropdown.cjs.map +1 -1
  55. package/dist/Dropdown/BasicDropdown.d.ts +2 -0
  56. package/dist/Dropdown/BasicDropdown.js +22 -7
  57. package/dist/Dropdown/BasicDropdown.js.map +1 -1
  58. package/dist/Dropdown/CommonStyling.cjs +7 -4
  59. package/dist/Dropdown/CommonStyling.cjs.map +1 -1
  60. package/dist/Dropdown/CommonStyling.d.ts +3 -1
  61. package/dist/Dropdown/CommonStyling.js +7 -4
  62. package/dist/Dropdown/CommonStyling.js.map +1 -1
  63. package/dist/Dropdown/DropdownContent.cjs +1 -1
  64. package/dist/Dropdown/DropdownContent.js +1 -1
  65. package/dist/Dropdown/DropdownFilter.cjs +16 -3
  66. package/dist/Dropdown/DropdownFilter.cjs.map +1 -1
  67. package/dist/Dropdown/DropdownFilter.d.ts +1 -0
  68. package/dist/Dropdown/DropdownFilter.js +16 -3
  69. package/dist/Dropdown/DropdownFilter.js.map +1 -1
  70. package/dist/Footer/Components/FooterNewsletterAndSocialSection.cjs.map +1 -1
  71. package/dist/Footer/Components/FooterNewsletterAndSocialSection.js.map +1 -1
  72. package/dist/GlobalNavigationBar/GlobalNavigationBar.cjs +3 -1
  73. package/dist/GlobalNavigationBar/GlobalNavigationBar.cjs.map +1 -1
  74. package/dist/GlobalNavigationBar/GlobalNavigationBar.js +4 -2
  75. package/dist/GlobalNavigationBar/GlobalNavigationBar.js.map +1 -1
  76. package/dist/GlobalNavigationBar/Logo.cjs.map +1 -1
  77. package/dist/GlobalNavigationBar/Logo.js.map +1 -1
  78. package/dist/GlobalNavigationBar/desktop/ExtendedMainMenu.cjs +7 -2
  79. package/dist/GlobalNavigationBar/desktop/ExtendedMainMenu.cjs.map +1 -1
  80. package/dist/GlobalNavigationBar/desktop/ExtendedMainMenu.d.ts +4 -0
  81. package/dist/GlobalNavigationBar/desktop/ExtendedMainMenu.js +6 -5
  82. package/dist/GlobalNavigationBar/desktop/ExtendedMainMenu.js.map +1 -1
  83. package/dist/GlobalNavigationBar/desktop/MainMenu.cjs +178 -56
  84. package/dist/GlobalNavigationBar/desktop/MainMenu.cjs.map +1 -1
  85. package/dist/GlobalNavigationBar/desktop/MainMenu.d.ts +2 -2
  86. package/dist/GlobalNavigationBar/desktop/MainMenu.js +178 -56
  87. package/dist/GlobalNavigationBar/desktop/MainMenu.js.map +1 -1
  88. package/dist/GlobalNavigationBar/desktop/SubMenu.cjs +243 -0
  89. package/dist/GlobalNavigationBar/desktop/SubMenu.cjs.map +1 -0
  90. package/dist/GlobalNavigationBar/desktop/SubMenu.d.ts +18 -0
  91. package/dist/GlobalNavigationBar/desktop/SubMenu.js +233 -0
  92. package/dist/GlobalNavigationBar/desktop/SubMenu.js.map +1 -0
  93. package/dist/GlobalNavigationBar/mobile/MobileMenu.cjs.map +1 -1
  94. package/dist/GlobalNavigationBar/mobile/MobileMenu.js.map +1 -1
  95. package/dist/GlobalNavigationBar/types.cjs.map +1 -1
  96. package/dist/GlobalNavigationBar/types.d.ts +12 -2
  97. package/dist/GlobalNavigationBar/types.js.map +1 -1
  98. package/dist/GlobalNavigationBar/utils.cjs +17 -0
  99. package/dist/GlobalNavigationBar/utils.cjs.map +1 -0
  100. package/dist/GlobalNavigationBar/utils.d.ts +2 -0
  101. package/dist/GlobalNavigationBar/utils.js +10 -0
  102. package/dist/GlobalNavigationBar/utils.js.map +1 -0
  103. package/dist/Image/ImageWithFallbacks.js +1 -1
  104. package/dist/InputFields/DatepickerField.cjs +54 -33
  105. package/dist/InputFields/DatepickerField.cjs.map +1 -1
  106. package/dist/InputFields/DatepickerField.d.ts +1 -0
  107. package/dist/InputFields/DatepickerField.js +55 -34
  108. package/dist/InputFields/DatepickerField.js.map +1 -1
  109. package/dist/InputFields/DatepickerFieldHeader.cjs.map +1 -1
  110. package/dist/InputFields/DatepickerFieldHeader.js +1 -1
  111. package/dist/InputFields/DatepickerFieldHeader.js.map +1 -1
  112. package/dist/InputFields/Label.cjs +12 -8
  113. package/dist/InputFields/Label.cjs.map +1 -1
  114. package/dist/InputFields/Label.js +12 -8
  115. package/dist/InputFields/Label.js.map +1 -1
  116. package/dist/InputFields/NumberField.cjs +33 -14
  117. package/dist/InputFields/NumberField.cjs.map +1 -1
  118. package/dist/InputFields/NumberField.d.ts +1 -0
  119. package/dist/InputFields/NumberField.js +36 -17
  120. package/dist/InputFields/NumberField.js.map +1 -1
  121. package/dist/InputFields/PasswordField.cjs +50 -44
  122. package/dist/InputFields/PasswordField.cjs.map +1 -1
  123. package/dist/InputFields/PasswordField.js +51 -45
  124. package/dist/InputFields/PasswordField.js.map +1 -1
  125. package/dist/InputFields/SearchBar.cjs +2 -1
  126. package/dist/InputFields/SearchBar.cjs.map +1 -1
  127. package/dist/InputFields/SearchBar.js +3 -2
  128. package/dist/InputFields/SearchBar.js.map +1 -1
  129. package/dist/InputFields/TextField.cjs +14 -2
  130. package/dist/InputFields/TextField.cjs.map +1 -1
  131. package/dist/InputFields/TextField.d.ts +1 -0
  132. package/dist/InputFields/TextField.js +15 -3
  133. package/dist/InputFields/TextField.js.map +1 -1
  134. package/dist/InputFields/Textarea.cjs +3 -8
  135. package/dist/InputFields/Textarea.cjs.map +1 -1
  136. package/dist/InputFields/Textarea.d.ts +7 -3
  137. package/dist/InputFields/Textarea.js +6 -12
  138. package/dist/InputFields/Textarea.js.map +1 -1
  139. package/dist/InputFields/components/SearchField.cjs +1 -1
  140. package/dist/InputFields/components/SearchField.cjs.map +1 -1
  141. package/dist/InputFields/components/SearchField.js +1 -1
  142. package/dist/InputFields/components/SearchField.js.map +1 -1
  143. package/dist/InputFields/styling.cjs +11 -11
  144. package/dist/InputFields/styling.cjs.map +1 -1
  145. package/dist/InputFields/styling.d.ts +2 -3
  146. package/dist/InputFields/styling.js +11 -10
  147. package/dist/InputFields/styling.js.map +1 -1
  148. package/dist/InputFields/types.cjs.map +1 -1
  149. package/dist/InputFields/types.d.ts +8 -4
  150. package/dist/InputFields/types.js.map +1 -1
  151. package/dist/LinearProgress/LinearProgress.js +1 -1
  152. package/dist/NavItem/NavItem.cjs +2 -1
  153. package/dist/NavItem/NavItem.cjs.map +1 -1
  154. package/dist/NavItem/NavItem.d.ts +1 -0
  155. package/dist/NavItem/NavItem.js +1 -1
  156. package/dist/NavItem/NavItem.js.map +1 -1
  157. package/dist/NavItem/NestedNavItem.cjs +38 -0
  158. package/dist/NavItem/NestedNavItem.cjs.map +1 -0
  159. package/dist/NavItem/NestedNavItem.d.ts +13 -0
  160. package/dist/NavItem/NestedNavItem.js +28 -0
  161. package/dist/NavItem/NestedNavItem.js.map +1 -0
  162. package/dist/Paginator/Paginator.cjs.map +1 -1
  163. package/dist/Paginator/Paginator.js.map +1 -1
  164. package/dist/Table/Table.cjs +1 -2
  165. package/dist/Table/Table.cjs.map +1 -1
  166. package/dist/Table/Table.js +1 -2
  167. package/dist/Table/Table.js.map +1 -1
  168. package/dist/Table/TableFooter.cjs.map +1 -1
  169. package/dist/Table/TableFooter.js +1 -1
  170. package/dist/Table/TableFooter.js.map +1 -1
  171. package/dist/Table/TableStyles.cjs +4 -4
  172. package/dist/Table/TableStyles.cjs.map +1 -1
  173. package/dist/Table/TableStyles.js +4 -4
  174. package/dist/Table/TableStyles.js.map +1 -1
  175. package/dist/Table/TableTypes.cjs.map +1 -1
  176. package/dist/Table/TableTypes.d.ts +0 -1
  177. package/dist/Table/TableTypes.js.map +1 -1
  178. package/dist/Tabs/HorizontalTabs.cjs +12 -10
  179. package/dist/Tabs/HorizontalTabs.cjs.map +1 -1
  180. package/dist/Tabs/HorizontalTabs.d.ts +1 -2
  181. package/dist/Tabs/HorizontalTabs.js +14 -13
  182. package/dist/Tabs/HorizontalTabs.js.map +1 -1
  183. package/dist/Tabs/TabLink.cjs +41 -17
  184. package/dist/Tabs/TabLink.cjs.map +1 -1
  185. package/dist/Tabs/TabLink.d.ts +14 -10
  186. package/dist/Tabs/TabLink.js +41 -17
  187. package/dist/Tabs/TabLink.js.map +1 -1
  188. package/dist/Tabs/VerticalTabs.cjs +2 -0
  189. package/dist/Tabs/VerticalTabs.cjs.map +1 -1
  190. package/dist/Tabs/VerticalTabs.d.ts +1 -0
  191. package/dist/Tabs/VerticalTabs.js +2 -0
  192. package/dist/Tabs/VerticalTabs.js.map +1 -1
  193. package/dist/Toggles/ToggleSwitch.cjs +1 -11
  194. package/dist/Toggles/ToggleSwitch.cjs.map +1 -1
  195. package/dist/Toggles/ToggleSwitch.js +2 -12
  196. package/dist/Toggles/ToggleSwitch.js.map +1 -1
  197. package/dist/Toggles/TogglerStyles.cjs +1 -1
  198. package/dist/Toggles/TogglerStyles.cjs.map +1 -1
  199. package/dist/Toggles/TogglerStyles.js +1 -1
  200. package/dist/Toggles/TogglerStyles.js.map +1 -1
  201. package/dist/Tooltips/TooltipOverflow.cjs +112 -0
  202. package/dist/Tooltips/TooltipOverflow.cjs.map +1 -0
  203. package/dist/Tooltips/TooltipOverflow.d.ts +10 -0
  204. package/dist/Tooltips/TooltipOverflow.js +102 -0
  205. package/dist/Tooltips/TooltipOverflow.js.map +1 -0
  206. package/dist/Tooltips/TooltipStyles.cjs +8 -5
  207. package/dist/Tooltips/TooltipStyles.cjs.map +1 -1
  208. package/dist/Tooltips/TooltipStyles.d.ts +3 -1
  209. package/dist/Tooltips/TooltipStyles.js +8 -5
  210. package/dist/Tooltips/TooltipStyles.js.map +1 -1
  211. package/dist/Tooltips/TooltipWrapper.cjs +2 -1
  212. package/dist/Tooltips/TooltipWrapper.cjs.map +1 -1
  213. package/dist/Tooltips/TooltipWrapper.js +2 -1
  214. package/dist/Tooltips/TooltipWrapper.js.map +1 -1
  215. package/dist/assets/index.cjs.map +1 -1
  216. package/dist/assets/index.js.map +1 -1
  217. package/dist/common/ActionWithin.cjs +1 -1
  218. package/dist/common/ActionWithin.js +1 -1
  219. package/dist/common/FocusVisible.cjs +1 -1
  220. package/dist/common/FocusVisible.js +1 -1
  221. package/dist/icons/index.cjs +1 -1
  222. package/dist/icons/index.cjs.map +1 -1
  223. package/dist/icons/index.js +1 -1
  224. package/dist/icons/index.js.map +1 -1
  225. package/dist/icons/systemicons/SystemIcons.cjs.map +1 -1
  226. package/dist/icons/systemicons/SystemIcons.js.map +1 -1
  227. package/package.json +2 -1
@@ -1,10 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
5
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
5
6
  import _pt from "prop-types";
6
7
  var _excluded = ["icon", "to", "exact", "disabled", "external", "action", "label", "note", "pinned"];
7
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
8
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
8
9
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
10
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
11
  import * as React from 'react';
@@ -13,31 +14,55 @@ import styled from 'styled-components';
13
14
  import { NavItem } from '../../NavItem';
14
15
  import { MoreHorizontal } from '../../icons/systemicons/SystemIcons';
15
16
  import { COLORS, BREAKPOINTS } from '../../styles';
16
- import ExtendedMainMenu from './ExtendedMainMenu';
17
+ import { Menu } from './ExtendedMainMenu';
18
+ import { SubMenu } from './SubMenu';
17
19
  import { IconButton } from '../../Button';
18
20
  import { defaultOnMouseDownHandler } from '../../common';
21
+ import { SystemIcons } from '../../icons';
22
+ import { NavItemDiv } from '../../NavItem/NavItem';
23
+ import { checkIfContainsItem } from '../utils';
19
24
  import { jsx as _jsx } from "react/jsx-runtime";
20
25
  import { jsxs as _jsxs } from "react/jsx-runtime";
21
- var NavContainer = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: none;\n flex-grow: 1;\n justify-content: flex-start;\n align-items: center;\n\n ", " {\n display: flex;\n }\n\n a {\n text-decoration: none;\n }\n"])), BREAKPOINTS.LARGE);
26
+ var NavContainer = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: none;\n flex-grow: 1;\n justify-content: flex-start;\n align-items: center;\n\n ", " {\n display: flex;\n }\n\n ", " {\n cursor: pointer;\n }\n\n a {\n text-decoration: none;\n }\n"])), BREAKPOINTS.LARGE, NavItemDiv);
22
27
  var NavButton = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n background: ", ";\n border: 0;\n"])), COLORS.white);
23
28
  var ExtendedMenuWrapper = styled.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n margin-left: ", ";\n\n position: absolute;\n flex-direction: column;\n left: 290px;\n top: 22px;\n\n height: 0;\n width: 0;\n\n &:focus-within,\n &:hover,\n &.open {\n background: ", ";\n }\n"])), function (props) {
24
29
  return props.floatRight ? 'auto' : 'unset';
25
30
  }, COLORS.white);
26
31
  var ExtendedSection = styled.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n"])));
32
+ var SubMenuWrapper = styled.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n ", " {\n top: ", ";\n left: ", ";\n }\n\n button {\n padding-left: 0px;\n }\n"])), Menu, function (props) {
33
+ return props.topLevel ? '100%' : '0px';
34
+ }, function (props) {
35
+ return props.topLevel ? '0px' : 'calc(100% - 12px)';
36
+ });
37
+ var ExtendedMenuOption = 'extendedOption';
27
38
  var MainMenu = function MainMenu(_ref) {
28
39
  var items = _ref.items,
29
40
  rightSideRef = _ref.rightSideRef;
30
- var _React$useState = React.useState(false),
31
- _React$useState2 = _slicedToArray(_React$useState, 2),
32
- showExtendedMenu = _React$useState2[0],
33
- setShowExtendedMenu = _React$useState2[1];
34
- var extendedMenuRef = React.useRef(null);
35
41
  var menuButtonRef = React.useRef(null);
42
+ //we have to use refs instead of 'state' here, because when onmouseleave is triggered for multiple nested divs, state update is not being updated in between
43
+ var dropdownMenusOpenedArray = React.useRef([]);
36
44
  var mainMenuRef = React.useRef(null);
37
- var _React$useState3 = React.useState(1),
45
+ var _React$useState = React.useState(1),
46
+ _React$useState2 = _slicedToArray(_React$useState, 2),
47
+ numberOfItemsAllowed = _React$useState2[0],
48
+ setNumberOfItemsAllowed = _React$useState2[1];
49
+ var _React$useState3 = React.useState([]),
38
50
  _React$useState4 = _slicedToArray(_React$useState3, 2),
39
- numberOfItemsAllowed = _React$useState4[0],
40
- setNumberOfItemsAllowed = _React$useState4[1];
51
+ subMenuRefs = _React$useState4[0],
52
+ setAllSubMenuRefs = _React$useState4[1];
53
+ var extendedMenuOptionRef = /*#__PURE__*/React.createRef();
54
+ React.useEffect(function () {
55
+ setAllSubMenuRefs(items.map(function (x) {
56
+ return x.type == 'desktopgroup' ? /*#__PURE__*/React.createRef() : undefined;
57
+ }));
58
+ }, [items]);
59
+ var _React$useState5 = React.useState({}),
60
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
61
+ forceUpdate = _React$useState6[1];
62
+ var _React$useState7 = React.useState(''),
63
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
64
+ activeItem = _React$useState8[0],
65
+ setActiveItemId = _React$useState8[1];
41
66
  var widthOfItem = 120;
42
67
  var recalculateNumberOfItemsAllowed = function recalculateNumberOfItemsAllowed() {
43
68
  if (rightSideRef !== null && rightSideRef !== void 0 && rightSideRef.current && mainMenuRef !== null && mainMenuRef !== void 0 && mainMenuRef.current) {
@@ -48,80 +73,177 @@ var MainMenu = function MainMenu(_ref) {
48
73
  }
49
74
  }
50
75
  };
51
- var handleClickExtendedMenuAction = function handleClickExtendedMenuAction() {
52
- setShowExtendedMenu(false);
76
+ var _onMouseLeave = function onMouseLeave(event, id) {
77
+ dropdownMenusOpenedArray.current = _toConsumableArray(dropdownMenusOpenedArray.current.filter(function (x) {
78
+ return x != id;
79
+ }));
80
+ //just trigger rerendering
81
+ forceUpdate({});
53
82
  };
54
- var handleClickOutside = function handleClickOutside(e) {
55
- var _extendedMenuRef$curr, _menuButtonRef$curren;
56
- if (!(extendedMenuRef !== null && extendedMenuRef !== void 0 && (_extendedMenuRef$curr = extendedMenuRef.current) !== null && _extendedMenuRef$curr !== void 0 && _extendedMenuRef$curr.contains(e.target)) && !(menuButtonRef !== null && menuButtonRef !== void 0 && (_menuButtonRef$curren = menuButtonRef.current) !== null && _menuButtonRef$curren !== void 0 && _menuButtonRef$curren.contains(e.target))) {
57
- setShowExtendedMenu(false);
83
+ var _onMouseEnter = function onMouseEnter(event, id) {
84
+ var existingRefForId = dropdownMenusOpenedArray.current.find(function (x) {
85
+ return x == id;
86
+ });
87
+ if (existingRefForId == null) {
88
+ dropdownMenusOpenedArray.current = [].concat(_toConsumableArray(dropdownMenusOpenedArray.current), [id]);
89
+ //just trigger rerendering
90
+ forceUpdate({});
58
91
  }
59
92
  };
60
93
  React.useEffect(function () {
61
94
  recalculateNumberOfItemsAllowed();
62
95
  // Bind the event listener
63
- document.addEventListener('click', handleClickOutside);
64
96
  window.addEventListener('resize', recalculateNumberOfItemsAllowed);
65
97
  return function () {
66
98
  // Unbind the event listener on clean up
67
- document.removeEventListener('click', handleClickOutside);
68
99
  window.removeEventListener('resize', recalculateNumberOfItemsAllowed);
69
100
  };
70
101
  }, []);
71
102
  React.useEffect(function () {
72
103
  recalculateNumberOfItemsAllowed();
73
104
  }, [items.length]);
105
+ var onFocus = function onFocus(event) {
106
+ //no open dropdowns if top level was entered
107
+ dropdownMenusOpenedArray.current = [];
108
+ forceUpdate({});
109
+ };
110
+ var onKeyDownTop = function onKeyDownTop(event) {
111
+ if (event.key === 'Escape' || event.key === 'Esc') {
112
+ dropdownMenusOpenedArray.current = [];
113
+ //just trigger rerendering
114
+ forceUpdate({});
115
+ }
116
+ };
74
117
  var renderItem = function renderItem(item, index) {
75
118
  if (index > numberOfItemsAllowed - 2) return null;
76
- var icon = item.icon,
77
- to = item.to,
78
- exact = item.exact,
79
- disabled = item.disabled,
80
- external = item.external,
81
- action = item.action,
82
- label = item.label,
83
- note = item.note,
84
- pinned = item.pinned,
85
- rest = _objectWithoutProperties(item, _excluded);
86
- return item !== null && item !== void 0 && item.disabled ? /*#__PURE__*/_jsx(NavItem, {
87
- as: NavButton,
88
- className: "disabled",
89
- onMouseDown: defaultOnMouseDownHandler,
90
- children: item === null || item === void 0 ? void 0 : item.label
91
- }, item.label) : /*#__PURE__*/_jsx(NavItem, _objectSpread(_objectSpread({
92
- as: NavLink,
93
- to: item.to || '',
94
- onMouseDown: defaultOnMouseDownHandler,
95
- onClick: function onClick(e) {
96
- return item.action && item.action(e);
97
- }
98
- }, rest), {}, {
99
- children: item === null || item === void 0 ? void 0 : item.label
100
- }), item.label);
119
+ if (item.type != 'desktopgroup') {
120
+ var _ref2 = item,
121
+ icon = _ref2.icon,
122
+ to = _ref2.to,
123
+ exact = _ref2.exact,
124
+ disabled = _ref2.disabled,
125
+ external = _ref2.external,
126
+ action = _ref2.action,
127
+ label = _ref2.label,
128
+ note = _ref2.note,
129
+ pinned = _ref2.pinned,
130
+ rest = _objectWithoutProperties(_ref2, _excluded);
131
+ return item !== null && item !== void 0 && item.disabled ? /*#__PURE__*/_jsx(NavItem, {
132
+ as: NavButton,
133
+ className: "disabled",
134
+ onMouseDown: defaultOnMouseDownHandler,
135
+ children: item === null || item === void 0 ? void 0 : item.label
136
+ }, item.label) : /*#__PURE__*/_jsx(NavItem, _objectSpread(_objectSpread({
137
+ as: NavLink,
138
+ onFocus: onFocus,
139
+ to: to || '',
140
+ onMouseDown: defaultOnMouseDownHandler,
141
+ onClick: function onClick(e) {
142
+ return action && action(e);
143
+ }
144
+ }, rest), {}, {
145
+ children: item === null || item === void 0 ? void 0 : item.label
146
+ }), label);
147
+ } else {
148
+ var existingRef = dropdownMenusOpenedArray.current.find(function (x) {
149
+ return x == item.id;
150
+ });
151
+ var onClick = function onClick() {
152
+ if (existingRef == null) {
153
+ dropdownMenusOpenedArray.current = [].concat(_toConsumableArray(dropdownMenusOpenedArray.current), [item.id]);
154
+ //just trigger rerendering
155
+ forceUpdate({});
156
+ }
157
+ };
158
+ var onKeyDown = function onKeyDown(event) {
159
+ if (event.key == 'Enter' || event.code == 'Space') {
160
+ dropdownMenusOpenedArray.current = [].concat(_toConsumableArray(dropdownMenusOpenedArray.current), [item.id]);
161
+ //just trigger rerendering
162
+ forceUpdate({});
163
+ }
164
+ };
165
+ return /*#__PURE__*/_jsxs("div", {
166
+ style: {
167
+ position: 'relative'
168
+ },
169
+ onMouseEnter: function onMouseEnter(event) {
170
+ var _item$id;
171
+ return _onMouseEnter(event, (_item$id = item.id) !== null && _item$id !== void 0 ? _item$id : '');
172
+ },
173
+ onMouseLeave: function onMouseLeave(event) {
174
+ var _item$id2;
175
+ return _onMouseLeave(event, (_item$id2 = item.id) !== null && _item$id2 !== void 0 ? _item$id2 : '');
176
+ },
177
+ children: [/*#__PURE__*/_jsxs(NavItem, {
178
+ onFocus: onFocus,
179
+ onKeyDown: onKeyDown,
180
+ tabIndex: 0,
181
+ className: existingRef != null || checkIfContainsItem(item, activeItem) ? 'active' : '',
182
+ to: null,
183
+ onClick: onClick,
184
+ children: [item === null || item === void 0 ? void 0 : item.label, " ", /*#__PURE__*/_jsx(SystemIcons.ArrowDropDown, {
185
+ size: "24px"
186
+ })]
187
+ }, item.label), /*#__PURE__*/_jsx(SubMenu, {
188
+ ref: subMenuRefs[index],
189
+ activeItemId: activeItem,
190
+ nestPath: [item.id],
191
+ onItemStateChanged: function onItemStateChanged(item, state) {
192
+ if (state) {
193
+ setActiveItemId(item);
194
+ } else if (item == activeItem) setActiveItemId('');
195
+ },
196
+ item: item,
197
+ dropdownMenusOpenedArray: dropdownMenusOpenedArray,
198
+ index: index + 1,
199
+ topLevel: true
200
+ })]
201
+ });
202
+ }
203
+ };
204
+ var extendedSectionKeyHandler = function extendedSectionKeyHandler(event) {
205
+ if (event.key == 'Enter' || event.code == 'Space') {
206
+ event.stopPropagation();
207
+ dropdownMenusOpenedArray.current = [ExtendedMenuOption];
208
+ forceUpdate({});
209
+ }
101
210
  };
102
211
  return /*#__PURE__*/_jsxs(NavContainer, {
103
212
  className: "GlobalNavigationMainMenu",
104
213
  ref: mainMenuRef,
105
- open: showExtendedMenu,
214
+ onKeyDown: onKeyDownTop,
106
215
  children: [items === null || items === void 0 ? void 0 : items.map(renderItem), items.length + 1 > numberOfItemsAllowed && /*#__PURE__*/_jsxs(ExtendedSection, {
216
+ onKeyDown: function onKeyDown(event) {
217
+ return extendedSectionKeyHandler(event);
218
+ },
219
+ onMouseEnter: function onMouseEnter(event) {
220
+ return _onMouseEnter(event, ExtendedMenuOption);
221
+ },
222
+ onMouseLeave: function onMouseLeave(event) {
223
+ return _onMouseLeave(event, ExtendedMenuOption);
224
+ },
107
225
  children: [/*#__PURE__*/_jsx(IconButton, {
108
226
  ref: menuButtonRef,
109
227
  variant: 'secondary',
110
228
  shape: 'circular',
111
- action: function action() {
112
- setShowExtendedMenu(!showExtendedMenu);
113
- },
229
+ action: function action() {},
114
230
  children: /*#__PURE__*/_jsx(MoreHorizontal, {
115
231
  size: "24px"
116
232
  })
117
- }), /*#__PURE__*/_jsx(ExtendedMenuWrapper, {
118
- ref: extendedMenuRef,
119
- className: showExtendedMenu ? 'open' : '',
120
- floatRight: false,
121
- children: /*#__PURE__*/_jsx(ExtendedMainMenu, {
122
- clickMenuAction: handleClickExtendedMenuAction,
123
- navigationOptions: items.slice(numberOfItemsAllowed - 1)
124
- })
233
+ }), /*#__PURE__*/_jsx(SubMenu, {
234
+ activeItemId: activeItem,
235
+ ref: extendedMenuOptionRef,
236
+ onItemStateChanged: function onItemStateChanged(item, state) {
237
+ if (state) setActiveItemId(item);else if (item == activeItem) setActiveItemId('');
238
+ },
239
+ nestPath: [ExtendedMenuOption],
240
+ item: {
241
+ items: items.slice(numberOfItemsAllowed - 1),
242
+ id: ExtendedMenuOption
243
+ },
244
+ topLevel: true,
245
+ index: 0,
246
+ dropdownMenusOpenedArray: dropdownMenusOpenedArray
125
247
  })]
126
248
  })]
127
249
  });
@@ -1 +1 @@
1
- {"version":3,"file":"MainMenu.js","names":["React","NavLink","styled","NavItem","MoreHorizontal","COLORS","BREAKPOINTS","ExtendedMainMenu","IconButton","defaultOnMouseDownHandler","NavContainer","div","LARGE","NavButton","button","white","ExtendedMenuWrapper","props","floatRight","ExtendedSection","MainMenu","items","rightSideRef","useState","showExtendedMenu","setShowExtendedMenu","extendedMenuRef","useRef","menuButtonRef","mainMenuRef","numberOfItemsAllowed","setNumberOfItemsAllowed","widthOfItem","recalculateNumberOfItemsAllowed","current","number","Math","floor","offsetLeft","handleClickExtendedMenuAction","handleClickOutside","e","contains","target","useEffect","document","addEventListener","window","removeEventListener","length","renderItem","item","index","icon","to","exact","disabled","external","action","label","note","pinned","rest","map","slice"],"sources":["../../../src/GlobalNavigationBar/desktop/MainMenu.tsx"],"sourcesContent":["import * as React from 'react';\nimport {NavLink} from 'react-router-dom';\nimport styled from 'styled-components';\n\nimport {NavItem} from '../../NavItem';\nimport {MoreHorizontal} from '../../icons/systemicons/SystemIcons';\nimport {COLORS, BREAKPOINTS} from '../../styles';\nimport ExtendedMainMenu from './ExtendedMainMenu';\nimport {IconButton} from '../../Button';\nimport {defaultOnMouseDownHandler} from '../../common';\nimport {MenuNavigationItemTypeItem} from '../types';\n\nconst NavContainer = styled.div<{ open: boolean }>`\n display: none;\n flex-grow: 1;\n justify-content: flex-start;\n align-items: center;\n\n ${BREAKPOINTS.LARGE} {\n display: flex;\n }\n\n a {\n text-decoration: none;\n }\n`;\n\nconst NavButton = styled.button`\n background: ${COLORS.white};\n border: 0;\n`;\n\ninterface ExtendedMenuWrapperProps {\n floatRight: boolean;\n}\n\nconst ExtendedMenuWrapper = styled.div<ExtendedMenuWrapperProps>`\n display: flex;\n margin-left: ${props => (props.floatRight ? 'auto' : 'unset')};\n\n position: absolute;\n flex-direction: column;\n left: 290px;\n top: 22px;\n\n height: 0;\n width: 0;\n\n &:focus-within,\n &:hover,\n &.open {\n background: ${COLORS.white};\n }\n`;\n\nconst ExtendedSection = styled.div`\n position: relative;\n`;\n\ntype Props = {\n items: MenuNavigationItemTypeItem[];\n rightSideRef?: React.RefObject<HTMLDivElement> | null | undefined;\n};\n\nconst MainMenu = ({items, rightSideRef}: Props): React.ReactElement<Props> => {\n const [showExtendedMenu, setShowExtendedMenu] = React.useState(false);\n const extendedMenuRef = React.useRef<any>(null);\n const menuButtonRef = React.useRef<HTMLButtonElement>(null);\n const mainMenuRef: React.RefObject<HTMLDivElement> | null | undefined = React.useRef(null);\n const [numberOfItemsAllowed, setNumberOfItemsAllowed] = React.useState<number>(1);\n\n const widthOfItem = 120;\n const recalculateNumberOfItemsAllowed = () => {\n if (rightSideRef?.current && mainMenuRef?.current) {\n const number = Math.floor((rightSideRef?.current?.offsetLeft - mainMenuRef?.current?.offsetLeft) / widthOfItem);\n if (number !== numberOfItemsAllowed) {\n setNumberOfItemsAllowed(number);\n }\n }\n };\n\n const handleClickExtendedMenuAction = () => {\n setShowExtendedMenu(false);\n };\n\n const handleClickOutside = (e: any) => {\n if (!extendedMenuRef?.current?.contains(e.target) && !menuButtonRef?.current?.contains(e.target)) {\n setShowExtendedMenu(false);\n }\n };\n\n React.useEffect(() => {\n recalculateNumberOfItemsAllowed();\n // Bind the event listener\n document.addEventListener('click', handleClickOutside);\n window.addEventListener('resize', recalculateNumberOfItemsAllowed);\n return () => {\n // Unbind the event listener on clean up\n document.removeEventListener('click', handleClickOutside);\n window.removeEventListener('resize', recalculateNumberOfItemsAllowed);\n };\n }, []);\n\n React.useEffect(() => {\n recalculateNumberOfItemsAllowed();\n }, [items.length])\n\n const renderItem = (item: MenuNavigationItemTypeItem, index: number) => {\n\n if (index > numberOfItemsAllowed - 2) return null\n\n const {icon, to, exact, disabled, external, action, label, note, pinned, ...rest} = item;\n\n return item?.disabled\n ? <NavItem as={NavButton}\n className=\"disabled\"\n key={item.label}\n onMouseDown={defaultOnMouseDownHandler}>\n {item?.label}\n </NavItem>\n : <NavItem as={NavLink}\n to={item.to || ''}\n key={item.label}\n onMouseDown={defaultOnMouseDownHandler}\n onClick={(e: React.MouseEvent) => item.action && item.action(e)}\n {...rest}>\n {item?.label}\n </NavItem>\n }\n\n return (\n <NavContainer className=\"GlobalNavigationMainMenu\" ref={mainMenuRef} open={showExtendedMenu}>\n {items?.map(renderItem)}\n {items.length + 1 > numberOfItemsAllowed && (\n <ExtendedSection>\n <IconButton\n ref={menuButtonRef}\n variant={'secondary'}\n shape={'circular'}\n action={() => {\n setShowExtendedMenu(!showExtendedMenu)\n }}>\n <MoreHorizontal size=\"24px\"/>\n </IconButton>\n <ExtendedMenuWrapper ref={extendedMenuRef} className={showExtendedMenu ? 'open' : ''} floatRight={false}>\n <ExtendedMainMenu clickMenuAction={handleClickExtendedMenuAction}\n navigationOptions={items.slice(numberOfItemsAllowed - 1)}/>\n </ExtendedMenuWrapper>\n </ExtendedSection>\n )}\n </NavContainer>\n );\n};\n\nexport default MainMenu;\n"],"mappings":";;;;;;;;;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAAQC,OAAO,QAAO,kBAAkB;AACxC,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,SAAQC,OAAO,QAAO,eAAe;AACrC,SAAQC,cAAc,QAAO,qCAAqC;AAClE,SAAQC,MAAM,EAAEC,WAAW,QAAO,cAAc;AAChD,OAAOC,gBAAgB,MAAM,oBAAoB;AACjD,SAAQC,UAAU,QAAO,cAAc;AACvC,SAAQC,yBAAyB,QAAO,cAAc;AAAC;AAAA;AAGvD,IAAMC,YAAY,GAAGR,MAAM,CAACS,GAAG,kPAM3BL,WAAW,CAACM,KAAK,CAOpB;AAED,IAAMC,SAAS,GAAGX,MAAM,CAACY,MAAM,6GACfT,MAAM,CAACU,KAAK,CAE3B;AAMD,IAAMC,mBAAmB,GAAGd,MAAM,CAACS,GAAG,0SAErB,UAAAM,KAAK;EAAA,OAAKA,KAAK,CAACC,UAAU,GAAG,MAAM,GAAG,OAAO;AAAA,CAAC,EA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AAA,uBACF,KAAC,cAAc;UAAC,IAAI,EAAC;QAAM;MAAE,EAClB,eACb,KAAC,mBAAmB;QAAC,GAAG,EAAEE,eAAgB;QAAC,SAAS,EAAEF,gBAAgB,GAAG,MAAM,GAAG,EAAG;QAAC,UAAU,EAAE,KAAM;QAAA,uBACtG,KAAC,gBAAgB;UAAC,eAAe,EAAEe,6BAA8B;UAC/C,iBAAiB,EAAElB,KAAK,CAAC2C,KAAK,CAAClC,oBAAoB,GAAG,CAAC;QAAE;MAAE,EACzD;IAAA,EAEzB;EAAA,EACY;AAEnB,CAAC;AAAC;EA5FAT,KAAK;AAAA;AA8FP,eAAeD,QAAQ"}
1
+ {"version":3,"file":"MainMenu.js","names":["React","NavLink","styled","NavItem","MoreHorizontal","COLORS","BREAKPOINTS","Menu","SubMenu","IconButton","defaultOnMouseDownHandler","SystemIcons","NavItemDiv","checkIfContainsItem","NavContainer","div","LARGE","NavButton","button","white","ExtendedMenuWrapper","props","floatRight","ExtendedSection","SubMenuWrapper","topLevel","ExtendedMenuOption","MainMenu","items","rightSideRef","menuButtonRef","useRef","dropdownMenusOpenedArray","mainMenuRef","useState","numberOfItemsAllowed","setNumberOfItemsAllowed","subMenuRefs","setAllSubMenuRefs","extendedMenuOptionRef","createRef","useEffect","map","x","type","undefined","forceUpdate","activeItem","setActiveItemId","widthOfItem","recalculateNumberOfItemsAllowed","current","number","Math","floor","offsetLeft","onMouseLeave","event","id","filter","onMouseEnter","existingRefForId","find","window","addEventListener","removeEventListener","length","onFocus","onKeyDownTop","key","renderItem","item","index","icon","to","exact","disabled","external","action","label","note","pinned","rest","e","existingRef","onClick","onKeyDown","code","position","state","extendedSectionKeyHandler","stopPropagation","slice"],"sources":["../../../src/GlobalNavigationBar/desktop/MainMenu.tsx"],"sourcesContent":["import * as React from 'react';\nimport { NavLink, useLocation } from 'react-router-dom';\nimport styled from 'styled-components';\n\nimport { NavItem } from '../../NavItem';\nimport { MoreHorizontal } from '../../icons/systemicons/SystemIcons';\nimport { COLORS, BREAKPOINTS } from '../../styles';\nimport ExtendedMainMenu, { Menu, MenuSection, MenuSectionList } from './ExtendedMainMenu';\nimport { SubMenu } from './SubMenu';\nimport { IconButton } from '../../Button';\nimport { defaultOnMouseDownHandler } from '../../common';\nimport { MenuNavigationItemTypeDesktopGroup, MenuNavigationItemTypeItem } from '../types';\nimport { DropdownContent } from '../../Dropdown';\nimport { VerticalTabEntry, VerticalTabs } from '../../Tabs';\nimport { Size } from '../../types';\nimport { SystemIcons } from '../../icons';\nimport Tabs from '../../Tabs/Tabs';\nimport TabLink from '../../Tabs/TabLink';\nimport { MenuItem } from '../../MenuItem';\nimport { NavItemDiv } from '../../NavItem/NavItem';\nimport { checkIfContainsItem } from '../utils';\n\nconst NavContainer = styled.div`\n display: none;\n flex-grow: 1;\n justify-content: flex-start;\n align-items: center;\n\n ${BREAKPOINTS.LARGE} {\n display: flex;\n }\n\n ${NavItemDiv} {\n cursor: pointer;\n }\n\n a {\n text-decoration: none;\n }\n`;\n\nconst NavButton = styled.button`\n background: ${COLORS.white};\n border: 0;\n`;\n\ninterface ExtendedMenuWrapperProps {\n floatRight: boolean;\n}\n\nconst ExtendedMenuWrapper = styled.div<ExtendedMenuWrapperProps>`\n display: flex;\n margin-left: ${(props) => (props.floatRight ? 'auto' : 'unset')};\n\n position: absolute;\n flex-direction: column;\n left: 290px;\n top: 22px;\n\n height: 0;\n width: 0;\n\n &:focus-within,\n &:hover,\n &.open {\n background: ${COLORS.white};\n }\n`;\n\nconst ExtendedSection = styled.div`\n position: relative;\n`;\n\nconst SubMenuWrapper = styled.div<{ topLevel: boolean }>`\n ${Menu} {\n top: ${(props) => (props.topLevel ? '100%' : '0px')};\n left: ${(props) => (props.topLevel ? '0px' : 'calc(100% - 12px)')};\n }\n\n button {\n padding-left: 0px;\n }\n`;\n\nconst ExtendedMenuOption = 'extendedOption';\n\ntype Props = {\n items: (MenuNavigationItemTypeItem | MenuNavigationItemTypeDesktopGroup)[];\n rightSideRef?: React.RefObject<HTMLDivElement> | null | undefined;\n};\n\nconst MainMenu = ({ items, rightSideRef }: Props): React.ReactElement<Props> => {\n const menuButtonRef = React.useRef<HTMLButtonElement>(null);\n //we have to use refs instead of 'state' here, because when onmouseleave is triggered for multiple nested divs, state update is not being updated in between\n const dropdownMenusOpenedArray = React.useRef<string[]>([]);\n const mainMenuRef: React.RefObject<HTMLDivElement> | null | undefined = React.useRef(null);\n const [numberOfItemsAllowed, setNumberOfItemsAllowed] = React.useState<number>(1);\n const [subMenuRefs, setAllSubMenuRefs] = React.useState<(React.RefObject<HTMLUListElement> | undefined)[]>([]);\n const extendedMenuOptionRef = React.createRef<HTMLUListElement>();\n\n React.useEffect(() => {\n setAllSubMenuRefs(items.map((x) => (x.type == 'desktopgroup' ? React.createRef<HTMLUListElement>() : undefined)));\n }, [items]);\n\n const [, forceUpdate] = React.useState({});\n const [activeItem, setActiveItemId] = React.useState<string>('');\n\n const widthOfItem = 120;\n const recalculateNumberOfItemsAllowed = () => {\n if (rightSideRef?.current && mainMenuRef?.current) {\n const number = Math.floor((rightSideRef?.current?.offsetLeft - mainMenuRef?.current?.offsetLeft) / widthOfItem);\n if (number !== numberOfItemsAllowed) {\n setNumberOfItemsAllowed(number);\n }\n }\n };\n\n const onMouseLeave = (event: any, id: string) => {\n dropdownMenusOpenedArray.current = [...dropdownMenusOpenedArray.current.filter((x) => x != id)];\n //just trigger rerendering\n forceUpdate({});\n };\n\n const onMouseEnter = (event: any, id: string) => {\n const existingRefForId = dropdownMenusOpenedArray.current.find((x) => x == id);\n if (existingRefForId == null) {\n dropdownMenusOpenedArray.current = [...dropdownMenusOpenedArray.current, id];\n //just trigger rerendering\n forceUpdate({});\n }\n };\n\n React.useEffect(() => {\n recalculateNumberOfItemsAllowed();\n // Bind the event listener\n window.addEventListener('resize', recalculateNumberOfItemsAllowed);\n return () => {\n // Unbind the event listener on clean up\n window.removeEventListener('resize', recalculateNumberOfItemsAllowed);\n };\n }, []);\n\n React.useEffect(() => {\n recalculateNumberOfItemsAllowed();\n }, [items.length]);\n\n const onFocus = (event: React.FocusEvent<HTMLDivElement>) => {\n //no open dropdowns if top level was entered\n dropdownMenusOpenedArray.current = [];\n forceUpdate({});\n };\n\n const onKeyDownTop = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Escape' || event.key === 'Esc') {\n dropdownMenusOpenedArray.current = [];\n //just trigger rerendering\n forceUpdate({});\n }\n };\n\n const renderItem = (item: MenuNavigationItemTypeItem | MenuNavigationItemTypeDesktopGroup, index: number) => {\n if (index > numberOfItemsAllowed - 2) return null;\n if (item.type != 'desktopgroup') {\n const { icon, to, exact, disabled, external, action, label, note, pinned, ...rest } = item as MenuNavigationItemTypeItem;\n return item?.disabled ? (\n <NavItem as={NavButton} className=\"disabled\" key={item.label} onMouseDown={defaultOnMouseDownHandler}>\n {item?.label}\n </NavItem>\n ) : (\n <NavItem as={NavLink} onFocus={onFocus} to={to || ''} key={label} onMouseDown={defaultOnMouseDownHandler} onClick={(e: React.MouseEvent) => action && action(e)} {...rest}>\n {item?.label}\n </NavItem>\n );\n } else {\n const existingRef = dropdownMenusOpenedArray.current.find((x) => x == item.id);\n const onClick = () => {\n if (existingRef == null) {\n dropdownMenusOpenedArray.current = [...dropdownMenusOpenedArray.current, item.id];\n //just trigger rerendering\n forceUpdate({});\n }\n };\n const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key == 'Enter' || event.code == 'Space') {\n dropdownMenusOpenedArray.current = [...dropdownMenusOpenedArray.current, item.id];\n //just trigger rerendering\n forceUpdate({});\n } \n };\n\n return (\n <div\n style={{ position: 'relative' }}\n onMouseEnter={(event) => onMouseEnter(event, item.id ?? '')}\n onMouseLeave={(event) => onMouseLeave(event, item.id ?? '')}>\n <NavItem\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n tabIndex={0}\n className={existingRef != null || checkIfContainsItem(item, activeItem) ? 'active' : ''}\n key={item.label}\n to={null}\n onClick={onClick}>\n {item?.label} <SystemIcons.ArrowDropDown size=\"24px\" />\n </NavItem>\n <SubMenu\n ref={subMenuRefs[index]}\n activeItemId={activeItem}\n nestPath={[item.id]}\n onItemStateChanged={(item, state) => {\n if (state) {\n setActiveItemId(item);\n } else if (item == activeItem) setActiveItemId('');\n }}\n item={item as MenuNavigationItemTypeDesktopGroup}\n dropdownMenusOpenedArray={dropdownMenusOpenedArray}\n index={index + 1}\n topLevel={true}\n />\n </div>\n );\n }\n };\n\n const extendedSectionKeyHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key == 'Enter' || event.code == 'Space') {\n event.stopPropagation();\n\n dropdownMenusOpenedArray.current = [ExtendedMenuOption];\n forceUpdate({});\n }\n };\n\n return (\n <NavContainer className=\"GlobalNavigationMainMenu\" ref={mainMenuRef} onKeyDown={onKeyDownTop}>\n {items?.map(renderItem)}\n {items.length + 1 > numberOfItemsAllowed && (\n <ExtendedSection\n onKeyDown={(event) => extendedSectionKeyHandler(event)}\n onMouseEnter={(event) => onMouseEnter(event, ExtendedMenuOption)}\n onMouseLeave={(event) => onMouseLeave(event, ExtendedMenuOption)}>\n <IconButton ref={menuButtonRef} variant={'secondary'} shape={'circular'} action={() => {}}>\n <MoreHorizontal size=\"24px\" />\n </IconButton>\n <SubMenu\n activeItemId={activeItem}\n ref={extendedMenuOptionRef}\n onItemStateChanged={(item, state) => {\n if (state) setActiveItemId(item);\n else if (item == activeItem) setActiveItemId('');\n }}\n nestPath={[ExtendedMenuOption]}\n item={{ items: items.slice(numberOfItemsAllowed - 1), id: ExtendedMenuOption }}\n topLevel={true}\n index={0}\n dropdownMenusOpenedArray={dropdownMenusOpenedArray}\n />\n </ExtendedSection>\n )}\n </NavContainer>\n );\n};\n\nexport default MainMenu;\n"],"mappings":";;;;;;;;;;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,OAAO,QAAqB,kBAAkB;AACvD,OAAOC,MAAM,MAAM,mBAAmB;AAEtC,SAASC,OAAO,QA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1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.SubMenuWrapper = exports.SubMenu = void 0;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+ var React = _interopRequireWildcard(require("react"));
14
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
15
+ var _ExtendedMainMenu = require("./ExtendedMainMenu");
16
+ var _types = require("../../types");
17
+ var _icons = require("../../icons");
18
+ var _utils = require("../utils");
19
+ var _Tabs = _interopRequireDefault(require("../../Tabs/Tabs"));
20
+ var _TabLink = _interopRequireDefault(require("../../Tabs/TabLink"));
21
+ var _MenuItem = require("../../MenuItem");
22
+ var _jsxRuntime = require("react/jsx-runtime");
23
+ var _templateObject;
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
+ var SubMenuWrapper = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n ", " {\n top: ", ";\n left: ", ";\n }\n\n ", "\n\n button {\n padding-left: 0px;\n }\n"])), _ExtendedMainMenu.Menu, function (props) {
27
+ return props.topLevel ? '100%' : '0px';
28
+ }, function (props) {
29
+ return props.topLevel ? '0px' : 'calc(100% - 12px)';
30
+ }, function (props) {
31
+ return !props.visible ? 'display: none;' : '';
32
+ });
33
+ exports.SubMenuWrapper = SubMenuWrapper;
34
+ var SubMenu = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
35
+ var item = _ref.item,
36
+ index = _ref.index,
37
+ topLevel = _ref.topLevel,
38
+ dropdownMenusOpenedArray = _ref.dropdownMenusOpenedArray,
39
+ onSubMenuHidden = _ref.onSubMenuHidden,
40
+ onSubMenuOpened = _ref.onSubMenuOpened,
41
+ onItemStateChanged = _ref.onItemStateChanged,
42
+ activeItemId = _ref.activeItemId,
43
+ nestPath = _ref.nestPath;
44
+ var _React$useState = React.useState({}),
45
+ _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
46
+ forceUpdate = _React$useState2[1];
47
+ var focusedRef = React.useRef({
48
+ index: -1
49
+ });
50
+ var _React$useState3 = React.useState([]),
51
+ _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
52
+ allRefs = _React$useState4[0],
53
+ setAllRefs = _React$useState4[1];
54
+ var _React$useState5 = React.useState([]),
55
+ _React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
56
+ subMenuRefs = _React$useState6[0],
57
+ setAllSubMenuRefs = _React$useState6[1];
58
+ React.useEffect(function () {
59
+ setAllRefs(item.items.map(function (x) {
60
+ return x.type == 'desktopgroup' ? /*#__PURE__*/React.createRef() : /*#__PURE__*/React.createRef();
61
+ }));
62
+ setAllSubMenuRefs(item.items.map(function (x) {
63
+ return x.type == 'desktopgroup' ? /*#__PURE__*/React.createRef() : undefined;
64
+ }));
65
+ }, [item]);
66
+ var existingRef = dropdownMenusOpenedArray.current.find(function (x) {
67
+ return x == item.id;
68
+ });
69
+ var _onMouseLeave = function onMouseLeave(event, id) {
70
+ dropdownMenusOpenedArray.current = (0, _toConsumableArray2.default)(dropdownMenusOpenedArray.current.filter(function (x) {
71
+ return x != id;
72
+ }));
73
+ //just trigger rerendering
74
+ onSubMenuHidden && onSubMenuHidden(id);
75
+ forceUpdate({});
76
+ };
77
+ var containActiveItem = false;
78
+ if (item.type == 'desktopgroup' && activeItemId) containActiveItem = (0, _utils.checkIfContainsItem)(item, activeItemId);
79
+ var _onMouseEnter = function onMouseEnter(event, id) {
80
+ var existingRefForId = dropdownMenusOpenedArray.current.find(function (x) {
81
+ return x == id;
82
+ });
83
+ if (existingRefForId == null) {
84
+ dropdownMenusOpenedArray.current = [].concat((0, _toConsumableArray2.default)(dropdownMenusOpenedArray.current), [id]);
85
+ //just trigger rerendering
86
+ onSubMenuOpened && onSubMenuOpened(id);
87
+ forceUpdate({});
88
+ }
89
+ };
90
+ var _onKeyDown = function onKeyDown(e) {
91
+ if (e.key === 'ArrowUp' || e.key === 'Up') {
92
+ e.stopPropagation();
93
+ e.preventDefault();
94
+ if (focusedRef.current.index > 0) {
95
+ setNewFocusedElement(focusedRef.current.index - 1);
96
+ }
97
+ } else if (e.key === 'ArrowDown' || e.key === 'Down') {
98
+ e.stopPropagation();
99
+ e.preventDefault();
100
+ if (focusedRef.current.index < allRefs.length - 1) setNewFocusedElement(focusedRef.current.index + 1);
101
+ } else if (e.key == 'Enter' || e.code == 'Space') {
102
+ e.stopPropagation();
103
+ if (focusedRef.current.index < 0) return;
104
+ var focusedItem = item.items[focusedRef.current.index];
105
+ if (focusedItem.type == 'desktopgroup') {
106
+ dropdownMenusOpenedArray.current = [].concat((0, _toConsumableArray2.default)(dropdownMenusOpenedArray.current), [focusedItem.id]);
107
+ forceUpdate({});
108
+ } else {
109
+ var _allRefs$focusedRef$c;
110
+ (_allRefs$focusedRef$c = allRefs[focusedRef.current.index].current) === null || _allRefs$focusedRef$c === void 0 ? void 0 : _allRefs$focusedRef$c.click();
111
+ forceUpdate({});
112
+ }
113
+
114
+ //just trigger rerendering
115
+ }
116
+ };
117
+
118
+ var setNewFocusedElement = function setNewFocusedElement(index) {
119
+ var _oldFocusedElement$cu;
120
+ var newFocusedElement = index >= 0 ? allRefs[index] : null;
121
+ var oldFocusedElement = focusedRef.current.index >= 0 ? allRefs[focusedRef.current.index] : null;
122
+ focusedRef.current.index = index;
123
+ if (oldFocusedElement) oldFocusedElement === null || oldFocusedElement === void 0 ? void 0 : (_oldFocusedElement$cu = oldFocusedElement.current) === null || _oldFocusedElement$cu === void 0 ? void 0 : _oldFocusedElement$cu.classList.remove('dropdown-hover');
124
+ if (newFocusedElement && newFocusedElement !== oldFocusedElement) {
125
+ var _newFocusedElement$cu, _newFocusedElement$cu2;
126
+ (_newFocusedElement$cu = newFocusedElement.current) === null || _newFocusedElement$cu === void 0 ? void 0 : _newFocusedElement$cu.classList.add('dropdown-hover');
127
+ (_newFocusedElement$cu2 = newFocusedElement.current) === null || _newFocusedElement$cu2 === void 0 ? void 0 : _newFocusedElement$cu2.scrollIntoView({
128
+ block: 'nearest',
129
+ inline: 'nearest'
130
+ });
131
+ }
132
+ };
133
+ var onFocus = function onFocus(event) {
134
+ event.stopPropagation();
135
+ dropdownMenusOpenedArray.current = (0, _toConsumableArray2.default)(nestPath !== null && nestPath !== void 0 ? nestPath : []);
136
+ setNewFocusedElement(0);
137
+ forceUpdate({});
138
+ };
139
+ var onBlur = function onBlur(event) {
140
+ event.stopPropagation();
141
+ setNewFocusedElement(-1);
142
+ };
143
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(SubMenuWrapper, {
144
+ id: item.id,
145
+ className: existingRef ? 'open' : '',
146
+ topLevel: topLevel,
147
+ visible: Boolean(existingRef),
148
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExtendedMainMenu.Menu, {
149
+ role: "menu",
150
+ ref: ref,
151
+ "aria-labelledby": "UserMenuButton",
152
+ onBlur: onBlur,
153
+ onFocus: onFocus,
154
+ onKeyDown: function onKeyDown(event) {
155
+ return _onKeyDown(event);
156
+ },
157
+ tabIndex: 0,
158
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExtendedMainMenu.MenuSection, {
159
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExtendedMainMenu.MenuSectionList, {
160
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tabs.default, {
161
+ size: _types.Size.Medium,
162
+ children: item.items.map(function (entry, index) {
163
+ var _entry$label2;
164
+ var isGroup = entry.type == 'desktopgroup';
165
+ var key = isGroup ? entry.id : entry.type == 'item' ? entry.to : '';
166
+ var SubItemOpened = Boolean(dropdownMenusOpenedArray.current.find(function (x) {
167
+ return x == entry.id;
168
+ }));
169
+ if (isGroup) {
170
+ var _entry$label;
171
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
172
+ style: {
173
+ position: 'relative'
174
+ },
175
+ onMouseEnter: function onMouseEnter(event) {
176
+ return _onMouseEnter(event, entry.id);
177
+ },
178
+ onMouseLeave: function onMouseLeave(event) {
179
+ return _onMouseLeave(event, entry.id);
180
+ },
181
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_MenuItem.MenuItem, {
182
+ tabIndex: -1,
183
+ ref: allRefs[index],
184
+ id: entry.id,
185
+ item: {
186
+ value: (_entry$label = entry.label) !== null && _entry$label !== void 0 ? _entry$label : ''
187
+ },
188
+ iconRight: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.SystemIcons.ArrowDropRight, {
189
+ size: "24px"
190
+ }),
191
+ active: SubItemOpened || Boolean(activeItemId) && activeItemId != '' && (0, _utils.checkIfContainsItem)(entry, activeItemId),
192
+ onClickHandler: function onClickHandler() {}
193
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(SubMenu, {
194
+ ref: subMenuRefs[index],
195
+ nestPath: [].concat((0, _toConsumableArray2.default)(nestPath !== null && nestPath !== void 0 ? nestPath : []), [entry.id]),
196
+ onItemStateChanged: onItemStateChanged,
197
+ activeItemId: activeItemId,
198
+ dropdownMenusOpenedArray: dropdownMenusOpenedArray,
199
+ item: entry,
200
+ index: index + 1,
201
+ topLevel: false
202
+ })]
203
+ });
204
+ }
205
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
206
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabLink.default, {
207
+ tabIndex: -1,
208
+ to: isGroup ? '' : key,
209
+ ref: allRefs[index],
210
+ onActiveStateChanged: function onActiveStateChanged(state) {
211
+ return onItemStateChanged && entry.type == 'item' && onItemStateChanged(entry.to, state);
212
+ },
213
+ forceDeactivate: isGroup,
214
+ requiredLine: (_entry$label2 = entry.label) !== null && _entry$label2 !== void 0 ? _entry$label2 : '',
215
+ optionalLine: '',
216
+ endLineIcon: isGroup ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.SystemIcons.ArrowDropRight, {
217
+ size: "24px"
218
+ }) : null,
219
+ OptionalLineIcon: '',
220
+ disabled: entry.disabled,
221
+ showNotificationDot: false,
222
+ size: _types.Size.Medium,
223
+ variant: "positive"
224
+ }, key)
225
+ });
226
+ })
227
+ })
228
+ })
229
+ })
230
+ })
231
+ });
232
+ });
233
+ exports.SubMenu = SubMenu;
234
+ SubMenu.propTypes = {
235
+ index: _propTypes.default.number.isRequired,
236
+ topLevel: _propTypes.default.bool.isRequired,
237
+ onSubMenuOpened: _propTypes.default.func,
238
+ onSubMenuHidden: _propTypes.default.func,
239
+ onItemStateChanged: _propTypes.default.func,
240
+ activeItemId: _propTypes.default.string,
241
+ nestPath: _propTypes.default.arrayOf(_propTypes.default.string)
242
+ };
243
+ //# sourceMappingURL=SubMenu.cjs.map