@elliemae/ds-menu 2.2.0-alpha.4 → 3.0.0-next.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.
Files changed (100) hide show
  1. package/cjs/Menu.js +181 -137
  2. package/cjs/MenuCombobox.js +53 -67
  3. package/cjs/MenuContext.js +11 -38
  4. package/cjs/MenuItems/CheckboxGroup.js +42 -49
  5. package/cjs/MenuItems/MenuItem.js +163 -116
  6. package/cjs/MenuItems/MenuItemCheckable.js +108 -77
  7. package/cjs/MenuItems/MenuItemCheckbox.js +41 -47
  8. package/cjs/MenuItems/MenuItemRadio.js +38 -50
  9. package/cjs/MenuItems/RadioGroup.js +39 -48
  10. package/cjs/MenuItems/SearchableGroup.js +92 -88
  11. package/cjs/MenuItems/SearchableList.js +95 -92
  12. package/cjs/MenuItems/SelectionGroup.js +90 -85
  13. package/cjs/MenuItems/Separator.js +40 -55
  14. package/cjs/MenuItems/SubMenu.js +160 -143
  15. package/cjs/MenuItems/menuItemFactory.js +68 -38
  16. package/cjs/VirtualMenuList.js +39 -69
  17. package/cjs/index.js +36 -63
  18. package/cjs/utils/useHeightByAmountOfItems.js +14 -43
  19. package/esm/Menu.js +149 -91
  20. package/esm/MenuCombobox.js +45 -38
  21. package/esm/MenuContext.js +5 -9
  22. package/esm/MenuItems/CheckboxGroup.js +31 -19
  23. package/esm/MenuItems/MenuItem.js +148 -84
  24. package/esm/MenuItems/MenuItemCheckable.js +96 -47
  25. package/esm/MenuItems/MenuItemCheckbox.js +33 -18
  26. package/esm/MenuItems/MenuItemRadio.js +28 -20
  27. package/esm/MenuItems/RadioGroup.js +28 -18
  28. package/esm/MenuItems/SearchableGroup.js +76 -53
  29. package/esm/MenuItems/SearchableList.js +82 -59
  30. package/esm/MenuItems/SelectionGroup.js +78 -54
  31. package/esm/MenuItems/Separator.js +29 -26
  32. package/esm/MenuItems/SubMenu.js +140 -107
  33. package/esm/MenuItems/menuItemFactory.js +60 -10
  34. package/esm/VirtualMenuList.js +32 -39
  35. package/esm/index.js +13 -34
  36. package/esm/utils/useHeightByAmountOfItems.js +11 -13
  37. package/package.json +11 -19
  38. package/types/Menu.d.ts +2 -3
  39. package/types/MenuContext.d.ts +2 -3
  40. package/types/MenuItems/CheckboxGroup.d.ts +5 -5
  41. package/types/MenuItems/MenuItem.d.ts +5 -5
  42. package/types/MenuItems/MenuItemCheckable.d.ts +15 -15
  43. package/types/MenuItems/MenuItemCheckbox.d.ts +2 -3
  44. package/types/MenuItems/MenuItemRadio.d.ts +5 -5
  45. package/types/MenuItems/RadioGroup.d.ts +5 -5
  46. package/types/MenuItems/SearchableGroup.d.ts +3 -3
  47. package/types/MenuItems/SearchableList.d.ts +16 -16
  48. package/types/MenuItems/SelectionGroup.d.ts +16 -16
  49. package/types/MenuItems/Separator.d.ts +1 -2
  50. package/types/MenuItems/SubMenu.d.ts +18 -18
  51. package/types/MenuItems/menuItemFactory.d.ts +3 -2
  52. package/types/VirtualMenuList.d.ts +1 -3
  53. package/types/index.d.ts +2 -3
  54. package/types/utils/useHeightByAmountOfItems.d.ts +1 -3
  55. package/cjs/Menu.js.map +0 -7
  56. package/cjs/MenuCombobox.js.map +0 -7
  57. package/cjs/MenuContext.js.map +0 -7
  58. package/cjs/MenuExports.js +0 -28
  59. package/cjs/MenuExports.js.map +0 -7
  60. package/cjs/MenuItems/CheckboxGroup.js.map +0 -7
  61. package/cjs/MenuItems/MenuItem.js.map +0 -7
  62. package/cjs/MenuItems/MenuItemCheckable.js.map +0 -7
  63. package/cjs/MenuItems/MenuItemCheckbox.js.map +0 -7
  64. package/cjs/MenuItems/MenuItemRadio.js.map +0 -7
  65. package/cjs/MenuItems/RadioGroup.js.map +0 -7
  66. package/cjs/MenuItems/SearchableGroup.js.map +0 -7
  67. package/cjs/MenuItems/SearchableList.js.map +0 -7
  68. package/cjs/MenuItems/SelectionGroup.js.map +0 -7
  69. package/cjs/MenuItems/Separator.js.map +0 -7
  70. package/cjs/MenuItems/SubMenu.js.map +0 -7
  71. package/cjs/MenuItems/menuItemFactory.js.map +0 -7
  72. package/cjs/MenuItems/renderMenuItems.js +0 -53
  73. package/cjs/MenuItems/renderMenuItems.js.map +0 -7
  74. package/cjs/VirtualMenuList.js.map +0 -7
  75. package/cjs/index.js.map +0 -7
  76. package/cjs/utils/useHeightByAmountOfItems.js.map +0 -7
  77. package/esm/Menu.js.map +0 -7
  78. package/esm/MenuCombobox.js.map +0 -7
  79. package/esm/MenuContext.js.map +0 -7
  80. package/esm/MenuExports.js +0 -3
  81. package/esm/MenuExports.js.map +0 -7
  82. package/esm/MenuItems/CheckboxGroup.js.map +0 -7
  83. package/esm/MenuItems/MenuItem.js.map +0 -7
  84. package/esm/MenuItems/MenuItemCheckable.js.map +0 -7
  85. package/esm/MenuItems/MenuItemCheckbox.js.map +0 -7
  86. package/esm/MenuItems/MenuItemRadio.js.map +0 -7
  87. package/esm/MenuItems/RadioGroup.js.map +0 -7
  88. package/esm/MenuItems/SearchableGroup.js.map +0 -7
  89. package/esm/MenuItems/SearchableList.js.map +0 -7
  90. package/esm/MenuItems/SelectionGroup.js.map +0 -7
  91. package/esm/MenuItems/Separator.js.map +0 -7
  92. package/esm/MenuItems/SubMenu.js.map +0 -7
  93. package/esm/MenuItems/menuItemFactory.js.map +0 -7
  94. package/esm/MenuItems/renderMenuItems.js +0 -24
  95. package/esm/MenuItems/renderMenuItems.js.map +0 -7
  96. package/esm/VirtualMenuList.js.map +0 -7
  97. package/esm/index.js.map +0 -7
  98. package/esm/utils/useHeightByAmountOfItems.js.map +0 -7
  99. package/types/MenuExports.d.ts +0 -1
  100. package/types/MenuItems/renderMenuItems.d.ts +0 -1
