@elliemae/ds-menu 1.57.1-rc.0 → 2.0.0-alpha.11

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 (114) hide show
  1. package/cjs/Menu.js +176 -39
  2. package/cjs/MenuCombobox.js +33 -80
  3. package/cjs/MenuContext.js +1 -2
  4. package/cjs/MenuItems/CheckboxGroup.js +12 -10
  5. package/cjs/MenuItems/MenuItem.js +186 -36
  6. package/cjs/MenuItems/MenuItemCheckable.js +109 -35
  7. package/cjs/MenuItems/MenuItemCheckbox.js +35 -34
  8. package/cjs/MenuItems/MenuItemRadio.js +31 -35
  9. package/cjs/MenuItems/RadioGroup.js +12 -10
  10. package/cjs/MenuItems/SearchableGroup.js +44 -59
  11. package/cjs/MenuItems/SearchableList.js +35 -56
  12. package/cjs/MenuItems/SelectionGroup.js +93 -36
  13. package/cjs/MenuItems/Separator.js +14 -16
  14. package/cjs/MenuItems/SubMenu.js +197 -36
  15. package/cjs/MenuItems/menuItemFactory.js +56 -36
  16. package/cjs/VirtualMenuList.js +23 -26
  17. package/cjs/index.js +27 -48
  18. package/cjs/utils/useHeightByAmountOfItems.js +8 -10
  19. package/esm/Menu.js +165 -31
  20. package/esm/MenuCombobox.js +28 -74
  21. package/esm/MenuContext.js +0 -1
  22. package/esm/MenuItems/CheckboxGroup.js +10 -7
  23. package/esm/MenuItems/MenuItem.js +178 -31
  24. package/esm/MenuItems/MenuItemCheckable.js +101 -30
  25. package/esm/MenuItems/MenuItemCheckbox.js +28 -30
  26. package/esm/MenuItems/MenuItemRadio.js +26 -30
  27. package/esm/MenuItems/RadioGroup.js +10 -7
  28. package/esm/MenuItems/SearchableGroup.js +42 -56
  29. package/esm/MenuItems/SearchableList.js +32 -51
  30. package/esm/MenuItems/SelectionGroup.js +87 -31
  31. package/esm/MenuItems/Separator.js +12 -14
  32. package/esm/MenuItems/SubMenu.js +186 -31
  33. package/esm/MenuItems/menuItemFactory.js +51 -31
  34. package/esm/VirtualMenuList.js +21 -24
  35. package/esm/index.js +7 -28
  36. package/esm/utils/useHeightByAmountOfItems.js +8 -10
  37. package/package.json +106 -21
  38. package/types/Menu.d.ts +5 -0
  39. package/types/MenuCombobox.d.ts +28 -0
  40. package/types/MenuContext.d.ts +3 -0
  41. package/types/MenuItems/CheckboxGroup.d.ts +12 -0
  42. package/types/MenuItems/MenuItem.d.ts +29 -0
  43. package/types/MenuItems/MenuItemCheckable.d.ts +42 -0
  44. package/types/MenuItems/MenuItemCheckbox.d.ts +6 -0
  45. package/types/MenuItems/MenuItemRadio.d.ts +13 -0
  46. package/types/MenuItems/RadioGroup.d.ts +11 -0
  47. package/types/MenuItems/SearchableGroup.d.ts +4 -0
  48. package/types/MenuItems/SearchableList.d.ts +40 -0
  49. package/types/MenuItems/SelectionGroup.d.ts +36 -0
  50. package/types/MenuItems/Separator.d.ts +16 -0
  51. package/types/MenuItems/SubMenu.d.ts +44 -0
  52. package/types/MenuItems/menuItemFactory.d.ts +3 -0
  53. package/types/VirtualMenuList.d.ts +8 -0
  54. package/types/index.d.ts +13 -0
  55. package/types/tests/Menu.test.d.ts +1 -0
  56. package/types/tests/MenuItem.test.d.ts +1 -0
  57. package/types/utils/useHeightByAmountOfItems.d.ts +5 -0
  58. package/Menu/package.json +0 -10
  59. package/MenuCombobox/package.json +0 -10
  60. package/MenuContext/package.json +0 -10
  61. package/MenuItems/CheckboxGroup/package.json +0 -10
  62. package/MenuItems/MenuItem/package.json +0 -10
  63. package/MenuItems/MenuItemCheckable/package.json +0 -10
  64. package/MenuItems/MenuItemCheckbox/package.json +0 -10
  65. package/MenuItems/MenuItemRadio/package.json +0 -10
  66. package/MenuItems/RadioGroup/package.json +0 -10
  67. package/MenuItems/SearchableGroup/package.json +0 -10
  68. package/MenuItems/SearchableList/package.json +0 -10
  69. package/MenuItems/SelectionGroup/package.json +0 -10
  70. package/MenuItems/Separator/package.json +0 -10
  71. package/MenuItems/SubMenu/package.json +0 -10
  72. package/MenuItems/menuItemFactory/package.json +0 -10
  73. package/VirtualMenuList/package.json +0 -10
  74. package/cjs/Menu.js.map +0 -1
  75. package/cjs/MenuCombobox.js.map +0 -1
  76. package/cjs/MenuContext.js.map +0 -1
  77. package/cjs/MenuItems/CheckboxGroup.js.map +0 -1
  78. package/cjs/MenuItems/MenuItem.js.map +0 -1
  79. package/cjs/MenuItems/MenuItemCheckable.js.map +0 -1
  80. package/cjs/MenuItems/MenuItemCheckbox.js.map +0 -1
  81. package/cjs/MenuItems/MenuItemRadio.js.map +0 -1
  82. package/cjs/MenuItems/RadioGroup.js.map +0 -1
  83. package/cjs/MenuItems/SearchableGroup.js.map +0 -1
  84. package/cjs/MenuItems/SearchableList.js.map +0 -1
  85. package/cjs/MenuItems/SelectionGroup.js.map +0 -1
  86. package/cjs/MenuItems/Separator.js.map +0 -1
  87. package/cjs/MenuItems/SubMenu.js.map +0 -1
  88. package/cjs/MenuItems/menuItemFactory.js.map +0 -1
  89. package/cjs/SubMenu-22be0a18.js +0 -806
  90. package/cjs/SubMenu-22be0a18.js.map +0 -1
  91. package/cjs/VirtualMenuList.js.map +0 -1
  92. package/cjs/index.js.map +0 -1
  93. package/cjs/utils/useHeightByAmountOfItems.js.map +0 -1
  94. package/esm/Menu.js.map +0 -1
  95. package/esm/MenuCombobox.js.map +0 -1
  96. package/esm/MenuContext.js.map +0 -1
  97. package/esm/MenuItems/CheckboxGroup.js.map +0 -1
  98. package/esm/MenuItems/MenuItem.js.map +0 -1
  99. package/esm/MenuItems/MenuItemCheckable.js.map +0 -1
  100. package/esm/MenuItems/MenuItemCheckbox.js.map +0 -1
  101. package/esm/MenuItems/MenuItemRadio.js.map +0 -1
  102. package/esm/MenuItems/RadioGroup.js.map +0 -1
  103. package/esm/MenuItems/SearchableGroup.js.map +0 -1
  104. package/esm/MenuItems/SearchableList.js.map +0 -1
  105. package/esm/MenuItems/SelectionGroup.js.map +0 -1
  106. package/esm/MenuItems/Separator.js.map +0 -1
  107. package/esm/MenuItems/SubMenu.js.map +0 -1
  108. package/esm/MenuItems/menuItemFactory.js.map +0 -1
  109. package/esm/SubMenu-a25e69ec.js +0 -778
  110. package/esm/SubMenu-a25e69ec.js.map +0 -1
  111. package/esm/VirtualMenuList.js.map +0 -1
  112. package/esm/index.js.map +0 -1
  113. package/esm/utils/useHeightByAmountOfItems.js.map +0 -1
  114. package/utils/useHeightByAmountOfItems/package.json +0 -10
