@snack-uikit/list 0.10.0 → 0.10.1-preview-69abc1d3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -24
- package/dist/components/Items/AccordionItem/AccordionItem.d.ts +4 -2
- package/dist/components/Items/AccordionItem/AccordionItem.js +18 -16
- package/dist/components/Items/BaseItem/BaseItem.d.ts +8 -4
- package/dist/components/Items/BaseItem/BaseItem.js +20 -14
- package/dist/components/Items/BaseItem/styles.module.css +9 -122
- package/dist/components/Items/GroupItem/GroupItem.d.ts +5 -1
- package/dist/components/Items/GroupItem/GroupItem.js +1 -3
- package/dist/components/Items/GroupSelectItem/GroupSelectItem.d.ts +4 -0
- package/dist/components/Items/GroupSelectItem/GroupSelectItem.js +18 -0
- package/dist/components/Items/GroupSelectItem/index.d.ts +1 -0
- package/dist/components/Items/GroupSelectItem/index.js +1 -0
- package/dist/components/Items/NextListItem/NextListItem.d.ts +6 -2
- package/dist/components/Items/NextListItem/NextListItem.js +53 -45
- package/dist/components/Items/NextListItem/constants.d.ts +2 -0
- package/dist/components/Items/NextListItem/constants.js +10 -0
- package/dist/components/Items/SearchItem/SearchItem.d.ts +3 -1
- package/dist/components/Items/SearchItem/SearchItem.js +5 -8
- package/dist/components/Items/hooks.d.ts +11 -10
- package/dist/components/Items/hooks.js +64 -46
- package/dist/components/Items/index.d.ts +1 -5
- package/dist/components/Items/index.js +1 -5
- package/dist/components/Items/types.d.ts +68 -34
- package/dist/components/Items/utils.d.ts +33 -16
- package/dist/components/Items/utils.js +132 -37
- package/dist/components/Lists/Droplist/DropList.d.ts +1 -1
- package/dist/components/Lists/Droplist/DropList.js +73 -50
- package/dist/components/Lists/List/List.d.ts +5 -9
- package/dist/components/Lists/List/List.js +56 -54
- package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +6 -20
- package/dist/components/Lists/ListPrivate/ListPrivate.js +9 -8
- package/dist/components/Lists/ListPrivate/styles.module.css +1 -0
- package/dist/components/Lists/contexts/CollapseProvider.d.ts +13 -1
- package/dist/components/Lists/contexts/CollapseProvider.js +2 -0
- package/dist/components/Lists/contexts/FocusListProvider.d.ts +9 -0
- package/dist/components/Lists/contexts/FocusListProvider.js +5 -0
- package/dist/components/Lists/contexts/NewListProvider.d.ts +32 -0
- package/dist/components/Lists/contexts/{ListProvider.js → NewListProvider.js} +10 -5
- package/dist/components/Lists/contexts/SelectionProvider.d.ts +25 -15
- package/dist/components/Lists/contexts/SelectionProvider.js +17 -13
- package/dist/components/Lists/contexts/index.d.ts +2 -2
- package/dist/components/Lists/contexts/index.js +2 -2
- package/dist/components/Lists/hooks.d.ts +10 -12
- package/dist/components/Lists/hooks.js +73 -40
- package/dist/components/Lists/types.d.ts +12 -14
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/helperComponents/ItemContent/ItemContent.d.ts +15 -0
- package/dist/helperComponents/ItemContent/ItemContent.js +23 -0
- package/dist/helperComponents/ItemContent/index.d.ts +1 -0
- package/dist/helperComponents/ItemContent/index.js +1 -0
- package/dist/helperComponents/ItemContent/styles.module.css +117 -0
- package/dist/helperComponents/ListEmptyState/ListEmptyState.d.ts +2 -2
- package/dist/helperComponents/ListEmptyState/ListEmptyState.js +13 -4
- package/dist/helperComponents/Separator/Separator.d.ts +8 -2
- package/dist/helperComponents/Separator/Separator.js +22 -2
- package/dist/helperComponents/Separator/constants.d.ts +2 -0
- package/dist/helperComponents/Separator/constants.js +5 -0
- package/dist/helperComponents/Separator/styles.module.css +20 -1
- package/dist/helperComponents/index.d.ts +1 -0
- package/dist/helperComponents/index.js +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +15 -10
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/legacy/components/Items/hooks.d.ts +12 -0
- package/dist/legacy/components/Items/hooks.js +33 -0
- package/dist/legacy/components/index.d.ts +1 -0
- package/dist/legacy/components/index.js +1 -0
- package/dist/legacy/hooks.d.ts +5 -0
- package/dist/legacy/hooks.js +15 -0
- package/dist/legacy/index.d.ts +3 -0
- package/dist/legacy/index.js +3 -0
- package/dist/{utils.d.ts → legacy/utils.d.ts} +2 -3
- package/dist/{utils.js → legacy/utils.js} +4 -12
- package/dist/types.d.ts +1 -1
- package/package.json +14 -14
- package/src/components/Items/AccordionItem/AccordionItem.tsx +24 -20
- package/src/components/Items/BaseItem/BaseItem.tsx +48 -43
- package/src/components/Items/BaseItem/styles.module.scss +8 -70
- package/src/components/Items/GroupItem/GroupItem.tsx +5 -5
- package/src/components/Items/GroupSelectItem/GroupSelectItem.tsx +44 -0
- package/src/components/Items/GroupSelectItem/index.ts +1 -0
- package/src/components/Items/NextListItem/NextListItem.tsx +86 -85
- package/src/components/Items/NextListItem/constants.ts +12 -0
- package/src/components/Items/SearchItem/SearchItem.tsx +6 -8
- package/src/components/Items/hooks.tsx +86 -66
- package/src/components/Items/index.ts +1 -5
- package/src/components/Items/types.ts +91 -42
- package/src/components/Items/utils.ts +193 -52
- package/src/components/Lists/Droplist/DropList.tsx +151 -98
- package/src/components/Lists/List/List.tsx +124 -104
- package/src/components/Lists/ListPrivate/ListPrivate.tsx +19 -20
- package/src/components/Lists/ListPrivate/styles.module.scss +1 -0
- package/src/components/Lists/contexts/CollapseProvider.tsx +22 -0
- package/src/components/Lists/contexts/FocusListProvider.tsx +16 -0
- package/src/components/Lists/contexts/NewListProvider.tsx +54 -0
- package/src/components/Lists/contexts/SelectionProvider.tsx +56 -39
- package/src/components/Lists/contexts/index.ts +3 -2
- package/src/components/Lists/hooks.ts +124 -75
- package/src/components/Lists/types.ts +20 -24
- package/src/components/index.ts +16 -2
- package/src/helperComponents/ItemContent/ItemContent.tsx +63 -0
- package/src/helperComponents/ItemContent/index.ts +1 -0
- package/src/helperComponents/ItemContent/styles.module.scss +78 -0
- package/src/helperComponents/ListEmptyState/ListEmptyState.tsx +26 -12
- package/src/helperComponents/Separator/Separator.tsx +49 -3
- package/src/helperComponents/Separator/constants.ts +7 -0
- package/src/helperComponents/Separator/styles.module.scss +41 -1
- package/src/helperComponents/index.ts +1 -0
- package/src/hooks.ts +21 -15
- package/src/index.ts +5 -2
- package/src/legacy/components/Items/hooks.tsx +53 -0
- package/src/legacy/components/index.ts +1 -0
- package/src/legacy/hooks.ts +27 -0
- package/src/legacy/index.ts +3 -0
- package/src/{utils.ts → legacy/utils.ts} +4 -13
- package/src/types.ts +1 -1
- package/dist/components/Items/NextListItem/hooks.d.ts +0 -19
- package/dist/components/Items/NextListItem/hooks.js +0 -80
- package/dist/components/Lists/contexts/ListProvider.d.ts +0 -17
- package/dist/components/Lists/contexts/ParentListProvider.d.ts +0 -18
- package/dist/components/Lists/contexts/ParentListProvider.js +0 -12
- package/src/components/Items/NextListItem/hooks.ts +0 -105
- package/src/components/Lists/contexts/CollapseProvider.ts +0 -9
- package/src/components/Lists/contexts/ListProvider.tsx +0 -28
- package/src/components/Lists/contexts/ParentListProvider.tsx +0 -35
|
@@ -1,43 +1,138 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { createRef } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export function
|
|
12
|
-
return 'items' in item && item['type'] === '
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return 'items' in item && item['type'] === undefined;
|
|
17
|
-
}
|
|
18
|
-
export function getSlicedItems({ items, hasSearch, pinTop, pinBottom, footerRefs, }) {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
-
const searchShift = hasSearch ? 1 : 0;
|
|
21
|
-
const pinTopNumber = (_a = pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) !== null && _a !== void 0 ? _a : 0;
|
|
22
|
-
const pinBottomNumber = (_b = pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom.length) !== null && _b !== void 0 ? _b : 0;
|
|
23
|
-
const footerElementsNumber = (_c = footerRefs === null || footerRefs === void 0 ? void 0 : footerRefs.length) !== null && _c !== void 0 ? _c : 0;
|
|
24
|
-
return {
|
|
25
|
-
pinTop: items.slice(searchShift, pinTopNumber + searchShift),
|
|
26
|
-
items: items.slice(pinTopNumber + searchShift, items.length - pinBottomNumber - footerElementsNumber),
|
|
27
|
-
pinBottom: items.slice(items.length - pinBottomNumber - footerElementsNumber, items.length - footerElementsNumber),
|
|
28
|
-
};
|
|
13
|
+
export function isBaseItem(item) {
|
|
14
|
+
return item && !('items' in item);
|
|
15
|
+
}
|
|
16
|
+
export function isAccordionItem(item) {
|
|
17
|
+
return item && 'items' in item && item['type'] === 'collapse';
|
|
18
|
+
}
|
|
19
|
+
export function isNextListItem(item) {
|
|
20
|
+
return item && 'items' in item && item['type'] === 'next-list';
|
|
21
|
+
}
|
|
22
|
+
export function isGroupItem(item) {
|
|
23
|
+
return item && 'items' in item && item['type'] === 'group';
|
|
24
|
+
}
|
|
25
|
+
export function isGroupSelectItem(item) {
|
|
26
|
+
return item && 'items' in item && item['type'] === 'group-select';
|
|
29
27
|
}
|
|
30
|
-
export function
|
|
31
|
-
return
|
|
32
|
-
|
|
28
|
+
export function isContentItem(item) {
|
|
29
|
+
return typeof item === 'object' && item['option'] !== undefined;
|
|
30
|
+
}
|
|
31
|
+
export const isBaseItemProps = isBaseItem;
|
|
32
|
+
export const isAccordionItemProps = isAccordionItem;
|
|
33
|
+
export const isNextListItemProps = isNextListItem;
|
|
34
|
+
export const isGroupItemProps = isGroupItem;
|
|
35
|
+
export function kindFlattenItems({ items, prefix, parentId }) {
|
|
36
|
+
const flattenItems = {};
|
|
37
|
+
const focusFlattenItems = {};
|
|
38
|
+
function flatten({ item, idx, prefix, parentId = '~main' }) {
|
|
39
|
+
var _a, _b;
|
|
33
40
|
const autoId = prefix !== undefined ? [prefix, idx].join('-') : String(idx);
|
|
34
|
-
const itemId = (_a = item.id) !== null && _a !== void 0 ? _a : autoId;
|
|
35
|
-
if (
|
|
36
|
-
|
|
41
|
+
const itemId = (_a = (!isGroupItem(item) ? item.id : undefined)) !== null && _a !== void 0 ? _a : autoId;
|
|
42
|
+
if (isBaseItem(item)) {
|
|
43
|
+
flattenItems[itemId] = Object.assign(Object.assign({}, item), { items: [], allChildIds: [], id: itemId });
|
|
44
|
+
focusFlattenItems[autoId] = {
|
|
45
|
+
key: autoId,
|
|
46
|
+
originalId: itemId,
|
|
47
|
+
id: autoId,
|
|
48
|
+
disabled: item.disabled,
|
|
49
|
+
parentId,
|
|
50
|
+
items: [],
|
|
51
|
+
allChildIds: [],
|
|
52
|
+
itemRef: item.itemRef || createRef(),
|
|
53
|
+
};
|
|
54
|
+
return { id: itemId, children: [itemId], autoId, focusChildren: [autoId] };
|
|
37
55
|
}
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
let allChildIds = [];
|
|
57
|
+
let allFocusChildIds = [];
|
|
58
|
+
const closeChildIds = [];
|
|
59
|
+
const autoChildIds = [];
|
|
60
|
+
const { items } = item, rest = __rest(item, ["items"]);
|
|
61
|
+
const childActiveParent = isGroupItem(item) ? parentId !== null && parentId !== void 0 ? parentId : '~main' : autoId;
|
|
62
|
+
for (let idx = 0; idx < items.length; idx++) {
|
|
63
|
+
const { id, children, autoId, focusChildren } = flatten({
|
|
64
|
+
item: items[idx],
|
|
65
|
+
idx,
|
|
66
|
+
prefix: itemId,
|
|
67
|
+
parentId: childActiveParent,
|
|
68
|
+
});
|
|
69
|
+
autoChildIds.push(autoId);
|
|
70
|
+
closeChildIds.push(id);
|
|
71
|
+
allChildIds = allChildIds.concat(children);
|
|
72
|
+
allFocusChildIds = allFocusChildIds.concat(focusChildren);
|
|
40
73
|
}
|
|
41
|
-
|
|
42
|
-
|
|
74
|
+
const children = [...new Set(allChildIds.concat(closeChildIds))];
|
|
75
|
+
const focusChildren = [...new Set(allFocusChildIds.concat(autoChildIds))];
|
|
76
|
+
flattenItems[itemId] = Object.assign(Object.assign({}, rest), { id: itemId, items: [], allChildIds: children });
|
|
77
|
+
focusFlattenItems[autoId] = {
|
|
78
|
+
key: autoId,
|
|
79
|
+
originalId: itemId,
|
|
80
|
+
id: autoId,
|
|
81
|
+
parentId,
|
|
82
|
+
items: autoChildIds,
|
|
83
|
+
allChildIds: focusChildren,
|
|
84
|
+
disabled: (item.type === 'collapse' || item.type === 'next-list') && item.disabled,
|
|
85
|
+
type: item.type,
|
|
86
|
+
itemRef: (_b = (!isGroupItem(item) ? item.itemRef : undefined)) !== null && _b !== void 0 ? _b : createRef(),
|
|
87
|
+
};
|
|
88
|
+
return { id: itemId, children, autoId, focusChildren };
|
|
89
|
+
}
|
|
90
|
+
const closeChildIds = [];
|
|
91
|
+
const autoChildIds = [];
|
|
92
|
+
let allChildIds = [];
|
|
93
|
+
for (let idx = 0; idx < items.length; idx++) {
|
|
94
|
+
const { id, children, autoId } = flatten({ item: items[idx], idx, prefix, parentId });
|
|
95
|
+
autoChildIds.push(autoId);
|
|
96
|
+
closeChildIds.push(id);
|
|
97
|
+
allChildIds.push(id);
|
|
98
|
+
allChildIds = allChildIds.concat(children);
|
|
99
|
+
}
|
|
100
|
+
const children = [...new Set(allChildIds)];
|
|
101
|
+
return {
|
|
102
|
+
focusCloseChildIds: autoChildIds,
|
|
103
|
+
allChildIds: children,
|
|
104
|
+
flattenItems,
|
|
105
|
+
focusFlattenItems,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export function extractActiveItems({ focusFlattenItems, focusCloseChildIds, openCollapseItems, }) {
|
|
109
|
+
const ids = [];
|
|
110
|
+
const expandedIds = [];
|
|
111
|
+
function internalFn(focusCloseChildIds) {
|
|
112
|
+
focusCloseChildIds.forEach(id => {
|
|
113
|
+
const child = focusFlattenItems[id];
|
|
114
|
+
if (child.type === 'group') {
|
|
115
|
+
internalFn(child.items);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!child.disabled) {
|
|
119
|
+
ids.push(child.id);
|
|
120
|
+
if (child.type === 'group-select') {
|
|
121
|
+
internalFn(child.items);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (child.type) {
|
|
125
|
+
expandedIds.push(id);
|
|
126
|
+
if (openCollapseItems.includes(id)) {
|
|
127
|
+
internalFn(child.items);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
internalFn(focusCloseChildIds);
|
|
134
|
+
return {
|
|
135
|
+
ids,
|
|
136
|
+
expandedIds,
|
|
137
|
+
};
|
|
43
138
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DroplistProps } from '../types';
|
|
2
|
-
export declare function Droplist({ items: itemsProp, search, pinBottom, pinTop, footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, open: openProp, onOpenChange, collapse, ...props }: DroplistProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function Droplist({ items: itemsProp, search, pinBottom: pinBottomProp, pinTop: pinTopProp, footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, open: openProp, onOpenChange, collapse, triggerClassName, selection, contentRender, size, marker, className, ...props }: DroplistProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,46 +10,71 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import cn from 'classnames';
|
|
13
14
|
import { cloneElement, isValidElement, useCallback, useMemo, useRef } from 'react';
|
|
14
|
-
import { useUncontrolledProp } from 'uncontrollable';
|
|
15
15
|
import { Dropdown } from '@snack-uikit/dropdown';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
16
|
+
import { useValueControl } from '@snack-uikit/utils';
|
|
17
|
+
import { extractActiveItems, kindFlattenItems, useCreateBaseItems } from '../../Items';
|
|
18
|
+
import { CollapseContext, FocusListContext, NewListContextProvider, SelectionProvider } from '../contexts';
|
|
19
|
+
import { useNewKeyboardNavigation } from '../hooks';
|
|
20
20
|
import { ListPrivate } from '../ListPrivate';
|
|
21
|
+
import styles from '../styles.module.css';
|
|
22
|
+
const DEFAULT_FALLBACK_PLACEMENTS = ['top', 'right', 'bottom', 'left'];
|
|
21
23
|
export function Droplist(_a) {
|
|
22
|
-
var
|
|
23
|
-
var { items: itemsProp, search, pinBottom, pinTop, footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, open: openProp, onOpenChange, collapse = {} } = _a, props = __rest(_a, ["items", "search", "pinBottom", "pinTop", "footerActiveElementsRefs", "children", "trigger", "placement", "widthStrategy", "triggerElemRef", "open", "onOpenChange", "collapse"]);
|
|
24
|
+
var { items: itemsProp, search, pinBottom: pinBottomProp = [], pinTop: pinTopProp = [], footerActiveElementsRefs, children, trigger, placement, widthStrategy, triggerElemRef: triggerElemRefProp, open: openProp, onOpenChange, collapse = {}, triggerClassName, selection, contentRender, size = 's', marker = true, className } = _a, props = __rest(_a, ["items", "search", "pinBottom", "pinTop", "footerActiveElementsRefs", "children", "trigger", "placement", "widthStrategy", "triggerElemRef", "open", "onOpenChange", "collapse", "triggerClassName", "selection", "contentRender", "size", "marker", "className"]);
|
|
24
25
|
const hasSearch = useMemo(() => Boolean(search), [search]);
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const [openCollapseItems = [], setOpenCollapsedItems] = useValueControl(collapse);
|
|
27
|
+
const toggleOpenCollapseItem = useCallback((id) => setOpenCollapsedItems((items) => (items === null || items === void 0 ? void 0 : items.includes(id)) ? items.filter(item => item !== id) : (items !== null && items !== void 0 ? items : []).concat([id])), [setOpenCollapsedItems]);
|
|
28
|
+
const [open = false, setOpen] = useValueControl({
|
|
29
|
+
value: openProp,
|
|
30
|
+
defaultValue: false,
|
|
31
|
+
onChange: onOpenChange,
|
|
30
32
|
});
|
|
31
|
-
const {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const { searchItem, footerItems } = useCreateBaseItems({ footerActiveElementsRefs });
|
|
34
|
+
/**
|
|
35
|
+
* Объект с пропсами всех вложенных айтемов; ключ id
|
|
36
|
+
*/
|
|
37
|
+
const _b = useMemo(() => {
|
|
38
|
+
const pinTop = kindFlattenItems({ items: pinTopProp, prefix: '~pinTop', parentId: '~main' });
|
|
39
|
+
const items = kindFlattenItems({ items: itemsProp, prefix: '~main', parentId: '~main' });
|
|
40
|
+
const pinBottom = kindFlattenItems({ items: pinBottomProp, prefix: '~pinBottom', parentId: '~main' });
|
|
41
|
+
const flattenItems = Object.assign(Object.assign(Object.assign({}, pinTop.flattenItems), pinBottom.flattenItems), items.flattenItems);
|
|
42
|
+
const focusFlattenItems = Object.assign(Object.assign(Object.assign({}, pinTop.focusFlattenItems), pinBottom.focusFlattenItems), items.focusFlattenItems);
|
|
43
|
+
[...footerItems, searchItem].forEach(item => {
|
|
44
|
+
flattenItems[item.id] = item;
|
|
45
|
+
focusFlattenItems[item.id] = Object.assign(Object.assign({}, item), { originalId: item.id, items: [], key: item.id, allChildIds: [] });
|
|
46
|
+
});
|
|
47
|
+
return { items, pinTop, pinBottom, flattenItems, focusFlattenItems };
|
|
48
|
+
}, [itemsProp, pinTopProp, pinBottomProp, searchItem, footerItems]), { flattenItems, focusFlattenItems } = _b, memorizedItems = __rest(_b, ["flattenItems", "focusFlattenItems"]);
|
|
49
|
+
const { ids, expandedIds } = useMemo(() => {
|
|
50
|
+
const { pinTop, items, pinBottom } = memorizedItems;
|
|
51
|
+
let ids = [];
|
|
52
|
+
let expandedIds = [];
|
|
53
|
+
if (hasSearch) {
|
|
54
|
+
ids.push(searchItem.id);
|
|
55
|
+
}
|
|
56
|
+
[pinTop, items, pinBottom].forEach(({ focusFlattenItems, focusCloseChildIds }) => {
|
|
57
|
+
const activeItems = extractActiveItems({ focusFlattenItems, focusCloseChildIds, openCollapseItems });
|
|
58
|
+
ids = ids.concat(activeItems.ids);
|
|
59
|
+
expandedIds = expandedIds.concat(activeItems.expandedIds);
|
|
60
|
+
});
|
|
61
|
+
footerItems.forEach(footerItem => {
|
|
62
|
+
ids.push(footerItem.id);
|
|
35
63
|
});
|
|
36
|
-
const items = searchItem.concat(res.items).concat(footerRefs);
|
|
37
64
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
itemRefs: extractItemRefs(searchItem).concat(res.itemRefs).concat(extractItemRefs(footerRefs)),
|
|
41
|
-
expandedIds: res.expandedIds,
|
|
65
|
+
ids,
|
|
66
|
+
expandedIds,
|
|
42
67
|
};
|
|
43
|
-
}, [
|
|
44
|
-
const slicedItems = useMemo(() => getSlicedItems({ items, hasSearch, pinTop, pinBottom, footerRefs }), [items, hasSearch, pinTop, pinBottom, footerRefs]);
|
|
68
|
+
}, [footerItems, hasSearch, memorizedItems, openCollapseItems, searchItem.id]);
|
|
45
69
|
const triggerElemRef = useRef(null);
|
|
46
70
|
const listRef = useRef(null);
|
|
47
|
-
const {
|
|
48
|
-
|
|
71
|
+
const { handleListKeyDownFactory, resetActiveItemId, activeItemId, forceUpdateActiveItemId } = useNewKeyboardNavigation({
|
|
72
|
+
mainRef: triggerElemRefProp !== null && triggerElemRefProp !== void 0 ? triggerElemRefProp : triggerElemRef,
|
|
73
|
+
focusFlattenItems,
|
|
74
|
+
});
|
|
75
|
+
const handleListKeyDown = useCallback((e) => handleListKeyDownFactory(ids, expandedIds)(e), [handleListKeyDownFactory, ids, expandedIds]);
|
|
49
76
|
const handleOpenChange = (open) => {
|
|
50
|
-
|
|
51
|
-
resetActiveFocusIndex();
|
|
52
|
-
setOpenCollapsedItems([]);
|
|
77
|
+
resetActiveItemId();
|
|
53
78
|
setOpen(open);
|
|
54
79
|
};
|
|
55
80
|
const onKeyDown = useCallback((e, cb) => {
|
|
@@ -58,12 +83,15 @@ export function Droplist(_a) {
|
|
|
58
83
|
setOpen(true);
|
|
59
84
|
setTimeout(() => {
|
|
60
85
|
var _a;
|
|
86
|
+
resetActiveItemId();
|
|
61
87
|
(_a = listRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
62
|
-
setActiveFocusIndex(0);
|
|
63
88
|
}, 0);
|
|
64
89
|
}
|
|
90
|
+
if (e.key === 'ArrowUp') {
|
|
91
|
+
setOpen(false);
|
|
92
|
+
}
|
|
65
93
|
cb === null || cb === void 0 ? void 0 : cb(e);
|
|
66
|
-
}, [
|
|
94
|
+
}, [resetActiveItemId, setOpen]);
|
|
67
95
|
const triggerElem = useMemo(() => {
|
|
68
96
|
if (isValidElement(children)) {
|
|
69
97
|
const props = typeof children.props === 'object' ? children.props : {};
|
|
@@ -77,24 +105,19 @@ export function Droplist(_a) {
|
|
|
77
105
|
}
|
|
78
106
|
return children;
|
|
79
107
|
}, [onKeyDown, children]);
|
|
80
|
-
return (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}, children: _jsx(Dropdown, Object.assign({ content: _jsx(ListPrivate, Object.assign({}, slicedItems, props, { onKeyDown: handleListKeyDown, tabIndex: 0, ref: listRef, search: search, limitedScrollHeight: true, parent: 'droplist' })), trigger: trigger, placement: placement, widthStrategy: widthStrategy }, (triggerElemRefProp
|
|
96
|
-
? {}
|
|
97
|
-
: {
|
|
98
|
-
triggerRef: triggerElemRef,
|
|
99
|
-
}), { open: open, onOpenChange: handleOpenChange, children: triggerElem })) }) })));
|
|
108
|
+
return (_jsx(NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, children: _jsx(SelectionProvider, Object.assign({}, selection, { children: _jsx(CollapseContext.Provider, { value: {
|
|
109
|
+
openCollapseItems,
|
|
110
|
+
toggleOpenCollapseItem,
|
|
111
|
+
}, children: _jsx(FocusListContext.Provider, { value: {
|
|
112
|
+
activeItemId,
|
|
113
|
+
handleListKeyDownFactory,
|
|
114
|
+
forceUpdateActiveItemId,
|
|
115
|
+
}, children: _jsx(Dropdown, Object.assign({ content: _jsx("div", { className: cn(styles.wrapper, className), children: _jsx(ListPrivate, Object.assign({}, props, { items: memorizedItems.items.focusCloseChildIds, pinTop: memorizedItems.pinTop.focusCloseChildIds, pinBottom: memorizedItems.pinBottom.focusCloseChildIds, onKeyDown: handleListKeyDown, searchItem: searchItem, tabIndex: 0, ref: listRef, search: search, onFocus: e => {
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(ids[0]);
|
|
118
|
+
}, limitedScrollHeight: true })) }), triggerClassName: triggerClassName, fallbackPlacements: DEFAULT_FALLBACK_PLACEMENTS, trigger: trigger, placement: placement, widthStrategy: widthStrategy }, (triggerElemRefProp
|
|
119
|
+
? {}
|
|
120
|
+
: {
|
|
121
|
+
triggerRef: triggerElemRef,
|
|
122
|
+
}), { open: open, onOpenChange: handleOpenChange, children: triggerElem })) }) }) })) }));
|
|
100
123
|
}
|
|
@@ -2,19 +2,15 @@ import { KeyboardEvent } from 'react';
|
|
|
2
2
|
export declare const List: import("react").ForwardRefExoticComponent<{
|
|
3
3
|
'data-test-id'?: string | undefined;
|
|
4
4
|
} & import("react").AriaAttributes & {
|
|
5
|
-
items: import("../../Items").
|
|
6
|
-
pinTop?: import("../../Items").
|
|
7
|
-
pinBottom?: import("../../Items").
|
|
5
|
+
items: import("../../Items").Item[];
|
|
6
|
+
pinTop?: import("../../Items").Item[] | undefined;
|
|
7
|
+
pinBottom?: import("../../Items").Item[] | undefined;
|
|
8
8
|
footer?: import("react").ReactNode;
|
|
9
9
|
footerActiveElementsRefs?: import("react").RefObject<HTMLElement>[] | undefined;
|
|
10
10
|
search?: import("../../..").SearchState | undefined;
|
|
11
11
|
tabIndex?: number | undefined;
|
|
12
|
-
collapse?:
|
|
13
|
-
value?: (string | number)[] | undefined;
|
|
14
|
-
onChange?(value: (string | number)[]): void;
|
|
15
|
-
defaultValue?: (string | number)[] | undefined;
|
|
16
|
-
} | undefined;
|
|
12
|
+
collapse?: import("../contexts").CollapseState | undefined;
|
|
17
13
|
className?: string | undefined;
|
|
18
14
|
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
19
15
|
loading?: boolean | undefined;
|
|
20
|
-
} & import("../contexts").SelectionState & import("../contexts").
|
|
16
|
+
} & import("../contexts").SelectionState & import("../contexts").PublicListContextType & import("../../../types").ScrollProps & import("../types").EmptyState & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -12,75 +12,77 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import cn from 'classnames';
|
|
14
14
|
import mergeRefs from 'merge-refs';
|
|
15
|
-
import { forwardRef, useMemo, useRef } from 'react';
|
|
16
|
-
import {
|
|
15
|
+
import { forwardRef, useCallback, useMemo, useRef } from 'react';
|
|
16
|
+
import { useValueControl } from '@snack-uikit/utils';
|
|
17
17
|
import { HiddenTabButton } from '../../../helperComponents';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { useKeyboardNavigation } from '../hooks';
|
|
18
|
+
import { extractActiveItems, kindFlattenItems, useCreateBaseItems } from '../../Items';
|
|
19
|
+
import { CollapseContext, FocusListContext, NewListContextProvider, SelectionProvider } from '../contexts';
|
|
20
|
+
import { useNewKeyboardNavigation } from '../hooks';
|
|
22
21
|
import { ListPrivate } from '../ListPrivate';
|
|
23
22
|
import styles from '../styles.module.css';
|
|
24
23
|
export const List = forwardRef((_a, ref) => {
|
|
25
|
-
var
|
|
26
|
-
var { items: itemsProp, search, pinBottom, pinTop, footerActiveElementsRefs, onKeyDown, tabIndex = 0, className, collapse = {} } = _a, props = __rest(_a, ["items", "search", "pinBottom", "pinTop", "footerActiveElementsRefs", "onKeyDown", "tabIndex", "className", "collapse"]);
|
|
24
|
+
var { items: itemsProp = [], search, pinBottom: pinBottomProp = [], pinTop: pinTopProp = [], footerActiveElementsRefs, onKeyDown, tabIndex = 0, className, collapse = {}, selection, contentRender, size = 's', marker = true } = _a, props = __rest(_a, ["items", "search", "pinBottom", "pinTop", "footerActiveElementsRefs", "onKeyDown", "tabIndex", "className", "collapse", "selection", "contentRender", "size", "marker"]);
|
|
27
25
|
const hasSearch = useMemo(() => Boolean(search), [search]);
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const [openCollapseItems = [], setOpenCollapsedItems] = useValueControl(collapse);
|
|
27
|
+
const toggleOpenCollapseItem = useCallback((id) => setOpenCollapsedItems((items) => (items === null || items === void 0 ? void 0 : items.includes(id)) ? items.filter(item => item !== id) : (items !== null && items !== void 0 ? items : []).concat([id])), [setOpenCollapsedItems]);
|
|
28
|
+
const { searchItem, footerItems } = useCreateBaseItems({ footerActiveElementsRefs });
|
|
29
|
+
/**
|
|
30
|
+
* Объект с пропсами всех вложенных айтемов; ключ id
|
|
31
|
+
*/
|
|
32
|
+
const _b = useMemo(() => {
|
|
33
|
+
const pinTop = kindFlattenItems({ items: pinTopProp, prefix: '~pinTop', parentId: '~main' });
|
|
34
|
+
const items = kindFlattenItems({ items: itemsProp, prefix: '~main', parentId: '~main' });
|
|
35
|
+
const pinBottom = kindFlattenItems({ items: pinBottomProp, prefix: '~pinBottom', parentId: '~main' });
|
|
36
|
+
const flattenItems = Object.assign(Object.assign(Object.assign({}, pinTop.flattenItems), pinBottom.flattenItems), items.flattenItems);
|
|
37
|
+
const focusFlattenItems = Object.assign(Object.assign(Object.assign({}, pinTop.focusFlattenItems), pinBottom.focusFlattenItems), items.focusFlattenItems);
|
|
38
|
+
[...footerItems, searchItem].forEach(item => {
|
|
39
|
+
flattenItems[item.id] = item;
|
|
40
|
+
focusFlattenItems[item.id] = Object.assign(Object.assign({}, item), { originalId: item.id, items: [], key: item.id, allChildIds: [] });
|
|
41
|
+
});
|
|
42
|
+
return { items, pinTop, pinBottom, flattenItems, focusFlattenItems };
|
|
43
|
+
}, [itemsProp, pinTopProp, pinBottomProp, searchItem, footerItems]), { flattenItems, focusFlattenItems } = _b, memorizedItems = __rest(_b, ["flattenItems", "focusFlattenItems"]);
|
|
44
|
+
const { ids, expandedIds } = useMemo(() => {
|
|
45
|
+
const { pinTop, items, pinBottom } = memorizedItems;
|
|
46
|
+
let ids = [];
|
|
47
|
+
let expandedIds = [];
|
|
48
|
+
if (hasSearch) {
|
|
49
|
+
ids.push(searchItem.id);
|
|
50
|
+
}
|
|
51
|
+
[pinTop, items, pinBottom].forEach(({ focusFlattenItems, focusCloseChildIds }) => {
|
|
52
|
+
const activeItems = extractActiveItems({ focusFlattenItems, focusCloseChildIds, openCollapseItems });
|
|
53
|
+
ids = ids.concat(activeItems.ids);
|
|
54
|
+
expandedIds = expandedIds.concat(activeItems.expandedIds);
|
|
55
|
+
});
|
|
56
|
+
footerItems.forEach(footerItem => {
|
|
57
|
+
ids.push(footerItem.id);
|
|
38
58
|
});
|
|
39
|
-
const items = searchItem.concat(res.items).concat(footerRefs);
|
|
40
59
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
itemRefs: extractItemRefs(searchItem).concat(res.itemRefs).concat(extractItemRefs(footerRefs)),
|
|
44
|
-
expandedIds: res.expandedIds,
|
|
60
|
+
ids,
|
|
61
|
+
expandedIds,
|
|
45
62
|
};
|
|
46
|
-
}, [
|
|
47
|
-
const slicedItems = useMemo(() => getSlicedItems({ items, hasSearch, pinTop, pinBottom, footerRefs }), [items, hasSearch, pinTop, pinBottom, footerRefs]);
|
|
63
|
+
}, [footerItems, hasSearch, memorizedItems, openCollapseItems, searchItem.id]);
|
|
48
64
|
const listRef = useRef(null);
|
|
49
65
|
const btnRef = useRef(null);
|
|
50
|
-
const {
|
|
51
|
-
|
|
52
|
-
ids,
|
|
53
|
-
expandedIds,
|
|
54
|
-
parentRef: listRef,
|
|
66
|
+
const { handleListKeyDownFactory, activeItemId, resetActiveItemId, forceUpdateActiveItemId } = useNewKeyboardNavigation({
|
|
67
|
+
mainRef: listRef,
|
|
55
68
|
btnRef,
|
|
56
|
-
|
|
69
|
+
focusFlattenItems,
|
|
57
70
|
});
|
|
58
|
-
const
|
|
71
|
+
const handleListKeyDown = useCallback((e) => handleListKeyDownFactory(ids, expandedIds)(e), [handleListKeyDownFactory, ids, expandedIds]);
|
|
72
|
+
const isActive = listRef.current === document.activeElement && activeItemId === undefined;
|
|
59
73
|
const mergedHandlerKeyDown = (e) => {
|
|
60
74
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
61
75
|
handleListKeyDown === null || handleListKeyDown === void 0 ? void 0 : handleListKeyDown(e);
|
|
62
76
|
};
|
|
63
|
-
const handleOnFocus = (
|
|
64
|
-
|
|
65
|
-
(e.relatedTarget && itemRefs.every(({ current }) => current !== e.relatedTarget))) {
|
|
66
|
-
resetActiveFocusIndex();
|
|
67
|
-
}
|
|
77
|
+
const handleOnFocus = () => {
|
|
78
|
+
resetActiveItemId();
|
|
68
79
|
};
|
|
69
|
-
return (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
parentOpenNestedIndex: openNestedIndex,
|
|
78
|
-
triggerRef: triggerRef !== null && triggerRef !== void 0 ? triggerRef : listRef,
|
|
79
|
-
parentRef: listRef,
|
|
80
|
-
parentSetActiveFocusIndex: setActiveFocusIndex,
|
|
81
|
-
parentResetNestedIndex: resetNestedIndex,
|
|
82
|
-
parentResetActiveFocusIndex: resetActiveFocusIndex,
|
|
83
|
-
openCollapsedItems,
|
|
84
|
-
toggleOpenCollapsedItems: id => setOpenCollapsedItems((items = []) => items.includes(id) ? items.filter(item => item !== id) : items === null || items === void 0 ? void 0 : items.concat([id])),
|
|
85
|
-
}, children: _jsxs("div", { className: cn(styles.wrapper, className), "data-active": isActive || undefined, children: [_jsx(ListPrivate, Object.assign({}, props, slicedItems, { ref: mergeRefs(ref, listRef), onFocus: handleOnFocus, onKeyDown: mergedHandlerKeyDown, tabIndex: tabIndex, search: search, nested: false, parent: 'list' })), _jsx(HiddenTabButton, { ref: btnRef, listRef: listRef, tabIndex: tabIndex })] }) }) })));
|
|
80
|
+
return (_jsx(NewListContextProvider, { flattenItems: flattenItems, focusFlattenItems: focusFlattenItems, contentRender: contentRender, size: size, marker: marker, children: _jsx(SelectionProvider, Object.assign({}, selection, { children: _jsx(CollapseContext.Provider, { value: {
|
|
81
|
+
openCollapseItems,
|
|
82
|
+
toggleOpenCollapseItem,
|
|
83
|
+
}, children: _jsx(FocusListContext.Provider, { value: {
|
|
84
|
+
activeItemId,
|
|
85
|
+
handleListKeyDownFactory,
|
|
86
|
+
forceUpdateActiveItemId,
|
|
87
|
+
}, children: _jsxs("div", { className: cn(styles.wrapper, className), "data-active": isActive || undefined, children: [_jsx(ListPrivate, Object.assign({}, props, { items: memorizedItems.items.focusCloseChildIds, pinTop: memorizedItems.pinTop.focusCloseChildIds, pinBottom: memorizedItems.pinBottom.focusCloseChildIds, searchItem: searchItem, ref: mergeRefs(ref, listRef), onFocus: handleOnFocus, onKeyDown: mergedHandlerKeyDown, tabIndex: tabIndex, search: search, nested: false })), _jsx(HiddenTabButton, { ref: btnRef, listRef: listRef, tabIndex: tabIndex })] }) }) }) })) }));
|
|
86
88
|
});
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const ListPrivate: import("react").ForwardRefExoticComponent<{
|
|
3
|
-
'data-test-id'?: string | undefined;
|
|
4
|
-
} & import("react").AriaAttributes & {
|
|
5
|
-
items: import("../../Items").ItemProps[];
|
|
6
|
-
pinTop?: import("../../Items").ItemProps[] | undefined;
|
|
7
|
-
pinBottom?: import("../../Items").ItemProps[] | undefined;
|
|
8
|
-
footer?: import("react").ReactNode;
|
|
9
|
-
footerActiveElementsRefs?: RefObject<HTMLElement>[] | undefined;
|
|
10
|
-
search?: import("../../..").SearchState | undefined;
|
|
11
|
-
tabIndex?: number | undefined;
|
|
12
|
-
collapse?: {
|
|
13
|
-
value?: (string | number)[] | undefined;
|
|
14
|
-
onChange?(value: (string | number)[]): void;
|
|
15
|
-
defaultValue?: (string | number)[] | undefined;
|
|
16
|
-
} | undefined;
|
|
17
|
-
className?: string | undefined;
|
|
18
|
-
onKeyDown?(e: import("react").KeyboardEvent<HTMLElement>): void;
|
|
19
|
-
loading?: boolean | undefined;
|
|
20
|
-
} & import("../contexts").SelectionState & import("../contexts").ListContextType & import("../../../types").ScrollProps & import("../types").EmptyState & import("../contexts").ListContextPrivateType & {
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ListPrivate: import("react").ForwardRefExoticComponent<Omit<import("../types").ListProps, "items" | "pinTop" | "pinBottom"> & {
|
|
21
3
|
nested?: boolean | undefined;
|
|
22
4
|
active?: boolean | undefined;
|
|
23
5
|
tabIndex?: number | undefined;
|
|
@@ -25,4 +7,8 @@ export declare const ListPrivate: import("react").ForwardRefExoticComponent<{
|
|
|
25
7
|
onBlur?(e: import("react").FocusEvent<HTMLElement, Element>): void;
|
|
26
8
|
onKeyDown?(e: import("react").KeyboardEvent<HTMLElement>): void;
|
|
27
9
|
limitedScrollHeight?: boolean | undefined;
|
|
10
|
+
searchItem?: import("../../Items").FlattenBaseItem | undefined;
|
|
11
|
+
pinTop?: import("../../Items").ItemId[] | undefined;
|
|
12
|
+
items: import("../../Items").ItemId[];
|
|
13
|
+
pinBottom?: import("../../Items").ItemId[] | undefined;
|
|
28
14
|
} & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -17,25 +17,26 @@ import { Scroll } from '@snack-uikit/scroll';
|
|
|
17
17
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
18
18
|
import { ListEmptyState, useEmptyState } from '../../../helperComponents';
|
|
19
19
|
import { PinBottomGroupItem, PinTopGroupItem, SearchItem, useRenderItems } from '../../Items';
|
|
20
|
-
import {
|
|
20
|
+
import { useNewListContext } from '../contexts';
|
|
21
21
|
import commonStyles from '../styles.module.css';
|
|
22
22
|
import styles from './styles.module.css';
|
|
23
23
|
export const ListPrivate = forwardRef((_a, ref) => {
|
|
24
|
-
var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, scrollRef, scrollContainerRef, footer, loading,
|
|
24
|
+
var { items, pinTop, pinBottom, onKeyDown, onBlur, onFocus, tabIndex, active, scroll, nested, search, searchItem, scrollRef, scrollContainerRef, footer, loading, limitedScrollHeight, className, noDataState, noResultsState, errorDataState, dataError, dataFiltered } = _a, props = __rest(_a, ["items", "pinTop", "pinBottom", "onKeyDown", "onBlur", "onFocus", "tabIndex", "active", "scroll", "nested", "search", "searchItem", "scrollRef", "scrollContainerRef", "footer", "loading", "limitedScrollHeight", "className", "noDataState", "noResultsState", "errorDataState", "dataError", "dataFiltered"]);
|
|
25
|
+
const { size = 's' } = useNewListContext();
|
|
25
26
|
const itemsJSX = useRenderItems(items);
|
|
26
|
-
const itemsPinTopJSX = useRenderItems(pinTop
|
|
27
|
-
const itemsPinBottomJSX = useRenderItems(pinBottom
|
|
27
|
+
const itemsPinTopJSX = useRenderItems(pinTop);
|
|
28
|
+
const itemsPinBottomJSX = useRenderItems(pinBottom);
|
|
28
29
|
const emptyStates = useEmptyState({ noDataState, noResultsState, errorDataState });
|
|
29
30
|
const hasNoItems = items.length === 0;
|
|
30
31
|
const loadingJSX = useMemo(() => loading && (_jsx("div", { role: 'spinbutton', tabIndex: -1, className: styles.loader, "data-size": size, "data-no-items": hasNoItems || undefined, "data-test-id": 'list__loader', children: _jsx(Spinner, { size: size === 'l' ? 's' : 'xs' }) })), [hasNoItems, loading, size]);
|
|
31
|
-
const content = useMemo(() => (_jsxs("div", { className: styles.content, children: [itemsJSX, loadingJSX, _jsx(ListEmptyState, { loading: loading, dataError: dataError, emptyStates: emptyStates,
|
|
32
|
-
const listJSX = (_jsxs("ul", Object.assign({ className: cn(commonStyles.listContainer, className), ref: ref, onKeyDown: onKeyDown, tabIndex: tabIndex, onFocus:
|
|
32
|
+
const content = useMemo(() => (_jsxs("div", { className: styles.content, children: [itemsJSX, loadingJSX, _jsx(ListEmptyState, { loading: loading, dataError: dataError, emptyStates: emptyStates, hasNoItems: hasNoItems, dataFiltered: dataFiltered !== null && dataFiltered !== void 0 ? dataFiltered : Boolean(search === null || search === void 0 ? void 0 : search.value) })] })), [dataError, dataFiltered, emptyStates, hasNoItems, itemsJSX, loading, loadingJSX, search === null || search === void 0 ? void 0 : search.value]);
|
|
33
|
+
const listJSX = (_jsxs("ul", Object.assign({ className: cn(commonStyles.listContainer, className), ref: ref, onKeyDown: onKeyDown, tabIndex: tabIndex, onFocus: onFocus, onBlur: onBlur, "data-active": active || undefined, role: 'menu' }, extractSupportProps(props), { children: [(Number(pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) > 0 || search) && (_jsxs(PinTopGroupItem, { children: [search && _jsx(SearchItem, Object.assign({ search: search }, searchItem)), Number(pinTop === null || pinTop === void 0 ? void 0 : pinTop.length) > 0 && itemsPinTopJSX] })), scroll ? (_jsxs(Scroll, { className: cn({
|
|
33
34
|
[commonStyles.scrollContainerS]: scroll && limitedScrollHeight && size === 's',
|
|
34
35
|
[commonStyles.scrollContainerM]: scroll && limitedScrollHeight && size === 'm',
|
|
35
36
|
[commonStyles.scrollContainerL]: scroll && limitedScrollHeight && size === 'l',
|
|
36
|
-
}), barHideStrategy: 'never', size: size === 's' ? 's' : 'm', ref: scrollContainerRef, children: [content, _jsx("div", { className: styles.scrollStub, ref: scrollRef })] })) : (_jsx(_Fragment, { children: content })), Number(pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom.length) > 0 && _jsx(PinBottomGroupItem, { children: itemsPinBottomJSX }), footer && _jsx("div", { className: styles.footer, children: footer })] })));
|
|
37
|
+
}), barHideStrategy: 'never', size: size === 's' ? 's' : 'm', ref: scrollContainerRef, children: [content, _jsx("div", { className: styles.scrollStub, ref: scrollRef })] })) : (_jsx(_Fragment, { children: content })), Number(pinBottom === null || pinBottom === void 0 ? void 0 : pinBottom.length) > 0 && _jsx(PinBottomGroupItem, { children: itemsPinBottomJSX }), footer && (_jsx("div", { className: styles.footer, onFocus: e => e.stopPropagation(), children: footer }))] })));
|
|
37
38
|
if (!nested) {
|
|
38
|
-
return
|
|
39
|
+
return listJSX;
|
|
39
40
|
}
|
|
40
41
|
return (_jsx("li", { style: { listStyleType: 'none' }, role: 'menuitem', children: listJSX }));
|
|
41
42
|
});
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { ItemId } from '../../Items';
|
|
3
|
+
export type CollapseLevelContextType = {
|
|
3
4
|
level?: number;
|
|
4
5
|
};
|
|
6
|
+
export declare const CollapseLevelContext: import("react").Context<CollapseLevelContextType>;
|
|
7
|
+
export declare const useCollapseLevelContext: () => CollapseLevelContextType;
|
|
8
|
+
export type CollapseContextType = {
|
|
9
|
+
openCollapseItems?: ItemId[];
|
|
10
|
+
toggleOpenCollapseItem?(id: ItemId): void;
|
|
11
|
+
};
|
|
5
12
|
export declare const CollapseContext: import("react").Context<CollapseContextType>;
|
|
6
13
|
export declare const useCollapseContext: () => CollapseContextType;
|
|
14
|
+
export type CollapseState = {
|
|
15
|
+
value?: ItemId[];
|
|
16
|
+
onChange?(value?: ItemId[]): void;
|
|
17
|
+
defaultValue?: ItemId[];
|
|
18
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
|
+
export const CollapseLevelContext = createContext({});
|
|
3
|
+
export const useCollapseLevelContext = () => useContext(CollapseLevelContext);
|
|
2
4
|
export const CollapseContext = createContext({});
|
|
3
5
|
export const useCollapseContext = () => useContext(CollapseContext);
|