@@ -1,35 +1,45 @@
1
- import * as React from "react";
2
- import React2, { useCallback, useRef, useState } from "react";
3
- import { PropTypes, describe } from "react-desc";
4
- import { ChevronSmallRight, MoreOptionsVert } from "@elliemae/ds-icons";
5
- import { useFocusGroupItem } from "@elliemae/ds-shared/FocusGroup";
6
- import { useHiddenController } from "@elliemae/ds-hidden";
7
- import { DSButton, BUTTON_VARIANT } from "@elliemae/ds-button";
8
- import { DSPopper, interactions } from "@elliemae/ds-popper";
9
- import styled from "styled-components";
10
- import { Menu } from "../Menu";
11
- import { MenuItem } from "./MenuItem";
12
- import { registerMenuItem } from "./menuItemFactory";
13
- const ChevronRightComp = styled.div`
14
- display: flex;
15
- justify-content: center;
16
- align-items: center;
17
- width: 28px; // same width as the ellipsis button
18
- `;
19
- const SubMenu = ({
20
- noAddon,
21
- leftAddon = void 0,
22
- label = void 0,
23
- interactionType = "hover",
24
- children: subitems,
25
- rightAddonType,
26
- disabledAddonInactive,
27
- checkableProps = {},
28
- customRenderer,
29
- onClick,
30
- closeMenu,
31
- id
32
- }) => {
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
8
+ import 'core-js/modules/web.dom-collections.iterator.js';
9
+ import { useRef, useState, useCallback } from 'react';
10
+ import { PropTypes, describe } from 'react-desc';
11
+ import { MoreOptionsVert, ChevronSmallRight } from '@elliemae/ds-icons';
12
+ import { useFocusGroupItem } from '@elliemae/ds-shared/FocusGroup';
13
+ import { useHiddenController } from '@elliemae/ds-hidden';
14
+ import DSButton, { BUTTON_VARIANT } from '@elliemae/ds-button';
15
+ import DSPopper, { interactions } from '@elliemae/ds-popper';
16
+ import styled from 'styled-components';
17
+ import { Menu } from '../Menu.js';
18
+ import MenuItem from './MenuItem.js';
19
+ import { jsx, Fragment } from 'react/jsx-runtime';
20
+
21
+ 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; }
22
+
23
+ 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; }
24
+ const ChevronRightComp = /*#__PURE__*/styled.div.withConfig({
25
+ componentId: "sc-1qhp1z-0"
26
+ })(["display:flex;justify-content:center;align-items:center;width:28px;"]);
27
+
28
+ function SubMenu(_ref) {
29
+ let {
30
+ noAddon,
31
+ leftAddon = undefined,
32
+ label = undefined,
33
+ interactionType = 'hover',
34
+ children: subitems,
35
+ rightAddonType,
36
+ disabledAddonInactive,
37
+ checkableProps = {},
38
+ customRenderer,
39
+ onClick,
40
+ closeMenu,
41
+ id
42
+ } = _ref;
33
43
  const itemRef = useRef(null);
34
44
  const focusOnOpen = useRef(false);
35
45
  const [isAddonHovered, setIsAddonHovered] = useState(false);
@@ -37,121 +47,144 @@ const SubMenu = ({
37
47
  visible = false,
38
48
  onShow,
39
49
  onHide
40
- } = useHiddenController(void 0, {
41
- interaction: "click"
50
+ } = useHiddenController(undefined, {
51
+ interaction: 'click'
42
52
  });
43
- const interaction = rightAddonType === "elipsis" ? "click" : "hover";
44
- const { focusItemByNode } = useFocusGroupItem();
45
- const handleShowSubItemsWithMouse = (e) => {
53
+ const interaction = rightAddonType === 'elipsis' ? 'click' : 'hover';
54
+ const {
55
+ focusItemByNode
56
+ } = useFocusGroupItem(); // todo: create a menu state to handle all related menu things
57
+
58
+ const handleShowSubItemsWithMouse = e => {
46
59
  e.stopPropagation();
47
60
  onShow();
48
61
  focusOnOpen.current = true;
49
62
  };
50
- const handleShowWithMouse = (e) => {
51
- if (onClick)
52
- onClick(e);
63
+
64
+ const handleShowWithMouse = e => {
65
+ if (onClick) onClick(e);
53
66
  };
67
+
54
68
  const handleShowWithMouseHover = () => {
55
69
  setIsAddonHovered(true);
56
70
  onShow();
57
71
  focusOnOpen.current = false;
58
72
  };
73
+
59
74
  const handleShowWithKeyboard = () => {
60
75
  onShow();
61
76
  focusOnOpen.current = true;
62
77
  };
78
+
63
79
  const handleOnMouseEnter = useCallback(() => {
64
80
  setIsAddonHovered(true);
65
81
  }, []);
66
82
  const handleOnMouseLeave = useCallback(() => {
67
83
  setIsAddonHovered(false);
68
84
  }, []);
69
- const hoverHandlers = interaction === "hover" ? {
85
+ const hoverHandlers = interaction === 'hover' ? {
70
86
  onMouseEnter: handleShowWithMouseHover,
71
87
  onMouseLeave: () => {
72
88
  onHide();
73
89
  setIsAddonHovered(false);
74
90
  }
75
- } : { onClick: handleShowWithMouse };
76
- const rightAddon = rightAddonType === "elipsis" ? /* @__PURE__ */ React2.createElement(DSButton, {
91
+ } : {
92
+ onClick: handleShowWithMouse
93
+ };
94
+ const rightAddon = rightAddonType === 'elipsis' ? /*#__PURE__*/_jsx(DSButton, {
77
95
  "aria-label": "vertical-elipsis",
78
96
  "data-testid": "vertical-elipsis",
79
97
  buttonType: "text",
80
- leftIcon: /* @__PURE__ */ React2.createElement(MoreOptionsVert, {
98
+ leftIcon: /*#__PURE__*/_jsx(MoreOptionsVert, {
81
99
  className: "submenu-arrow",
82
- color: visible || isAddonHovered ? ["brand-primary", 800] : ["neutral", 500],
100
+ color: visible || isAddonHovered ? ['brand-primary', 800] : ['neutral', 500],
83
101
  size: "s"
84
102
  }),
85
- onClick: (e) => handleShowSubItemsWithMouse(e),
103
+ onClick: e => handleShowSubItemsWithMouse(e),
86
104
  size: "m",
87
105
  variant: BUTTON_VARIANT.DEFAULT
88
- }) : /* @__PURE__ */ React2.createElement(ChevronRightComp, null, /* @__PURE__ */ React2.createElement(ChevronSmallRight, {
106
+ }) : /*#__PURE__*/_jsx(ChevronRightComp, {}, void 0, /*#__PURE__*/_jsx(ChevronSmallRight, {
89
107
  "data-testid": "chevron-right",
90
108
  className: "submenu-arrow",
91
- color: visible || isAddonHovered ? ["brand-primary", 800] : ["neutral", 500],
109
+ color: visible || isAddonHovered ? ['brand-primary', 800] : ['neutral', 500],
92
110
  size: "sm"
93
111
  }));
94
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(DSPopper, {
95
- contentComponent: /* @__PURE__ */ React2.createElement(Menu, {
96
- focusKeyBindings: {
97
- ArrowLeft: [() => focusItemByNode(itemRef.current), "exit"]
98
- },
99
- focusOnOpen: focusOnOpen.current,
100
- onExitFocusGroup: onHide,
101
- ...hoverHandlers,
102
- closeMenu,
103
- visible
104
- }, subitems),
105
- interactionType,
106
- isOpen: visible,
107
- onOpen: (opening) => opening ? onShow() : onHide(),
108
- placement: "right-start",
109
- showArrow: false,
110
- triggerComponent: /* @__PURE__ */ React2.createElement(MenuItem, {
111
- customRenderer,
112
- disabledAddonInactive,
113
- id,
114
- innerRef: itemRef,
115
- label,
116
- leftAddon,
117
- noAddon,
118
- onFocus: handleOnMouseEnter,
119
- onBlur: handleOnMouseLeave,
120
- onMouseEnter: handleOnMouseEnter,
121
- onMouseLeave: handleOnMouseLeave,
122
- ...hoverHandlers,
123
- onKeyDown: (e) => {
124
- if (e.key === "ArrowRight" || e.key === "Enter" || e.keyCode === 32) {
125
- handleShowWithKeyboard();
126
- }
127
- },
128
- rightAddon,
129
- ...checkableProps
112
+ return /*#__PURE__*/jsx(Fragment, {
113
+ children: /*#__PURE__*/_jsx(DSPopper, {
114
+ contentComponent: /*#__PURE__*/jsx(Menu, _objectSpread(_objectSpread({
115
+ focusKeyBindings: {
116
+ ArrowLeft: [() => focusItemByNode(itemRef.current), 'exit']
117
+ },
118
+ focusOnOpen: focusOnOpen.current,
119
+ onExitFocusGroup: onHide
120
+ }, hoverHandlers), {}, {
121
+ closeMenu: closeMenu,
122
+ visible: visible,
123
+ children: subitems
124
+ })),
125
+ interactionType: interactionType,
126
+ isOpen: visible,
127
+ onOpen: opening => opening ? onShow() : onHide(),
128
+ placement: "right-start",
129
+ showArrow: false,
130
+ triggerComponent: /*#__PURE__*/jsx(MenuItem, _objectSpread(_objectSpread({
131
+ customRenderer: customRenderer,
132
+ disabledAddonInactive: disabledAddonInactive,
133
+ id: id,
134
+ innerRef: itemRef,
135
+ label: label,
136
+ leftAddon: leftAddon,
137
+ noAddon: noAddon,
138
+ onFocus: handleOnMouseEnter,
139
+ onBlur: handleOnMouseLeave,
140
+ onMouseEnter: handleOnMouseEnter,
141
+ onMouseLeave: handleOnMouseLeave
142
+ }, hoverHandlers), {}, {
143
+ onKeyDown: e => {
144
+ if (e.key === 'ArrowRight' || e.key === 'Enter' || e.keyCode === 32) {
145
+ handleShowWithKeyboard();
146
+ }
147
+ },
148
+ rightAddon: rightAddon
149
+ }, checkableProps))
130
150
  })
131
- }));
132
- };
151
+ });
152
+ }
153
+
133
154
  const props = {
134
- noAddon: PropTypes.bool.description("dont show addon for submenu"),
135
- leftAddon: PropTypes.node.description("left addon"),
136
- label: PropTypes.string.description("submenu label"),
137
- interactionType: PropTypes.oneOf(interactions).description("A type indicating how to open/close the tooltip"),
138
- children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]).description("sub menu items"),
139
- rightAddonType: PropTypes.oneOf(["ellipsis"]).description("right addon, ellipsis or undefined"),
140
- disabledAddonInactive: PropTypes.bool.description(""),
141
- checkableProps: PropTypes.object.description("props passed to MenuItem component"),
142
- customRenderer: PropTypes.func.description("custom renderer for menu item"),
143
- onClick: PropTypes.func.description("on click handler"),
144
- closeMenu: PropTypes.any.description(""),
145
- id: PropTypes.string.description("component id")
155
+ /** dont show addon for submenu */
156
+ noAddon: PropTypes.bool.description('dont show addon for submenu'),
157
+
158
+ /** left addon */
159
+ leftAddon: PropTypes.node.description('left addon'),
160
+
161
+ /** submenu label */
162
+ label: PropTypes.string.description('submenu label'),
163
+
164
+ /** A type indicating how to open/close the tooltip */
165
+ interactionType: PropTypes.oneOf(interactions).description('A type indicating how to open/close the tooltip'),
166
+
167
+ /** sub menu items */
168
+ children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]).description('sub menu items'),
169
+
170
+ /** right addon, ellipsis or undefined */
171
+ rightAddonType: PropTypes.oneOf(['ellipsis']).description('right addon, ellipsis or undefined'),
172
+ disabledAddonInactive: PropTypes.bool.description(''),
173
+
174
+ /** props passed to MenuItem component */
175
+ checkableProps: PropTypes.object.description('props passed to MenuItem component'),
176
+
177
+ /** custom renderer for menu item */
178
+ customRenderer: PropTypes.func.description('custom renderer for menu item'),
179
+
180
+ /** on click handler */
181
+ onClick: PropTypes.func.description('on click handler'),
182
+ closeMenu: PropTypes.any.description(''),
183
+
184
+ /** component id */
185
+ id: PropTypes.string.description('component id')
146
186
  };
147
- SubMenu.propTypes = props;
148
- registerMenuItem("submenu", SubMenu);
149
187
  const DSSubMenuWithSchema = describe(SubMenu);
150
188
  DSSubMenuWithSchema.propTypes = props;
151
- var SubMenu_default = SubMenu;
152
- export {
153
- DSSubMenuWithSchema,
154
- SubMenu,
155
- SubMenu_default as default
156
- };
157
- //# sourceMappingURL=SubMenu.js.map
189
+
190
+ export { DSSubMenuWithSchema, SubMenu as default };
@@ -1,12 +1,62 @@
1
- import * as React from "react";
2
- const itemTypes = {};
3
- const menuItemFactory = (type = "", items, defaultItem = itemTypes.menuitem) => {
4
- const itemsObject = items || itemTypes;
5
- return itemsObject[type] || itemsObject[type.toLowerCase()] || defaultItem;
1
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
+ import 'core-js/modules/esnext.async-iterator.map.js';
3
+ import 'core-js/modules/esnext.iterator.map.js';
4
+ import 'core-js/modules/esnext.async-iterator.filter.js';
5
+ import 'core-js/modules/esnext.iterator.constructor.js';
6
+ import 'core-js/modules/esnext.iterator.filter.js';
7
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
8
+ import 'core-js/modules/esnext.iterator.for-each.js';
9
+ import { createElement } from 'react';
10
+ import { isFunction } from '@elliemae/ds-utilities';
11
+ import MenuSeparator from './Separator.js';
12
+ import MenuItem from './MenuItem.js';
13
+ import SubMenu from './SubMenu.js';
14
+ import SelectionGroup from './SelectionGroup.js';
15
+ import MenuItemCheckbox from './MenuItemCheckbox.js';
16
+ import MenuItemRadio from './MenuItemRadio.js';
17
+
18
+ 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; }
19
+
20
+ 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; }
21
+ const itemTypes = {
22
+ separator: MenuSeparator,
23
+ menuitem: MenuItem,
24
+ radio: MenuItemRadio,
25
+ checkbox: MenuItemCheckbox,
26
+ submenu: SubMenu,
27
+ 'selection-group': SelectionGroup
6
28
  };
7
- const registerMenuItem = (type, item) => itemTypes[type] = item;
8
- export {
9
- menuItemFactory,
10
- registerMenuItem
29
+ const fallback = {
30
+ SelectionGroup: 'selection-group'
11
31
  };
12
- //# sourceMappingURL=menuItemFactory.js.map
32
+ function menuItemFactory() {
33
+ let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
34
+ let items = arguments.length > 1 ? arguments[1] : undefined;
35
+ let defaultItem = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : itemTypes.menuitem;
36
+ const itemsObject = items || itemTypes;
37
+ const parsedType = fallback[type] || type.toLowerCase();
38
+ return itemsObject[parsedType] || defaultItem;
39
+ }
40
+ function renderMenuItems(options) {
41
+ let factory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : menuItemFactory;
42
+ return options.map((option, index) => {
43
+ if (isFunction(option.renderer)) {
44
+ return option.renderer({
45
+ key: option.id,
46
+ item: option
47
+ });
48
+ }
49
+
50
+ const ItemComponent = factory(option.type);
51
+ const children = option.subItems && renderMenuItems(option.subItems, factory);
52
+ return /*#__PURE__*/createElement(ItemComponent, _objectSpread(_objectSpread({}, option), {}, {
53
+ key: option.id || index,
54
+ item: option,
55
+ onClick: null,
56
+ onMouseDown: option.onClick // onClick callback called in onMouseDown due to events order issue
57
+
58
+ }), children);
59
+ });
60
+ }
61
+
62
+ export { menuItemFactory, renderMenuItems };
@@ -1,49 +1,42 @@
1
- import * as React from "react";
2
- import React2 from "react";
3
- import { FixedSizeList as List } from "react-window";
4
- import { useHeightByAmountOfItems } from "./utils/useHeightByAmountOfItems";
5
- const MenuItem = ({ data, index, style }) => /* @__PURE__ */ React2.createElement("div", {
6
- key: index,
7
- style
8
- }, data && data[index] ? data[index] : "");
9
- function resolveComputation(items, cb, timeout = 1e3) {
10
- return () => new Promise((resolve) => {
11
- const doResolve = (result2) => {
12
- cb(result2);
13
- resolve(result2);
14
- };
15
- let result = 0;
16
- const timer = setTimeout(() => doResolve(result), timeout);
17
- items.forEach((option) => {
18
- result = option.props.label.length > result ? option.props.label.length : result;
19
- });
20
- clearTimeout(timer);
21
- doResolve(result);
22
- });
23
- }
24
- function VirtualMenuList({
25
- items,
26
- itemHeight = 32,
27
- amountItemsInWindow = 5,
28
- width,
29
- height
30
- }) {
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
3
+ import 'core-js/modules/esnext.iterator.constructor.js';
4
+ import 'core-js/modules/esnext.iterator.for-each.js';
5
+ import 'react';
6
+ import { FixedSizeList } from 'react-window';
7
+ import useHeightByAmountOfItems from './utils/useHeightByAmountOfItems.js';
8
+
9
+ const MenuItem = _ref => {
10
+ let {
11
+ data,
12
+ index,
13
+ style
14
+ } = _ref;
15
+ return /*#__PURE__*/_jsx("div", {
16
+ style: style
17
+ }, index, data && data[index] ? data[index] : '');
18
+ }; // eslint-disable-next-line no-unused-vars
19
+
20
+ function VirtualMenuList(_ref2) {
21
+ let {
22
+ items,
23
+ itemHeight = 32,
24
+ amountItemsInWindow = 5,
25
+ width,
26
+ height
27
+ } = _ref2;
31
28
  const computedListHeight = useHeightByAmountOfItems({
32
29
  amountItems: amountItemsInWindow,
33
30
  itemHeight,
34
31
  items
35
32
  });
36
- return /* @__PURE__ */ React2.createElement(List, {
33
+ return /*#__PURE__*/_jsx(FixedSizeList, {
37
34
  height: height || computedListHeight,
38
35
  itemCount: items.length,
39
36
  itemData: items,
40
37
  itemSize: itemHeight,
41
- width
42
- }, MenuItem);
38
+ width: width
39
+ }, void 0, MenuItem);
43
40
  }
44
- var VirtualMenuList_default = VirtualMenuList;
45
- export {
46
- VirtualMenuList,
47
- VirtualMenuList_default as default
48
- };
49
- //# sourceMappingURL=VirtualMenuList.js.map
41
+
42
+ export { VirtualMenuList as default };
package/esm/index.js CHANGED
@@ -1,34 +1,13 @@
1
- import * as React from "react";
2
- import { DSMenuItemWithSchema } from "./MenuItems/MenuItem";
3
- import { DSSubMenuWithSchema } from "./MenuItems/SubMenu";
4
- import { DSMenuCheckboxGroupWithSchema } from "./MenuItems/CheckboxGroup";
5
- import { DSMenuItemCheckeableWithSchema } from "./MenuItems/MenuItemCheckable";
6
- import { DSMenuItemRadioWithSchema } from "./MenuItems/MenuItemRadio";
7
- import { DSMenuRadioGroupWithSchema } from "./MenuItems/RadioGroup";
8
- import { DSMenuSearchableGroupWithSchema } from "./MenuItems/SearchableGroup";
9
- import { DSMenuSearchableListWithSchema } from "./MenuItems/SearchableList";
10
- import { DSMenuSeparatorWithSchema } from "./MenuItems/Separator";
11
- import { DSMenuSelectionGroupWithSchema } from "./MenuItems/SelectionGroup";
12
- import { default as default2 } from "./MenuCombobox";
13
- import { menuItemFactory } from "./MenuItems/menuItemFactory";
14
- import { renderMenuItems } from "./MenuItems/renderMenuItems";
15
- import { DSMenuWithSchema, Menu, Menu as Menu2 } from "./Menu";
16
- export {
17
- DSMenuCheckboxGroupWithSchema,
18
- DSMenuItemCheckeableWithSchema,
19
- DSMenuItemRadioWithSchema,
20
- DSMenuItemWithSchema,
21
- DSMenuRadioGroupWithSchema,
22
- DSMenuSearchableGroupWithSchema,
23
- DSMenuSearchableListWithSchema,
24
- DSMenuSelectionGroupWithSchema,
25
- DSMenuSeparatorWithSchema,
26
- DSMenuWithSchema,
27
- DSSubMenuWithSchema,
28
- Menu,
29
- default2 as MenuCombobox,
30
- Menu2 as default,
31
- menuItemFactory,
32
- renderMenuItems
33
- };
34
- //# sourceMappingURL=index.js.map
1
+ export { DSMenuWithSchema, Menu, Menu as default } from './Menu.js';
2
+ export { DSMenuItemWithSchema } from './MenuItems/MenuItem.js';
3
+ export { DSSubMenuWithSchema } from './MenuItems/SubMenu.js';
4
+ export { DSMenuCheckboxGroupWithSchema } from './MenuItems/CheckboxGroup.js';
5
+ export { DSMenuItemCheckeableWithSchema } from './MenuItems/MenuItemCheckable.js';
6
+ export { DSMenuItemRadioWithSchema } from './MenuItems/MenuItemRadio.js';
7
+ export { DSMenuRadioGroupWithSchema } from './MenuItems/RadioGroup.js';
8
+ export { DSMenuSearchableGroupWithSchema } from './MenuItems/SearchableGroup.js';
9
+ export { DSMenuSearchableListWithSchema } from './MenuItems/SearchableList.js';
10
+ export { DSMenuSeparatorWithSchema } from './MenuItems/Separator.js';
11
+ export { DSMenuSelectionGroupWithSchema } from './MenuItems/SelectionGroup.js';
12
+ export { default as MenuCombobox } from './MenuCombobox.js';
13
+ export { menuItemFactory, renderMenuItems } from './MenuItems/menuItemFactory.js';
@@ -1,20 +1,18 @@
1
- import * as React from "react";
2
- import { useMemo } from "react";
1
+ import { useMemo } from 'react';
2
+
3
3
  const calculateHeight = (itemHeight, amountItemsInWindow, itemsLength) => {
4
4
  const realAmountItemsInWindow = itemsLength < amountItemsInWindow ? itemsLength : amountItemsInWindow;
5
5
  return itemHeight * realAmountItemsInWindow;
6
6
  };
7
- function useHeightByAmountOfItems({
8
- itemHeight,
9
- amountItems,
10
- items
11
- }) {
7
+
8
+ function useHeightByAmountOfItems(_ref) {
9
+ let {
10
+ itemHeight,
11
+ amountItems,
12
+ items
13
+ } = _ref;
12
14
  const calculatedHeight = useMemo(() => calculateHeight(itemHeight, amountItems, items.length), [amountItems, items]);
13
15
  return calculatedHeight;
14
16
  }
15
- var useHeightByAmountOfItems_default = useHeightByAmountOfItems;
16
- export {
17
- useHeightByAmountOfItems_default as default,
18
- useHeightByAmountOfItems
19
- };
20
- //# sourceMappingURL=useHeightByAmountOfItems.js.map
17
+
18
+ export { useHeightByAmountOfItems as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-menu",
3
- "version": "2.2.0-alpha.4",
3
+ "version": "3.0.0-next.2",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Menu",
6
6
  "module": "./esm/index.js",
@@ -39,10 +39,6 @@
39
39
  "import": "./esm/MenuItems/SearchableGroup.js",
40
40
  "require": "./cjs/MenuItems/SearchableGroup.js"
41
41
  },
42
- "./MenuItems/renderMenuItems": {
43
- "import": "./esm/MenuItems/renderMenuItems.js",
44
- "require": "./cjs/MenuItems/renderMenuItems.js"
45
- },
46
42
  "./MenuItems/RadioGroup": {
47
43
  "import": "./esm/MenuItems/RadioGroup.js",
48
44
  "require": "./cjs/MenuItems/RadioGroup.js"
@@ -71,10 +67,6 @@
71
67
  "import": "./esm/MenuItems/CheckboxGroup.js",
72
68
  "require": "./cjs/MenuItems/CheckboxGroup.js"
73
69
  },
74
- "./MenuExports": {
75
- "import": "./esm/MenuExports.js",
76
- "require": "./cjs/MenuExports.js"
77
- },
78
70
  "./MenuContext": {
79
71
  "import": "./esm/MenuContext.js",
80
72
  "require": "./cjs/MenuContext.js"
@@ -108,16 +100,16 @@
108
100
  "build": "node ../../scripts/build/build.js"
109
101
  },
110
102
  "dependencies": {
111
- "@elliemae/ds-button": "2.2.0-alpha.4",
112
- "@elliemae/ds-classnames": "2.2.0-alpha.4",
113
- "@elliemae/ds-form": "2.2.0-alpha.4",
114
- "@elliemae/ds-hidden": "2.2.0-alpha.4",
115
- "@elliemae/ds-icons": "2.2.0-alpha.4",
116
- "@elliemae/ds-popper": "2.2.0-alpha.4",
117
- "@elliemae/ds-separator": "2.2.0-alpha.4",
118
- "@elliemae/ds-shared": "2.2.0-alpha.4",
119
- "@elliemae/ds-truncated-tooltip-text": "2.2.0-alpha.4",
120
- "@elliemae/ds-utilities": "2.2.0-alpha.4",
103
+ "@elliemae/ds-button": "3.0.0-next.2",
104
+ "@elliemae/ds-classnames": "3.0.0-next.2",
105
+ "@elliemae/ds-form": "3.0.0-next.2",
106
+ "@elliemae/ds-hidden": "3.0.0-next.2",
107
+ "@elliemae/ds-icons": "3.0.0-next.2",
108
+ "@elliemae/ds-popper": "3.0.0-next.2",
109
+ "@elliemae/ds-separator": "3.0.0-next.2",
110
+ "@elliemae/ds-shared": "3.0.0-next.2",
111
+ "@elliemae/ds-truncated-tooltip-text": "3.0.0-next.2",
112
+ "@elliemae/ds-utilities": "3.0.0-next.2",
121
113
  "prop-types": "~15.7.2",
122
114
  "react-desc": "~4.1.3",
123
115
  "react-spring": "~8.0.27",
package/types/Menu.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /// <reference path="../../../../shared/typings/react-desc.d.ts" />
2
2
  import React from 'react';
3
- import { menuItemFactory } from './MenuItems/menuItemFactory';
4
- import { renderMenuItems } from './MenuItems/renderMenuItems';
3
+ import { renderMenuItems, menuItemFactory } from './MenuItems/menuItemFactory';
5
4
  declare const Menu: any;
6
5
  declare const DSMenuWithSchema: {
7
6
  (props?: {
@@ -25,5 +24,5 @@ declare const DSMenuWithSchema: {
25
24
  propTypes: unknown;
26
25
  toTypescript: () => import("react-desc").TypescriptSchema;
27
26
  };
28
- export { menuItemFactory, renderMenuItems, DSMenuWithSchema, Menu };
27
+ export { Menu, menuItemFactory, renderMenuItems, DSMenuWithSchema };
29
28
  export default Menu;
@@ -1,4 +1,3 @@
1
1
  import React from 'react';
2
- declare const MenuContext: React.Context<unknown>;
3
- export { MenuContext };
4
- export default MenuContext;
2
+ declare const _default: React.Context<unknown>;
3
+ export default _default;
@@ -1,8 +1,8 @@
1
1
  /// <reference path="../../../../../shared/typings/react-desc.d.ts" />
2
2
  /// <reference types="react" />
3
- declare const CheckboxGroup: {
4
- (props: any): JSX.Element;
5
- propTypes: {
3
+ declare function CheckboxGroup(props: any): JSX.Element;
4
+ declare namespace CheckboxGroup {
5
+ var propTypes: {
6
6
  active: {
7
7
  defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
8
8
  deprecated: import("react-desc").PropTypesDescValidator;
@@ -22,11 +22,11 @@ declare const CheckboxGroup: {
22
22
  isRequired: import("react-desc").PropTypesDescValue;
23
23
  };
24
24
  };
25
- };
25
+ }
26
26
  declare const DSMenuCheckboxGroupWithSchema: {
27
27
  (props?: any): JSX.Element;
28
28
  propTypes: unknown;
29
29
  toTypescript: () => import("react-desc").TypescriptSchema;
30
30
  };
31
- export { DSMenuCheckboxGroupWithSchema, CheckboxGroup };
32
31
  export default CheckboxGroup;
32
+ export { DSMenuCheckboxGroupWithSchema };