@elliemae/ds-menu 2.2.2-rc.1 → 2.3.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Menu.js +151 -0
- package/dist/cjs/Menu.js.map +7 -0
- package/dist/cjs/MenuCombobox.js +70 -0
- package/dist/cjs/MenuCombobox.js.map +7 -0
- package/dist/cjs/MenuContext.js +38 -0
- package/dist/cjs/MenuContext.js.map +7 -0
- package/dist/cjs/MenuExports.js +36 -0
- package/dist/cjs/MenuExports.js.map +7 -0
- package/dist/cjs/MenuItems/CheckboxGroup.js +52 -0
- package/dist/cjs/MenuItems/CheckboxGroup.js.map +7 -0
- package/dist/cjs/MenuItems/MenuItem.js +157 -0
- package/dist/cjs/MenuItems/MenuItem.js.map +7 -0
- package/dist/cjs/MenuItems/MenuItemCheckable.js +88 -0
- package/dist/cjs/MenuItems/MenuItemCheckable.js.map +7 -0
- package/dist/cjs/MenuItems/MenuItemCheckbox.js +48 -0
- package/dist/cjs/MenuItems/MenuItemCheckbox.js.map +7 -0
- package/dist/cjs/MenuItems/MenuItemRadio.js +53 -0
- package/dist/cjs/MenuItems/MenuItemRadio.js.map +7 -0
- package/dist/cjs/MenuItems/RadioGroup.js +51 -0
- package/dist/cjs/MenuItems/RadioGroup.js.map +7 -0
- package/dist/cjs/MenuItems/SearchableGroup.js +97 -0
- package/dist/cjs/MenuItems/SearchableGroup.js.map +7 -0
- package/dist/cjs/MenuItems/SearchableList.js +114 -0
- package/dist/cjs/MenuItems/SearchableList.js.map +7 -0
- package/dist/cjs/MenuItems/SelectionGroup.js +102 -0
- package/dist/cjs/MenuItems/SelectionGroup.js.map +7 -0
- package/dist/cjs/MenuItems/Separator.js +59 -0
- package/dist/cjs/MenuItems/Separator.js.map +7 -0
- package/dist/cjs/MenuItems/SubMenu.js +187 -0
- package/dist/cjs/MenuItems/SubMenu.js.map +7 -0
- package/dist/cjs/MenuItems/menuItemFactory.js +41 -0
- package/dist/cjs/MenuItems/menuItemFactory.js.map +7 -0
- package/dist/cjs/MenuItems/renderMenuItems.js +54 -0
- package/dist/cjs/MenuItems/renderMenuItems.js.map +7 -0
- package/dist/cjs/VirtualMenuList.js +78 -0
- package/dist/cjs/VirtualMenuList.js.map +7 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/utils/useHeightByAmountOfItems.js +49 -0
- package/dist/cjs/utils/useHeightByAmountOfItems.js.map +7 -0
- package/dist/esm/Menu.js +122 -0
- package/dist/esm/Menu.js.map +7 -0
- package/dist/esm/MenuCombobox.js +41 -0
- package/dist/esm/MenuCombobox.js.map +7 -0
- package/dist/esm/MenuContext.js +9 -0
- package/dist/esm/MenuContext.js.map +7 -0
- package/dist/esm/MenuExports.js +7 -0
- package/dist/esm/MenuExports.js.map +7 -0
- package/dist/esm/MenuItems/CheckboxGroup.js +23 -0
- package/dist/esm/MenuItems/CheckboxGroup.js.map +7 -0
- package/dist/esm/MenuItems/MenuItem.js +128 -0
- package/dist/esm/MenuItems/MenuItem.js.map +7 -0
- package/dist/esm/MenuItems/MenuItemCheckable.js +59 -0
- package/dist/esm/MenuItems/MenuItemCheckable.js.map +7 -0
- package/dist/esm/MenuItems/MenuItemCheckbox.js +19 -0
- package/dist/esm/MenuItems/MenuItemCheckbox.js.map +7 -0
- package/dist/esm/MenuItems/MenuItemRadio.js +24 -0
- package/dist/esm/MenuItems/MenuItemRadio.js.map +7 -0
- package/dist/esm/MenuItems/RadioGroup.js +22 -0
- package/dist/esm/MenuItems/RadioGroup.js.map +7 -0
- package/dist/esm/MenuItems/SearchableGroup.js +68 -0
- package/dist/esm/MenuItems/SearchableGroup.js.map +7 -0
- package/dist/esm/MenuItems/SearchableList.js +85 -0
- package/dist/esm/MenuItems/SearchableList.js.map +7 -0
- package/dist/esm/MenuItems/SelectionGroup.js +73 -0
- package/dist/esm/MenuItems/SelectionGroup.js.map +7 -0
- package/dist/esm/MenuItems/Separator.js +30 -0
- package/dist/esm/MenuItems/Separator.js.map +7 -0
- package/dist/esm/MenuItems/SubMenu.js +158 -0
- package/dist/esm/MenuItems/SubMenu.js.map +7 -0
- package/dist/esm/MenuItems/menuItemFactory.js +12 -0
- package/dist/esm/MenuItems/menuItemFactory.js.map +7 -0
- package/dist/esm/MenuItems/renderMenuItems.js +25 -0
- package/dist/esm/MenuItems/renderMenuItems.js.map +7 -0
- package/dist/esm/VirtualMenuList.js +49 -0
- package/dist/esm/VirtualMenuList.js.map +7 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/index.js.map +7 -0
- package/{esm → dist/esm}/utils/useHeightByAmountOfItems.js +13 -11
- package/dist/esm/utils/useHeightByAmountOfItems.js.map +7 -0
- package/{types → dist/types}/Menu.d.ts +4 -2
- package/{types → dist/types}/MenuCombobox.d.ts +0 -0
- package/dist/types/MenuContext.d.ts +4 -0
- package/dist/types/MenuExports.d.ts +1 -0
- package/{types → dist/types}/MenuItems/CheckboxGroup.d.ts +5 -5
- package/{types → dist/types}/MenuItems/MenuItem.d.ts +5 -5
- package/{types → dist/types}/MenuItems/MenuItemCheckable.d.ts +15 -14
- package/{types → dist/types}/MenuItems/MenuItemCheckbox.d.ts +3 -2
- package/{types → dist/types}/MenuItems/MenuItemRadio.d.ts +5 -5
- package/{types → dist/types}/MenuItems/RadioGroup.d.ts +5 -5
- package/{types → dist/types}/MenuItems/SearchableGroup.d.ts +3 -3
- package/{types → dist/types}/MenuItems/SearchableList.d.ts +16 -16
- package/{types → dist/types}/MenuItems/SelectionGroup.d.ts +16 -16
- package/{types → dist/types}/MenuItems/Separator.d.ts +2 -1
- package/{types → dist/types}/MenuItems/SubMenu.d.ts +18 -18
- package/dist/types/MenuItems/menuItemFactory.d.ts +2 -0
- package/dist/types/MenuItems/renderMenuItems.d.ts +1 -0
- package/{types → dist/types}/VirtualMenuList.d.ts +3 -1
- package/{types → dist/types}/index.d.ts +3 -2
- package/{types → dist/types}/tests/Menu.test.d.ts +0 -0
- package/{types → dist/types}/tests/MenuItem.test.d.ts +0 -0
- package/dist/types/utils/useHeightByAmountOfItems.d.ts +7 -0
- package/package.json +72 -62
- package/cjs/Menu.js +0 -195
- package/cjs/MenuCombobox.js +0 -56
- package/cjs/MenuContext.js +0 -11
- package/cjs/MenuItems/CheckboxGroup.js +0 -45
- package/cjs/MenuItems/MenuItem.js +0 -203
- package/cjs/MenuItems/MenuItemCheckable.js +0 -119
- package/cjs/MenuItems/MenuItemCheckbox.js +0 -42
- package/cjs/MenuItems/MenuItemRadio.js +0 -41
- package/cjs/MenuItems/RadioGroup.js +0 -42
- package/cjs/MenuItems/SearchableGroup.js +0 -101
- package/cjs/MenuItems/SearchableList.js +0 -117
- package/cjs/MenuItems/SelectionGroup.js +0 -107
- package/cjs/MenuItems/Separator.js +0 -44
- package/cjs/MenuItems/SubMenu.js +0 -203
- package/cjs/MenuItems/menuItemFactory.js +0 -73
- package/cjs/VirtualMenuList.js +0 -48
- package/cjs/index.js +0 -36
- package/cjs/utils/useHeightByAmountOfItems.js +0 -20
- package/esm/Menu.js +0 -180
- package/esm/MenuCombobox.js +0 -48
- package/esm/MenuContext.js +0 -5
- package/esm/MenuItems/CheckboxGroup.js +0 -35
- package/esm/MenuItems/MenuItem.js +0 -191
- package/esm/MenuItems/MenuItemCheckable.js +0 -108
- package/esm/MenuItems/MenuItemCheckbox.js +0 -34
- package/esm/MenuItems/MenuItemRadio.js +0 -32
- package/esm/MenuItems/RadioGroup.js +0 -32
- package/esm/MenuItems/SearchableGroup.js +0 -91
- package/esm/MenuItems/SearchableList.js +0 -108
- package/esm/MenuItems/SelectionGroup.js +0 -97
- package/esm/MenuItems/Separator.js +0 -33
- package/esm/MenuItems/SubMenu.js +0 -190
- package/esm/MenuItems/menuItemFactory.js +0 -64
- package/esm/VirtualMenuList.js +0 -42
- package/esm/index.js +0 -13
- package/types/MenuContext.d.ts +0 -3
- package/types/MenuItems/menuItemFactory.d.ts +0 -3
- package/types/utils/useHeightByAmountOfItems.d.ts +0 -5
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useEffect, useMemo, useState, useRef, useContext } from "react";
|
|
3
|
+
import { aggregatedClasses } from "@elliemae/ds-classnames";
|
|
4
|
+
import { focusGroupManagerHoc } from "@elliemae/ds-shared/FocusGroup";
|
|
5
|
+
import { DSSearchBox } from "@elliemae/ds-form/SearchBox";
|
|
6
|
+
import { PropTypes, describe } from "react-desc";
|
|
7
|
+
import { VirtualMenuList } from "../VirtualMenuList";
|
|
8
|
+
import { MenuContext } from "../MenuContext";
|
|
9
|
+
const SearchBoxWrapper = aggregatedClasses("div")("menu-search-group", "search-wrapper");
|
|
10
|
+
const NoOptionsWrapper = aggregatedClasses("div")("menu-search-group", "no-options");
|
|
11
|
+
const SearchableGroup = ({
|
|
12
|
+
children,
|
|
13
|
+
amountItemsInWindow = 5,
|
|
14
|
+
searchTerm: searchTermProp = "",
|
|
15
|
+
noOptionsText = "No options",
|
|
16
|
+
height,
|
|
17
|
+
width,
|
|
18
|
+
focusOnOpen = false
|
|
19
|
+
}) => {
|
|
20
|
+
const searchRef = useRef(null);
|
|
21
|
+
const [searchTerm, setSearchTerm] = useState(searchTermProp);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (searchRef.current)
|
|
24
|
+
searchRef.current.focus();
|
|
25
|
+
}, []);
|
|
26
|
+
const { visible } = useContext(MenuContext) || {};
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (focusOnOpen && visible) {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
if (searchRef.current)
|
|
31
|
+
searchRef.current.focus();
|
|
32
|
+
}, 0);
|
|
33
|
+
}
|
|
34
|
+
}, [focusOnOpen, visible]);
|
|
35
|
+
const filteredChildren = useMemo(() => children.filter((child) => !searchTerm || child.props.label.toLowerCase().startsWith(searchTerm.toLowerCase())), [children, searchTerm]);
|
|
36
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(SearchBoxWrapper, null, /* @__PURE__ */ React2.createElement(DSSearchBox, {
|
|
37
|
+
innerRef: searchRef,
|
|
38
|
+
onSearch: ({ value }) => setSearchTerm(value),
|
|
39
|
+
searchOnEnter: false,
|
|
40
|
+
showIcon: false,
|
|
41
|
+
value: searchTerm
|
|
42
|
+
})), !filteredChildren.length && /* @__PURE__ */ React2.createElement(NoOptionsWrapper, null, noOptionsText), /* @__PURE__ */ React2.createElement(VirtualMenuList, {
|
|
43
|
+
amountItemsInWindow,
|
|
44
|
+
height,
|
|
45
|
+
items: filteredChildren,
|
|
46
|
+
width
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
const props = {
|
|
50
|
+
amountItemsInWindow: PropTypes.number.description("The amount of items that are going to be rendered in the group"),
|
|
51
|
+
searchTerm: PropTypes.string.description("A search term"),
|
|
52
|
+
noOptionsText: PropTypes.string.description("Text to show when there's no options to show"),
|
|
53
|
+
children: PropTypes.array.description("array of children for search list"),
|
|
54
|
+
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description("height for virtual list wrapper"),
|
|
55
|
+
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description("width for virtual list wrapper"),
|
|
56
|
+
focusOnOpen: PropTypes.bool.description("weather to focus on searchable group on open")
|
|
57
|
+
};
|
|
58
|
+
SearchableGroup.propTypes = props;
|
|
59
|
+
const DSMenuSearchableGroupWithSchema = describe(SearchableGroup);
|
|
60
|
+
DSMenuSearchableGroupWithSchema.propTypes = props;
|
|
61
|
+
const SearchableGroupHOC = focusGroupManagerHoc(SearchableGroup);
|
|
62
|
+
var SearchableGroup_default = SearchableGroupHOC;
|
|
63
|
+
export {
|
|
64
|
+
DSMenuSearchableGroupWithSchema,
|
|
65
|
+
SearchableGroupHOC as SearchableGroup,
|
|
66
|
+
SearchableGroup_default as default
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=SearchableGroup.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/SearchableGroup.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useEffect, useMemo, useState, useRef, useContext } from 'react';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { focusGroupManagerHoc } from '@elliemae/ds-shared/FocusGroup';\nimport { DSSearchBox } from '@elliemae/ds-form/SearchBox';\nimport { PropTypes, describe } from 'react-desc';\nimport { VirtualMenuList } from '../VirtualMenuList';\nimport { MenuContext } from '../MenuContext';\n\nconst SearchBoxWrapper = aggregatedClasses('div')(\n 'menu-search-group',\n 'search-wrapper',\n);\nconst NoOptionsWrapper = aggregatedClasses('div')(\n 'menu-search-group',\n 'no-options',\n);\n\nconst SearchableGroup = ({\n children,\n amountItemsInWindow = 5,\n searchTerm: searchTermProp = '',\n noOptionsText = 'No options',\n height,\n width,\n focusOnOpen = false,\n}) => {\n const searchRef = useRef(null);\n const [searchTerm, setSearchTerm] = useState(searchTermProp);\n\n useEffect(() => {\n if (searchRef.current) searchRef.current.focus();\n }, []);\n\n const { visible } = useContext(MenuContext) || {};\n\n useEffect(() => {\n if (focusOnOpen && visible) {\n setTimeout(() => {\n if (searchRef.current) searchRef.current.focus();\n }, 0);\n }\n }, [focusOnOpen, visible]);\n\n const filteredChildren = useMemo(\n () =>\n children.filter(\n (child) =>\n !searchTerm ||\n child.props.label.toLowerCase().startsWith(searchTerm.toLowerCase()),\n ),\n [children, searchTerm],\n );\n\n return (\n <>\n <SearchBoxWrapper>\n <DSSearchBox\n innerRef={searchRef}\n onSearch={({ value }) => setSearchTerm(value)}\n searchOnEnter={false}\n showIcon={false}\n value={searchTerm}\n />\n </SearchBoxWrapper>\n {!filteredChildren.length && (\n <NoOptionsWrapper>{noOptionsText}</NoOptionsWrapper>\n )}\n <VirtualMenuList\n amountItemsInWindow={amountItemsInWindow}\n height={height}\n items={filteredChildren}\n width={width}\n />\n </>\n );\n};\n\nconst props = {\n /** The amount of items that are going to be rendered in the group */\n amountItemsInWindow: PropTypes.number.description(\n 'The amount of items that are going to be rendered in the group',\n ),\n /** A search term */\n searchTerm: PropTypes.string.description('A search term'),\n /** Text to show when there's no options to show */\n noOptionsText: PropTypes.string.description(\n \"Text to show when there's no options to show\",\n ),\n /** array of children for search list */\n children: PropTypes.array.description('array of children for search list'),\n /** height for virtual list wrapper */\n height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description(\n 'height for virtual list wrapper',\n ),\n /** width for virtual list wrapper */\n width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description(\n 'width for virtual list wrapper',\n ),\n /** weather to focus on searchable group on open */\n focusOnOpen: PropTypes.bool.description(\n 'weather to focus on searchable group on open',\n ),\n};\n\nSearchableGroup.propTypes = props;\n\nconst DSMenuSearchableGroupWithSchema = describe(SearchableGroup);\nDSMenuSearchableGroupWithSchema.propTypes = props;\n\nconst SearchableGroupHOC = focusGroupManagerHoc(SearchableGroup);\n\nexport { DSMenuSearchableGroupWithSchema, SearchableGroupHOC as SearchableGroup };\nexport default SearchableGroupHOC;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,mBAAmB,kBAAkB,OACzC,qBACA;AAEF,MAAM,mBAAmB,kBAAkB,OACzC,qBACA;AAGF,MAAM,kBAAkB,CAAC;AAAA,EACvB;AAAA,EACA,sBAAsB;AAAA,EACtB,YAAY,iBAAiB;AAAA,EAC7B,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,MACV;AACJ,QAAM,YAAY,OAAO;AACzB,QAAM,CAAC,YAAY,iBAAiB,SAAS;AAE7C,YAAU,MAAM;AACd,QAAI,UAAU;AAAS,gBAAU,QAAQ;AAAA,KACxC;AAEH,QAAM,EAAE,YAAY,WAAW,gBAAgB;AAE/C,YAAU,MAAM;AACd,QAAI,eAAe,SAAS;AAC1B,iBAAW,MAAM;AACf,YAAI,UAAU;AAAS,oBAAU,QAAQ;AAAA,SACxC;AAAA;AAAA,KAEJ,CAAC,aAAa;AAEjB,QAAM,mBAAmB,QACvB,MACE,SAAS,OACP,CAAC,UACC,CAAC,cACD,MAAM,MAAM,MAAM,cAAc,WAAW,WAAW,iBAE5D,CAAC,UAAU;AAGb,SACE,4DACE,qCAAC,kBAAD,MACE,qCAAC,aAAD;AAAA,IACE,UAAU;AAAA,IACV,UAAU,CAAC,EAAE,YAAY,cAAc;AAAA,IACvC,eAAe;AAAA,IACf,UAAU;AAAA,IACV,OAAO;AAAA,OAGV,CAAC,iBAAiB,UACjB,qCAAC,kBAAD,MAAmB,gBAErB,qCAAC,iBAAD;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA;AAAA;AAMR,MAAM,QAAQ;AAAA,EAEZ,qBAAqB,UAAU,OAAO,YACpC;AAAA,EAGF,YAAY,UAAU,OAAO,YAAY;AAAA,EAEzC,eAAe,UAAU,OAAO,YAC9B;AAAA,EAGF,UAAU,UAAU,MAAM,YAAY;AAAA,EAEtC,QAAQ,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,SAAS,YAChE;AAAA,EAGF,OAAO,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,SAAS,YAC/D;AAAA,EAGF,aAAa,UAAU,KAAK,YAC1B;AAAA;AAIJ,gBAAgB,YAAY;AAE5B,MAAM,kCAAkC,SAAS;AACjD,gCAAgC,YAAY;AAE5C,MAAM,qBAAqB,qBAAqB;AAGhD,IAAO,0BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import { PropTypes, describe } from "react-desc";
|
|
4
|
+
import { uniqBy } from "@elliemae/ds-utilities";
|
|
5
|
+
import { DSComboBox2 as DSComboBox } from "@elliemae/ds-form/ComboBox/v2/Combobox";
|
|
6
|
+
const noop = () => {
|
|
7
|
+
};
|
|
8
|
+
const SearchableList = ({
|
|
9
|
+
onSelectMenuItem = noop,
|
|
10
|
+
components = {},
|
|
11
|
+
searchTerm: searchTermProp = "",
|
|
12
|
+
items = [],
|
|
13
|
+
dropdownFilterOptions = {},
|
|
14
|
+
returnValue,
|
|
15
|
+
extraListProps = {},
|
|
16
|
+
appendTermInList = false,
|
|
17
|
+
maxOptions = 10,
|
|
18
|
+
loading = false
|
|
19
|
+
}) => {
|
|
20
|
+
const [searchTerm, setInputValue] = useState(searchTermProp);
|
|
21
|
+
const handleInputChange = useCallback((value, args) => {
|
|
22
|
+
const action = args ? args.action : null;
|
|
23
|
+
if (action === "input-blur" || action === "menu-close")
|
|
24
|
+
return;
|
|
25
|
+
setInputValue(value);
|
|
26
|
+
}, [searchTerm]);
|
|
27
|
+
const handleFilterByText = useCallback(() => {
|
|
28
|
+
if (searchTerm)
|
|
29
|
+
onSelectMenuItem(searchTerm);
|
|
30
|
+
}, [searchTerm]);
|
|
31
|
+
const handleKeyDown = useCallback((e) => {
|
|
32
|
+
if (e.key === "ArrowRight") {
|
|
33
|
+
handleFilterByText();
|
|
34
|
+
}
|
|
35
|
+
}, [searchTerm]);
|
|
36
|
+
const options = useMemo(() => searchTerm && appendTermInList ? uniqBy([
|
|
37
|
+
{
|
|
38
|
+
id: searchTerm,
|
|
39
|
+
label: searchTerm
|
|
40
|
+
}
|
|
41
|
+
].concat(items), (item) => item.label) : items, [searchTerm, appendTermInList]);
|
|
42
|
+
return /* @__PURE__ */ React2.createElement(DSComboBox, {
|
|
43
|
+
autoFocus: true,
|
|
44
|
+
components: { DropdownIndicator: null, ...components },
|
|
45
|
+
customMenuItemOptions: {
|
|
46
|
+
useTruncatedText: true
|
|
47
|
+
},
|
|
48
|
+
inlineMenu: true,
|
|
49
|
+
inputValue: searchTerm,
|
|
50
|
+
menuIsOpen: true,
|
|
51
|
+
onChange: onSelectMenuItem,
|
|
52
|
+
onFilterByInputText: handleFilterByText,
|
|
53
|
+
onInputChange: handleInputChange,
|
|
54
|
+
onKeyDown: handleKeyDown,
|
|
55
|
+
options,
|
|
56
|
+
returnValue,
|
|
57
|
+
valueProperty: "id",
|
|
58
|
+
maxOptions,
|
|
59
|
+
loading,
|
|
60
|
+
...extraListProps,
|
|
61
|
+
...dropdownFilterOptions
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const props = {
|
|
65
|
+
onSelectMenuItem: PropTypes.func.description("callback after item gets selected"),
|
|
66
|
+
components: PropTypes.shape({}).description("Object with custom components for react-select"),
|
|
67
|
+
searchTerm: PropTypes.string.description("search term to filter for"),
|
|
68
|
+
items: PropTypes.array.description("item options"),
|
|
69
|
+
dropdownFilterOptions: PropTypes.shape({}).description("options"),
|
|
70
|
+
returnValue: PropTypes.bool.description("Whether the combo box is has value to return or not"),
|
|
71
|
+
extraListProps: PropTypes.shape({}).description("extra props to pass down to combo"),
|
|
72
|
+
appendTermInList: PropTypes.bool.description("append search term as item on the list"),
|
|
73
|
+
maxOptions: PropTypes.number.description("maxoptions for combobox"),
|
|
74
|
+
loading: PropTypes.bool.description("loading flag")
|
|
75
|
+
};
|
|
76
|
+
SearchableList.propTypes = props;
|
|
77
|
+
const DSMenuSearchableListWithSchema = describe(SearchableList);
|
|
78
|
+
DSMenuSearchableListWithSchema.propTypes = props;
|
|
79
|
+
var SearchableList_default = SearchableList;
|
|
80
|
+
export {
|
|
81
|
+
DSMenuSearchableListWithSchema,
|
|
82
|
+
SearchableList,
|
|
83
|
+
SearchableList_default as default
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=SearchableList.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/SearchableList.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useCallback, useMemo, useState } from 'react';\nimport { PropTypes, describe } from 'react-desc';\nimport { uniqBy } from '@elliemae/ds-utilities';\nimport { DSComboBox2 as DSComboBox } from '@elliemae/ds-form/ComboBox/v2/Combobox';\n\nconst noop = () => {};\n\nconst SearchableList = ({\n onSelectMenuItem = noop,\n components = {},\n searchTerm: searchTermProp = '',\n items = [],\n dropdownFilterOptions = {},\n returnValue,\n extraListProps = {},\n appendTermInList = false,\n maxOptions = 10,\n loading = false,\n}) => {\n const [searchTerm, setInputValue] = useState(searchTermProp);\n\n const handleInputChange = useCallback(\n (value, args) => {\n const action = args ? args.action : null;\n if (action === 'input-blur' || action === 'menu-close') return;\n setInputValue(value);\n },\n [searchTerm],\n );\n\n const handleFilterByText = useCallback(() => {\n if (searchTerm) onSelectMenuItem(searchTerm);\n }, [searchTerm]);\n\n const handleKeyDown = useCallback(\n (e) => {\n if (e.key === 'ArrowRight') {\n handleFilterByText();\n }\n },\n [searchTerm],\n );\n\n const options = useMemo(\n () =>\n searchTerm && appendTermInList\n ? uniqBy(\n [\n {\n id: searchTerm,\n label: searchTerm,\n },\n ].concat(items),\n (item) => item.label,\n )\n : items,\n [searchTerm, appendTermInList],\n );\n\n return (\n <DSComboBox\n autoFocus\n components={{ DropdownIndicator: null, ...components }}\n customMenuItemOptions={{\n useTruncatedText: true,\n }}\n inlineMenu\n inputValue={searchTerm}\n menuIsOpen\n onChange={onSelectMenuItem}\n onFilterByInputText={handleFilterByText}\n onInputChange={handleInputChange}\n onKeyDown={handleKeyDown}\n options={options}\n returnValue={returnValue}\n valueProperty=\"id\"\n maxOptions={maxOptions}\n loading={loading}\n {...extraListProps}\n {...dropdownFilterOptions}\n />\n );\n};\n\nconst props = {\n /** callback after item gets selected */\n onSelectMenuItem: PropTypes.func.description('callback after item gets selected'),\n /** Object with custom components for react-select */\n components: PropTypes.shape({}).description('Object with custom components for react-select'),\n /** search term to filter for */\n searchTerm: PropTypes.string.description('search term to filter for'),\n /** item options */\n items: PropTypes.array.description('item options'),\n /** options */\n dropdownFilterOptions: PropTypes.shape({}).description('options'),\n /** Whether the combo box is has value to return or not */\n returnValue: PropTypes.bool.description('Whether the combo box is has value to return or not'),\n /** extra props to pass down to combo */\n extraListProps: PropTypes.shape({}).description('extra props to pass down to combo'),\n /** append search term as item on the list */\n appendTermInList: PropTypes.bool.description('append search term as item on the list'),\n /** maxoptions for combobox */\n maxOptions: PropTypes.number.description('maxoptions for combobox'),\n /** loading flag */\n loading: PropTypes.bool.description('loading flag'),\n};\n\nSearchableList.propTypes = props;\n\nconst DSMenuSearchableListWithSchema = describe(SearchableList);\n\nDSMenuSearchableListWithSchema.propTypes = props;\n\nexport { DSMenuSearchableListWithSchema, SearchableList };\nexport default SearchableList;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AAEA,MAAM,OAAO,MAAM;AAAA;AAEnB,MAAM,iBAAiB,CAAC;AAAA,EACtB,mBAAmB;AAAA,EACnB,aAAa;AAAA,EACb,YAAY,iBAAiB;AAAA,EAC7B,QAAQ;AAAA,EACR,wBAAwB;AAAA,EACxB;AAAA,EACA,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,aAAa;AAAA,EACb,UAAU;AAAA,MACN;AACJ,QAAM,CAAC,YAAY,iBAAiB,SAAS;AAE7C,QAAM,oBAAoB,YACxB,CAAC,OAAO,SAAS;AACf,UAAM,SAAS,OAAO,KAAK,SAAS;AACpC,QAAI,WAAW,gBAAgB,WAAW;AAAc;AACxD,kBAAc;AAAA,KAEhB,CAAC;AAGH,QAAM,qBAAqB,YAAY,MAAM;AAC3C,QAAI;AAAY,uBAAiB;AAAA,KAChC,CAAC;AAEJ,QAAM,gBAAgB,YACpB,CAAC,MAAM;AACL,QAAI,EAAE,QAAQ,cAAc;AAC1B;AAAA;AAAA,KAGJ,CAAC;AAGH,QAAM,UAAU,QACd,MACE,cAAc,mBACV,OACE;AAAA,IACE;AAAA,MACE,IAAI;AAAA,MACJ,OAAO;AAAA;AAAA,IAET,OAAO,QACT,CAAC,SAAS,KAAK,SAEjB,OACN,CAAC,YAAY;AAGf,SACE,qCAAC,YAAD;AAAA,IACE,WAAS;AAAA,IACT,YAAY,EAAE,mBAAmB,SAAS;AAAA,IAC1C,uBAAuB;AAAA,MACrB,kBAAkB;AAAA;AAAA,IAEpB,YAAU;AAAA,IACV,YAAY;AAAA,IACZ,YAAU;AAAA,IACV,UAAU;AAAA,IACV,qBAAqB;AAAA,IACrB,eAAe;AAAA,IACf,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,eAAc;AAAA,IACd;AAAA,IACA;AAAA,OACI;AAAA,OACA;AAAA;AAAA;AAKV,MAAM,QAAQ;AAAA,EAEZ,kBAAkB,UAAU,KAAK,YAAY;AAAA,EAE7C,YAAY,UAAU,MAAM,IAAI,YAAY;AAAA,EAE5C,YAAY,UAAU,OAAO,YAAY;AAAA,EAEzC,OAAO,UAAU,MAAM,YAAY;AAAA,EAEnC,uBAAuB,UAAU,MAAM,IAAI,YAAY;AAAA,EAEvD,aAAa,UAAU,KAAK,YAAY;AAAA,EAExC,gBAAgB,UAAU,MAAM,IAAI,YAAY;AAAA,EAEhD,kBAAkB,UAAU,KAAK,YAAY;AAAA,EAE7C,YAAY,UAAU,OAAO,YAAY;AAAA,EAEzC,SAAS,UAAU,KAAK,YAAY;AAAA;AAGtC,eAAe,YAAY;AAE3B,MAAM,iCAAiC,SAAS;AAEhD,+BAA+B,YAAY;AAG3C,IAAO,yBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useMemo } from "react";
|
|
3
|
+
import { PropTypes, describe } from "react-desc";
|
|
4
|
+
import { useCheckableGroup } from "@elliemae/ds-shared/CheckableGroup";
|
|
5
|
+
import { SearchableGroup } from "./SearchableGroup";
|
|
6
|
+
import { registerMenuItem, menuItemFactory } from "./menuItemFactory";
|
|
7
|
+
import { VirtualMenuList } from "../VirtualMenuList";
|
|
8
|
+
const noop = () => null;
|
|
9
|
+
const SelectionGroup = ({
|
|
10
|
+
multi = false,
|
|
11
|
+
searchable = false,
|
|
12
|
+
focusOnOpen = false,
|
|
13
|
+
onSelect = noop,
|
|
14
|
+
children,
|
|
15
|
+
items = void 0,
|
|
16
|
+
active = multi ? [] : "",
|
|
17
|
+
width,
|
|
18
|
+
height,
|
|
19
|
+
maxOptions = 5
|
|
20
|
+
}) => {
|
|
21
|
+
const renderedItems = useMemo(() => items && items.map((item) => {
|
|
22
|
+
const Component = menuItemFactory(multi ? "checkbox" : "radio");
|
|
23
|
+
return /* @__PURE__ */ React2.createElement(Component, {
|
|
24
|
+
...item,
|
|
25
|
+
key: item.name || item.id || item.key,
|
|
26
|
+
item,
|
|
27
|
+
name: item.id || item.name
|
|
28
|
+
});
|
|
29
|
+
}), [items]);
|
|
30
|
+
const decoratedGroupChildren = useCheckableGroup({
|
|
31
|
+
children: renderedItems || children,
|
|
32
|
+
multi,
|
|
33
|
+
active,
|
|
34
|
+
onCheck: onSelect
|
|
35
|
+
});
|
|
36
|
+
if (searchable) {
|
|
37
|
+
return /* @__PURE__ */ React2.createElement(SearchableGroup, {
|
|
38
|
+
focusOnOpen,
|
|
39
|
+
height,
|
|
40
|
+
items,
|
|
41
|
+
width
|
|
42
|
+
}, decoratedGroupChildren);
|
|
43
|
+
}
|
|
44
|
+
return /* @__PURE__ */ React2.createElement(VirtualMenuList, {
|
|
45
|
+
height,
|
|
46
|
+
items: decoratedGroupChildren,
|
|
47
|
+
width,
|
|
48
|
+
amountItemsInWindow: maxOptions
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const props = {
|
|
52
|
+
multi: PropTypes.bool.description("toggle on multi select"),
|
|
53
|
+
searchable: PropTypes.bool.description("toggle on searchable behavior"),
|
|
54
|
+
focusOnOpen: PropTypes.bool.description("toggle to focus component on open"),
|
|
55
|
+
onSelect: PropTypes.func.description("callback that triggers when select happens"),
|
|
56
|
+
children: PropTypes.node.description(""),
|
|
57
|
+
items: PropTypes.array.description("selection group items"),
|
|
58
|
+
active: PropTypes.oneOfType([PropTypes.string, PropTypes.array]).description("array of values for multi and string for single selection"),
|
|
59
|
+
width: PropTypes.number.description("selection group width"),
|
|
60
|
+
height: PropTypes.number.description("selection group height")
|
|
61
|
+
};
|
|
62
|
+
SelectionGroup.propTypes = props;
|
|
63
|
+
registerMenuItem("selectiongroup", SelectionGroup);
|
|
64
|
+
registerMenuItem("SelectionGroup", SelectionGroup);
|
|
65
|
+
const DSMenuSelectionGroupWithSchema = describe(SelectionGroup);
|
|
66
|
+
DSMenuSelectionGroupWithSchema.propTypes = props;
|
|
67
|
+
var SelectionGroup_default = SelectionGroup;
|
|
68
|
+
export {
|
|
69
|
+
DSMenuSelectionGroupWithSchema,
|
|
70
|
+
SelectionGroup,
|
|
71
|
+
SelectionGroup_default as default
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=SelectionGroup.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/SelectionGroup.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useMemo } from 'react';\nimport { PropTypes, describe } from 'react-desc';\nimport { useCheckableGroup } from '@elliemae/ds-shared/CheckableGroup';\nimport { SearchableGroup } from './SearchableGroup';\nimport { registerMenuItem, menuItemFactory } from './menuItemFactory';\nimport { VirtualMenuList } from '../VirtualMenuList';\n\nconst noop = () => null;\n\nconst SelectionGroup = ({\n multi = false,\n searchable = false,\n focusOnOpen = false,\n onSelect = noop,\n children,\n items = undefined,\n active = multi ? [] : '',\n width,\n height,\n maxOptions = 5,\n}) => {\n const renderedItems = useMemo(\n () =>\n items &&\n items.map((item) => {\n const Component = menuItemFactory(multi ? 'checkbox' : 'radio');\n return <Component {...item} key={item.name || item.id || item.key} item={item} name={item.id || item.name} />;\n }),\n [items],\n );\n const decoratedGroupChildren = useCheckableGroup({\n children: renderedItems || children,\n multi,\n active,\n onCheck: onSelect,\n });\n\n if (searchable) {\n return (\n <SearchableGroup focusOnOpen={focusOnOpen} height={height} items={items} width={width}>\n {decoratedGroupChildren}\n </SearchableGroup>\n );\n }\n return (\n <VirtualMenuList height={height} items={decoratedGroupChildren} width={width} amountItemsInWindow={maxOptions} />\n );\n};\n\nconst props = {\n /** toggle on multi select */\n multi: PropTypes.bool.description('toggle on multi select'),\n /** toggle on searchable behavior */\n searchable: PropTypes.bool.description('toggle on searchable behavior'),\n /** toggle to focus component on open */\n focusOnOpen: PropTypes.bool.description('toggle to focus component on open'),\n /** callback that triggers when select happens */\n onSelect: PropTypes.func.description('callback that triggers when select happens'),\n children: PropTypes.node.description(''),\n /** selection group items */\n items: PropTypes.array.description('selection group items'),\n /** array of values for multi and string for single selection */\n active: PropTypes.oneOfType([PropTypes.string, PropTypes.array]).description(\n 'array of values for multi and string for single selection',\n ),\n /** selection group width */\n width: PropTypes.number.description('selection group width'),\n /** selection group height */\n height: PropTypes.number.description('selection group height'),\n};\n\nSelectionGroup.propTypes = props;\nregisterMenuItem('selectiongroup', SelectionGroup);\nregisterMenuItem('SelectionGroup', SelectionGroup);\n\nconst DSMenuSelectionGroupWithSchema = describe(SelectionGroup);\nDSMenuSelectionGroupWithSchema.propTypes = props;\n\nexport { DSMenuSelectionGroupWithSchema, SelectionGroup };\nexport default SelectionGroup;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,OAAO,MAAM;AAEnB,MAAM,iBAAiB,CAAC;AAAA,EACtB,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX;AAAA,EACA,QAAQ;AAAA,EACR,SAAS,QAAQ,KAAK;AAAA,EACtB;AAAA,EACA;AAAA,EACA,aAAa;AAAA,MACT;AACJ,QAAM,gBAAgB,QACpB,MACE,SACA,MAAM,IAAI,CAAC,SAAS;AAClB,UAAM,YAAY,gBAAgB,QAAQ,aAAa;AACvD,WAAO,qCAAC,WAAD;AAAA,SAAe;AAAA,MAAM,KAAK,KAAK,QAAQ,KAAK,MAAM,KAAK;AAAA,MAAK;AAAA,MAAY,MAAM,KAAK,MAAM,KAAK;AAAA;AAAA,MAEzG,CAAC;AAEH,QAAM,yBAAyB,kBAAkB;AAAA,IAC/C,UAAU,iBAAiB;AAAA,IAC3B;AAAA,IACA;AAAA,IACA,SAAS;AAAA;AAGX,MAAI,YAAY;AACd,WACE,qCAAC,iBAAD;AAAA,MAAiB;AAAA,MAA0B;AAAA,MAAgB;AAAA,MAAc;AAAA,OACtE;AAAA;AAIP,SACE,qCAAC,iBAAD;AAAA,IAAiB;AAAA,IAAgB,OAAO;AAAA,IAAwB;AAAA,IAAc,qBAAqB;AAAA;AAAA;AAIvG,MAAM,QAAQ;AAAA,EAEZ,OAAO,UAAU,KAAK,YAAY;AAAA,EAElC,YAAY,UAAU,KAAK,YAAY;AAAA,EAEvC,aAAa,UAAU,KAAK,YAAY;AAAA,EAExC,UAAU,UAAU,KAAK,YAAY;AAAA,EACrC,UAAU,UAAU,KAAK,YAAY;AAAA,EAErC,OAAO,UAAU,MAAM,YAAY;AAAA,EAEnC,QAAQ,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,QAAQ,YAC/D;AAAA,EAGF,OAAO,UAAU,OAAO,YAAY;AAAA,EAEpC,QAAQ,UAAU,OAAO,YAAY;AAAA;AAGvC,eAAe,YAAY;AAC3B,iBAAiB,kBAAkB;AACnC,iBAAiB,kBAAkB;AAEnC,MAAM,iCAAiC,SAAS;AAChD,+BAA+B,YAAY;AAG3C,IAAO,yBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import { describe, PropTypes } from "react-desc";
|
|
4
|
+
import { aggregatedClasses } from "@elliemae/ds-classnames";
|
|
5
|
+
import { DSSeparator } from "@elliemae/ds-separator";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { registerMenuItem } from "./menuItemFactory";
|
|
8
|
+
const blockName = "menu-separator";
|
|
9
|
+
const Li = styled.li`
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: flex-start;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
`;
|
|
14
|
+
const Title = aggregatedClasses("h5")(blockName, "title");
|
|
15
|
+
const MenuSeparator = ({ title, showSeparator = true }) => /* @__PURE__ */ React2.createElement(Li, null, showSeparator && /* @__PURE__ */ React2.createElement(DSSeparator, null), title && /* @__PURE__ */ React2.createElement(Title, null, title));
|
|
16
|
+
const props = {
|
|
17
|
+
title: PropTypes.string.description("menu separator h5 title"),
|
|
18
|
+
showSeparator: PropTypes.bool.description("toggle separator on and off")
|
|
19
|
+
};
|
|
20
|
+
MenuSeparator.propTypes = props;
|
|
21
|
+
registerMenuItem("separator", MenuSeparator);
|
|
22
|
+
const DSMenuSeparatorWithSchema = describe(MenuSeparator);
|
|
23
|
+
DSMenuSeparatorWithSchema.propTypes = props;
|
|
24
|
+
var Separator_default = MenuSeparator;
|
|
25
|
+
export {
|
|
26
|
+
DSMenuSeparatorWithSchema,
|
|
27
|
+
MenuSeparator,
|
|
28
|
+
Separator_default as default
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=Separator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/Separator.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { describe, PropTypes } from 'react-desc';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport { DSSeparator } from '@elliemae/ds-separator';\nimport styled from 'styled-components';\nimport { registerMenuItem } from './menuItemFactory';\n\nconst blockName = 'menu-separator';\nconst Li = styled.li`\n display: flex;\n align-items: flex-start;\n flex-direction: column;\n`;\n\nconst Title = aggregatedClasses('h5')(blockName, 'title');\nconst MenuSeparator = ({ title, showSeparator = true }) => (\n <Li>\n {showSeparator && <DSSeparator />}\n {title && <Title>{title}</Title>}\n </Li>\n);\n\nconst props = {\n /** menu separator h5 title */\n title: PropTypes.string.description('menu separator h5 title'),\n /** toggle separator on and off */\n showSeparator: PropTypes.bool.description('toggle separator on and off'),\n};\n\nMenuSeparator.propTypes = props;\nregisterMenuItem('separator', MenuSeparator);\n\nconst DSMenuSeparatorWithSchema = describe(MenuSeparator);\nDSMenuSeparatorWithSchema.propTypes = props;\n\nexport { DSMenuSeparatorWithSchema, MenuSeparator };\nexport default MenuSeparator;\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,YAAY;AAClB,MAAM,KAAK,OAAO;AAAA;AAAA;AAAA;AAAA;AAMlB,MAAM,QAAQ,kBAAkB,MAAM,WAAW;AACjD,MAAM,gBAAgB,CAAC,EAAE,OAAO,gBAAgB,WAC9C,qCAAC,IAAD,MACG,iBAAiB,qCAAC,aAAD,OACjB,SAAS,qCAAC,OAAD,MAAQ;AAItB,MAAM,QAAQ;AAAA,EAEZ,OAAO,UAAU,OAAO,YAAY;AAAA,EAEpC,eAAe,UAAU,KAAK,YAAY;AAAA;AAG5C,cAAc,YAAY;AAC1B,iBAAiB,aAAa;AAE9B,MAAM,4BAA4B,SAAS;AAC3C,0BAA0B,YAAY;AAGtC,IAAO,oBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2, { useCallback, useRef, useState } from "react";
|
|
3
|
+
import { PropTypes, describe } from "react-desc";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { ChevronSmallRight, MoreOptionsVert } from "@elliemae/ds-icons";
|
|
6
|
+
import { useFocusGroupItem } from "@elliemae/ds-shared/FocusGroup";
|
|
7
|
+
import { useHiddenController } from "@elliemae/ds-hidden";
|
|
8
|
+
import { DSButton, BUTTON_VARIANT } from "@elliemae/ds-button";
|
|
9
|
+
import { DSPopper, interactions } from "@elliemae/ds-popper";
|
|
10
|
+
import { Menu, setSubMenu } 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
|
+
}) => {
|
|
33
|
+
const itemRef = useRef(null);
|
|
34
|
+
const focusOnOpen = useRef(false);
|
|
35
|
+
const [isAddonHovered, setIsAddonHovered] = useState(false);
|
|
36
|
+
const {
|
|
37
|
+
visible = false,
|
|
38
|
+
onShow,
|
|
39
|
+
onHide
|
|
40
|
+
} = useHiddenController(void 0, {
|
|
41
|
+
interaction: "click"
|
|
42
|
+
});
|
|
43
|
+
const interaction = rightAddonType === "elipsis" ? "click" : "hover";
|
|
44
|
+
const { focusItemByNode } = useFocusGroupItem();
|
|
45
|
+
const handleShowSubItemsWithMouse = (e) => {
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
onShow();
|
|
48
|
+
focusOnOpen.current = true;
|
|
49
|
+
};
|
|
50
|
+
const handleShowWithMouse = (e) => {
|
|
51
|
+
if (onClick)
|
|
52
|
+
onClick(e);
|
|
53
|
+
};
|
|
54
|
+
const handleShowWithMouseHover = () => {
|
|
55
|
+
setIsAddonHovered(true);
|
|
56
|
+
onShow();
|
|
57
|
+
focusOnOpen.current = false;
|
|
58
|
+
};
|
|
59
|
+
const handleShowWithKeyboard = () => {
|
|
60
|
+
onShow();
|
|
61
|
+
focusOnOpen.current = true;
|
|
62
|
+
};
|
|
63
|
+
const handleOnMouseEnter = useCallback(() => {
|
|
64
|
+
setIsAddonHovered(true);
|
|
65
|
+
}, []);
|
|
66
|
+
const handleOnMouseLeave = useCallback(() => {
|
|
67
|
+
setIsAddonHovered(false);
|
|
68
|
+
}, []);
|
|
69
|
+
const hoverHandlers = interaction === "hover" ? {
|
|
70
|
+
onMouseEnter: handleShowWithMouseHover,
|
|
71
|
+
onMouseLeave: () => {
|
|
72
|
+
onHide();
|
|
73
|
+
setIsAddonHovered(false);
|
|
74
|
+
}
|
|
75
|
+
} : { onClick: handleShowWithMouse };
|
|
76
|
+
const rightAddon = rightAddonType === "elipsis" ? /* @__PURE__ */ React2.createElement(DSButton, {
|
|
77
|
+
"aria-label": "vertical-elipsis",
|
|
78
|
+
"data-testid": "vertical-elipsis",
|
|
79
|
+
buttonType: "text",
|
|
80
|
+
leftIcon: /* @__PURE__ */ React2.createElement(MoreOptionsVert, {
|
|
81
|
+
className: "submenu-arrow",
|
|
82
|
+
color: visible || isAddonHovered ? ["brand-primary", 800] : ["neutral", 500],
|
|
83
|
+
size: "s"
|
|
84
|
+
}),
|
|
85
|
+
onClick: (e) => handleShowSubItemsWithMouse(e),
|
|
86
|
+
size: "m",
|
|
87
|
+
variant: BUTTON_VARIANT.DEFAULT
|
|
88
|
+
}) : /* @__PURE__ */ React2.createElement(ChevronRightComp, null, /* @__PURE__ */ React2.createElement(ChevronSmallRight, {
|
|
89
|
+
"data-testid": "chevron-right",
|
|
90
|
+
className: "submenu-arrow",
|
|
91
|
+
color: visible || isAddonHovered ? ["brand-primary", 800] : ["neutral", 500],
|
|
92
|
+
size: "sm"
|
|
93
|
+
}));
|
|
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
|
|
130
|
+
})
|
|
131
|
+
}));
|
|
132
|
+
};
|
|
133
|
+
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")
|
|
146
|
+
};
|
|
147
|
+
SubMenu.propTypes = props;
|
|
148
|
+
registerMenuItem("submenu", SubMenu);
|
|
149
|
+
setSubMenu(SubMenu);
|
|
150
|
+
const DSSubMenuWithSchema = describe(SubMenu);
|
|
151
|
+
DSSubMenuWithSchema.propTypes = props;
|
|
152
|
+
var SubMenu_default = SubMenu;
|
|
153
|
+
export {
|
|
154
|
+
DSSubMenuWithSchema,
|
|
155
|
+
SubMenu,
|
|
156
|
+
SubMenu_default as default
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=SubMenu.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/SubMenu.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable indent */\n/* eslint-disable max-lines */\nimport React, { useCallback, useRef, useState } from 'react';\nimport { PropTypes, describe } from 'react-desc';\nimport styled from 'styled-components';\nimport { ChevronSmallRight, MoreOptionsVert } from '@elliemae/ds-icons';\nimport { useFocusGroupItem } from '@elliemae/ds-shared/FocusGroup';\nimport { useHiddenController } from '@elliemae/ds-hidden';\nimport { DSButton, BUTTON_VARIANT } from '@elliemae/ds-button';\nimport { DSPopper, interactions } from '@elliemae/ds-popper';\nimport { Menu, setSubMenu } from '../Menu';\nimport { MenuItem } from './MenuItem';\nimport { registerMenuItem } from './menuItemFactory';\n\nconst ChevronRightComp = styled.div`\n display: flex;\n justify-content: center;\n align-items: center;\n width: 28px; // same width as the ellipsis button\n`;\n\nconst SubMenu = ({\n noAddon,\n leftAddon = undefined,\n label = undefined,\n interactionType = 'hover',\n children: subitems,\n rightAddonType,\n disabledAddonInactive,\n checkableProps = {},\n customRenderer,\n onClick,\n closeMenu,\n id,\n}) => {\n const itemRef = useRef(null);\n const focusOnOpen = useRef(false);\n const [isAddonHovered, setIsAddonHovered] = useState<boolean>(false);\n const {\n visible = false,\n onShow,\n onHide,\n } = useHiddenController(undefined, {\n interaction: 'click',\n });\n\n const interaction = rightAddonType === 'elipsis' ? 'click' : 'hover';\n\n const { focusItemByNode } = useFocusGroupItem();\n // todo: create a menu state to handle all related menu things\n const handleShowSubItemsWithMouse = (e) => {\n e.stopPropagation();\n onShow();\n focusOnOpen.current = true;\n };\n const handleShowWithMouse = (e) => {\n if (onClick) onClick(e);\n };\n const handleShowWithMouseHover = () => {\n setIsAddonHovered(true);\n onShow();\n focusOnOpen.current = false;\n };\n\n const handleShowWithKeyboard = () => {\n onShow();\n focusOnOpen.current = true;\n };\n\n const handleOnMouseEnter = useCallback(() => {\n setIsAddonHovered(true);\n }, []);\n\n const handleOnMouseLeave = useCallback(() => {\n setIsAddonHovered(false);\n }, []);\n\n const hoverHandlers =\n interaction === 'hover'\n ? {\n onMouseEnter: handleShowWithMouseHover,\n onMouseLeave: () => {\n onHide();\n setIsAddonHovered(false);\n },\n }\n : { onClick: handleShowWithMouse };\n\n const rightAddon =\n rightAddonType === 'elipsis' ? (\n <DSButton\n aria-label=\"vertical-elipsis\"\n data-testid=\"vertical-elipsis\"\n buttonType=\"text\"\n leftIcon={\n <MoreOptionsVert\n className=\"submenu-arrow\"\n color={visible || isAddonHovered ? ['brand-primary', 800] : ['neutral', 500]}\n size=\"s\"\n />\n }\n onClick={(e) => handleShowSubItemsWithMouse(e)}\n size=\"m\"\n variant={BUTTON_VARIANT.DEFAULT}\n />\n ) : (\n <ChevronRightComp>\n <ChevronSmallRight\n data-testid=\"chevron-right\"\n className=\"submenu-arrow\"\n color={visible || isAddonHovered ? ['brand-primary', 800] : ['neutral', 500]}\n size=\"sm\"\n />\n </ChevronRightComp>\n );\n\n return (\n <>\n <DSPopper\n contentComponent={\n <Menu\n focusKeyBindings={{\n ArrowLeft: [() => focusItemByNode(itemRef.current), 'exit'],\n }}\n focusOnOpen={focusOnOpen.current}\n onExitFocusGroup={onHide}\n {...hoverHandlers}\n closeMenu={closeMenu}\n visible={visible}\n >\n {subitems}\n </Menu>\n }\n interactionType={interactionType}\n isOpen={visible}\n onOpen={(opening) => (opening ? onShow() : onHide())}\n placement=\"right-start\"\n showArrow={false}\n triggerComponent={\n <MenuItem\n customRenderer={customRenderer}\n disabledAddonInactive={disabledAddonInactive}\n id={id}\n innerRef={itemRef}\n label={label}\n leftAddon={leftAddon}\n noAddon={noAddon}\n onFocus={handleOnMouseEnter}\n onBlur={handleOnMouseLeave}\n onMouseEnter={handleOnMouseEnter}\n onMouseLeave={handleOnMouseLeave}\n {...hoverHandlers}\n onKeyDown={(e) => {\n if (e.key === 'ArrowRight' || e.key === 'Enter' || e.keyCode === 32) {\n handleShowWithKeyboard();\n }\n }}\n rightAddon={rightAddon}\n {...checkableProps}\n />\n }\n />\n </>\n );\n};\n\nconst props = {\n /** dont show addon for submenu */\n noAddon: PropTypes.bool.description('dont show addon for submenu'),\n /** left addon */\n leftAddon: PropTypes.node.description('left addon'),\n /** submenu label */\n label: PropTypes.string.description('submenu label'),\n /** A type indicating how to open/close the tooltip */\n interactionType: PropTypes.oneOf(interactions).description('A type indicating how to open/close the tooltip'),\n /** sub menu items */\n children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]).description('sub menu items'),\n /** right addon, ellipsis or undefined */\n rightAddonType: PropTypes.oneOf(['ellipsis']).description('right addon, ellipsis or undefined'),\n disabledAddonInactive: PropTypes.bool.description(''),\n /** props passed to MenuItem component */\n checkableProps: PropTypes.object.description('props passed to MenuItem component'),\n /** custom renderer for menu item */\n customRenderer: PropTypes.func.description('custom renderer for menu item'),\n /** on click handler */\n onClick: PropTypes.func.description('on click handler'),\n closeMenu: PropTypes.any.description(''),\n /** component id */\n id: PropTypes.string.description('component id'),\n};\n\nSubMenu.propTypes = props;\nregisterMenuItem('submenu', SubMenu);\nsetSubMenu(SubMenu);\nconst DSSubMenuWithSchema = describe(SubMenu);\n\nDSSubMenuWithSchema.propTypes = props;\n\nexport { DSSubMenuWithSchema, SubMenu };\nexport default SubMenu;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
|
6
|
+
};
|
|
7
|
+
const registerMenuItem = (type, item) => itemTypes[type] = item;
|
|
8
|
+
export {
|
|
9
|
+
menuItemFactory,
|
|
10
|
+
registerMenuItem
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=menuItemFactory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/menuItemFactory.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\n\nconst itemTypes = {};\n\nexport const menuItemFactory = (type = '', items, defaultItem = itemTypes.menuitem) => {\n const itemsObject = items || itemTypes;\n return itemsObject[type] || itemsObject[type.toLowerCase()] || defaultItem;\n};\n\nexport const registerMenuItem = (type, item) => (itemTypes[type] = item);\n"],
|
|
5
|
+
"mappings": "AAAA;ACEA,MAAM,YAAY;AAEX,MAAM,kBAAkB,CAAC,OAAO,IAAI,OAAO,cAAc,UAAU,aAAa;AACrF,QAAM,cAAc,SAAS;AAC7B,SAAO,YAAY,SAAS,YAAY,KAAK,kBAAkB;AAAA;AAG1D,MAAM,mBAAmB,CAAC,MAAM,SAAU,UAAU,QAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import React2 from "react";
|
|
3
|
+
import { isFunction } from "@elliemae/ds-utilities";
|
|
4
|
+
import { menuItemFactory } from "./menuItemFactory";
|
|
5
|
+
const renderMenuItems = (options, factory = menuItemFactory) => options.map((option, index) => {
|
|
6
|
+
if (isFunction(option.renderer)) {
|
|
7
|
+
return option.renderer({
|
|
8
|
+
key: option.id,
|
|
9
|
+
item: option
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const ItemComponent = factory(option.type);
|
|
13
|
+
const children = option.subItems && renderMenuItems(option.subItems, factory);
|
|
14
|
+
return /* @__PURE__ */ React2.createElement(ItemComponent, {
|
|
15
|
+
...option,
|
|
16
|
+
key: option.id || index,
|
|
17
|
+
item: option,
|
|
18
|
+
onClick: null,
|
|
19
|
+
onMouseDown: option.onClick
|
|
20
|
+
}, children);
|
|
21
|
+
});
|
|
22
|
+
export {
|
|
23
|
+
renderMenuItems
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=renderMenuItems.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/MenuItems/renderMenuItems.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable import/no-cycle */\nimport React from 'react';\nimport { isFunction } from '@elliemae/ds-utilities';\nimport { menuItemFactory } from './menuItemFactory';\n\nexport const renderMenuItems = (options, factory = menuItemFactory) =>\n options.map((option, index) => {\n if (isFunction(option.renderer)) {\n return option.renderer({\n key: option.id,\n item: option,\n });\n }\n const ItemComponent = factory(option.type);\n const children = option.subItems && renderMenuItems(option.subItems, factory);\n return (\n <ItemComponent\n {...option}\n key={option.id || index}\n item={option}\n onClick={null}\n onMouseDown={option.onClick}\n // onClick callback called in onMouseDown due to events order issue\n >\n {children}\n </ItemComponent>\n );\n });\n"],
|
|
5
|
+
"mappings": "AAAA;ACCA;AACA;AACA;AAEO,MAAM,kBAAkB,CAAC,SAAS,UAAU,oBACjD,QAAQ,IAAI,CAAC,QAAQ,UAAU;AAC7B,MAAI,WAAW,OAAO,WAAW;AAC/B,WAAO,OAAO,SAAS;AAAA,MACrB,KAAK,OAAO;AAAA,MACZ,MAAM;AAAA;AAAA;AAGV,QAAM,gBAAgB,QAAQ,OAAO;AACrC,QAAM,WAAW,OAAO,YAAY,gBAAgB,OAAO,UAAU;AACrE,SACE,qCAAC,eAAD;AAAA,OACM;AAAA,IACJ,KAAK,OAAO,MAAM;AAAA,IAClB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aAAa,OAAO;AAAA,KAGnB;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}) {
|
|
31
|
+
const computedListHeight = useHeightByAmountOfItems({
|
|
32
|
+
amountItems: amountItemsInWindow,
|
|
33
|
+
itemHeight,
|
|
34
|
+
items
|
|
35
|
+
});
|
|
36
|
+
return /* @__PURE__ */ React2.createElement(List, {
|
|
37
|
+
height: height || computedListHeight,
|
|
38
|
+
itemCount: items.length,
|
|
39
|
+
itemData: items,
|
|
40
|
+
itemSize: itemHeight,
|
|
41
|
+
width
|
|
42
|
+
}, MenuItem);
|
|
43
|
+
}
|
|
44
|
+
var VirtualMenuList_default = VirtualMenuList;
|
|
45
|
+
export {
|
|
46
|
+
VirtualMenuList,
|
|
47
|
+
VirtualMenuList_default as default
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=VirtualMenuList.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/VirtualMenuList.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { FixedSizeList as List } from 'react-window';\nimport { useHeightByAmountOfItems } from './utils/useHeightByAmountOfItems';\n\nconst MenuItem = ({ data, index, style }) => (\n <div key={index} style={style}>\n {data && data[index] ? data[index] : ''}\n </div>\n);\n\n// eslint-disable-next-line no-unused-vars\nfunction resolveComputation(items, cb, timeout = 1000) {\n return () =>\n new Promise(resolve => {\n const doResolve = result => {\n cb(result);\n resolve(result);\n };\n let result = 0;\n const timer = setTimeout(() => doResolve(result), timeout);\n items.forEach(option => {\n result =\n option.props.label.length > result\n ? option.props.label.length\n : result;\n });\n\n clearTimeout(timer);\n doResolve(result);\n });\n}\n\nfunction VirtualMenuList({\n items,\n itemHeight = 32,\n amountItemsInWindow = 5,\n width,\n height,\n}) {\n const computedListHeight = useHeightByAmountOfItems({\n amountItems: amountItemsInWindow,\n itemHeight,\n items,\n });\n\n return (\n <List\n height={height || computedListHeight}\n itemCount={items.length}\n itemData={items}\n itemSize={itemHeight}\n width={width}\n >\n {MenuItem}\n </List>\n );\n}\n\nexport { VirtualMenuList };\nexport default VirtualMenuList;"],
|
|
5
|
+
"mappings": "AAAA;ACAA;AACA;AACA;AAEA,MAAM,WAAW,CAAC,EAAE,MAAM,OAAO,YAC/B,qCAAC,OAAD;AAAA,EAAK,KAAK;AAAA,EAAO;AAAA,GACd,QAAQ,KAAK,SAAS,KAAK,SAAS;AAKzC,4BAA4B,OAAO,IAAI,UAAU,KAAM;AACrD,SAAO,MACL,IAAI,QAAQ,aAAW;AACrB,UAAM,YAAY,aAAU;AAC1B,SAAG;AACH,cAAQ;AAAA;AAEV,QAAI,SAAS;AACb,UAAM,QAAQ,WAAW,MAAM,UAAU,SAAS;AAClD,UAAM,QAAQ,YAAU;AACtB,eACE,OAAO,MAAM,MAAM,SAAS,SACxB,OAAO,MAAM,MAAM,SACnB;AAAA;AAGR,iBAAa;AACb,cAAU;AAAA;AAAA;AAIhB,yBAAyB;AAAA,EACvB;AAAA,EACA,aAAa;AAAA,EACb,sBAAsB;AAAA,EACtB;AAAA,EACA;AAAA,GACC;AACD,QAAM,qBAAqB,yBAAyB;AAAA,IAClD,aAAa;AAAA,IACb;AAAA,IACA;AAAA;AAGF,SACE,qCAAC,MAAD;AAAA,IACE,QAAQ,UAAU;AAAA,IAClB,WAAW,MAAM;AAAA,IACjB,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,KAEC;AAAA;AAMP,IAAO,0BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|