@snack-uikit/list 0.9.2-preview-0f7b85a9.0 → 0.9.2-preview-0a44b2fc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -23
- package/dist/components/Items/AccordionItem/AccordionItem.d.ts +2 -2
- package/dist/components/Items/AccordionItem/AccordionItem.js +19 -16
- package/dist/components/Items/BaseItem/BaseItem.d.ts +5 -4
- package/dist/components/Items/BaseItem/BaseItem.js +22 -16
- package/dist/components/Items/BaseItem/styles.module.css +9 -122
- package/dist/components/Items/GroupItem/GroupItem.d.ts +2 -2
- package/dist/components/Items/GroupItem/GroupItem.js +3 -3
- package/dist/components/Items/NextListItem/NextListItem.d.ts +2 -2
- package/dist/components/Items/NextListItem/NextListItem.js +37 -36
- package/dist/components/Items/SearchItem/SearchItem.d.ts +3 -1
- package/dist/components/Items/SearchItem/SearchItem.js +7 -8
- package/dist/components/Items/hooks.d.ts +14 -9
- package/dist/components/Items/hooks.js +46 -30
- package/dist/components/Items/types.d.ts +41 -26
- package/dist/components/Items/utils.d.ts +7 -17
- package/dist/components/Items/utils.js +3 -31
- package/dist/components/Lists/Droplist/DropList.d.ts +2 -1
- package/dist/components/Lists/Droplist/DropList.js +85 -50
- package/dist/components/Lists/List/List.d.ts +7 -11
- package/dist/components/Lists/List/List.js +61 -53
- package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +18 -20
- package/dist/components/Lists/ListPrivate/ListPrivate.js +10 -9
- 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 +27 -0
- package/dist/components/Lists/contexts/{ListProvider.js → NewListProvider.js} +10 -5
- package/dist/components/Lists/contexts/SelectionProvider.d.ts +28 -15
- package/dist/components/Lists/contexts/SelectionProvider.js +14 -8
- package/dist/components/Lists/contexts/index.d.ts +2 -2
- package/dist/components/Lists/contexts/index.js +2 -2
- package/dist/components/Lists/hooks.d.ts +11 -11
- package/dist/components/Lists/hooks.js +80 -41
- package/dist/components/Lists/types.d.ts +19 -15
- 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/index.d.ts +1 -0
- package/dist/helperComponents/index.js +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +15 -10
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/legacy/components/Items/hooks.d.ts +12 -0
- package/dist/legacy/components/Items/hooks.js +33 -0
- package/dist/legacy/components/index.d.ts +1 -0
- package/dist/legacy/components/index.js +1 -0
- package/dist/legacy/hooks.d.ts +5 -0
- package/dist/legacy/hooks.js +15 -0
- package/dist/legacy/index.d.ts +3 -0
- package/dist/legacy/index.js +3 -0
- package/dist/legacy/utils.d.ts +29 -0
- package/dist/legacy/utils.js +107 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +27 -25
- package/dist/utils.js +74 -103
- package/package.json +12 -12
- package/src/components/Items/AccordionItem/AccordionItem.tsx +26 -19
- package/src/components/Items/BaseItem/BaseItem.tsx +48 -46
- package/src/components/Items/BaseItem/styles.module.scss +8 -70
- package/src/components/Items/GroupItem/GroupItem.tsx +6 -5
- package/src/components/Items/NextListItem/NextListItem.tsx +67 -78
- package/src/components/Items/SearchItem/SearchItem.tsx +8 -8
- package/src/components/Items/hooks.tsx +76 -54
- package/src/components/Items/types.ts +61 -31
- package/src/components/Items/utils.ts +9 -58
- package/src/components/Lists/Droplist/DropList.tsx +155 -102
- package/src/components/Lists/List/List.tsx +120 -105
- package/src/components/Lists/ListPrivate/ListPrivate.tsx +26 -27
- package/src/components/Lists/contexts/CollapseProvider.tsx +22 -0
- package/src/components/Lists/contexts/FocusListProvider.tsx +16 -0
- package/src/components/Lists/contexts/NewListProvider.tsx +49 -0
- package/src/components/Lists/contexts/SelectionProvider.tsx +63 -36
- package/src/components/Lists/contexts/index.ts +3 -2
- package/src/components/Lists/hooks.ts +139 -75
- package/src/components/Lists/types.ts +29 -27
- 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 +21 -13
- package/src/helperComponents/index.ts +1 -0
- package/src/hooks.ts +21 -15
- package/src/index.ts +9 -2
- package/src/legacy/components/Items/hooks.tsx +53 -0
- package/src/legacy/components/index.ts +1 -0
- package/src/legacy/hooks.ts +27 -0
- package/src/legacy/index.ts +3 -0
- package/src/legacy/utils.ts +166 -0
- package/src/types.ts +1 -1
- package/src/utils.ts +153 -139
- package/dist/components/Items/NextListItem/hooks.d.ts +0 -19
- package/dist/components/Items/NextListItem/hooks.js +0 -80
- package/dist/components/Lists/contexts/ListProvider.d.ts +0 -17
- package/dist/components/Lists/contexts/ParentListProvider.d.ts +0 -18
- package/dist/components/Lists/contexts/ParentListProvider.js +0 -12
- package/src/components/Items/NextListItem/hooks.ts +0 -105
- package/src/components/Lists/contexts/CollapseProvider.ts +0 -9
- package/src/components/Lists/contexts/ListProvider.tsx +0 -28
- package/src/components/Lists/contexts/ParentListProvider.tsx +0 -35
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
|
-
##
|
|
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
|
-
|
|
22
|
-
`
|
|
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
|
-
|
|
|
46
|
-
|
|
|
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 {
|
|
2
|
-
export declare function AccordionItem({ items
|
|
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 {
|
|
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
|
|
20
|
-
const { level = 1 } =
|
|
21
|
-
const {
|
|
22
|
-
const {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 { isIndeterminate, 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
|
-
|
|
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,
|
|
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, indeterminate: isIndeterminate && !checked, 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,10 @@
|
|
|
1
|
-
|
|
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
5
|
onSelect?(): void;
|
|
6
6
|
isParentNode?: boolean;
|
|
7
|
+
onOpenNestedList?(e?: KeyboardEvent<HTMLElement>): void;
|
|
7
8
|
};
|
|
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;
|
|
9
|
+
export declare function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, 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
10
|
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 {
|
|
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
|
|
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, 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", "onSelect", "onOpenNestedList", "isParentNode", "className", "inactive", "itemWrapRender", "meta"]);
|
|
25
25
|
const interactive = !inactive;
|
|
26
|
-
const {
|
|
27
|
-
const {
|
|
28
|
-
const {
|
|
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 : 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
|
|
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
|
-
|
|
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
|
|
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
|
|
82
|
+
return itemJSX;
|
|
77
83
|
}
|
|
78
|
-
return itemWrapRender(
|
|
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
|
|
45
|
-
height:100
|
|
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] .
|
|
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 {
|
|
2
|
-
export declare function GroupItem({ label, truncate, divider, items, mode }:
|
|
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 {
|
|
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 } =
|
|
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 {
|
|
2
|
-
export declare function NextListItem({ items
|
|
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 {
|
|
17
|
-
import {
|
|
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
|
|
32
|
-
const
|
|
33
|
-
const [
|
|
34
|
-
const {
|
|
35
|
-
items
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
const {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
}, [id, onSublistOpenChanged, resetActiveFocusIndex, resetNestedIndex, setOpen]);
|
|
49
|
+
}, [handleListKeyDownFactory, ids, expandedIds, id, forceUpdateActiveItemId]);
|
|
50
|
+
const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items, id, disabled, allChildIds });
|
|
50
51
|
const handleOutsideClick = useCallback(() => {
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
forceUpdateActiveItemId === null || forceUpdateActiveItemId === void 0 ? void 0 : forceUpdateActiveItemId('~drop-focus');
|
|
53
|
+
setOpen(false);
|
|
53
54
|
return true;
|
|
54
|
-
}, [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
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: isIndeterminate && !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 {
|
|
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();
|
|
@@ -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
|
-
|
|
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:
|
|
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
|
}
|