@@ -1,65 +1,48 @@
1
- import _extends from '@babel/runtime/helpers/esm/extends';
2
1
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
- import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
4
- import React, { useState, useCallback, useMemo } from 'react';
2
+ import 'core-js/modules/web.dom-collections.iterator.js';
3
+ import { useState, useCallback, useMemo } from 'react';
5
4
  import { PropTypes, describe } from 'react-desc';
6
- import { uniqBy } from '@elliemae/ds-utilities';
7
- import { DSComboBox } from '@elliemae/ds-form';
5
+ import { uniqBy } from '@elliemae/ds-utilities/utils';
6
+ import DSComboBox from '@elliemae/ds-form/ComboBox';
7
+ import { jsx } from 'react/jsx-runtime';
8
8
 
9
9
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
10
10
 
11
11
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
12
12
 
13
- var noop = function noop() {};
14
-
15
- function SearchableList(_ref) {
16
- var _ref$onSelectMenuItem = _ref.onSelectMenuItem,
17
- onSelectMenuItem = _ref$onSelectMenuItem === void 0 ? noop : _ref$onSelectMenuItem,
18
- _ref$components = _ref.components,
19
- components = _ref$components === void 0 ? {} : _ref$components,
20
- _ref$searchTerm = _ref.searchTerm,
21
- searchTermProp = _ref$searchTerm === void 0 ? '' : _ref$searchTerm,
22
- _ref$items = _ref.items,
23
- items = _ref$items === void 0 ? [] : _ref$items,
24
- _ref$dropdownFilterOp = _ref.dropdownFilterOptions,
25
- dropdownFilterOptions = _ref$dropdownFilterOp === void 0 ? {} : _ref$dropdownFilterOp,
26
- returnValue = _ref.returnValue,
27
- _ref$extraListProps = _ref.extraListProps,
28
- extraListProps = _ref$extraListProps === void 0 ? {} : _ref$extraListProps,
29
- _ref$appendTermInList = _ref.appendTermInList,
30
- appendTermInList = _ref$appendTermInList === void 0 ? false : _ref$appendTermInList,
31
- _ref$maxOptions = _ref.maxOptions,
32
- maxOptions = _ref$maxOptions === void 0 ? 10 : _ref$maxOptions,
33
- _ref$loading = _ref.loading,
34
- loading = _ref$loading === void 0 ? false : _ref$loading;
35
-
36
- var _useState = useState(searchTermProp),
37
- _useState2 = _slicedToArray(_useState, 2),
38
- searchTerm = _useState2[0],
39
- setInputValue = _useState2[1];
40
-
41
- var handleInputChange = useCallback(function (value, args) {
42
- var action = args ? args.action : null;
13
+ const noop = () => {};
14
+
15
+ function SearchableList({
16
+ onSelectMenuItem = noop,
17
+ components = {},
18
+ searchTerm: searchTermProp = '',
19
+ items = [],
20
+ dropdownFilterOptions = {},
21
+ returnValue,
22
+ extraListProps = {},
23
+ appendTermInList = false,
24
+ maxOptions = 10,
25
+ loading = false
26
+ }) {
27
+ const [searchTerm, setInputValue] = useState(searchTermProp);
28
+ const handleInputChange = useCallback((value, args) => {
29
+ const action = args ? args.action : null;
43
30
  if (action === 'input-blur' || action === 'menu-close') return;
44
31
  setInputValue(value);
45
32
  }, [searchTerm]);
46
- var handleFilterByText = useCallback(function () {
33
+ const handleFilterByText = useCallback(() => {
47
34
  if (searchTerm) onSelectMenuItem(searchTerm);
48
35
  }, [searchTerm]);
49
- var handleKeyDown = useCallback(function (e) {
36
+ const handleKeyDown = useCallback(e => {
50
37
  if (e.key === 'ArrowRight') {
51
38
  handleFilterByText();
52
39
  }
53
40
  }, [searchTerm]);
54
- var options = useMemo(function () {
55
- return searchTerm && appendTermInList ? uniqBy([{
56
- id: searchTerm,
57
- label: searchTerm
58
- }].concat(items), function (item) {
59
- return item.label;
60
- }) : items;
61
- }, [searchTerm, appendTermInList]);
62
- return /*#__PURE__*/React.createElement(DSComboBox, _extends({
41
+ const options = useMemo(() => searchTerm && appendTermInList ? uniqBy([{
42
+ id: searchTerm,
43
+ label: searchTerm
44
+ }].concat(items), item => item.label) : items, [searchTerm, appendTermInList]);
45
+ return /*#__PURE__*/jsx(DSComboBox, _objectSpread(_objectSpread({
63
46
  autoFocus: true,
64
47
  components: _objectSpread({
65
48
  DropdownIndicator: null
@@ -79,10 +62,10 @@ function SearchableList(_ref) {
79
62
  valueProperty: "id",
80
63
  maxOptions: maxOptions,
81
64
  loading: loading
82
- }, extraListProps, dropdownFilterOptions));
65
+ }, extraListProps), dropdownFilterOptions));
83
66
  }
84
67
 
85
- var props = {
68
+ const props = {
86
69
  /** callback after item gets selected */
87
70
  onSelectMenuItem: PropTypes.func.description('callback after item gets selected'),
88
71
 
@@ -113,9 +96,7 @@ var props = {
113
96
  /** loading flag */
114
97
  loading: PropTypes.bool.description('loading flag')
115
98
  };
116
- SearchableList.propTypes = props;
117
- var DSMenuSearchableListWithSchema = describe(SearchableList);
99
+ const DSMenuSearchableListWithSchema = describe(SearchableList);
118
100
  DSMenuSearchableListWithSchema.propTypes = props;
119
101
 
120
102
  export { DSMenuSearchableListWithSchema, SearchableList as default };
121
- //# sourceMappingURL=SearchableList.js.map
@@ -1,31 +1,87 @@
1
- import '@babel/runtime/helpers/esm/extends';
2
- import 'react';
3
- import 'react-desc';
4
- import '@elliemae/ds-shared/CheckableGroup';
5
- import './SearchableGroup.js';
6
- export { d as DSMenuSelectionGroupWithSchema, S as default } from '../SubMenu-a25e69ec.js';
7
- import '../VirtualMenuList.js';
8
- import '@babel/runtime/helpers/esm/slicedToArray';
9
- import '@elliemae/ds-classnames';
10
- import '@elliemae/ds-shared/FocusGroup';
11
- import '@elliemae/ds-form/SearchBox';
12
- import '../MenuContext.js';
13
- import 'react-window';
14
- import '../utils/useHeightByAmountOfItems.js';
15
- import '@elliemae/ds-icons';
16
- import '@elliemae/ds-hidden';
17
- import '@elliemae/ds-button';
18
- import '@elliemae/ds-popper';
19
- import 'styled-components';
20
- import '@babel/runtime/helpers/esm/objectWithoutProperties';
21
- import '@babel/runtime/helpers/esm/defineProperty';
22
- import 'lodash';
23
- import 'react-spring/web.cjs';
24
- import '@elliemae/ds-utilities';
25
- import '@elliemae/ds-truncated-tooltip-text';
26
- import './Separator.js';
27
- import '@elliemae/ds-separator';
28
- import '@elliemae/ds-form';
29
- import './CheckboxGroup.js';
30
- import './RadioGroup.js';
31
- //# sourceMappingURL=SelectionGroup.js.map
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
3
+ import { useMemo, createElement } from 'react';
4
+ import { PropTypes, describe } from 'react-desc';
5
+ import { useCheckableGroup } from '@elliemae/ds-shared/CheckableGroup';
6
+ import SearchableGroup from './SearchableGroup.js';
7
+ import { menuItemFactory } from './menuItemFactory.js';
8
+ import VirtualMenuList from '../VirtualMenuList.js';
9
+
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
+
14
+ const noop = () => null;
15
+
16
+ function SelectionGroup({
17
+ multi = false,
18
+ searchable = false,
19
+ focusOnOpen = false,
20
+ onSelect = noop,
21
+ children,
22
+ items = undefined,
23
+ active = multi ? [] : '',
24
+ width,
25
+ height
26
+ }) {
27
+ const renderedItems = useMemo(() => items && items.map(item => {
28
+ const Component = menuItemFactory(multi ? 'checkbox' : 'radio');
29
+ return /*#__PURE__*/createElement(Component, _objectSpread(_objectSpread({}, item), {}, {
30
+ key: item.name || item.id || item.key,
31
+ item: item,
32
+ name: item.id || item.name
33
+ }));
34
+ }), [items]);
35
+ const decoratedGroupChildren = useCheckableGroup({
36
+ children: renderedItems || children,
37
+ multi,
38
+ active,
39
+ onCheck: onSelect
40
+ });
41
+
42
+ if (searchable) {
43
+ return /*#__PURE__*/_jsx(SearchableGroup, {
44
+ focusOnOpen: focusOnOpen,
45
+ height: height,
46
+ items: items,
47
+ width: width
48
+ }, void 0, decoratedGroupChildren);
49
+ }
50
+
51
+ return /*#__PURE__*/_jsx(VirtualMenuList, {
52
+ height: height,
53
+ items: decoratedGroupChildren,
54
+ width: width
55
+ });
56
+ }
57
+
58
+ const props = {
59
+ /** toggle on multi select */
60
+ multi: PropTypes.bool.description('toggle on multi select'),
61
+
62
+ /** toggle on searchable behavior */
63
+ searchable: PropTypes.bool.description('toggle on searchable behavior'),
64
+
65
+ /** toggle to focus component on open */
66
+ focusOnOpen: PropTypes.bool.description('toggle to focus component on open'),
67
+
68
+ /** callback that triggers when select happens */
69
+ onSelect: PropTypes.func.description('callback that triggers when select happens'),
70
+ children: PropTypes.node.description(''),
71
+
72
+ /** selection group items */
73
+ items: PropTypes.array.description('selection group items'),
74
+
75
+ /** array of values for multi and string for single selection */
76
+ active: PropTypes.oneOfType([PropTypes.string, PropTypes.array]).description('array of values for multi and string for single selection'),
77
+
78
+ /** selection group width */
79
+ width: PropTypes.number.description('selection group width'),
80
+
81
+ /** selection group height */
82
+ height: PropTypes.number.description('selection group height')
83
+ };
84
+ const DSMenuSelectionGroupWithSchema = describe(SelectionGroup);
85
+ DSMenuSelectionGroupWithSchema.propTypes = props;
86
+
87
+ export { DSMenuSelectionGroupWithSchema, SelectionGroup as default };
@@ -1,32 +1,30 @@
1
- import React from 'react';
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'react';
2
3
  import { PropTypes, describe } from 'react-desc';
3
4
  import { aggregatedClasses } from '@elliemae/ds-classnames';
4
5
  import DSSeparator from '@elliemae/ds-separator';
5
6
  import styled from 'styled-components';
6
7
 
7
- var blockName = 'menu-separator';
8
- var Li = /*#__PURE__*/styled.li.withConfig({
8
+ var _DSSeparator;
9
+ const blockName = 'menu-separator';
10
+ const Li = /*#__PURE__*/styled.li.withConfig({
9
11
  componentId: "sc-aysbq3-0"
10
12
  })(["display:flex;align-items:flex-start;flex-direction:column;"]);
11
- var Title = aggregatedClasses('h5')(blockName, 'title');
13
+ const Title = aggregatedClasses('h5')(blockName, 'title');
12
14
 
13
- var MenuSeparator = function MenuSeparator(_ref) {
14
- var title = _ref.title,
15
- _ref$showSeparator = _ref.showSeparator,
16
- showSeparator = _ref$showSeparator === void 0 ? true : _ref$showSeparator;
17
- return /*#__PURE__*/React.createElement(Li, null, showSeparator && /*#__PURE__*/React.createElement(DSSeparator, null), title && /*#__PURE__*/React.createElement(Title, null, title));
18
- };
15
+ const MenuSeparator = ({
16
+ title,
17
+ showSeparator = true
18
+ }) => /*#__PURE__*/_jsx(Li, {}, void 0, showSeparator && (_DSSeparator || (_DSSeparator = /*#__PURE__*/_jsx(DSSeparator, {}))), title && /*#__PURE__*/_jsx(Title, {}, void 0, title));
19
19
 
20
- var props = {
20
+ const props = {
21
21
  /** menu separator h5 title */
22
22
  title: PropTypes.string.description('menu separator h5 title'),
23
23
 
24
24
  /** toggle separator on and off */
25
25
  showSeparator: PropTypes.bool.description('toggle separator on and off')
26
26
  };
27
- MenuSeparator.propTypes = props;
28
- var DSMenuSeparatorWithSchema = describe(MenuSeparator);
27
+ const DSMenuSeparatorWithSchema = describe(MenuSeparator);
29
28
  DSMenuSeparatorWithSchema.propTypes = props;
30
29
 
31
30
  export { DSMenuSeparatorWithSchema, MenuSeparator as default };
32
- //# sourceMappingURL=Separator.js.map
@@ -1,31 +1,186 @@
1
- import '@babel/runtime/helpers/esm/extends';
2
- import '@babel/runtime/helpers/esm/slicedToArray';
3
- import 'react';
4
- import 'react-desc';
5
- import '@elliemae/ds-icons';
6
- import '@elliemae/ds-shared/FocusGroup';
7
- import '@elliemae/ds-hidden';
8
- import '@elliemae/ds-button';
9
- import '@elliemae/ds-popper';
10
- import 'styled-components';
11
- export { a as DSSubMenuWithSchema, j as default } from '../SubMenu-a25e69ec.js';
12
- import '@babel/runtime/helpers/esm/objectWithoutProperties';
13
- import '@babel/runtime/helpers/esm/defineProperty';
14
- import 'lodash';
15
- import '@elliemae/ds-classnames';
16
- import 'react-spring/web.cjs';
17
- import '@elliemae/ds-utilities';
18
- import '@elliemae/ds-truncated-tooltip-text';
19
- import './Separator.js';
20
- import '@elliemae/ds-separator';
21
- import '@elliemae/ds-shared/CheckableGroup';
22
- import './SearchableGroup.js';
23
- import '@elliemae/ds-form/SearchBox';
24
- import '../VirtualMenuList.js';
25
- import 'react-window';
26
- import '../utils/useHeightByAmountOfItems.js';
27
- import '../MenuContext.js';
28
- import '@elliemae/ds-form';
29
- import './CheckboxGroup.js';
30
- import './RadioGroup.js';
31
- //# sourceMappingURL=SubMenu.js.map
1
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
3
+ import 'core-js/modules/web.dom-collections.iterator.js';
4
+ import { useRef, useState, useCallback } from 'react';
5
+ import { PropTypes, describe } from 'react-desc';
6
+ import ChevronRight from '@elliemae/ds-icons/ChevronSmallRight';
7
+ import VerticalElipsis from '@elliemae/ds-icons/MoreOptionsVert';
8
+ import { useFocusGroupItem } from '@elliemae/ds-shared/FocusGroup';
9
+ import { useHiddenController } from '@elliemae/ds-hidden';
10
+ import DSButton, { BUTTON_VARIANT } from '@elliemae/ds-button';
11
+ import DSPopper from '@elliemae/ds-popper';
12
+ import { interactions } from '@elliemae/ds-popper/interaction';
13
+ import styled from 'styled-components';
14
+ import { Menu } from '../Menu.js';
15
+ import MenuItem from './MenuItem.js';
16
+ import { jsx, Fragment } from 'react/jsx-runtime';
17
+
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
+ const ChevronRightComp = /*#__PURE__*/styled.div.withConfig({
22
+ componentId: "sc-1qhp1z-0"
23
+ })(["display:flex;justify-content:center;align-items:center;width:28px;"]);
24
+
25
+ function SubMenu({
26
+ noAddon,
27
+ leftAddon = undefined,
28
+ label = undefined,
29
+ interactionType = 'hover',
30
+ children: subitems,
31
+ rightAddonType,
32
+ disabledAddonInactive,
33
+ checkableProps = {},
34
+ customRenderer,
35
+ onClick,
36
+ closeMenu,
37
+ id
38
+ }) {
39
+ const itemRef = useRef(null);
40
+ const focusOnOpen = useRef(false);
41
+ const [isAddonHovered, setIsAddonHovered] = useState(false);
42
+ const {
43
+ visible = false,
44
+ onShow,
45
+ onHide
46
+ } = useHiddenController(undefined, {
47
+ interaction: 'click'
48
+ });
49
+ const interaction = rightAddonType === 'elipsis' ? 'click' : 'hover';
50
+ const {
51
+ focusItemByNode
52
+ } = useFocusGroupItem(); // todo: create a menu state to handle all related menu things
53
+
54
+ const handleShowSubItemsWithMouse = e => {
55
+ e.stopPropagation();
56
+ onShow();
57
+ focusOnOpen.current = true;
58
+ };
59
+
60
+ const handleShowWithMouse = e => {
61
+ if (onClick) onClick(e);
62
+ };
63
+
64
+ const handleShowWithMouseHover = () => {
65
+ setIsAddonHovered(true);
66
+ onShow();
67
+ focusOnOpen.current = false;
68
+ };
69
+
70
+ const handleShowWithKeyboard = () => {
71
+ onShow();
72
+ focusOnOpen.current = true;
73
+ };
74
+
75
+ const handleOnMouseEnter = useCallback(() => {
76
+ setIsAddonHovered(true);
77
+ }, []);
78
+ const handleOnMouseLeave = useCallback(() => {
79
+ setIsAddonHovered(false);
80
+ }, []);
81
+ const hoverHandlers = interaction === 'hover' ? {
82
+ onMouseEnter: handleShowWithMouseHover,
83
+ onMouseLeave: () => {
84
+ onHide();
85
+ setIsAddonHovered(false);
86
+ }
87
+ } : {
88
+ onClick: handleShowWithMouse
89
+ };
90
+ const rightAddon = rightAddonType === 'elipsis' ? /*#__PURE__*/_jsx(DSButton, {
91
+ "aria-label": "vertical-elipsis",
92
+ "data-testid": "vertical-elipsis",
93
+ buttonType: "text",
94
+ leftIcon: /*#__PURE__*/_jsx(VerticalElipsis, {
95
+ className: "submenu-arrow",
96
+ color: visible || isAddonHovered ? ['brand-primary', 800] : ['neutral', 500],
97
+ size: "s"
98
+ }),
99
+ onClick: e => handleShowSubItemsWithMouse(e),
100
+ size: "m",
101
+ variant: BUTTON_VARIANT.DEFAULT
102
+ }) : /*#__PURE__*/_jsx(ChevronRightComp, {}, void 0, /*#__PURE__*/_jsx(ChevronRight, {
103
+ "data-testid": "chevron-right",
104
+ className: "submenu-arrow",
105
+ color: visible || isAddonHovered ? ['brand-primary', 800] : ['neutral', 500],
106
+ size: "sm"
107
+ }));
108
+ return /*#__PURE__*/jsx(Fragment, {
109
+ children: /*#__PURE__*/_jsx(DSPopper, {
110
+ contentComponent: /*#__PURE__*/jsx(Menu, _objectSpread(_objectSpread({
111
+ focusKeyBindings: {
112
+ ArrowLeft: [() => focusItemByNode(itemRef.current), 'exit']
113
+ },
114
+ focusOnOpen: focusOnOpen.current,
115
+ onExitFocusGroup: onHide
116
+ }, hoverHandlers), {}, {
117
+ closeMenu: closeMenu,
118
+ visible: visible,
119
+ children: subitems
120
+ })),
121
+ interactionType: interactionType,
122
+ isOpen: visible,
123
+ onOpen: opening => opening ? onShow() : onHide(),
124
+ placement: "right-start",
125
+ showArrow: false,
126
+ triggerComponent: /*#__PURE__*/jsx(MenuItem, _objectSpread(_objectSpread({
127
+ customRenderer: customRenderer,
128
+ disabledAddonInactive: disabledAddonInactive,
129
+ id: id,
130
+ innerRef: itemRef,
131
+ label: label,
132
+ leftAddon: leftAddon,
133
+ noAddon: noAddon,
134
+ onFocus: handleOnMouseEnter,
135
+ onBlur: handleOnMouseLeave,
136
+ onMouseEnter: handleOnMouseEnter,
137
+ onMouseLeave: handleOnMouseLeave
138
+ }, hoverHandlers), {}, {
139
+ onKeyDown: e => {
140
+ if (e.key === 'ArrowRight' || e.key === 'Enter' || e.keyCode === 32) {
141
+ handleShowWithKeyboard();
142
+ }
143
+ },
144
+ rightAddon: rightAddon
145
+ }, checkableProps))
146
+ })
147
+ });
148
+ }
149
+
150
+ const props = {
151
+ /** dont show addon for submenu */
152
+ noAddon: PropTypes.bool.description('dont show addon for submenu'),
153
+
154
+ /** left addon */
155
+ leftAddon: PropTypes.node.description('left addon'),
156
+
157
+ /** submenu label */
158
+ label: PropTypes.string.description('submenu label'),
159
+
160
+ /** A type indicating how to open/close the tooltip */
161
+ interactionType: PropTypes.oneOf(interactions).description('A type indicating how to open/close the tooltip'),
162
+
163
+ /** sub menu items */
164
+ children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]).description('sub menu items'),
165
+
166
+ /** right addon, ellipsis or undefined */
167
+ rightAddonType: PropTypes.oneOf(['ellipsis']).description('right addon, ellipsis or undefined'),
168
+ disabledAddonInactive: PropTypes.bool.description(''),
169
+
170
+ /** props passed to MenuItem component */
171
+ checkableProps: PropTypes.object.description('props passed to MenuItem component'),
172
+
173
+ /** custom renderer for menu item */
174
+ customRenderer: PropTypes.func.description('custom renderer for menu item'),
175
+
176
+ /** on click handler */
177
+ onClick: PropTypes.func.description('on click handler'),
178
+ closeMenu: PropTypes.any.description(''),
179
+
180
+ /** component id */
181
+ id: PropTypes.string.description('component id')
182
+ };
183
+ const DSSubMenuWithSchema = describe(SubMenu);
184
+ DSSubMenuWithSchema.propTypes = props;
185
+
186
+ export { DSSubMenuWithSchema, SubMenu as default };
@@ -1,31 +1,51 @@
1
- import '@babel/runtime/helpers/esm/extends';
2
- import 'react';
3
- import '@elliemae/ds-utilities';
4
- import './Separator.js';
5
- export { m as menuItemFactory, r as renderMenuItems } from '../SubMenu-a25e69ec.js';
6
- import 'react-desc';
7
- import '@elliemae/ds-classnames';
8
- import '@elliemae/ds-separator';
9
- import 'styled-components';
10
- import '@babel/runtime/helpers/esm/slicedToArray';
11
- import '@elliemae/ds-icons';
12
- import '@elliemae/ds-shared/FocusGroup';
13
- import '@elliemae/ds-hidden';
14
- import '@elliemae/ds-button';
15
- import '@elliemae/ds-popper';
16
- import '@babel/runtime/helpers/esm/objectWithoutProperties';
17
- import '@babel/runtime/helpers/esm/defineProperty';
18
- import 'lodash';
19
- import 'react-spring/web.cjs';
20
- import '@elliemae/ds-truncated-tooltip-text';
21
- import '@elliemae/ds-shared/CheckableGroup';
22
- import './SearchableGroup.js';
23
- import '@elliemae/ds-form/SearchBox';
24
- import '../VirtualMenuList.js';
25
- import 'react-window';
26
- import '../utils/useHeightByAmountOfItems.js';
27
- import '../MenuContext.js';
28
- import '@elliemae/ds-form';
29
- import './CheckboxGroup.js';
30
- import './RadioGroup.js';
31
- //# sourceMappingURL=menuItemFactory.js.map
1
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
+ import { createElement } from 'react';
3
+ import { isFunction } from '@elliemae/ds-utilities/utils';
4
+ import MenuSeparator from './Separator.js';
5
+ import MenuItem from './MenuItem.js';
6
+ import SubMenu from './SubMenu.js';
7
+ import SelectionGroup from './SelectionGroup.js';
8
+ import MenuItemCheckbox from './MenuItemCheckbox.js';
9
+ import MenuItemRadio from './MenuItemRadio.js';
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
14
+ const itemTypes = {
15
+ separator: MenuSeparator,
16
+ menuitem: MenuItem,
17
+ radio: MenuItemRadio,
18
+ checkbox: MenuItemCheckbox,
19
+ submenu: SubMenu,
20
+ 'selection-group': SelectionGroup
21
+ };
22
+ const fallback = {
23
+ SelectionGroup: 'selection-group'
24
+ };
25
+ function menuItemFactory(type = '', items, defaultItem = itemTypes.menuitem) {
26
+ const itemsObject = items || itemTypes;
27
+ const parsedType = fallback[type] || type.toLowerCase();
28
+ return itemsObject[parsedType] || defaultItem;
29
+ }
30
+ function renderMenuItems(options, factory = menuItemFactory) {
31
+ return options.map((option, index) => {
32
+ if (isFunction(option.renderer)) {
33
+ return option.renderer({
34
+ key: option.id,
35
+ item: option
36
+ });
37
+ }
38
+
39
+ const ItemComponent = factory(option.type);
40
+ const children = option.subItems && renderMenuItems(option.subItems, factory);
41
+ return /*#__PURE__*/createElement(ItemComponent, _objectSpread(_objectSpread({}, option), {}, {
42
+ key: option.id || index,
43
+ item: option,
44
+ onClick: null,
45
+ onMouseDown: option.onClick // onClick callback called in onMouseDown due to events order issue
46
+
47
+ }), children);
48
+ });
49
+ }
50
+
51
+ export { menuItemFactory, renderMenuItems };
@@ -1,38 +1,35 @@
1
- import React from 'react';
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'react';
2
3
  import { FixedSizeList } from 'react-window';
3
4
  import useHeightByAmountOfItems from './utils/useHeightByAmountOfItems.js';
4
5
 
5
- var MenuItem = function MenuItem(_ref) {
6
- var data = _ref.data,
7
- index = _ref.index,
8
- style = _ref.style;
9
- return /*#__PURE__*/React.createElement("div", {
10
- key: index,
11
- style: style
12
- }, data[index]);
13
- }; // eslint-disable-next-line no-unused-vars
6
+ const MenuItem = ({
7
+ data,
8
+ index,
9
+ style
10
+ }) => /*#__PURE__*/_jsx("div", {
11
+ style: style
12
+ }, index, data && data[index] ? data[index] : ''); // eslint-disable-next-line no-unused-vars
14
13
 
15
- function VirtualMenuList(_ref2) {
16
- var items = _ref2.items,
17
- _ref2$itemHeight = _ref2.itemHeight,
18
- itemHeight = _ref2$itemHeight === void 0 ? 32 : _ref2$itemHeight,
19
- _ref2$amountItemsInWi = _ref2.amountItemsInWindow,
20
- amountItemsInWindow = _ref2$amountItemsInWi === void 0 ? 5 : _ref2$amountItemsInWi,
21
- width = _ref2.width,
22
- height = _ref2.height;
23
- var computedListHeight = useHeightByAmountOfItems({
14
+ function VirtualMenuList({
15
+ items,
16
+ itemHeight = 32,
17
+ amountItemsInWindow = 5,
18
+ width,
19
+ height
20
+ }) {
21
+ const computedListHeight = useHeightByAmountOfItems({
24
22
  amountItems: amountItemsInWindow,
25
- itemHeight: itemHeight,
26
- items: items
23
+ itemHeight,
24
+ items
27
25
  });
28
- return /*#__PURE__*/React.createElement(FixedSizeList, {
26
+ return /*#__PURE__*/_jsx(FixedSizeList, {
29
27
  height: height || computedListHeight,
30
28
  itemCount: items.length,
31
29
  itemData: items,
32
30
  itemSize: itemHeight,
33
31
  width: width
34
- }, MenuItem);
32
+ }, void 0, MenuItem);
35
33
  }
36
34
 
37
35
  export { VirtualMenuList as default };
38
- //# sourceMappingURL=VirtualMenuList.js.map