@snack-uikit/list 0.9.2-preview-c8f85f20.0 → 0.9.2-preview-2855fb42.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 (105) hide show
  1. package/README.md +51 -23
  2. package/dist/components/Items/AccordionItem/AccordionItem.d.ts +2 -2
  3. package/dist/components/Items/AccordionItem/AccordionItem.js +19 -16
  4. package/dist/components/Items/BaseItem/BaseItem.d.ts +6 -4
  5. package/dist/components/Items/BaseItem/BaseItem.js +22 -16
  6. package/dist/components/Items/BaseItem/styles.module.css +9 -122
  7. package/dist/components/Items/GroupItem/GroupItem.d.ts +2 -2
  8. package/dist/components/Items/GroupItem/GroupItem.js +3 -3
  9. package/dist/components/Items/NextListItem/NextListItem.d.ts +2 -2
  10. package/dist/components/Items/NextListItem/NextListItem.js +37 -36
  11. package/dist/components/Items/SearchItem/SearchItem.d.ts +3 -1
  12. package/dist/components/Items/SearchItem/SearchItem.js +7 -8
  13. package/dist/components/Items/hooks.d.ts +15 -10
  14. package/dist/components/Items/hooks.js +48 -46
  15. package/dist/components/Items/types.d.ts +41 -26
  16. package/dist/components/Items/utils.d.ts +7 -17
  17. package/dist/components/Items/utils.js +3 -31
  18. package/dist/components/Lists/Droplist/DropList.d.ts +2 -1
  19. package/dist/components/Lists/Droplist/DropList.js +85 -50
  20. package/dist/components/Lists/List/List.d.ts +7 -11
  21. package/dist/components/Lists/List/List.js +61 -53
  22. package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +18 -20
  23. package/dist/components/Lists/ListPrivate/ListPrivate.js +10 -9
  24. package/dist/components/Lists/contexts/CollapseProvider.d.ts +13 -1
  25. package/dist/components/Lists/contexts/CollapseProvider.js +2 -0
  26. package/dist/components/Lists/contexts/FocusListProvider.d.ts +9 -0
  27. package/dist/components/Lists/contexts/FocusListProvider.js +5 -0
  28. package/dist/components/Lists/contexts/NewListProvider.d.ts +27 -0
  29. package/dist/components/Lists/contexts/{ListProvider.js → NewListProvider.js} +10 -5
  30. package/dist/components/Lists/contexts/SelectionProvider.d.ts +28 -15
  31. package/dist/components/Lists/contexts/SelectionProvider.js +14 -8
  32. package/dist/components/Lists/contexts/index.d.ts +2 -2
  33. package/dist/components/Lists/contexts/index.js +2 -2
  34. package/dist/components/Lists/hooks.d.ts +11 -11
  35. package/dist/components/Lists/hooks.js +80 -41
  36. package/dist/components/Lists/types.d.ts +19 -15
  37. package/dist/helperComponents/ItemContent/ItemContent.d.ts +15 -0
  38. package/dist/helperComponents/ItemContent/ItemContent.js +23 -0
  39. package/dist/helperComponents/ItemContent/index.d.ts +1 -0
  40. package/dist/helperComponents/ItemContent/index.js +1 -0
  41. package/dist/helperComponents/ItemContent/styles.module.css +117 -0
  42. package/dist/helperComponents/ListEmptyState/ListEmptyState.d.ts +2 -2
  43. package/dist/helperComponents/ListEmptyState/ListEmptyState.js +13 -4
  44. package/dist/helperComponents/index.d.ts +1 -0
  45. package/dist/helperComponents/index.js +1 -0
  46. package/dist/hooks.d.ts +1 -1
  47. package/dist/hooks.js +15 -10
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.js +3 -2
  50. package/dist/legacy/components/Items/hooks.d.ts +12 -0
  51. package/dist/legacy/components/Items/hooks.js +33 -0
  52. package/dist/legacy/components/index.d.ts +1 -0
  53. package/dist/legacy/components/index.js +1 -0
  54. package/dist/legacy/hooks.d.ts +5 -0
  55. package/dist/legacy/hooks.js +15 -0
  56. package/dist/legacy/index.d.ts +3 -0
  57. package/dist/legacy/index.js +3 -0
  58. package/dist/legacy/utils.d.ts +29 -0
  59. package/dist/legacy/utils.js +107 -0
  60. package/dist/types.d.ts +1 -1
  61. package/dist/utils.d.ts +27 -25
  62. package/dist/utils.js +75 -103
  63. package/package.json +12 -12
  64. package/src/components/Items/AccordionItem/AccordionItem.tsx +28 -20
  65. package/src/components/Items/BaseItem/BaseItem.tsx +50 -46
  66. package/src/components/Items/BaseItem/styles.module.scss +8 -70
  67. package/src/components/Items/GroupItem/GroupItem.tsx +6 -5
  68. package/src/components/Items/NextListItem/NextListItem.tsx +69 -79
  69. package/src/components/Items/SearchItem/SearchItem.tsx +8 -8
  70. package/src/components/Items/hooks.tsx +76 -69
  71. package/src/components/Items/types.ts +61 -31
  72. package/src/components/Items/utils.ts +9 -58
  73. package/src/components/Lists/Droplist/DropList.tsx +155 -102
  74. package/src/components/Lists/List/List.tsx +120 -105
  75. package/src/components/Lists/ListPrivate/ListPrivate.tsx +26 -27
  76. package/src/components/Lists/contexts/CollapseProvider.tsx +22 -0
  77. package/src/components/Lists/contexts/FocusListProvider.tsx +16 -0
  78. package/src/components/Lists/contexts/NewListProvider.tsx +49 -0
  79. package/src/components/Lists/contexts/SelectionProvider.tsx +63 -36
  80. package/src/components/Lists/contexts/index.ts +3 -2
  81. package/src/components/Lists/hooks.ts +139 -75
  82. package/src/components/Lists/types.ts +29 -27
  83. package/src/helperComponents/ItemContent/ItemContent.tsx +63 -0
  84. package/src/helperComponents/ItemContent/index.ts +1 -0
  85. package/src/helperComponents/ItemContent/styles.module.scss +78 -0
  86. package/src/helperComponents/ListEmptyState/ListEmptyState.tsx +26 -12
  87. package/src/helperComponents/index.ts +1 -0
  88. package/src/hooks.ts +21 -15
  89. package/src/index.ts +9 -2
  90. package/src/legacy/components/Items/hooks.tsx +53 -0
  91. package/src/legacy/components/index.ts +1 -0
  92. package/src/legacy/hooks.ts +27 -0
  93. package/src/legacy/index.ts +3 -0
  94. package/src/legacy/utils.ts +166 -0
  95. package/src/types.ts +1 -1
  96. package/src/utils.ts +154 -139
  97. package/dist/components/Items/NextListItem/hooks.d.ts +0 -19
  98. package/dist/components/Items/NextListItem/hooks.js +0 -80
  99. package/dist/components/Lists/contexts/ListProvider.d.ts +0 -17
  100. package/dist/components/Lists/contexts/ParentListProvider.d.ts +0 -18
  101. package/dist/components/Lists/contexts/ParentListProvider.js +0 -12
  102. package/src/components/Items/NextListItem/hooks.ts +0 -105
  103. package/src/components/Lists/contexts/CollapseProvider.ts +0 -9
  104. package/src/components/Lists/contexts/ListProvider.tsx +0 -28
  105. package/src/components/Lists/contexts/ParentListProvider.tsx +0 -35
