@snack-uikit/list 0.1.1-preview-57c837e3.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.
Files changed (151) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +201 -0
  3. package/README.md +73 -0
  4. package/dist/components/Items/AccordionItem/AccordionItem.d.ts +2 -0
  5. package/dist/components/Items/AccordionItem/AccordionItem.js +41 -0
  6. package/dist/components/Items/AccordionItem/index.d.ts +1 -0
  7. package/dist/components/Items/AccordionItem/index.js +1 -0
  8. package/dist/components/Items/BaseItem/BaseItem.d.ts +8 -0
  9. package/dist/components/Items/BaseItem/BaseItem.js +67 -0
  10. package/dist/components/Items/BaseItem/constants.d.ts +2 -0
  11. package/dist/components/Items/BaseItem/constants.js +5 -0
  12. package/dist/components/Items/BaseItem/index.d.ts +1 -0
  13. package/dist/components/Items/BaseItem/index.js +1 -0
  14. package/dist/components/Items/BaseItem/styles.module.css +205 -0
  15. package/dist/components/Items/GroupItem/GroupItem.d.ts +2 -0
  16. package/dist/components/Items/GroupItem/GroupItem.js +9 -0
  17. package/dist/components/Items/GroupItem/index.d.ts +1 -0
  18. package/dist/components/Items/GroupItem/index.js +1 -0
  19. package/dist/components/Items/NextListItem/NextListItem.d.ts +2 -0
  20. package/dist/components/Items/NextListItem/NextListItem.js +66 -0
  21. package/dist/components/Items/NextListItem/hooks.d.ts +19 -0
  22. package/dist/components/Items/NextListItem/hooks.js +80 -0
  23. package/dist/components/Items/NextListItem/index.d.ts +1 -0
  24. package/dist/components/Items/NextListItem/index.js +1 -0
  25. package/dist/components/Items/PinGroupItem/PinGroupItem.d.ts +7 -0
  26. package/dist/components/Items/PinGroupItem/PinGroupItem.js +15 -0
  27. package/dist/components/Items/PinGroupItem/index.d.ts +1 -0
  28. package/dist/components/Items/PinGroupItem/index.js +1 -0
  29. package/dist/components/Items/PinGroupItem/styles.module.css +31 -0
  30. package/dist/components/Items/SearchItem/SearchItem.d.ts +5 -0
  31. package/dist/components/Items/SearchItem/SearchItem.js +28 -0
  32. package/dist/components/Items/SearchItem/index.d.ts +1 -0
  33. package/dist/components/Items/SearchItem/index.js +1 -0
  34. package/dist/components/Items/SearchItem/styles.module.css +11 -0
  35. package/dist/components/Items/hooks.d.ts +22 -0
  36. package/dist/components/Items/hooks.js +61 -0
  37. package/dist/components/Items/index.d.ts +9 -0
  38. package/dist/components/Items/index.js +9 -0
  39. package/dist/components/Items/styles.module.css +74 -0
  40. package/dist/components/Items/types.d.ts +43 -0
  41. package/dist/components/Items/types.js +1 -0
  42. package/dist/components/Items/utils.d.ts +17 -0
  43. package/dist/components/Items/utils.js +42 -0
  44. package/dist/components/Lists/Droplist/DropList.d.ts +2 -0
  45. package/dist/components/Lists/Droplist/DropList.js +97 -0
  46. package/dist/components/Lists/Droplist/index.d.ts +1 -0
  47. package/dist/components/Lists/Droplist/index.js +1 -0
  48. package/dist/components/Lists/List/List.d.ts +14 -0
  49. package/dist/components/Lists/List/List.js +77 -0
  50. package/dist/components/Lists/List/index.d.ts +1 -0
  51. package/dist/components/Lists/List/index.js +1 -0
  52. package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +22 -0
  53. package/dist/components/Lists/ListPrivate/ListPrivate.js +41 -0
  54. package/dist/components/Lists/ListPrivate/index.d.ts +1 -0
  55. package/dist/components/Lists/ListPrivate/index.js +1 -0
  56. package/dist/components/Lists/ListPrivate/styles.module.css +46 -0
  57. package/dist/components/Lists/contexts/CollapseProvider.d.ts +6 -0
  58. package/dist/components/Lists/contexts/CollapseProvider.js +3 -0
  59. package/dist/components/Lists/contexts/ListProvider.d.ts +12 -0
  60. package/dist/components/Lists/contexts/ListProvider.js +22 -0
  61. package/dist/components/Lists/contexts/ParentListProvider.d.ts +18 -0
  62. package/dist/components/Lists/contexts/ParentListProvider.js +12 -0
  63. package/dist/components/Lists/contexts/SelectionProvider.d.ts +53 -0
  64. package/dist/components/Lists/contexts/SelectionProvider.js +61 -0
  65. package/dist/components/Lists/contexts/index.d.ts +4 -0
  66. package/dist/components/Lists/contexts/index.js +4 -0
  67. package/dist/components/Lists/hooks.d.ts +16 -0
  68. package/dist/components/Lists/hooks.js +73 -0
  69. package/dist/components/Lists/index.d.ts +4 -0
  70. package/dist/components/Lists/index.js +2 -0
  71. package/dist/components/Lists/styles.module.css +70 -0
  72. package/dist/components/Lists/types.d.ts +35 -0
  73. package/dist/components/Lists/types.js +1 -0
  74. package/dist/components/index.d.ts +2 -0
  75. package/dist/components/index.js +1 -0
  76. package/dist/helperComponents/CollapseBlockPrivate/CollapseBlockPrivate.d.ts +9 -0
  77. package/dist/helperComponents/CollapseBlockPrivate/CollapseBlockPrivate.js +20 -0
  78. package/dist/helperComponents/CollapseBlockPrivate/index.d.ts +1 -0
  79. package/dist/helperComponents/CollapseBlockPrivate/index.js +1 -0
  80. package/dist/helperComponents/CollapseBlockPrivate/styles.module.css +38 -0
  81. package/dist/helperComponents/HiddenTabButton/HiddenTabButton.d.ts +6 -0
  82. package/dist/helperComponents/HiddenTabButton/HiddenTabButton.js +17 -0
  83. package/dist/helperComponents/HiddenTabButton/index.d.ts +1 -0
  84. package/dist/helperComponents/HiddenTabButton/index.js +1 -0
  85. package/dist/helperComponents/HiddenTabButton/styles.module.css +9 -0
  86. package/dist/helperComponents/Separator/Separator.d.ts +7 -0
  87. package/dist/helperComponents/Separator/Separator.js +12 -0
  88. package/dist/helperComponents/Separator/index.d.ts +1 -0
  89. package/dist/helperComponents/Separator/index.js +1 -0
  90. package/dist/helperComponents/Separator/styles.module.css +112 -0
  91. package/dist/helperComponents/index.d.ts +3 -0
  92. package/dist/helperComponents/index.js +3 -0
  93. package/dist/index.d.ts +1 -0
  94. package/dist/index.js +1 -0
  95. package/dist/types.d.ts +12 -0
  96. package/dist/types.js +1 -0
  97. package/dist/utils.d.ts +18 -0
  98. package/dist/utils.js +69 -0
  99. package/package.json +48 -0
  100. package/src/components/Items/AccordionItem/AccordionItem.tsx +60 -0
  101. package/src/components/Items/AccordionItem/index.ts +1 -0
  102. package/src/components/Items/BaseItem/BaseItem.tsx +150 -0
  103. package/src/components/Items/BaseItem/constants.ts +7 -0
  104. package/src/components/Items/BaseItem/index.ts +1 -0
  105. package/src/components/Items/BaseItem/styles.module.scss +190 -0
  106. package/src/components/Items/GroupItem/GroupItem.tsx +17 -0
  107. package/src/components/Items/GroupItem/index.ts +1 -0
  108. package/src/components/Items/NextListItem/NextListItem.tsx +131 -0
  109. package/src/components/Items/NextListItem/hooks.ts +105 -0
  110. package/src/components/Items/NextListItem/index.ts +1 -0
  111. package/src/components/Items/PinGroupItem/PinGroupItem.tsx +28 -0
  112. package/src/components/Items/PinGroupItem/index.ts +1 -0
  113. package/src/components/Items/PinGroupItem/styles.module.scss +38 -0
  114. package/src/components/Items/SearchItem/SearchItem.tsx +52 -0
  115. package/src/components/Items/SearchItem/index.ts +1 -0
  116. package/src/components/Items/SearchItem/styles.module.scss +13 -0
  117. package/src/components/Items/hooks.tsx +101 -0
  118. package/src/components/Items/index.ts +9 -0
  119. package/src/components/Items/styles.module.scss +78 -0
  120. package/src/components/Items/types.ts +61 -0
  121. package/src/components/Items/utils.ts +69 -0
  122. package/src/components/Lists/Droplist/DropList.tsx +166 -0
  123. package/src/components/Lists/Droplist/index.ts +1 -0
  124. package/src/components/Lists/List/List.tsx +120 -0
  125. package/src/components/Lists/List/index.ts +1 -0
  126. package/src/components/Lists/ListPrivate/ListPrivate.tsx +149 -0
  127. package/src/components/Lists/ListPrivate/index.ts +1 -0
  128. package/src/components/Lists/ListPrivate/styles.module.scss +48 -0
  129. package/src/components/Lists/contexts/CollapseProvider.ts +9 -0
  130. package/src/components/Lists/contexts/ListProvider.tsx +24 -0
  131. package/src/components/Lists/contexts/ParentListProvider.tsx +35 -0
  132. package/src/components/Lists/contexts/SelectionProvider.tsx +171 -0
  133. package/src/components/Lists/contexts/index.ts +4 -0
  134. package/src/components/Lists/hooks.ts +99 -0
  135. package/src/components/Lists/index.ts +10 -0
  136. package/src/components/Lists/styles.module.scss +73 -0
  137. package/src/components/Lists/types.ts +47 -0
  138. package/src/components/index.ts +3 -0
  139. package/src/helperComponents/CollapseBlockPrivate/CollapseBlockPrivate.tsx +34 -0
  140. package/src/helperComponents/CollapseBlockPrivate/index.ts +1 -0
  141. package/src/helperComponents/CollapseBlockPrivate/styles.module.scss +51 -0
  142. package/src/helperComponents/HiddenTabButton/HiddenTabButton.tsx +27 -0
  143. package/src/helperComponents/HiddenTabButton/index.ts +1 -0
  144. package/src/helperComponents/HiddenTabButton/styles.module.scss +11 -0
  145. package/src/helperComponents/Separator/Separator.tsx +33 -0
  146. package/src/helperComponents/Separator/index.ts +1 -0
  147. package/src/helperComponents/Separator/styles.module.scss +63 -0
  148. package/src/helperComponents/index.ts +3 -0
  149. package/src/index.ts +1 -0
  150. package/src/types.ts +14 -0
  151. package/src/utils.ts +106 -0
