@snack-uikit/list 0.11.1-preview-5d3667ec.0 → 0.11.1
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/CHANGELOG.md +13 -0
- package/README.md +22 -61
- 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 +20 -119
- 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 +55 -45
- package/dist/components/Items/NextListItem/constants.d.ts +2 -0
- package/dist/components/Items/NextListItem/constants.js +10 -0
- package/dist/components/Items/PinGroupItem/PinGroupItem.js +7 -3
- package/dist/components/Items/PinGroupItem/styles.module.css +26 -14
- 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/styles.module.css +33 -26
- package/dist/components/Items/types.d.ts +68 -34
- package/dist/components/Items/utils.d.ts +34 -16
- package/dist/components/Items/utils.js +135 -37
- package/dist/components/Lists/Droplist/DropList.d.ts +1 -1
- package/dist/components/Lists/Droplist/DropList.js +78 -50
- package/dist/components/Lists/List/List.d.ts +5 -9
- package/dist/components/Lists/List/List.js +61 -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 +3 -2
- package/dist/components/Lists/contexts/index.js +3 -2
- package/dist/components/Lists/hooks.d.ts +10 -12
- package/dist/components/Lists/hooks.js +73 -40
- package/dist/components/Lists/index.d.ts +2 -1
- package/dist/components/Lists/index.js +1 -0
- 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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/types.d.ts +1 -1
- package/package.json +13 -18
- package/src/components/Items/AccordionItem/AccordionItem.tsx +24 -20
- package/src/components/Items/BaseItem/BaseItem.tsx +91 -82
- package/src/components/Items/BaseItem/styles.module.scss +19 -77
- 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 +88 -85
- package/src/components/Items/NextListItem/constants.ts +12 -0
- package/src/components/Items/PinGroupItem/PinGroupItem.tsx +14 -4
- package/src/components/Items/PinGroupItem/styles.module.scss +14 -14
- 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/styles.module.scss +36 -25
- package/src/components/Items/types.ts +91 -42
- package/src/components/Items/utils.ts +199 -52
- package/src/components/Lists/Droplist/DropList.tsx +155 -98
- package/src/components/Lists/List/List.tsx +129 -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 +15 -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/index.ts +2 -2
- package/src/components/Lists/types.ts +20 -24
- package/src/components/index.ts +17 -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/index.ts +4 -2
- 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/dist/hooks.d.ts +0 -5
- package/dist/hooks.js +0 -15
- package/dist/utils.d.ts +0 -30
- package/dist/utils.js +0 -115
- 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
- package/src/hooks.ts +0 -27
- package/src/utils.ts +0 -175
|
@@ -10,58 +10,68 @@ 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 { useCallback, useMemo, useRef, useState } from 'react';
|
|
13
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
14
14
|
import { Dropdown } from '@snack-uikit/dropdown';
|
|
15
15
|
import { ChevronRightSVG } from '@snack-uikit/icons';
|
|
16
|
-
import {
|
|
17
|
-
import { ParentListContext, useParentListContext } from '../../Lists/contexts';
|
|
16
|
+
import { useCollapseContext, useFocusListContext, useNewListContext, useSelectionContext } from '../../Lists/contexts';
|
|
18
17
|
import { ListPrivate } from '../../Lists/ListPrivate';
|
|
19
18
|
import { BaseItem } from '../BaseItem';
|
|
20
19
|
import { useGroupItemSelection } from '../hooks';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
'right',
|
|
24
|
-
'right-start',
|
|
25
|
-
'right-end',
|
|
26
|
-
'left',
|
|
27
|
-
'left-start',
|
|
28
|
-
'left-end',
|
|
29
|
-
];
|
|
20
|
+
import { extractActiveItems, isNextListItem } from '../utils';
|
|
21
|
+
import { FALLBACK_PLACEMENTS } from './constants';
|
|
30
22
|
export function NextListItem(_a) {
|
|
31
|
-
var { items
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
var { items, placement = 'right-start', id, scroll, scrollRef, disabled, onSublistOpenChanged, allChildIds, loading = false, focusId = id } = _a, option = __rest(_a, ["items", "placement", "id", "scroll", "scrollRef", "disabled", "onSublistOpenChanged", "allChildIds", "loading", "focusId"]);
|
|
24
|
+
const { flattenItems, focusFlattenItems } = useNewListContext();
|
|
25
|
+
const { isSelectionMultiple } = useSelectionContext();
|
|
26
|
+
const { openCollapseItems = [] } = useCollapseContext();
|
|
27
|
+
const item = flattenItems[id];
|
|
28
|
+
const { ids, expandedIds } = useMemo(() => {
|
|
29
|
+
const { ids, expandedIds } = extractActiveItems({
|
|
30
|
+
focusCloseChildIds: items,
|
|
31
|
+
focusFlattenItems,
|
|
32
|
+
openCollapseItems,
|
|
33
|
+
isSelectionMultiple,
|
|
34
|
+
});
|
|
35
|
+
return { ids, expandedIds: expandedIds.concat([id]) };
|
|
36
|
+
}, [focusFlattenItems, id, isSelectionMultiple, items, openCollapseItems]);
|
|
37
|
+
const { handleListKeyDownFactory, activeItemId, forceUpdateActiveItemId } = useFocusListContext();
|
|
38
|
+
const [open, setOpen] = useState();
|
|
39
|
+
const handleListKeyDown = useCallback((e) => {
|
|
40
|
+
handleListKeyDownFactory(ids, expandedIds)(e);
|
|
41
|
+
if (e.key === 'ArrowLeft') {
|
|
42
|
+
forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(focusId);
|
|
43
|
+
setOpen(false);
|
|
44
|
+
e.stopPropagation();
|
|
45
|
+
return;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
}, [handleListKeyDownFactory, ids, expandedIds, forceUpdateActiveItemId, focusId]);
|
|
48
|
+
const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({
|
|
49
|
+
items: isNextListItem(item) ? item.items : [],
|
|
50
|
+
id,
|
|
51
|
+
disabled,
|
|
52
|
+
allChildIds,
|
|
53
|
+
});
|
|
50
54
|
const handleOutsideClick = useCallback(() => {
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId('~drop-focus');
|
|
56
|
+
setOpen(false);
|
|
53
57
|
return true;
|
|
54
|
-
}, [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
}, [forceUpdateActiveItemId]);
|
|
59
|
+
const isOpen = useMemo(() => Boolean(!disabled && activeItemId && focusFlattenItems[focusId].allChildIds.includes(activeItemId)), [activeItemId, disabled, focusFlattenItems, focusId]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
setOpen(open => open && isOpen);
|
|
62
|
+
}, [id, isOpen]);
|
|
63
|
+
const listRef = useRef(null);
|
|
64
|
+
return (_jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: items, nested: true, scroll: scroll, tabIndex: 0, ref: listRef, onFocus: e => {
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(ids[0]);
|
|
67
|
+
}, scrollRef: scrollRef, limitedScrollHeight: true, loading: loading }), trigger: 'hover', open: isOpen || open, onOpenChange: value => {
|
|
68
|
+
setOpen(value);
|
|
69
|
+
onSublistOpenChanged === null || onSublistOpenChanged === void 0 ? void 0 : onSublistOpenChanged(value, id);
|
|
70
|
+
}, placement: placement, widthStrategy: 'auto', children: _jsx(BaseItem, Object.assign({}, option, { disabled: disabled, open: open, expandIcon: _jsx(ChevronRightSVG, {}), id: id, isParentNode: true, indeterminate: indeterminate, checked: checked, onOpenNestedList: () => {
|
|
71
|
+
setOpen(true);
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
var _a;
|
|
74
|
+
(_a = listRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
75
|
+
}, 0);
|
|
76
|
+
}, onSelect: handleOnSelect })) }));
|
|
67
77
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
+
import { Divider } from '@snack-uikit/divider';
|
|
4
|
+
import { useNewListContext } from '../../Lists/contexts';
|
|
3
5
|
import styles from './styles.module.css';
|
|
4
6
|
export function PinTopGroupItem({ children }) {
|
|
7
|
+
const { size = 's' } = useNewListContext();
|
|
5
8
|
if (!children) {
|
|
6
9
|
return null;
|
|
7
10
|
}
|
|
8
|
-
return (
|
|
11
|
+
return (_jsxs("div", { className: cn(styles.pinTopItem), "data-size": size, "data-test-id": 'list__pin-top-group-item', children: [_jsx("div", { children: children }), _jsx(Divider, { weight: 'regular' })] }));
|
|
9
12
|
}
|
|
10
13
|
export function PinBottomGroupItem({ children }) {
|
|
14
|
+
const { size = 's' } = useNewListContext();
|
|
11
15
|
if (!children) {
|
|
12
16
|
return null;
|
|
13
17
|
}
|
|
14
|
-
return (
|
|
18
|
+
return (_jsxs("div", { className: cn(styles.pinBottomItem), "data-size": size, "data-test-id": 'list__pin-bottom-group-item', children: [_jsx(Divider, { weight: 'regular' }), _jsx("div", { children: children })] }));
|
|
15
19
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
.pinTopItem{
|
|
2
|
-
padding-bottom:var(--radius-drop-list-container, 8px);
|
|
3
|
-
border-bottom:var(--border-width-droplist-pin-content, 1px);
|
|
4
2
|
display:flex;
|
|
5
3
|
flex-direction:column;
|
|
6
|
-
border
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
border:none;
|
|
5
|
+
}
|
|
6
|
+
.pinTopItem[data-size=s]{
|
|
7
|
+
padding-bottom:var(--radius-drop-list-container, 8px);
|
|
8
|
+
gap:var(--radius-drop-list-container, 8px);
|
|
9
|
+
}
|
|
10
|
+
.pinTopItem[data-size=m]{
|
|
11
|
+
padding-bottom:var(--radius-drop-list-container, 8px);
|
|
12
|
+
gap:var(--radius-drop-list-container, 8px);
|
|
13
|
+
}
|
|
14
|
+
.pinTopItem[data-size=l]{
|
|
15
|
+
padding-bottom:var(--radius-drop-list-container, 8px);
|
|
16
|
+
gap:var(--radius-drop-list-container, 8px);
|
|
11
17
|
}
|
|
12
18
|
.pinTopItem li,
|
|
13
19
|
.pinTopItem ul{
|
|
@@ -15,15 +21,21 @@
|
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
.pinBottomItem{
|
|
18
|
-
padding-top:var(--radius-drop-list-container, 8px);
|
|
19
|
-
border-top:var(--border-width-droplist-pin-content, 1px);
|
|
20
24
|
display:flex;
|
|
21
25
|
flex-direction:column;
|
|
22
|
-
border
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
border:none;
|
|
27
|
+
}
|
|
28
|
+
.pinBottomItem[data-size=s]{
|
|
29
|
+
padding-top:var(--radius-drop-list-container, 8px);
|
|
30
|
+
gap:var(--radius-drop-list-container, 8px);
|
|
31
|
+
}
|
|
32
|
+
.pinBottomItem[data-size=m]{
|
|
33
|
+
padding-top:var(--radius-drop-list-container, 8px);
|
|
34
|
+
gap:var(--radius-drop-list-container, 8px);
|
|
35
|
+
}
|
|
36
|
+
.pinBottomItem[data-size=l]{
|
|
37
|
+
padding-top:var(--radius-drop-list-container, 8px);
|
|
38
|
+
gap:var(--radius-drop-list-container, 8px);
|
|
27
39
|
}
|
|
28
40
|
.pinBottomItem li,
|
|
29
41
|
.pinBottomItem ul{
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
1
2
|
import { SearchState } from '../../../types';
|
|
2
3
|
export type SearchItemProps = {
|
|
3
4
|
search?: SearchState;
|
|
5
|
+
itemRef?: RefObject<HTMLElement>;
|
|
4
6
|
};
|
|
5
|
-
export declare function SearchItem({ search }: SearchItemProps): import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
+
export declare function SearchItem({ search, itemRef }: SearchItemProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { SearchPrivate } from '@snack-uikit/search-private';
|
|
4
|
-
import {
|
|
4
|
+
import { useNewListContext } from '../../Lists/contexts';
|
|
5
5
|
import commonStyles from '../styles.module.css';
|
|
6
6
|
import styles from './styles.module.css';
|
|
7
|
-
export function SearchItem({ search }) {
|
|
8
|
-
const {
|
|
9
|
-
const { size } = useListContext();
|
|
7
|
+
export function SearchItem({ search, itemRef }) {
|
|
8
|
+
const { size = 's' } = useNewListContext();
|
|
10
9
|
const handleKeyDown = (e) => {
|
|
11
10
|
if (['ArrowDown', 'ArrowUp'].includes(e.key)) {
|
|
12
11
|
e.preventDefault();
|
|
13
12
|
}
|
|
14
13
|
if (['ArrowRight'].includes(e.key)) {
|
|
15
14
|
e.stopPropagation();
|
|
15
|
+
e.preventDefault();
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
const handleFocus = (e) => {
|
|
19
|
-
if (e.target === parentItemRefs[0].current) {
|
|
20
|
-
parentSetActiveFocusIndex === null || parentSetActiveFocusIndex === void 0 ? void 0 : parentSetActiveFocusIndex(0);
|
|
21
|
-
}
|
|
22
19
|
e.stopPropagation();
|
|
23
20
|
};
|
|
24
21
|
if (!Boolean(search)) {
|
|
25
22
|
return null;
|
|
26
23
|
}
|
|
27
|
-
return (_jsx("div", { className: cn(commonStyles.listItem, styles.searchItem), "data-size": size, "data-test-id": 'list__search-item', children: _jsx(SearchPrivate, Object.assign({ size: size, tabIndex: -1, onKeyDown: handleKeyDown, onFocus: handleFocus }, search, { ref:
|
|
24
|
+
return (_jsx("div", { className: cn(commonStyles.listItem, styles.searchItem), "data-size": size, "data-test-id": 'list__search-item', children: _jsx(SearchPrivate, Object.assign({ size: size, tabIndex: -1, onKeyDown: handleKeyDown, onFocus: handleFocus }, search, { ref: itemRef })) }));
|
|
28
25
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
export declare function useRenderItems(
|
|
4
|
-
type
|
|
2
|
+
import { Flatten, FlattenBaseItem, ItemId } from './types';
|
|
3
|
+
export declare function useRenderItems(focusCloseChildIds?: ItemId[]): import("react/jsx-runtime").JSX.Element[] | null[];
|
|
4
|
+
type UseCreateBaseItemsProps = {
|
|
5
5
|
search?: boolean;
|
|
6
6
|
footerActiveElementsRefs?: RefObject<HTMLElement>[];
|
|
7
7
|
};
|
|
8
|
-
export declare function
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export declare function useCreateBaseItems({ footerActiveElementsRefs }: UseCreateBaseItemsProps): {
|
|
9
|
+
searchItem: Flatten<FlattenBaseItem, 'itemRef'>;
|
|
10
|
+
footerItems: Flatten<FlattenBaseItem, 'itemRef'>[];
|
|
11
11
|
};
|
|
12
12
|
type UseGroupItemSelectionProps = {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
allChildIds: ItemId[];
|
|
14
|
+
items: ItemId[];
|
|
15
|
+
id: ItemId;
|
|
15
16
|
disabled?: boolean;
|
|
16
17
|
};
|
|
17
|
-
export declare function useGroupItemSelection({ id,
|
|
18
|
+
export declare function useGroupItemSelection({ id, allChildIds }: UseGroupItemSelectionProps): {
|
|
18
19
|
checked: boolean | undefined;
|
|
19
|
-
|
|
20
|
+
indeterminate: boolean;
|
|
20
21
|
handleOnSelect: () => void;
|
|
21
22
|
};
|
|
22
23
|
export {};
|
|
@@ -1,61 +1,79 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
|
-
import { createRef,
|
|
3
|
-
import {
|
|
4
|
-
import { useSelectionContext } from '../Lists/contexts';
|
|
2
|
+
import { createRef, useMemo } from 'react';
|
|
3
|
+
import { useNewListContext, useSelectionContext } from '../Lists/contexts';
|
|
5
4
|
import { AccordionItem } from './AccordionItem';
|
|
6
5
|
import { BaseItem } from './BaseItem';
|
|
7
6
|
import { GroupItem } from './GroupItem';
|
|
7
|
+
import { GroupSelectItem } from './GroupSelectItem';
|
|
8
8
|
import { NextListItem } from './NextListItem';
|
|
9
|
-
import {
|
|
10
|
-
export function useRenderItems(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import { isAccordionItem, isGroupItem, isGroupSelectItem, isNextListItem } from './utils';
|
|
10
|
+
export function useRenderItems(focusCloseChildIds) {
|
|
11
|
+
const { focusFlattenItems, flattenItems } = useNewListContext();
|
|
12
|
+
const { isSelectionMultiple } = useSelectionContext();
|
|
13
|
+
return useMemo(() => {
|
|
14
|
+
if (!focusCloseChildIds) {
|
|
15
|
+
return [null];
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
return focusCloseChildIds.map(id => {
|
|
18
|
+
const { itemRef, key, originalId, items } = focusFlattenItems[id];
|
|
19
|
+
const flattenItem = flattenItems[originalId];
|
|
20
|
+
if (isGroupItem(flattenItem) ||
|
|
21
|
+
(!isSelectionMultiple && isGroupSelectItem(flattenItem))) {
|
|
22
|
+
return _createElement(GroupItem, Object.assign({}, flattenItem, { items: items, key: key }));
|
|
23
|
+
}
|
|
24
|
+
if (isGroupSelectItem(flattenItem)) {
|
|
25
|
+
return _createElement(GroupSelectItem, Object.assign({}, flattenItem, { items: items, itemRef: itemRef, key: key }));
|
|
26
|
+
}
|
|
27
|
+
if (isAccordionItem(flattenItem)) {
|
|
28
|
+
return _createElement(AccordionItem, Object.assign({}, flattenItem, { items: items, itemRef: itemRef, key: key }));
|
|
29
|
+
}
|
|
30
|
+
if (isNextListItem(flattenItem)) {
|
|
31
|
+
return _createElement(NextListItem, Object.assign({}, flattenItem, { focusId: id, items: items, itemRef: itemRef, key: key }));
|
|
32
|
+
}
|
|
33
|
+
return _createElement(BaseItem, Object.assign({}, flattenItem, { itemRef: itemRef, key: key }));
|
|
34
|
+
});
|
|
35
|
+
}, [flattenItems, focusCloseChildIds, focusFlattenItems, isSelectionMultiple]);
|
|
23
36
|
}
|
|
24
|
-
export function
|
|
25
|
-
return useMemo(() =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
export function useCreateBaseItems({ footerActiveElementsRefs }) {
|
|
38
|
+
return useMemo(() => {
|
|
39
|
+
var _a;
|
|
40
|
+
return ({
|
|
41
|
+
searchItem: {
|
|
42
|
+
itemRef: createRef(),
|
|
43
|
+
id: '~search',
|
|
44
|
+
parentId: '~main',
|
|
45
|
+
items: [],
|
|
46
|
+
allChildIds: [],
|
|
47
|
+
},
|
|
48
|
+
footerItems: (_a = footerActiveElementsRefs === null || footerActiveElementsRefs === void 0 ? void 0 : footerActiveElementsRefs.map((itemRef, idx) => ({
|
|
49
|
+
id: `~footer__${idx}`,
|
|
50
|
+
itemRef,
|
|
51
|
+
parentId: '~main',
|
|
52
|
+
items: [],
|
|
53
|
+
allChildIds: [],
|
|
54
|
+
}))) !== null && _a !== void 0 ? _a : [],
|
|
55
|
+
});
|
|
56
|
+
}, [footerActiveElementsRefs]);
|
|
31
57
|
}
|
|
32
|
-
export function useGroupItemSelection({ id,
|
|
58
|
+
export function useGroupItemSelection({ id, allChildIds }) {
|
|
33
59
|
const { value, setValue, isSelectionMultiple } = useSelectionContext();
|
|
34
|
-
const {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}, [checked, disabled, id, isSelectionMultiple, setValue, value]);
|
|
60
|
+
const { flattenItems } = useNewListContext();
|
|
61
|
+
const baseChildIds = useMemo(() => allChildIds.filter(itemId => {
|
|
62
|
+
const item = flattenItems[itemId];
|
|
63
|
+
return item && !('type' in item);
|
|
64
|
+
}), [allChildIds, flattenItems]);
|
|
65
|
+
const checked = isSelectionMultiple
|
|
66
|
+
? value && Boolean(value.length) && baseChildIds.every(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
|
|
67
|
+
: undefined;
|
|
68
|
+
const indeterminate = isSelectionMultiple
|
|
69
|
+
? !checked && baseChildIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
|
|
70
|
+
: baseChildIds.includes(value !== null && value !== void 0 ? value : '');
|
|
49
71
|
const handleOnSelect = () => {
|
|
50
72
|
if (checked) {
|
|
51
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (isIndeterminate) {
|
|
55
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...childIds, id])));
|
|
73
|
+
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !baseChildIds.includes(itemId)));
|
|
56
74
|
return;
|
|
57
75
|
}
|
|
58
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : [])
|
|
76
|
+
setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...baseChildIds])));
|
|
59
77
|
};
|
|
60
|
-
return { checked,
|
|
78
|
+
return { checked, indeterminate, handleOnSelect };
|
|
61
79
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export * from './BaseItem';
|
|
2
|
-
export * from './NextListItem';
|
|
3
|
-
export * from './AccordionItem';
|
|
4
|
-
export * from './GroupItem';
|
|
5
|
-
export * from './SearchItem';
|
|
6
1
|
export * from './hooks';
|
|
7
2
|
export * from './types';
|
|
8
3
|
export * from './utils';
|
|
4
|
+
export * from './SearchItem';
|
|
9
5
|
export * from './PinGroupItem';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export * from './BaseItem';
|
|
2
|
-
export * from './NextListItem';
|
|
3
|
-
export * from './AccordionItem';
|
|
4
|
-
export * from './GroupItem';
|
|
5
|
-
export * from './SearchItem';
|
|
6
1
|
export * from './hooks';
|
|
7
2
|
export * from './types';
|
|
8
3
|
export * from './utils';
|
|
4
|
+
export * from './SearchItem';
|
|
9
5
|
export * from './PinGroupItem';
|
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
.itemWrapper{
|
|
2
|
+
position:relative;
|
|
3
|
+
min-width:100%;
|
|
4
|
+
margin:0;
|
|
5
|
+
padding:0;
|
|
6
|
+
}
|
|
7
|
+
.itemWrapper::before, .itemWrapper::after{
|
|
8
|
+
pointer-events:none;
|
|
9
|
+
content:"";
|
|
10
|
+
position:absolute;
|
|
11
|
+
top:0;
|
|
12
|
+
left:0;
|
|
13
|
+
width:100%;
|
|
14
|
+
height:100%;
|
|
15
|
+
background-color:transparent;
|
|
16
|
+
}
|
|
17
|
+
.itemWrapper[data-disabled], .itemWrapper:disabled{
|
|
18
|
+
cursor:not-allowed;
|
|
19
|
+
background-color:transparent;
|
|
20
|
+
outline:none;
|
|
21
|
+
}
|
|
22
|
+
.itemWrapper[data-disabled]::before, .itemWrapper:disabled::before{
|
|
23
|
+
display:none;
|
|
24
|
+
}
|
|
25
|
+
.itemWrapper[data-disabled]::after, .itemWrapper:disabled::after{
|
|
26
|
+
cursor:not-allowed;
|
|
27
|
+
background-color:transparent;
|
|
28
|
+
}
|
|
29
|
+
.itemWrapper:not([data-inactive], [data-disabled])[data-open]::before, .itemWrapper:not([data-inactive], [data-disabled])[data-focused]::before, .itemWrapper:not([data-inactive], [data-disabled]):hover::before, .itemWrapper:not([data-inactive], [data-disabled]):focus-visible::before{
|
|
30
|
+
opacity:var(--opacity-a008, 0.08);
|
|
31
|
+
background-color:var(--sys-neutral-accent-default, #6f717c);
|
|
32
|
+
}
|
|
33
|
+
|
|
1
34
|
.listItem{
|
|
2
35
|
cursor:pointer;
|
|
3
36
|
position:relative;
|
|
@@ -40,32 +73,6 @@
|
|
|
40
73
|
padding-right:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
|
|
41
74
|
gap:var(--space-drop-list-item-l-container-gap, 8px);
|
|
42
75
|
}
|
|
43
|
-
.listItem::after{
|
|
44
|
-
pointer-events:none;
|
|
45
|
-
content:"";
|
|
46
|
-
position:absolute;
|
|
47
|
-
top:0;
|
|
48
|
-
left:0;
|
|
49
|
-
width:100%;
|
|
50
|
-
height:100%;
|
|
51
|
-
background-color:transparent;
|
|
52
|
-
}
|
|
53
|
-
.listItem[data-disabled], .listItem:disabled{
|
|
54
|
-
cursor:not-allowed;
|
|
55
|
-
background-color:transparent;
|
|
56
|
-
outline:none;
|
|
57
|
-
}
|
|
58
|
-
.listItem[data-disabled]::before, .listItem:disabled::before{
|
|
59
|
-
display:none;
|
|
60
|
-
}
|
|
61
|
-
.listItem[data-disabled]::after, .listItem:disabled::after{
|
|
62
|
-
cursor:not-allowed;
|
|
63
|
-
background-color:transparent;
|
|
64
|
-
}
|
|
65
|
-
.listItem:not([data-inactive], [data-disabled])[data-open]::after, .listItem:not([data-inactive], [data-disabled])[data-focused]::after, .listItem:not([data-inactive], [data-disabled]):hover::after, .listItem:not([data-inactive], [data-disabled]):focus-visible::after{
|
|
66
|
-
opacity:var(--opacity-a008, 0.08);
|
|
67
|
-
background-color:var(--sys-neutral-accent-default, #6f717c);
|
|
68
|
-
}
|
|
69
76
|
.listItem:not([data-inactive], [data-disabled])[data-focused], .listItem:not([data-inactive], [data-disabled]):focus-visible{
|
|
70
77
|
outline-width:var(--border-state-focus-s-border-width, 2px);
|
|
71
78
|
outline-style:var(--border-state-focus-s-border-style, solid);
|