package/README.md CHANGED
@@ -8,20 +8,13 @@
8
8
 
9
9
  [//]: DOCUMENTATION_SECTION_START
10
10
  [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
11
- ## useFuzzySearch
12
- Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
13
- ### Props
14
- | name | type | default value | description |
15
- |------|------|---------------|-------------|
16
- ## extractChildIds
11
+ ## kindFlattenItems
17
12
  ### Props
18
13
  | name | type | default value | description |
19
14
  |------|------|---------------|-------------|
20
- | items* | `ItemProps[]` | - | |
21
- ## flattenItems
22
- `flattenItems`
23
-
24
- Функция разворачивает массив айтемов в плоский список
15
+ | items* | `ItemProps<Meta>[]` | - | |
16
+ | prefix | `string \| number` | - | |
17
+ | parentId | `ItemId` | - | |
25
18
  ## isAccordionItemProps
26
19
  ### Props
27
20
  | name | type | default value | description |
@@ -42,8 +35,9 @@
42
35
  ### Props
43
36
  | name | type | default value | description |
44
37
  |------|------|---------------|-------------|
45
- | items* | `ItemProps[]` | - | |
46
- | id | `string \| number` | - | |
38
+ | id* | `ItemId` | - | |
39
+ | items* | `ItemId[]` | - | |
40
+ | allChildIds* | `ItemId[]` | - | |
47
41
  | disabled | `boolean` | - | |
48
42
  ## isSelectionSingleProps
49
43
  ### Props
@@ -57,25 +51,27 @@
57
51
  ### Props
58
52
  | name | type | default value | description |
59
53
  |------|------|---------------|-------------|
60
- | items* | `ItemProps[]` | - | Основные элементы списка |
54
+ | items* | `ItemProps<Meta>[]` | - | Основные элементы списка |
61
55
  | children* | `ReactNode \| ({onKeyDown}) => ReactNode * Рендер функция принимает аргументы `onKeyDown` - хендлер ввода, для поддержки управления с клавиатуры` | - | Триггер для дроплиста |
62
56
  | triggerElemRef | `RefObject<HTMLElement>` | - | Ссылка на элемент-триггер для дроплиста |
57
+ | triggerClassName | `string` | - | CSS-класс триггера |
63
58
  | open | `boolean` | - | Управляет состоянием показан/не показан. |
64
59
  | onOpenChange | `(isOpen: boolean) => void` | - | Колбек отображения компонента. Срабатывает при изменении состояния open. |
65
60
  | widthStrategy | enum PopoverWidthStrategy: `"auto"`, `"gte"`, `"eq"` | auto | Стратегия управления шириной контейнера поповера <br> - `auto` - соответствует ширине контента, <br> - `gte` - Great Than or Equal, равен ширине таргета или больше ее, если контент в поповере шире, <br> - `eq` - Equal, строго равен ширине таргета. |
66
61
  | trigger | enum Trigger: `"click"`, `"hover"`, `"focusVisible"`, `"focus"`, `"hoverAndFocusVisible"`, `"hoverAndFocus"`, `"clickAndFocusVisible"` | - | Условие отображения поповера: <br> - `click` - открывать по клику <br> - `hover` - открывать по ховеру <br> - `focusVisible` - открывать по focus-visible <br> - `focus` - открывать по фокусу <br> - `hoverAndFocusVisible` - открывать по ховеру и focus-visible <br> - `hoverAndFocus` - открывать по ховеру и фокусу <br> - `clickAndFocusVisible` - открывать по клику и focus-visible |
67
62
  | placement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Положение поповера относительно своего триггера (children). |
68
63
  | className | `string` | - | CSS-класс |
69
- | size | "s" \| "m" \| "l" | - | Размер списка |
70
- | pinTop | `ItemProps[]` | - | Элементы списка, закрепленные сверху |
71
- | pinBottom | `ItemProps[]` | - | Элементы списка, закрепленные снизу |
64
+ | size | "s" \| "m" \| "l" | s | Размер списка |
65
+ | pinTop | `ItemProps<Meta>[]` | - | Элементы списка, закрепленные сверху |
66
+ | pinBottom | `ItemProps<Meta>[]` | - | Элементы списка, закрепленные снизу |
72
67
  | footer | `ReactNode ;` | - | Кастомизируемый элемент в конце списка |
73
68
  | footerActiveElementsRefs | `RefObject<HTMLElement>[]` | - | Список ссылок на кастомные элементы, помещенные в специальную секцию внизу списка |
74
69
  | search | `SearchState` | - | Настройки поисковой строки |
75
70
  | collapse | `CollapseState` | {} | Настройки раскрытия элементов |
76
71
  | loading | `boolean` | - | Флаг, отвещающий за состояние загрузки списка |
77
72
  | selection | `SelectionSingleState \| SelectionMultipleState` | - | |
78
- | marker | `boolean` | - | Отображать ли маркер у выбранного жлемента списка |
73
+ | marker | `boolean` | true | Отображать ли маркер у выбранного жлемента списка |
74
+ | contentRender | `(props: ContentRenderProps<Meta>) => ReactNode` | - | Рендер функция основного контента айтема |
79
75
  | scroll | `boolean` | - | Включить ли скролл для основной части списка |
80
76
  | scrollRef | `RefObject<HTMLElement>` | - | Ссылка на элемент, обозначающий самый конец прокручиваемого списка |
81
77
  | scrollContainerRef | `RefObject<HTMLElement>` | - | Ссылка на контейнер, который скроллится |
@@ -88,9 +84,9 @@
88
84
  ### Props
89
85
  | name | type | default value | description |
90
86
  |------|------|---------------|-------------|
91
- | items* | `ItemProps[]` | - | Основные элементы списка |
92
- | pinTop | `ItemProps[]` | - | Элементы списка, закрепленные сверху |
93
- | pinBottom | `ItemProps[]` | - | Элементы списка, закрепленные снизу |
87
+ | items* | `ItemProps<unknown>[]` | - | Основные элементы списка |
88
+ | pinTop | `ItemProps<unknown>[]` | - | Элементы списка, закрепленные сверху |
89
+ | pinBottom | `ItemProps<unknown>[]` | - | Элементы списка, закрепленные снизу |
94
90
  | footer | `ReactNode ;` | - | Кастомизируемый элемент в конце списка |
95
91
  | footerActiveElementsRefs | `RefObject<HTMLElement>[]` | - | Список ссылок на кастомные элементы, помещенные в специальную секцию внизу списка |
96
92
  | search | `SearchState` | - | Настройки поисковой строки |
@@ -100,8 +96,9 @@
100
96
  | onKeyDown | `(e: KeyboardEvent<HTMLElement>) => void` | - | |
101
97
  | loading | `boolean` | - | Флаг, отвещающий за состояние загрузки списка |
102
98
  | selection | `SelectionSingleState \| SelectionMultipleState` | - | |
103
- | size | "s" \| "m" \| "l" | - | Размер списка |
104
- | marker | `boolean` | - | Отображать ли маркер у выбранного жлемента списка |
99
+ | size | "s" \| "m" \| "l" | s | Размер списка |
100
+ | marker | `boolean` | true | Отображать ли маркер у выбранного жлемента списка |
101
+ | contentRender | `(props: ContentRenderProps<unknown>) => ReactNode` | - | Рендер функция основного контента айтема |
105
102
  | scroll | `boolean` | - | Включить ли скролл для основной части списка |
106
103
  | scrollRef | `RefObject<HTMLElement>` | - | Ссылка на элемент, обозначающий самый конец прокручиваемого списка |
107
104
  | scrollContainerRef | `RefObject<HTMLElement>` | - | Ссылка на контейнер, который скроллится |
@@ -112,6 +109,37 @@
112
109
  | errorDataState | `EmptyStateProps` | - | Экран при ошибке запроса |
113
110
  | ref | `Ref<HTMLElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
114
111
  | key | `Key` | - | |
112
+ ## ItemContent
113
+ ### Props
114
+ | name | type | default value | description |
115
+ |------|------|---------------|-------------|
116
+ | option* | `string \| number` | - | |
117
+ | caption | `string` | - | |
118
+ | description | `string` | - | |
119
+ | truncate | `{ option?: number; description?: number; variant?: "end" \| "middle"; }` | - | |
120
+ | disabled | `boolean` | - | |
121
+ | className | `string` | - | CSS-класс |
122
+ ## useFuzzySearch
123
+ Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
124
+ ### Props
125
+ | name | type | default value | description |
126
+ |------|------|---------------|-------------|
127
+ ## extractChildIds
128
+ ### Props
129
+ | name | type | default value | description |
130
+ |------|------|---------------|-------------|
131
+ | items* | `ItemProps[]` | - | |
132
+ ## flattenItems
133
+ `flattenItems`
134
+
135
+ Функция разворачивает массив айтемов в плоский список
136
+ ## useLegacyGroupItemSelection
137
+ ### Props
138
+ | name | type | default value | description |
139
+ |------|------|---------------|-------------|
140
+ | items* | `ItemProps[]` | - | |
141
+ | id | `string \| number` | - | |
142
+ | disabled | `boolean` | - | |
115
143
 
116
144
 
117
145
  [//]: DOCUMENTATION_SECTION_END
@@ -1,2 +1,2 @@
1
- import { AccordionItemProps } from '../types';
2
- export declare function AccordionItem({ items: itemsProp, id, disabled, ...option }: AccordionItemProps): import("react/jsx-runtime").JSX.Element;
1
+ import { FlattenAccordionItem } from '../types';
2
+ export declare function AccordionItem<Meta>({ items, id, disabled, allChildIds, ...option }: FlattenAccordionItem<Meta>): import("react/jsx-runtime").JSX.Element;
@@ -10,29 +10,32 @@ 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 } from 'react';
13
14
  import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
14
15
  import { CollapseBlockPrivate } from '../../../helperComponents';
15
- import { CollapseContext, useCollapseContext, useParentListContext } from '../../Lists/contexts';
16
+ import { CollapseLevelContext, useCollapseContext, useCollapseLevelContext, useNewListContext, } from '../../Lists/contexts';
16
17
  import { BaseItem } from '../BaseItem';
17
18
  import { useGroupItemSelection, useRenderItems } from '../hooks';
18
19
  export function AccordionItem(_a) {
19
- var { items: itemsProp, id, disabled } = _a, option = __rest(_a, ["items", "id", "disabled"]);
20
- const { level = 1 } = useCollapseContext();
21
- const { toggleOpenCollapsedItems, openCollapsedItems } = useParentListContext();
22
- const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items: itemsProp, id, disabled });
23
- const isOpen = Boolean(openCollapsedItems === null || openCollapsedItems === void 0 ? void 0 : openCollapsedItems.includes(id !== null && id !== void 0 ? id : ''));
24
- const handleKeyDown = (e) => {
25
- if (e.key === 'ArrowRight') {
26
- toggleOpenCollapsedItems === null || toggleOpenCollapsedItems === void 0 ? void 0 : toggleOpenCollapsedItems(id !== null && id !== void 0 ? id : '');
27
- e.preventDefault();
28
- e.stopPropagation();
29
- }
30
- };
31
- const itemsJSX = useRenderItems(itemsProp);
20
+ var { items, id, disabled, allChildIds } = _a, option = __rest(_a, ["items", "id", "disabled", "allChildIds"]);
21
+ const { level = 1 } = useCollapseLevelContext();
22
+ const { openCollapseItems = [], toggleOpenCollapseItem } = useCollapseContext();
23
+ const { flattenedItems } = useNewListContext();
24
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({
25
+ items,
26
+ id,
27
+ disabled,
28
+ allChildIds,
29
+ });
30
+ const isOpen = Boolean(openCollapseItems.includes(id !== null && id !== void 0 ? id : ''));
31
+ const handleKeyDown = useCallback(() => {
32
+ toggleOpenCollapseItem === null || toggleOpenCollapseItem === void 0 ? void 0 : toggleOpenCollapseItem(id !== null && id !== void 0 ? id : '');
33
+ }, [id, toggleOpenCollapseItem]);
34
+ const itemsJSX = useRenderItems({ items, flattenedItems });
32
35
  const handleItemClick = (e) => {
33
36
  var _a;
34
- toggleOpenCollapsedItems === null || toggleOpenCollapsedItems === void 0 ? void 0 : toggleOpenCollapsedItems(id !== null && id !== void 0 ? id : '');
37
+ toggleOpenCollapseItem === null || toggleOpenCollapseItem === void 0 ? void 0 : toggleOpenCollapseItem(id !== null && id !== void 0 ? id : '');
35
38
  (_a = option.onClick) === null || _a === void 0 ? void 0 : _a.call(option, e);
36
39
  };
37
- return (_jsx(CollapseBlockPrivate, { header: _jsx(BaseItem, Object.assign({}, option, { id: id, disabled: disabled, expandIcon: isOpen ? _jsx(ChevronUpSVG, {}) : _jsx(ChevronDownSVG, {}), onClick: handleItemClick, isParentNode: true, onKeyDown: handleKeyDown, indeterminate: isIndeterminate && !checked, onSelect: !disabled ? handleOnSelect : undefined })), expanded: isOpen, "data-test-id": `list__accordion-item-${id}`, children: _jsx(CollapseContext.Provider, { value: { level: level + 1 }, children: itemsJSX }) }));
40
+ return (_jsx(CollapseBlockPrivate, { header: _jsx(BaseItem, Object.assign({}, option, { id: id, disabled: disabled, expandIcon: isOpen ? _jsx(ChevronUpSVG, {}) : _jsx(ChevronDownSVG, {}), onClick: handleItemClick, isParentNode: true, onOpenNestedList: handleKeyDown, checked: checked, indeterminate: indeterminate, onSelect: !disabled ? handleOnSelect : undefined })), expanded: isOpen, "data-test-id": `list__accordion-item-${id}`, children: _jsx(CollapseLevelContext.Provider, { value: { level: level + 1 }, children: itemsJSX }) }));
38
41
  }
@@ -1,9 +1,11 @@
1
- /// <reference types="react" />
2
- import { BaseItemPrivateProps, BaseItemProps } from '../types';
3
- type AllBaseItemProps = BaseItemProps & BaseItemPrivateProps & {
1
+ import { KeyboardEvent } from 'react';
2
+ import { AnyType, BaseItemPrivateProps, BaseItemProps } from '../types';
3
+ type AllBaseItemProps<Meta = AnyType> = BaseItemProps<Meta> & BaseItemPrivateProps & {
4
4
  indeterminate?: boolean;
5
+ checked?: boolean;
5
6
  onSelect?(): void;
6
7
  isParentNode?: boolean;
8
+ onOpenNestedList?(e?: KeyboardEvent<HTMLElement>): void;
7
9
  };
8
- export declare function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender, ...rest }: AllBaseItemProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
10
+ export declare function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, checked: checkedProp, onSelect, onOpenNestedList, isParentNode, className, inactive, itemWrapRender, meta, ...rest }: AllBaseItemProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
9
11
  export {};
@@ -12,38 +12,44 @@ 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 { Checkbox, Switch } from '@snack-uikit/toggles';
15
- import { TruncateString } from '@snack-uikit/truncate-string';
16
15
  import { extractSupportProps } from '@snack-uikit/utils';
17
- import { useCollapseContext, useListContext, useParentListContext, useSelectionContext } from '../../Lists/contexts';
16
+ import { ItemContent } from '../../../helperComponents';
17
+ import { useCollapseLevelContext, useFocusListContext, useNewListContext, useSelectionContext, } from '../../Lists/contexts';
18
18
  import commonStyles from '../styles.module.css';
19
+ import { isContentItemProps } from '../utils';
19
20
  import { CHECKBOX_SIZE_MAP } from './constants';
20
21
  import styles from './styles.module.css';
21
22
  export function BaseItem(_a) {
22
- var _b, _c;
23
- var { beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "onMouseDown", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "onSelect", "isParentNode", "className", "inactive", "itemWrapRender"]);
24
- const { option, caption, description, truncate: contentTruncate } = content || {};
23
+ var _b;
24
+ var { beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, checked: checkedProp, onSelect, onOpenNestedList, isParentNode, className, inactive, itemWrapRender, meta } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "onMouseDown", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "checked", "onSelect", "onOpenNestedList", "isParentNode", "className", "inactive", "itemWrapRender", "meta"]);
25
25
  const interactive = !inactive;
26
- const { parentResetActiveFocusIndex } = useParentListContext();
27
- const { size, marker, parent } = useListContext();
28
- const { level = 0 } = useCollapseContext();
26
+ const { size = 's', marker, contentRender } = useNewListContext();
27
+ const { level = 0 } = useCollapseLevelContext();
28
+ const { forceUpdateActiveItemId } = useFocusListContext();
29
29
  const { value, onChange, mode, isSelectionSingle, isSelectionMultiple } = useSelectionContext();
30
- const isChecked = isSelectionSingle ? value === id : value === null || value === void 0 ? void 0 : value.includes(id);
30
+ const isChecked = isSelectionSingle ? value === id : checkedProp !== null && checkedProp !== void 0 ? checkedProp : value === null || value === void 0 ? void 0 : value.includes(id !== null && id !== void 0 ? id : '');
31
31
  const handleChange = () => {
32
- onChange === null || onChange === void 0 ? void 0 : onChange(id !== null && id !== void 0 ? id : '');
32
+ onChange === null || onChange === void 0 ? void 0 : onChange(id !== null && id !== void 0 ? id : '', meta);
33
33
  };
34
- const handleItemMouseDown = (e) => {
34
+ const handleItemClick = (e) => {
35
35
  if (disabled)
36
36
  return;
37
37
  if (interactive) {
38
- parentResetActiveFocusIndex === null || parentResetActiveFocusIndex === void 0 ? void 0 : parentResetActiveFocusIndex();
39
38
  if (!isParentNode) {
40
39
  handleChange();
41
40
  }
42
41
  }
43
- onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(e);
42
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
43
+ forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId('~drop-focus');
44
44
  };
45
45
  const handleItemKeyDown = (e) => {
46
46
  onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
47
+ if (e.code === 'ArrowRight') {
48
+ onOpenNestedList === null || onOpenNestedList === void 0 ? void 0 : onOpenNestedList(e);
49
+ e.preventDefault();
50
+ e.stopPropagation();
51
+ return;
52
+ }
47
53
  if (e.code === 'Space' || e.key === 'Enter') {
48
54
  if (isSelectionMultiple && isParentNode && onSelect) {
49
55
  onSelect();
@@ -71,9 +77,9 @@ export function BaseItem(_a) {
71
77
  e.stopPropagation();
72
78
  };
73
79
  const props = extractSupportProps(rest);
74
- const item = (_jsxs("li", { "data-type": 'outside', role: 'menuitem', "data-test-id": props['data-test-id'] || 'list__base-item_' + id, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem, className), "data-size": size, onClick: onClick, onMouseDown: handleItemMouseDown, tabIndex: -1, "data-non-pointer": inactive && !onClick, "data-inactive": inactive || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "data-disabled": disabled || undefined, "aria-disabled": disabled || undefined, "data-parent": parent || 'list', onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, children: [!switchProp && isSelectionSingle && marker && !isParentNode && interactive && (_jsx("div", { className: styles.markerContainer, "data-test-id": 'list__base-item-marker' })), !switchProp && isSelectionMultiple && interactive && (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: CHECKBOX_SIZE_MAP[size !== null && size !== void 0 ? size : 's'], disabled: disabled, tabIndex: -1, onChange: handleCheckboxChange, checked: isChecked, "data-test-id": 'list__base-item-checkbox', onClick: handleCheckboxClick, indeterminate: indeterminate }) })), beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), _jsxs("div", { className: styles.content, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.option, children: _jsx(TruncateString, { variant: contentTruncate === null || contentTruncate === void 0 ? void 0 : contentTruncate.variant, text: option, maxLines: (_b = contentTruncate === null || contentTruncate === void 0 ? void 0 : contentTruncate.option) !== null && _b !== void 0 ? _b : 1, "data-test-id": 'list__base-item-option' }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: (_c = contentTruncate === null || contentTruncate === void 0 ? void 0 : contentTruncate.description) !== null && _c !== void 0 ? _c : 2, "data-test-id": 'list__base-item-description' }) }))] }), afterContent, switchProp && interactive && (_jsx(Switch, { disabled: disabled, checked: isChecked, "data-test-id": 'list__base-item-switch' })), !switchProp && expandIcon && _jsx("span", { className: styles.expandableIcon, children: expandIcon })] }));
80
+ const itemJSX = (_jsxs("li", { role: 'menuitem', "data-test-id": props['data-test-id'] || 'list__base-item_' + id, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem, className), "data-size": size, onClick: handleItemClick, onMouseDown: onMouseDown, tabIndex: -1, "data-non-pointer": inactive && !onClick, "data-inactive": inactive || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "data-disabled": disabled || undefined, "aria-disabled": disabled || undefined, "data-parent": parent || 'list', onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, children: [!switchProp && isSelectionSingle && marker && !isParentNode && interactive && (_jsx("div", { className: styles.markerContainer, "data-test-id": 'list__base-item-marker' })), !switchProp && isSelectionMultiple && interactive && (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: CHECKBOX_SIZE_MAP[size !== null && size !== void 0 ? size : 's'], disabled: disabled, tabIndex: -1, onChange: handleCheckboxChange, checked: isChecked, "data-test-id": 'list__base-item-checkbox', onClick: handleCheckboxClick, indeterminate: indeterminate }) })), beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), content && isContentItemProps(content) ? ((_b = contentRender === null || contentRender === void 0 ? void 0 : contentRender({ id, meta })) !== null && _b !== void 0 ? _b : _jsx(ItemContent, Object.assign({ disabled: disabled }, content))) : (_jsxs("div", { className: styles.content, children: [" ", content, " "] })), afterContent, switchProp && interactive && (_jsx(Switch, { disabled: disabled, checked: isChecked, "data-test-id": 'list__base-item-switch' })), !switchProp && expandIcon && _jsx("span", { className: styles.expandableIcon, children: expandIcon })] }));
75
81
  if (!itemWrapRender) {
76
- return item;
82
+ return itemJSX;
77
83
  }
78
- return itemWrapRender(item);
84
+ return itemWrapRender(itemJSX);
79
85
  }
@@ -1,25 +1,3 @@
1
- .headline{
2
- display:flex;
3
- align-items:center;
4
- }
5
-
6
- .option{
7
- overflow:hidden;
8
- flex:1;
9
- color:var(--sys-neutral-text-main, #33333b);
10
- }
11
-
12
- .caption{
13
- overflow:hidden;
14
- color:var(--sys-neutral-text-light, #868892);
15
- text-overflow:ellipsis;
16
- white-space:nowrap;
17
- }
18
-
19
- .description{
20
- color:var(--sys-neutral-text-support, #656771);
21
- }
22
-
23
1
  .checkbox{
24
2
  display:inline-flex;
25
3
  flex-grow:0;
@@ -41,8 +19,8 @@
41
19
  color:var(--sys-neutral-text-light, #868892);
42
20
  }
43
21
  .beforeContent svg{
44
- width:100% !important;
45
- height:100% !important;
22
+ max-width:100%;
23
+ max-height:100%;
46
24
  }
47
25
 
48
26
  .expandableIcon{
@@ -71,119 +49,22 @@
71
49
  height:100%;
72
50
  }
73
51
 
74
- .content{
75
- overflow:hidden;
76
- flex-grow:1;
77
- flex-shrink:1;
78
- box-sizing:border-box;
79
- }
80
-
81
52
  .droplistItem{
82
53
  width:100%;
83
54
  }
84
55
  .droplistItem[data-size=s]{
85
56
  padding-left:calc(var(--level, 0) * var(--dimension-050m, 4px) + var(--space-drop-list-item-s-container-horizontal-padding, 8px));
86
57
  }
87
- .droplistItem[data-size=s] .headline{
88
- gap:var(--space-drop-list-item-s-container-headline-gap, 8px);
89
- height:var(--size-drop-list-item-headline, 24px);
90
- }
91
- .droplistItem[data-size=s] .option{
92
- font-family:var(--sans-body-s-font-family, SB Sans Interface);
93
- font-weight:var(--sans-body-s-font-weight, Regular);
94
- line-height:var(--sans-body-s-line-height, 16px);
95
- font-size:var(--sans-body-s-font-size, 12px);
96
- letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
97
- paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
98
- }
99
- .droplistItem[data-size=s] .caption{
100
- font-family:var(--sans-body-s-font-family, SB Sans Interface);
101
- font-weight:var(--sans-body-s-font-weight, Regular);
102
- line-height:var(--sans-body-s-line-height, 16px);
103
- font-size:var(--sans-body-s-font-size, 12px);
104
- letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
105
- paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
106
- }
107
- .droplistItem[data-size=s] .description{
108
- font-family:var(--sans-body-s-font-family, SB Sans Interface);
109
- font-weight:var(--sans-body-s-font-weight, Regular);
110
- line-height:var(--sans-body-s-line-height, 16px);
111
- font-size:var(--sans-body-s-font-size, 12px);
112
- letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
113
- paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
114
- }
115
58
  .droplistItem[data-size=m]{
116
59
  padding-left:calc(var(--level, 0) * var(--dimension-050m, 4px) + var(--space-drop-list-item-m-container-horizontal-padding, 10px));
117
60
  }
118
- .droplistItem[data-size=m] .headline{
119
- gap:var(--space-drop-list-item-m-container-headline-gap, 8px);
120
- height:var(--size-drop-list-item-headline, 24px);
121
- }
122
- .droplistItem[data-size=m] .option{
123
- font-family:var(--sans-body-m-font-family, SB Sans Interface);
124
- font-weight:var(--sans-body-m-font-weight, Regular);
125
- line-height:var(--sans-body-m-line-height, 20px);
126
- font-size:var(--sans-body-m-font-size, 14px);
127
- letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
128
- paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
129
- }
130
- .droplistItem[data-size=m] .caption{
131
- font-family:var(--sans-body-s-font-family, SB Sans Interface);
132
- font-weight:var(--sans-body-s-font-weight, Regular);
133
- line-height:var(--sans-body-s-line-height, 16px);
134
- font-size:var(--sans-body-s-font-size, 12px);
135
- letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
136
- paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
137
- }
138
- .droplistItem[data-size=m] .description{
139
- font-family:var(--sans-body-s-font-family, SB Sans Interface);
140
- font-weight:var(--sans-body-s-font-weight, Regular);
141
- line-height:var(--sans-body-s-line-height, 16px);
142
- font-size:var(--sans-body-s-font-size, 12px);
143
- letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
144
- paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
145
- }
146
61
  .droplistItem[data-size=l]{
147
62
  padding-left:calc(var(--level, 0) * var(--dimension-050m, 4px) + var(--space-drop-list-item-l-container-horizontal-padding, 12px));
148
63
  }
149
- .droplistItem[data-size=l] .headline{
150
- gap:var(--space-drop-list-item-l-container-headline-gap, 8px);
151
- height:var(--size-drop-list-item-headline, 24px);
152
- }
153
- .droplistItem[data-size=l] .option{
154
- font-family:var(--sans-body-l-font-family, SB Sans Interface);
155
- font-weight:var(--sans-body-l-font-weight, Regular);
156
- line-height:var(--sans-body-l-line-height, 24px);
157
- font-size:var(--sans-body-l-font-size, 16px);
158
- letter-spacing:var(--sans-body-l-letter-spacing, 0.1px);
159
- paragraph-spacing:var(--sans-body-l-paragraph-spacing, 8.8px);
160
- }
161
- .droplistItem[data-size=l] .caption{
162
- font-family:var(--sans-body-m-font-family, SB Sans Interface);
163
- font-weight:var(--sans-body-m-font-weight, Regular);
164
- line-height:var(--sans-body-m-line-height, 20px);
165
- font-size:var(--sans-body-m-font-size, 14px);
166
- letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
167
- paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
168
- }
169
- .droplistItem[data-size=l] .description{
170
- font-family:var(--sans-body-m-font-family, SB Sans Interface);
171
- font-weight:var(--sans-body-m-font-weight, Regular);
172
- line-height:var(--sans-body-m-line-height, 20px);
173
- font-size:var(--sans-body-m-font-size, 14px);
174
- letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
175
- paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
176
- }
177
64
  .droplistItem[data-non-pointer]{
178
65
  cursor:inherit;
179
66
  }
180
- .droplistItem[aria-disabled] .option,
181
- .droplistItem[aria-disabled] .description,
182
- .droplistItem[aria-disabled] .caption,
183
- .droplistItem[aria-disabled] .expandableIcon, .droplistItem[data-disabled] .option,
184
- .droplistItem[data-disabled] .description,
185
- .droplistItem[data-disabled] .caption,
186
- .droplistItem[data-disabled] .expandableIcon{
67
+ .droplistItem[aria-disabled] .expandableIcon, .droplistItem[data-disabled] .expandableIcon{
187
68
  color:var(--sys-neutral-text-disabled, #b3b6bf);
188
69
  }
189
70
  .droplistItem[aria-disabled] .beforeContent, .droplistItem[data-disabled] .beforeContent{
@@ -208,4 +89,10 @@
208
89
  }
209
90
  .droplistItem[data-has-checked][data-disabled] .markerContainer:before, .droplistItem[data-checked][data-disabled] .markerContainer:before{
210
91
  background-color:var(--sys-neutral-text-disabled, #b3b6bf);
92
+ }
93
+
94
+ .content{
95
+ flex-grow:1;
96
+ flex-shrink:1;
97
+ box-sizing:border-box;
211
98
  }
@@ -1,2 +1,2 @@
1
- import { GroupItemProps } from '../types';
2
- export declare function GroupItem({ label, truncate, divider, items, mode }: GroupItemProps): import("react/jsx-runtime").JSX.Element;
1
+ import { AnyType, FlattenGroupListItem } from '../types';
2
+ export declare function GroupItem<Meta = AnyType>({ label, truncate, divider, items, mode }: FlattenGroupListItem<Meta>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Separator } from '../../../helperComponents';
3
- import { useListContext } from '../../Lists/contexts';
3
+ import { useNewListContext } from '../../Lists/contexts';
4
4
  import { useRenderItems } from '../hooks';
5
5
  export function GroupItem({ label, truncate, divider, items, mode }) {
6
- const { size } = useListContext();
7
- const itemsJSX = useRenderItems(items);
6
+ const { flattenedItems, size = 's' } = useNewListContext();
7
+ const itemsJSX = useRenderItems({ items, flattenedItems });
8
8
  return (_jsxs(_Fragment, { children: [_jsx(Separator, { label: label, truncate: truncate, divider: divider, mode: mode, size: size }), itemsJSX] }));
9
9
  }
@@ -1,2 +1,2 @@
1
- import { NextListItemProps } from '../types';
2
- export declare function NextListItem({ items: itemsProp, placement, id, search, scroll, scrollRef, disabled, onSublistOpenChanged, ...option }: NextListItemProps): import("react/jsx-runtime").JSX.Element;
1
+ import { AnyType, FlattenNextListItem } from '../types';
2
+ export declare function NextListItem<Meta = AnyType>({ items, placement, id, search, scroll, scrollRef, disabled, allChildIds, ...option }: FlattenNextListItem<Meta>): import("react/jsx-runtime").JSX.Element;
@@ -13,12 +13,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { useCallback, useMemo, useRef, useState } from 'react';
14
14
  import { Dropdown } from '@snack-uikit/dropdown';
15
15
  import { ChevronRightSVG } from '@snack-uikit/icons';
16
- import { withCollapsedItems } from '../../../utils';
17
- import { ParentListContext, useParentListContext } from '../../Lists/contexts';
16
+ import { extractActiveItems } from '../../../utils';
17
+ import { useCollapseContext, useFocusListContext, useNewListContext } from '../../Lists/contexts';
18
18
  import { ListPrivate } from '../../Lists/ListPrivate';
19
19
  import { BaseItem } from '../BaseItem';
20
20
  import { useGroupItemSelection } from '../hooks';
21
- import { useKeyboardNavigation } from './hooks';
22
21
  const FALLBACK_PLACEMENTS = [
23
22
  'right',
24
23
  'right-start',
@@ -26,42 +25,44 @@ const FALLBACK_PLACEMENTS = [
26
25
  'left',
27
26
  'left-start',
28
27
  'left-end',
28
+ 'bottom',
29
+ 'top',
29
30
  ];
30
31
  export function NextListItem(_a) {
31
- var { items: itemsProp, placement = 'right-start', id, search, scroll, scrollRef, disabled, onSublistOpenChanged } = _a, option = __rest(_a, ["items", "placement", "id", "search", "scroll", "scrollRef", "disabled", "onSublistOpenChanged"]);
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([]);
32
+ var { items, placement = 'right-start', id, search, scroll, scrollRef, disabled, allChildIds } = _a, option = __rest(_a, ["items", "placement", "id", "search", "scroll", "scrollRef", "disabled", "allChildIds"]);
33
+ const { flattenedItems } = useNewListContext();
34
+ const { openCollapseItems = [] } = useCollapseContext();
35
+ const { ids, expandedIds } = useMemo(() => {
36
+ const { ids, expandedIds } = extractActiveItems({ items, flattenedItems, openCollapseItems });
37
+ return { ids, expandedIds: expandedIds.concat([id]) };
38
+ }, [flattenedItems, id, items, openCollapseItems]);
39
+ const { handleListKeyDownFactory, activeItemId, forceUpdateActiveItemId } = useFocusListContext();
40
+ const [open, setOpen] = useState();
41
+ const handleListKeyDown = useCallback((e) => {
42
+ handleListKeyDownFactory(ids, expandedIds)(e);
43
+ if (e.code === 'ArrowLeft') {
44
+ forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(id);
45
+ setOpen(false);
46
+ e.stopPropagation();
47
+ return;
46
48
  }
47
- onSublistOpenChanged === null || onSublistOpenChanged === void 0 ? void 0 : onSublistOpenChanged(open, id);
48
- setOpen(open);
49
- }, [id, onSublistOpenChanged, resetActiveFocusIndex, resetNestedIndex, setOpen]);
49
+ }, [handleListKeyDownFactory, ids, expandedIds, id, forceUpdateActiveItemId]);
50
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({ items, id, disabled, allChildIds });
50
51
  const handleOutsideClick = useCallback(() => {
51
- parentResetNestedIndex === null || parentResetNestedIndex === void 0 ? void 0 : parentResetNestedIndex();
52
- parentResetActiveFocusIndex === null || parentResetActiveFocusIndex === void 0 ? void 0 : parentResetActiveFocusIndex();
52
+ forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId('~drop-focus');
53
+ setOpen(false);
53
54
  return true;
54
- }, [parentResetActiveFocusIndex, parentResetNestedIndex]);
55
- return (_jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ParentListContext.Provider, { value: {
56
- parentIds: ids,
57
- parentActiveFocusIndex: activeFocusIndex,
58
- parentExpandedIds: expandedIds,
59
- parentItemRefs: itemRefs,
60
- parentOpenNestedIndex: openNestedIndex,
61
- triggerRef,
62
- parentRef: listRef,
63
- parentResetNestedIndex: resetNestedIndex,
64
- parentResetActiveFocusIndex: resetActiveFocusIndex,
65
- toggleOpenCollapsedItems: id => setOpenCollapsedItems(items => items.includes(id) ? items.filter(item => item !== id) : items.concat([id])),
66
- }, children: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: items, nested: true, search: search, scroll: scroll, scrollRef: scrollRef, limitedScrollHeight: true }) }), trigger: 'hover', open: (open || parentIds[parentOpenNestedIndex] === id) && !disabled, onOpenChange: handleOpenChange, placement: placement, widthStrategy: 'auto', children: _jsx(BaseItem, Object.assign({}, option, { disabled: disabled, open: open, expandIcon: _jsx(ChevronRightSVG, {}), id: id, isParentNode: true, indeterminate: isIndeterminate && !checked, onSelect: handleOnSelect })) }));
55
+ }, [forceUpdateActiveItemId]);
56
+ const isOpen = useMemo(() => Boolean(!disabled && activeItemId && allChildIds.includes(activeItemId)), [activeItemId, allChildIds, disabled]);
57
+ const listRef = useRef(null);
58
+ return (_jsx(Dropdown, { outsideClick: handleOutsideClick, fallbackPlacements: FALLBACK_PLACEMENTS, content: _jsx(ListPrivate, { onKeyDown: handleListKeyDown, items: { flattenedItems, items }, nested: true, search: search, scroll: scroll, tabIndex: 0, ref: listRef, onFocus: e => {
59
+ e.stopPropagation();
60
+ forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId(ids[0]);
61
+ }, scrollRef: scrollRef, limitedScrollHeight: true }), trigger: 'hover', open: isOpen || open, onOpenChange: setOpen, placement: placement, children: _jsx(BaseItem, Object.assign({}, option, { disabled: disabled, open: open, expandIcon: _jsx(ChevronRightSVG, {}), id: id, isParentNode: true, indeterminate: indeterminate, checked: checked, onOpenNestedList: () => {
62
+ setOpen(true);
63
+ setTimeout(() => {
64
+ var _a;
65
+ (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.focus();
66
+ }, 0);
67
+ }, onSelect: handleOnSelect })) }));
67
68
  }
@@ -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,12 +1,11 @@
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 { useListContext, useParentListContext } from '../../Lists/contexts';
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 { parentItemRefs, parentSetActiveFocusIndex } = useParentListContext();
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();
@@ -16,13 +15,13 @@ export function SearchItem({ search }) {
16
15
  }
17
16
  };
18
17
  const handleFocus = (e) => {
19
- if (e.target === parentItemRefs[0].current) {
20
- parentSetActiveFocusIndex === null || parentSetActiveFocusIndex === void 0 ? void 0 : parentSetActiveFocusIndex(0);
21
- }
18
+ // if (e.target === parentItemRefs[0].current) {
19
+ // parentSetActiveFocusIndex?.(0);
20
+ // }
22
21
  e.stopPropagation();
23
22
  };
24
23
  if (!Boolean(search)) {
25
24
  return null;
26
25
  }
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] })) }));
26
+ 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
27
  }