@@ -0,0 +1 @@
1
+ export * from './GroupItem';
@@ -0,0 +1 @@
1
+ export * from './GroupItem';
@@ -0,0 +1,2 @@
1
+ import { NextListItemProps } from '../types';
2
+ export declare function NextListItem({ items: itemsProp, placement, id, search, scroll, scrollRef, disabled, ...option }: NextListItemProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,66 @@
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
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { useCallback, useMemo, useRef, useState } from 'react';
14
+ import { Dropdown } from '@snack-uikit/dropdown';
15
+ import { ChevronRightSVG } from '@snack-uikit/icons';
16
+ import { withCollapsedItems } from '../../../utils';
17
+ import { ParentListContext, useParentListContext } from '../../Lists/contexts';
18
+ import { ListPrivate } from '../../Lists/ListPrivate';
19
+ import { BaseItem } from '../BaseItem';
20
+ import { useGroupItemSelection } from '../hooks';
21
+ import { useKeyboardNavigation } from './hooks';
22
+ const FALLBACK_PLACEMENTS = [
23
+ 'right',
24
+ 'right-start',
25
+ 'right-end',
26
+ 'left',
27
+ 'left-start',
28
+ 'left-end',
29
+ ];
30
+ export function NextListItem(_a) {
31
+ var { items: itemsProp, placement = 'right-start', id, search, scroll, scrollRef, disabled } = _a, option = __rest(_a, ["items", "placement", "id", "search", "scroll", "scrollRef", "disabled"]);
32
+ const listRef = useRef(null);
33
+ const [openCollapsedItems, setOpenCollapsedItems] = useState([]);
34
+ const { items, itemRefs, ids, expandedIds } = useMemo(() => withCollapsedItems({
35
+ items: itemsProp,
36
+ openCollapsedItems,
37
+ }), [itemsProp, openCollapsedItems]);
38
+ const { parentOpenNestedIndex, parentIds, triggerRef, parentResetNestedIndex, parentResetActiveFocusIndex } = useParentListContext();
39
+ const { open, setOpen, handleListKeyDown, activeFocusIndex, openNestedIndex, resetNestedIndex, resetActiveFocusIndex, } = useKeyboardNavigation({ ids, expandedIds, itemRefs, id });
40
+ const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items: itemsProp, id, disabled });
41
+ const handleOpenChange = useCallback((open) => {
42
+ if (!open) {
43
+ resetActiveFocusIndex();
44
+ resetNestedIndex();
45
+ setOpenCollapsedItems([]);
46
+ }
47
+ setOpen(open);
48
+ }, [resetActiveFocusIndex, resetNestedIndex, setOpen]);
49
+ const handleOutsideClick = useCallback(() => {
50
+ parentResetNestedIndex === null || parentResetNestedIndex === void 0 ? void 0 : parentResetNestedIndex();
51
+ parentResetActiveFocusIndex === null || parentResetActiveFocusIndex === void 0 ? void 0 : parentResetActiveFocusIndex();
52
+ return true;
53
+ }, [parentResetActiveFocusIndex, parentResetNestedIndex]);
54
+ return (_jsx("li", { style: { listStyleType: 'none' }, children: _jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ParentListContext.Provider, { value: {
55
+ parentIds: ids,
56
+ parentActiveFocusIndex: activeFocusIndex,
57
+ parentExpandedIds: expandedIds,
58
+ parentItemRefs: itemRefs,
59
+ parentOpenNestedIndex: openNestedIndex,
60
+ triggerRef,
61
+ parentRef: listRef,
62
+ parentResetNestedIndex: resetNestedIndex,
63
+ parentResetActiveFocusIndex: resetActiveFocusIndex,
64
+ toggleOpenCollapsedItems: id => setOpenCollapsedItems(items => items.includes(id) ? items.filter(item => item !== id) : items.concat([id])),
65
+ }, children: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: items, nested: true, search: search, scroll: scroll, scrollRef: scrollRef }) }), trigger: 'hover', open: (open || parentIds[parentOpenNestedIndex] === id) && !disabled, onOpenChange: handleOpenChange, placement: placement, children: _jsx(BaseItem, Object.assign({}, option, { disabled: disabled, open: open, expandIcon: _jsx(ChevronRightSVG, {}), id: id, isParentNode: true, indeterminate: isIndeterminate && !checked, onSelect: handleOnSelect })) }) }));
66
+ }
@@ -0,0 +1,19 @@
1
+ import { KeyboardEvent, RefObject } from 'react';
2
+ type UseKeyboardNavigationProps = {
3
+ ids: Array<number | string>;
4
+ expandedIds: Array<number | string>;
5
+ itemRefs?: RefObject<HTMLButtonElement>[];
6
+ id?: string | number;
7
+ };
8
+ export declare function useKeyboardNavigation({ ids, expandedIds, itemRefs, id }: UseKeyboardNavigationProps): {
9
+ activeFocusIndex: number;
10
+ setActiveFocusIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
11
+ openNestedIndex: number;
12
+ setOpenNestedIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
13
+ resetNestedIndex: () => void;
14
+ resetActiveFocusIndex: () => void;
15
+ handleListKeyDown: (e: KeyboardEvent<HTMLUListElement>) => void;
16
+ open: boolean;
17
+ setOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
18
+ };
19
+ export {};
@@ -0,0 +1,80 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { useParentListContext } from '../../Lists/contexts';
3
+ export function useKeyboardNavigation({ ids, expandedIds, itemRefs, id }) {
4
+ const { triggerRef, parentResetNestedIndex, parentIds, parentItemRefs, parentOpenNestedIndex } = useParentListContext();
5
+ const [activeFocusIndex, setActiveFocusIndex] = useState(-1);
6
+ const [openNestedIndex, setOpenNestedIndex] = useState(-1);
7
+ const [open, setOpen] = useState(false);
8
+ const handleListKeyDown = (e) => {
9
+ var _a, _b;
10
+ switch (e.key) {
11
+ case 'ArrowDown': {
12
+ setActiveFocusIndex(activeIndex => Math.min(activeIndex + 1, ids.length - 1));
13
+ e.stopPropagation();
14
+ e.preventDefault();
15
+ return;
16
+ }
17
+ case 'ArrowUp': {
18
+ setActiveFocusIndex(activeIndex => Math.max(activeIndex - 1, 0));
19
+ e.preventDefault();
20
+ e.stopPropagation();
21
+ return;
22
+ }
23
+ case 'ArrowRight': {
24
+ e.stopPropagation();
25
+ e.preventDefault();
26
+ if (expandedIds.includes(ids[activeFocusIndex])) {
27
+ setOpenNestedIndex(activeFocusIndex);
28
+ }
29
+ return;
30
+ }
31
+ case 'ArrowLeft': {
32
+ (_a = parentItemRefs === null || parentItemRefs === void 0 ? void 0 : parentItemRefs[parentOpenNestedIndex].current) === null || _a === void 0 ? void 0 : _a.focus();
33
+ parentResetNestedIndex === null || parentResetNestedIndex === void 0 ? void 0 : parentResetNestedIndex();
34
+ setActiveFocusIndex(-1);
35
+ setOpenNestedIndex(-1);
36
+ setOpen(false);
37
+ e.stopPropagation();
38
+ e.preventDefault();
39
+ return;
40
+ }
41
+ case 'Tab': {
42
+ (_b = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current) === null || _b === void 0 ? void 0 : _b.focus();
43
+ parentResetNestedIndex === null || parentResetNestedIndex === void 0 ? void 0 : parentResetNestedIndex();
44
+ setActiveFocusIndex(-1);
45
+ setOpen(false);
46
+ e.preventDefault();
47
+ return;
48
+ }
49
+ default: {
50
+ break;
51
+ }
52
+ }
53
+ };
54
+ useEffect(() => {
55
+ var _a, _b;
56
+ (_b = (_a = itemRefs === null || itemRefs === void 0 ? void 0 : itemRefs[activeFocusIndex]) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.focus();
57
+ }, [activeFocusIndex, itemRefs]);
58
+ useEffect(() => {
59
+ if (parentIds[parentOpenNestedIndex] === id && openNestedIndex === -1) {
60
+ setOpen(true);
61
+ setActiveFocusIndex(activeIndex => (activeIndex === -1 ? 0 : activeIndex));
62
+ }
63
+ }, [id, openNestedIndex, parentIds, parentOpenNestedIndex]);
64
+ const resetNestedIndex = () => {
65
+ setActiveFocusIndex(openNestedIndex);
66
+ setOpenNestedIndex(-1);
67
+ };
68
+ const resetActiveFocusIndex = useCallback(() => setActiveFocusIndex(-1), []);
69
+ return {
70
+ activeFocusIndex,
71
+ setActiveFocusIndex,
72
+ openNestedIndex,
73
+ setOpenNestedIndex,
74
+ resetNestedIndex,
75
+ resetActiveFocusIndex,
76
+ handleListKeyDown,
77
+ open,
78
+ setOpen,
79
+ };
80
+ }
@@ -0,0 +1 @@
1
+ export * from './NextListItem';
@@ -0,0 +1 @@
1
+ export * from './NextListItem';
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+ export declare function PinTopGroupItem({ children }: {
3
+ children: ReactNode;
4
+ }): import("react/jsx-runtime").JSX.Element | null;
5
+ export declare function PinBottomGroupItem({ children }: {
6
+ children: ReactNode;
7
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import cn from 'classnames';
3
+ import styles from './styles.module.css';
4
+ export function PinTopGroupItem({ children }) {
5
+ if (!children) {
6
+ return null;
7
+ }
8
+ return (_jsx("div", { className: cn(styles.pinTopItem), "data-test-id": 'list__pin-top-group-item', children: children }));
9
+ }
10
+ export function PinBottomGroupItem({ children }) {
11
+ if (!children) {
12
+ return null;
13
+ }
14
+ return (_jsx("div", { className: cn(styles.pinBottomItem), "data-test-id": 'list__pin-bottom-group-item', children: children }));
15
+ }
@@ -0,0 +1 @@
1
+ export * from './PinGroupItem';
@@ -0,0 +1 @@
1
+ export * from './PinGroupItem';
@@ -0,0 +1,31 @@
1
+ .pinTopItem{
2
+ padding-bottom:var(--radius-drop-list-container, 8px);
3
+ border-bottom:var(--border-width-droplist-pin-content, 1px);
4
+ display:flex;
5
+ flex-direction:column;
6
+ border-color:var(--sys-neutral-decor-default, #dedede);
7
+ border-style:solid;
8
+ border-top:0;
9
+ border-right:0;
10
+ border-left:0;
11
+ }
12
+ .pinTopItem li,
13
+ .pinTopItem ul{
14
+ list-style-type:none;
15
+ }
16
+
17
+ .pinBottomItem{
18
+ padding-top:var(--radius-drop-list-container, 8px);
19
+ border-top:var(--border-width-droplist-pin-content, 1px);
20
+ display:flex;
21
+ flex-direction:column;
22
+ border-color:var(--sys-neutral-decor-default, #dedede);
23
+ border-style:solid;
24
+ border-right:0;
25
+ border-bottom:0;
26
+ border-left:0;
27
+ }
28
+ .pinBottomItem li,
29
+ .pinBottomItem ul{
30
+ list-style-type:none;
31
+ }
@@ -0,0 +1,5 @@
1
+ import { SearchState } from '../../../types';
2
+ export type SearchItemProps = {
3
+ search?: SearchState;
4
+ };
5
+ export declare function SearchItem({ search }: SearchItemProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import cn from 'classnames';
3
+ import { SearchPrivate } from '@snack-uikit/search-private';
4
+ import { useListContext, useParentListContext } from '../../Lists/contexts';
5
+ import commonStyles from '../styles.module.css';
6
+ import styles from './styles.module.css';
7
+ export function SearchItem({ search }) {
8
+ const { parentItemRefs, parentSetActiveFocusIndex } = useParentListContext();
9
+ const { size } = useListContext();
10
+ const handleKeyDown = (e) => {
11
+ if (['ArrowDown', 'ArrowUp'].includes(e.key)) {
12
+ e.preventDefault();
13
+ }
14
+ if (['ArrowRight'].includes(e.key)) {
15
+ e.stopPropagation();
16
+ }
17
+ };
18
+ const handleFocus = (e) => {
19
+ if (e.target === parentItemRefs[0].current) {
20
+ parentSetActiveFocusIndex === null || parentSetActiveFocusIndex === void 0 ? void 0 : parentSetActiveFocusIndex(0);
21
+ }
22
+ e.stopPropagation();
23
+ };
24
+ if (!Boolean(search)) {
25
+ return null;
26
+ }
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: parentItemRefs[0] })) }));
28
+ }
@@ -0,0 +1 @@
1
+ export * from './SearchItem';
@@ -0,0 +1 @@
1
+ export * from './SearchItem';
@@ -0,0 +1,11 @@
1
+ .searchItem{
2
+ width:100%;
3
+ }
4
+ .searchItem:focus-within, .searchItem:focus-visible{
5
+ outline-width:var(--border-state-focus-s-border-width, 2px);
6
+ outline-style:var(--border-state-focus-s-border-style, solid);
7
+ outline-color:var(--border-state-focus-s-border-color, );
8
+ outline-offset:calc(var(--border-state-focus-s-border-width, 2px) * -1);
9
+ max-width:100%;
10
+ outline-color:var(--sys-primary-decor-activated, #c5b2f1);
11
+ }
@@ -0,0 +1,22 @@
1
+ import { RefObject } from 'react';
2
+ import { ItemProps } from './types';
3
+ export declare function useRenderItems(items: ItemProps[]): import("react/jsx-runtime").JSX.Element[];
4
+ type UseItemsWithIdsProps = {
5
+ search?: boolean;
6
+ footerActiveElementsRefs?: RefObject<HTMLElement>[];
7
+ };
8
+ export declare function useItemsWithIds({ search, footerActiveElementsRefs }: UseItemsWithIdsProps): {
9
+ search: ItemProps[];
10
+ footerRefs: ItemProps[];
11
+ };
12
+ type UseGroupItemSelectionProps = {
13
+ items: ItemProps[];
14
+ id?: string | number;
15
+ disabled?: boolean;
16
+ };
17
+ export declare function useGroupItemSelection({ id, items, disabled }: UseGroupItemSelectionProps): {
18
+ checked: boolean | undefined;
19
+ isIndeterminate: boolean;
20
+ handleOnSelect: () => void;
21
+ };
22
+ export {};
@@ -0,0 +1,61 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { createRef, useEffect, useMemo } from 'react';
3
+ import { extractChildIds } from '../../utils';
4
+ import { useSelectionContext } from '../Lists/contexts';
5
+ import { AccordionItem } from './AccordionItem';
6
+ import { BaseItem } from './BaseItem';
7
+ import { GroupItem } from './GroupItem';
8
+ import { NextListItem } from './NextListItem';
9
+ import { addItemsIds, isAccordionItemProps, isGroupItemProps, isNextListItemProps } from './utils';
10
+ export function useRenderItems(items) {
11
+ return useMemo(() => items.map((item, idx) => {
12
+ if (isGroupItemProps(item)) {
13
+ return _createElement(GroupItem, Object.assign({}, item, { key: item.id }));
14
+ }
15
+ if (isAccordionItemProps(item)) {
16
+ return _createElement(AccordionItem, Object.assign({}, item, { key: idx }));
17
+ }
18
+ if (isNextListItemProps(item)) {
19
+ return _createElement(NextListItem, Object.assign({}, item, { key: item.id }));
20
+ }
21
+ return _createElement(BaseItem, Object.assign({}, item, { key: item.id }));
22
+ }), [items]);
23
+ }
24
+ export function useItemsWithIds({ search, footerActiveElementsRefs }) {
25
+ return useMemo(() => ({
26
+ search: addItemsIds(search ? [{ itemRef: createRef() }] : [], 'search'),
27
+ footerRefs: addItemsIds(footerActiveElementsRefs
28
+ ? footerActiveElementsRefs === null || footerActiveElementsRefs === void 0 ? void 0 : footerActiveElementsRefs.map(ref => ({ itemRef: ref }))
29
+ : [], 'footer'),
30
+ }), [footerActiveElementsRefs, search]);
31
+ }
32
+ export function useGroupItemSelection({ id, items, disabled }) {
33
+ const { value, setValue, isSelectionMultiple } = useSelectionContext();
34
+ const childIds = useMemo(() => extractChildIds({ items }), [items]);
35
+ const isIndeterminate = isSelectionMultiple
36
+ ? childIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
37
+ : childIds.includes(value !== null && value !== void 0 ? value : '');
38
+ const checked = isSelectionMultiple ? childIds.every(childId => value === null || value === void 0 ? void 0 : value.includes(childId)) : undefined;
39
+ useEffect(() => {
40
+ if (isSelectionMultiple) {
41
+ if (checked && !(value === null || value === void 0 ? void 0 : value.includes(id))) {
42
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([id !== null && id !== void 0 ? id : '']));
43
+ }
44
+ if (!checked && (value === null || value === void 0 ? void 0 : value.includes(id))) {
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]);
49
+ const handleOnSelect = () => {
50
+ if (checked) {
51
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !childIds.includes(itemId)));
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])));
56
+ return;
57
+ }
58
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([...childIds, id !== null && id !== void 0 ? id : '']));
59
+ };
60
+ return { checked, isIndeterminate, handleOnSelect };
61
+ }
@@ -0,0 +1,9 @@
1
+ export * from './BaseItem';
2
+ export * from './NextListItem';
3
+ export * from './AccordionItem';
4
+ export * from './GroupItem';
5
+ export * from './SearchItem';
6
+ export * from './hooks';
7
+ export * from './types';
8
+ export * from './utils';
9
+ export * from './PinGroupItem';
@@ -0,0 +1,9 @@
1
+ export * from './BaseItem';
2
+ export * from './NextListItem';
3
+ export * from './AccordionItem';
4
+ export * from './GroupItem';
5
+ export * from './SearchItem';
6
+ export * from './hooks';
7
+ export * from './types';
8
+ export * from './utils';
9
+ export * from './PinGroupItem';
@@ -0,0 +1,74 @@
1
+ .listItem{
2
+ cursor:pointer;
3
+ position:relative;
4
+ display:flex;
5
+ flex-direction:row;
6
+ align-items:center;
7
+ box-sizing:border-box;
8
+ width:-moz-max-content;
9
+ width:max-content;
10
+ min-width:100%;
11
+ margin:0;
12
+ padding:0;
13
+ color:var(--sys-neutral-text-main, #333333);
14
+ text-align:start;
15
+ -webkit-appearance:unset;
16
+ -moz-appearance:unset;
17
+ appearance:unset;
18
+ background-color:transparent;
19
+ border:none;
20
+ outline:none;
21
+ }
22
+ .listItem[data-size=s]{
23
+ padding-top:var(--space-drop-list-item-s-container-vertical-padding, 4px);
24
+ padding-bottom:var(--space-drop-list-item-s-container-vertical-padding, 4px);
25
+ padding-left:var(--space-drop-list-item-s-container-horizontal-padding, 8px);
26
+ padding-right:var(--space-drop-list-item-s-container-horizontal-padding, 8px);
27
+ gap:var(--space-drop-list-item-s-container-gap, 8px);
28
+ }
29
+ .listItem[data-size=m]{
30
+ padding-top:var(--space-drop-list-item-m-container-vertical-padding, 8px);
31
+ padding-bottom:var(--space-drop-list-item-m-container-vertical-padding, 8px);
32
+ padding-left:var(--space-drop-list-item-m-container-horizontal-padding, 10px);
33
+ padding-right:var(--space-drop-list-item-m-container-horizontal-padding, 10px);
34
+ gap:var(--space-drop-list-item-m-container-gap, 8px);
35
+ }
36
+ .listItem[data-size=l]{
37
+ padding-top:var(--space-drop-list-item-l-container-vertical-padding, 12px);
38
+ padding-bottom:var(--space-drop-list-item-l-container-vertical-padding, 12px);
39
+ padding-left:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
40
+ padding-right:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
41
+ gap:var(--space-drop-list-item-l-container-gap, 8px);
42
+ }
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-open]::after, .listItem[data-focused]::after, .listItem:hover::after, .listItem:focus-visible::after{
54
+ opacity:var(--opacity-a008, 0.08);
55
+ background-color:var(--sys-neutral-accent-default, #757575);
56
+ }
57
+ .listItem[data-focused], .listItem:focus-visible{
58
+ outline-width:var(--border-state-focus-s-border-width, 2px);
59
+ outline-style:var(--border-state-focus-s-border-style, solid);
60
+ outline-color:var(--border-state-focus-s-border-color, );
61
+ outline-offset:calc(var(--border-state-focus-s-border-width, 2px) * -1);
62
+ }
63
+ .listItem:disabled{
64
+ cursor:not-allowed;
65
+ background-color:transparent;
66
+ outline:none;
67
+ }
68
+ .listItem:disabled::before{
69
+ display:none;
70
+ }
71
+ .listItem:disabled::after{
72
+ cursor:not-allowed;
73
+ background-color:transparent;
74
+ }
@@ -0,0 +1,43 @@
1
+ import { FocusEvent, KeyboardEvent, MouseEvent, ReactNode, RefObject } from 'react';
2
+ import { WithSupportProps } from '@snack-uikit/utils';
3
+ import { SeparatorProps } from '../../helperComponents';
4
+ import { ScrollProps, SearchState } from '../../types';
5
+ export type ItemContentProps = {
6
+ option: string;
7
+ caption?: string;
8
+ description?: string;
9
+ };
10
+ export type BaseItemPrivateProps = {
11
+ expandIcon?: ReactNode;
12
+ open?: boolean;
13
+ };
14
+ export type BaseItemProps = WithSupportProps<{
15
+ beforeContent?: ReactNode;
16
+ afterContent?: ReactNode;
17
+ content: ItemContentProps;
18
+ onClick?(e: MouseEvent<HTMLButtonElement>): void;
19
+ onKeyDown?(e: KeyboardEvent<HTMLButtonElement>): void;
20
+ onFocus?(e: FocusEvent<HTMLButtonElement>): void;
21
+ onBlur?(e: FocusEvent<HTMLButtonElement>): void;
22
+ id?: string | number;
23
+ disabled?: boolean;
24
+ itemRef?: RefObject<HTMLButtonElement>;
25
+ }>;
26
+ export type SwitchProps = {
27
+ switch?: boolean;
28
+ };
29
+ export type ItemProps = (BaseItemProps & SwitchProps) | AccordionItemProps | NextListItemProps | GroupItemProps;
30
+ export type AccordionItemProps = BaseItemProps & {
31
+ items: ItemProps[];
32
+ type: 'collapse';
33
+ };
34
+ export type NextListItemProps = BaseItemProps & {
35
+ items: ItemProps[];
36
+ type: 'next-list';
37
+ placement?: 'right-start' | 'left-start' | 'left' | 'right' | 'left-end' | 'right-end';
38
+ search?: SearchState;
39
+ } & ScrollProps;
40
+ export type GroupItemProps = SeparatorProps & {
41
+ items: ItemProps[];
42
+ id?: string | number;
43
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { AccordionItemProps, BaseItemProps, GroupItemProps, ItemProps, NextListItemProps } from './types';
2
+ export declare function isBaseItemProps(item: any): item is BaseItemProps;
3
+ export declare function isAccordionItemProps(item: any): item is AccordionItemProps;
4
+ export declare function isNextListItemProps(item: any): item is NextListItemProps;
5
+ export declare function isGroupItemProps(item: any): item is GroupItemProps;
6
+ export declare function getSlicedItems({ items, hasSearch, pinTop, pinBottom, footerRefs, }: {
7
+ items: ItemProps[];
8
+ hasSearch: boolean;
9
+ footerRefs: ItemProps[];
10
+ pinTop?: ItemProps[];
11
+ pinBottom?: ItemProps[];
12
+ }): {
13
+ pinTop: ItemProps[];
14
+ items: ItemProps[];
15
+ pinBottom: ItemProps[];
16
+ };
17
+ export declare function addItemsIds(itemsProp: ItemProps[], prefix?: string | number): ItemProps[];
@@ -0,0 +1,42 @@
1
+ import { createRef } from 'react';
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ export function isBaseItemProps(item) {
4
+ return 'content' in item;
5
+ }
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ export function isAccordionItemProps(item) {
8
+ return 'items' in item && item['type'] === 'collapse';
9
+ }
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ export function isNextListItemProps(item) {
12
+ return 'items' in item && item['type'] === 'next-list';
13
+ }
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ export function isGroupItemProps(item) {
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
+ };
29
+ }
30
+ export function addItemsIds(itemsProp, prefix) {
31
+ return itemsProp.map((item, idx) => {
32
+ var _a;
33
+ const itemId = (_a = item.id) !== null && _a !== void 0 ? _a : (prefix !== undefined ? [prefix, idx].join('-') : String(idx));
34
+ if (isGroupItemProps(item)) {
35
+ return Object.assign(Object.assign({}, item), { id: itemId, items: addItemsIds(item.items, itemId) });
36
+ }
37
+ if (isAccordionItemProps(item) || isNextListItemProps(item)) {
38
+ return Object.assign(Object.assign({}, item), { id: itemId, items: addItemsIds(item.items, itemId), itemRef: item.itemRef || createRef() });
39
+ }
40
+ return Object.assign(Object.assign({}, item), { id: itemId, itemRef: item.itemRef || createRef() });
41
+ });
42
+ }
@@ -0,0 +1,2 @@
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, ...props }: DroplistProps): import("react/jsx-runtime").JSX.Element;