@snack-uikit/list 0.11.1-preview-5d3667ec.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +22 -61
- package/dist/components/Items/AccordionItem/AccordionItem.d.ts +4 -2
- package/dist/components/Items/AccordionItem/AccordionItem.js +18 -16
- package/dist/components/Items/BaseItem/BaseItem.d.ts +8 -4
- package/dist/components/Items/BaseItem/BaseItem.js +20 -14
- package/dist/components/Items/BaseItem/styles.module.css +20 -119
- package/dist/components/Items/GroupItem/GroupItem.d.ts +5 -1
- package/dist/components/Items/GroupItem/GroupItem.js +1 -3
- package/dist/components/Items/GroupSelectItem/GroupSelectItem.d.ts +4 -0
- package/dist/components/Items/GroupSelectItem/GroupSelectItem.js +18 -0
- package/dist/components/Items/GroupSelectItem/index.d.ts +1 -0
- package/dist/components/Items/GroupSelectItem/index.js +1 -0
- package/dist/components/Items/NextListItem/NextListItem.d.ts +6 -2
- package/dist/components/Items/NextListItem/NextListItem.js +55 -45
- package/dist/components/Items/NextListItem/constants.d.ts +2 -0
- package/dist/components/Items/NextListItem/constants.js +10 -0
- package/dist/components/Items/PinGroupItem/PinGroupItem.js +7 -3
- package/dist/components/Items/PinGroupItem/styles.module.css +26 -14
- package/dist/components/Items/SearchItem/SearchItem.d.ts +3 -1
- package/dist/components/Items/SearchItem/SearchItem.js +5 -8
- package/dist/components/Items/hooks.d.ts +11 -10
- package/dist/components/Items/hooks.js +64 -46
- package/dist/components/Items/index.d.ts +1 -5
- package/dist/components/Items/index.js +1 -5
- package/dist/components/Items/styles.module.css +33 -26
- package/dist/components/Items/types.d.ts +68 -34
- package/dist/components/Items/utils.d.ts +34 -16
- package/dist/components/Items/utils.js +135 -37
- package/dist/components/Lists/Droplist/DropList.d.ts +1 -1
- package/dist/components/Lists/Droplist/DropList.js +78 -50
- package/dist/components/Lists/List/List.d.ts +5 -9
- package/dist/components/Lists/List/List.js +61 -54
- package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +6 -20
- package/dist/components/Lists/ListPrivate/ListPrivate.js +9 -8
- package/dist/components/Lists/ListPrivate/styles.module.css +1 -0
- package/dist/components/Lists/contexts/CollapseProvider.d.ts +13 -1
- package/dist/components/Lists/contexts/CollapseProvider.js +2 -0
- package/dist/components/Lists/contexts/FocusListProvider.d.ts +9 -0
- package/dist/components/Lists/contexts/FocusListProvider.js +5 -0
- package/dist/components/Lists/contexts/NewListProvider.d.ts +32 -0
- package/dist/components/Lists/contexts/{ListProvider.js → NewListProvider.js} +10 -5
- package/dist/components/Lists/contexts/SelectionProvider.d.ts +25 -15
- package/dist/components/Lists/contexts/SelectionProvider.js +17 -13
- package/dist/components/Lists/contexts/index.d.ts +3 -2
- package/dist/components/Lists/contexts/index.js +3 -2
- package/dist/components/Lists/hooks.d.ts +10 -12
- package/dist/components/Lists/hooks.js +73 -40
- package/dist/components/Lists/index.d.ts +2 -1
- package/dist/components/Lists/index.js +1 -0
- package/dist/components/Lists/types.d.ts +12 -14
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/helperComponents/ItemContent/ItemContent.d.ts +15 -0
- package/dist/helperComponents/ItemContent/ItemContent.js +23 -0
- package/dist/helperComponents/ItemContent/index.d.ts +1 -0
- package/dist/helperComponents/ItemContent/index.js +1 -0
- package/dist/helperComponents/ItemContent/styles.module.css +117 -0
- package/dist/helperComponents/ListEmptyState/ListEmptyState.d.ts +2 -2
- package/dist/helperComponents/ListEmptyState/ListEmptyState.js +13 -4
- package/dist/helperComponents/Separator/Separator.d.ts +8 -2
- package/dist/helperComponents/Separator/Separator.js +22 -2
- package/dist/helperComponents/Separator/constants.d.ts +2 -0
- package/dist/helperComponents/Separator/constants.js +5 -0
- package/dist/helperComponents/Separator/styles.module.css +20 -1
- package/dist/helperComponents/index.d.ts +1 -0
- package/dist/helperComponents/index.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/types.d.ts +1 -1
- package/package.json +13 -18
- package/src/components/Items/AccordionItem/AccordionItem.tsx +24 -20
- package/src/components/Items/BaseItem/BaseItem.tsx +91 -82
- package/src/components/Items/BaseItem/styles.module.scss +19 -77
- package/src/components/Items/GroupItem/GroupItem.tsx +5 -5
- package/src/components/Items/GroupSelectItem/GroupSelectItem.tsx +44 -0
- package/src/components/Items/GroupSelectItem/index.ts +1 -0
- package/src/components/Items/NextListItem/NextListItem.tsx +88 -85
- package/src/components/Items/NextListItem/constants.ts +12 -0
- package/src/components/Items/PinGroupItem/PinGroupItem.tsx +14 -4
- package/src/components/Items/PinGroupItem/styles.module.scss +14 -14
- package/src/components/Items/SearchItem/SearchItem.tsx +6 -8
- package/src/components/Items/hooks.tsx +86 -66
- package/src/components/Items/index.ts +1 -5
- package/src/components/Items/styles.module.scss +36 -25
- package/src/components/Items/types.ts +91 -42
- package/src/components/Items/utils.ts +199 -52
- package/src/components/Lists/Droplist/DropList.tsx +155 -98
- package/src/components/Lists/List/List.tsx +129 -104
- package/src/components/Lists/ListPrivate/ListPrivate.tsx +19 -20
- package/src/components/Lists/ListPrivate/styles.module.scss +1 -0
- package/src/components/Lists/contexts/CollapseProvider.tsx +22 -0
- package/src/components/Lists/contexts/FocusListProvider.tsx +15 -0
- package/src/components/Lists/contexts/NewListProvider.tsx +54 -0
- package/src/components/Lists/contexts/SelectionProvider.tsx +56 -39
- package/src/components/Lists/contexts/index.ts +3 -2
- package/src/components/Lists/hooks.ts +124 -75
- package/src/components/Lists/index.ts +2 -2
- package/src/components/Lists/types.ts +20 -24
- package/src/components/index.ts +17 -2
- package/src/helperComponents/ItemContent/ItemContent.tsx +63 -0
- package/src/helperComponents/ItemContent/index.ts +1 -0
- package/src/helperComponents/ItemContent/styles.module.scss +78 -0
- package/src/helperComponents/ListEmptyState/ListEmptyState.tsx +26 -12
- package/src/helperComponents/Separator/Separator.tsx +49 -3
- package/src/helperComponents/Separator/constants.ts +7 -0
- package/src/helperComponents/Separator/styles.module.scss +41 -1
- package/src/helperComponents/index.ts +1 -0
- package/src/index.ts +4 -2
- package/src/types.ts +1 -1
- package/dist/components/Items/NextListItem/hooks.d.ts +0 -19
- package/dist/components/Items/NextListItem/hooks.js +0 -80
- package/dist/components/Lists/contexts/ListProvider.d.ts +0 -17
- package/dist/components/Lists/contexts/ParentListProvider.d.ts +0 -18
- package/dist/components/Lists/contexts/ParentListProvider.js +0 -12
- package/dist/hooks.d.ts +0 -5
- package/dist/hooks.js +0 -15
- package/dist/utils.d.ts +0 -30
- package/dist/utils.js +0 -115
- package/src/components/Items/NextListItem/hooks.ts +0 -105
- package/src/components/Lists/contexts/CollapseProvider.ts +0 -9
- package/src/components/Lists/contexts/ListProvider.tsx +0 -28
- package/src/components/Lists/contexts/ParentListProvider.tsx +0 -35
- package/src/hooks.ts +0 -27
- package/src/utils.ts +0 -175
|
@@ -1,73 +1,106 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function
|
|
3
|
-
const [
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
var _a, _b, _c, _d;
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
export function useNewKeyboardNavigation({ mainRef, btnRef, focusFlattenItems, }) {
|
|
3
|
+
const [activeItemId, setActiveItemId] = useState();
|
|
4
|
+
const activeItemIdRef = useRef();
|
|
5
|
+
const handleListKeyDownFactory = useCallback((ids, expandedIds) => (e) => {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
7
7
|
switch (e.key) {
|
|
8
8
|
case 'ArrowDown': {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
if (activeItemIdRef.current !== undefined) {
|
|
10
|
+
const activeIndex = ids.findIndex(id => id === activeItemIdRef.current);
|
|
11
|
+
const nextId = Math.min(activeIndex + 1, ids.length - 1);
|
|
12
|
+
const itemId = ids[nextId];
|
|
13
|
+
const item = focusFlattenItems[itemId];
|
|
14
|
+
activeItemIdRef.current = itemId;
|
|
15
|
+
setActiveItemId(itemId);
|
|
16
|
+
if (item.type !== 'group') {
|
|
17
|
+
(_b = (_a = item.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const itemId = ids[0];
|
|
22
|
+
const item = focusFlattenItems[itemId];
|
|
23
|
+
activeItemIdRef.current = itemId;
|
|
24
|
+
setActiveItemId(itemId);
|
|
25
|
+
if (item.type !== 'group') {
|
|
26
|
+
(_d = (_c = item.itemRef) === null || _c === void 0 ? void 0 : _c.current) === null || _d === void 0 ? void 0 : _d.focus();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
14
29
|
e.stopPropagation();
|
|
15
30
|
e.preventDefault();
|
|
16
31
|
return;
|
|
17
32
|
}
|
|
18
33
|
case 'ArrowUp': {
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
if (ids[0] === activeItemIdRef.current) {
|
|
35
|
+
const item = focusFlattenItems[ids[0]];
|
|
36
|
+
if (item.parentId === '~main') {
|
|
37
|
+
activeItemIdRef.current = undefined;
|
|
38
|
+
setActiveItemId(undefined);
|
|
39
|
+
(_e = mainRef === null || mainRef === void 0 ? void 0 : mainRef.current) === null || _e === void 0 ? void 0 : _e.focus();
|
|
40
|
+
}
|
|
22
41
|
return;
|
|
23
42
|
}
|
|
24
|
-
|
|
43
|
+
if (activeItemIdRef.current !== undefined) {
|
|
44
|
+
const activeIndex = ids.findIndex(id => id === activeItemIdRef.current);
|
|
45
|
+
const nextId = Math.max(activeIndex - 1, 0);
|
|
46
|
+
const itemId = ids[nextId];
|
|
47
|
+
const item = focusFlattenItems[itemId];
|
|
48
|
+
activeItemIdRef.current = itemId;
|
|
49
|
+
setActiveItemId(itemId);
|
|
50
|
+
if (item.type !== 'group') {
|
|
51
|
+
(_g = (_f = item.itemRef) === null || _f === void 0 ? void 0 : _f.current) === null || _g === void 0 ? void 0 : _g.focus();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
25
54
|
e.stopPropagation();
|
|
26
55
|
e.preventDefault();
|
|
27
56
|
return;
|
|
28
57
|
}
|
|
29
58
|
case 'ArrowRight': {
|
|
30
|
-
if (expandedIds.includes(
|
|
31
|
-
|
|
59
|
+
if (activeItemIdRef.current !== undefined && expandedIds.includes(activeItemIdRef.current)) {
|
|
60
|
+
const item = focusFlattenItems[activeItemIdRef.current];
|
|
61
|
+
const newItemId = item.items[0];
|
|
62
|
+
const newItem = focusFlattenItems[newItemId];
|
|
63
|
+
activeItemIdRef.current = newItemId;
|
|
64
|
+
setActiveItemId(newItemId);
|
|
65
|
+
setTimeout(() => { var _a, _b; return (_b = (_a = newItem.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.focus(); }, 0);
|
|
32
66
|
}
|
|
33
67
|
e.stopPropagation();
|
|
34
68
|
e.preventDefault();
|
|
35
69
|
return;
|
|
36
70
|
}
|
|
37
71
|
case 'Tab': {
|
|
38
|
-
if (
|
|
72
|
+
if (activeItemIdRef.current !== undefined) {
|
|
39
73
|
e.preventDefault();
|
|
40
|
-
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
activeItemIdRef.current = undefined;
|
|
76
|
+
setActiveItemId(undefined);
|
|
77
|
+
(_h = mainRef === null || mainRef === void 0 ? void 0 : mainRef.current) === null || _h === void 0 ? void 0 : _h.focus();
|
|
41
78
|
}
|
|
42
|
-
else
|
|
43
|
-
btnRef && !e.shiftKey ? (
|
|
79
|
+
else {
|
|
80
|
+
btnRef && !e.shiftKey ? (_j = btnRef === null || btnRef === void 0 ? void 0 : btnRef.current) === null || _j === void 0 ? void 0 : _j.focus() : (_k = mainRef === null || mainRef === void 0 ? void 0 : mainRef.current) === null || _k === void 0 ? void 0 : _k.focus();
|
|
44
81
|
}
|
|
45
|
-
setOpenNestedIndex(-1);
|
|
46
|
-
setActiveFocusIndex(-1);
|
|
47
82
|
return;
|
|
48
83
|
}
|
|
49
84
|
default: {
|
|
50
85
|
return;
|
|
51
86
|
}
|
|
52
87
|
}
|
|
53
|
-
};
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
const
|
|
59
|
-
setActiveFocusIndex(-1);
|
|
60
|
-
};
|
|
61
|
-
useEffect(() => {
|
|
88
|
+
}, [focusFlattenItems, mainRef, btnRef]);
|
|
89
|
+
const resetActiveItemId = useCallback(() => {
|
|
90
|
+
setActiveItemId(undefined);
|
|
91
|
+
activeItemIdRef.current = undefined;
|
|
92
|
+
}, []);
|
|
93
|
+
const forceUpdateActiveItemId = useCallback((itemId) => {
|
|
62
94
|
var _a, _b;
|
|
63
|
-
|
|
64
|
-
|
|
95
|
+
setActiveItemId(itemId);
|
|
96
|
+
activeItemIdRef.current = itemId;
|
|
97
|
+
const item = focusFlattenItems[itemId];
|
|
98
|
+
(_b = (_a = item === null || item === void 0 ? void 0 : item.itemRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
99
|
+
}, [focusFlattenItems]);
|
|
65
100
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
resetActiveFocusIndex,
|
|
71
|
-
handleListKeyDown,
|
|
101
|
+
resetActiveItemId,
|
|
102
|
+
activeItemId,
|
|
103
|
+
forceUpdateActiveItemId,
|
|
104
|
+
handleListKeyDownFactory,
|
|
72
105
|
};
|
|
73
106
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './Droplist';
|
|
2
2
|
export * from './List';
|
|
3
3
|
export type { ListProps, DroplistProps } from './types';
|
|
4
|
-
export type { SelectionSingleState, SelectionMultipleState, SelectionSingleProps, SelectionMultipleProps,
|
|
4
|
+
export type { SelectionSingleState, SelectionMultipleState, SelectionSingleProps, SelectionMultipleProps, SelectionSingleValueType, } from './contexts';
|
|
5
|
+
export { useSelectionContext, useCollapseContext, isSelectionSingleProps, isSelectionMultipleProps } from './contexts';
|
|
@@ -3,13 +3,8 @@ import { DropdownProps } from '@snack-uikit/dropdown';
|
|
|
3
3
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
4
|
import { EmptyStateProps } from '../../helperComponents';
|
|
5
5
|
import { ScrollProps, SearchState } from '../../types';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
type CollapseState = {
|
|
9
|
-
value?: (string | number)[];
|
|
10
|
-
onChange?(value: (string | number)[]): void;
|
|
11
|
-
defaultValue?: (string | number)[];
|
|
12
|
-
};
|
|
6
|
+
import { FlattenBaseItem, Item, ItemId } from '../Items';
|
|
7
|
+
import { CollapseState, PublicListContextType, SelectionState } from './contexts';
|
|
13
8
|
export type EmptyState = {
|
|
14
9
|
dataFiltered?: boolean;
|
|
15
10
|
dataError?: boolean;
|
|
@@ -22,11 +17,11 @@ export type EmptyState = {
|
|
|
22
17
|
};
|
|
23
18
|
export type ListProps = WithSupportProps<{
|
|
24
19
|
/** Основные элементы списка */
|
|
25
|
-
items:
|
|
20
|
+
items: Item[];
|
|
26
21
|
/** Элементы списка, закрепленные сверху */
|
|
27
|
-
pinTop?:
|
|
22
|
+
pinTop?: Item[];
|
|
28
23
|
/** Элементы списка, закрепленные снизу */
|
|
29
|
-
pinBottom?:
|
|
24
|
+
pinBottom?: Item[];
|
|
30
25
|
/**
|
|
31
26
|
* Кастомизируемый элемент в конце списка
|
|
32
27
|
* @type ReactNode;
|
|
@@ -45,7 +40,7 @@ export type ListProps = WithSupportProps<{
|
|
|
45
40
|
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
46
41
|
/** Флаг, отвещающий за состояние загрузки списка */
|
|
47
42
|
loading?: boolean;
|
|
48
|
-
} & SelectionState &
|
|
43
|
+
} & SelectionState & PublicListContextType & ScrollProps & EmptyState>;
|
|
49
44
|
export type DroplistProps = {
|
|
50
45
|
/** Ссылка на элемент-триггер для дроплиста */
|
|
51
46
|
triggerElemRef?: RefObject<HTMLElement>;
|
|
@@ -57,8 +52,8 @@ export type DroplistProps = {
|
|
|
57
52
|
children: ReactNode | ((params: {
|
|
58
53
|
onKeyDown?: (e: KeyboardEvent<HTMLElement>) => void;
|
|
59
54
|
}) => ReactNode);
|
|
60
|
-
} & Pick<DropdownProps, 'trigger' | 'placement' | 'widthStrategy' | 'open' | 'onOpenChange'> & Omit<ListProps, 'tabIndex' | 'onKeyDown'>;
|
|
61
|
-
export type ListPrivateProps = ListProps
|
|
55
|
+
} & Pick<DropdownProps, 'trigger' | 'placement' | 'widthStrategy' | 'open' | 'onOpenChange' | 'triggerClassName'> & Omit<ListProps, 'tabIndex' | 'onKeyDown'>;
|
|
56
|
+
export type ListPrivateProps = Omit<ListProps, 'pinTop' | 'pinBottom' | 'items'> & {
|
|
62
57
|
nested?: boolean;
|
|
63
58
|
active?: boolean;
|
|
64
59
|
tabIndex?: number;
|
|
@@ -66,5 +61,8 @@ export type ListPrivateProps = ListProps & ListContextPrivateType & {
|
|
|
66
61
|
onBlur?(e: FocusEvent<HTMLElement>): void;
|
|
67
62
|
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
68
63
|
limitedScrollHeight?: boolean;
|
|
64
|
+
searchItem?: FlattenBaseItem;
|
|
65
|
+
pinTop?: ItemId[];
|
|
66
|
+
items: ItemId[];
|
|
67
|
+
pinBottom?: ItemId[];
|
|
69
68
|
};
|
|
70
|
-
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './Lists';
|
|
2
|
-
export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
|
|
3
|
-
export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
|
|
2
|
+
export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps, GroupSelectItemProps, ItemId, } from './Items';
|
|
3
|
+
export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps, isGroupSelectItem, } from './Items';
|
|
4
4
|
export { useGroupItemSelection } from './Items/hooks';
|
package/dist/components/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './Lists';
|
|
2
|
-
export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
|
|
2
|
+
export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps, isGroupSelectItem, } from './Items';
|
|
3
3
|
export { useGroupItemSelection } from './Items/hooks';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TruncateStringProps } from '@snack-uikit/truncate-string';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
export type ItemContentProps = WithSupportProps<{
|
|
4
|
+
option: string | number;
|
|
5
|
+
caption?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
truncate?: {
|
|
8
|
+
option?: number;
|
|
9
|
+
description?: number;
|
|
10
|
+
variant?: TruncateStringProps['variant'];
|
|
11
|
+
};
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function ItemContent({ truncate, caption, description, option, className, disabled, ...rest }: ItemContentProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import cn from 'classnames';
|
|
14
|
+
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
15
|
+
import { extractSupportProps } from '@snack-uikit/utils';
|
|
16
|
+
import { useNewListContext } from '../../components/Lists/contexts';
|
|
17
|
+
import styles from './styles.module.css';
|
|
18
|
+
export function ItemContent(_a) {
|
|
19
|
+
var _b, _c;
|
|
20
|
+
var { truncate, caption, description, option, className, disabled } = _a, rest = __rest(_a, ["truncate", "caption", "description", "option", "className", "disabled"]);
|
|
21
|
+
const { size = 's' } = useNewListContext();
|
|
22
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.content, className) }, extractSupportProps(rest), { "data-size": size !== null && size !== void 0 ? size : 's', "data-disabled": disabled || undefined, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.label, children: _jsx(TruncateString, { variant: truncate === null || truncate === void 0 ? void 0 : truncate.variant, text: String(option), maxLines: (_b = truncate === null || truncate === void 0 ? void 0 : truncate.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 = truncate === null || truncate === void 0 ? void 0 : truncate.description) !== null && _c !== void 0 ? _c : 2, "data-test-id": 'list__base-item-description' }) }))] })));
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ItemContent';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ItemContent';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
.headline{
|
|
2
|
+
display:flex;
|
|
3
|
+
align-items:center;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.label{
|
|
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
|
+
.content{
|
|
24
|
+
overflow:hidden;
|
|
25
|
+
flex-grow:1;
|
|
26
|
+
flex-shrink:1;
|
|
27
|
+
box-sizing:border-box;
|
|
28
|
+
}
|
|
29
|
+
.content[data-size=s] .headline{
|
|
30
|
+
gap:var(--space-drop-list-item-s-container-headline-gap, 8px);
|
|
31
|
+
height:var(--size-drop-list-item-headline, 24px);
|
|
32
|
+
}
|
|
33
|
+
.content[data-size=s] .label{
|
|
34
|
+
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
35
|
+
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
36
|
+
line-height:var(--sans-body-s-line-height, 16px);
|
|
37
|
+
font-size:var(--sans-body-s-font-size, 12px);
|
|
38
|
+
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
39
|
+
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
40
|
+
}
|
|
41
|
+
.content[data-size=s] .caption{
|
|
42
|
+
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
43
|
+
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
44
|
+
line-height:var(--sans-body-s-line-height, 16px);
|
|
45
|
+
font-size:var(--sans-body-s-font-size, 12px);
|
|
46
|
+
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
47
|
+
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
48
|
+
}
|
|
49
|
+
.content[data-size=s] .description{
|
|
50
|
+
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
51
|
+
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
52
|
+
line-height:var(--sans-body-s-line-height, 16px);
|
|
53
|
+
font-size:var(--sans-body-s-font-size, 12px);
|
|
54
|
+
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
55
|
+
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
56
|
+
}
|
|
57
|
+
.content[data-size=m] .headline{
|
|
58
|
+
gap:var(--space-drop-list-item-m-container-headline-gap, 8px);
|
|
59
|
+
height:var(--size-drop-list-item-headline, 24px);
|
|
60
|
+
}
|
|
61
|
+
.content[data-size=m] .label{
|
|
62
|
+
font-family:var(--sans-body-m-font-family, SB Sans Interface);
|
|
63
|
+
font-weight:var(--sans-body-m-font-weight, Regular);
|
|
64
|
+
line-height:var(--sans-body-m-line-height, 20px);
|
|
65
|
+
font-size:var(--sans-body-m-font-size, 14px);
|
|
66
|
+
letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
|
|
67
|
+
paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
|
|
68
|
+
}
|
|
69
|
+
.content[data-size=m] .caption{
|
|
70
|
+
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
71
|
+
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
72
|
+
line-height:var(--sans-body-s-line-height, 16px);
|
|
73
|
+
font-size:var(--sans-body-s-font-size, 12px);
|
|
74
|
+
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
75
|
+
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
76
|
+
}
|
|
77
|
+
.content[data-size=m] .description{
|
|
78
|
+
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
79
|
+
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
80
|
+
line-height:var(--sans-body-s-line-height, 16px);
|
|
81
|
+
font-size:var(--sans-body-s-font-size, 12px);
|
|
82
|
+
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
83
|
+
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
84
|
+
}
|
|
85
|
+
.content[data-size=l] .headline{
|
|
86
|
+
gap:var(--space-drop-list-item-l-container-headline-gap, 8px);
|
|
87
|
+
height:var(--size-drop-list-item-headline, 24px);
|
|
88
|
+
}
|
|
89
|
+
.content[data-size=l] .label{
|
|
90
|
+
font-family:var(--sans-body-l-font-family, SB Sans Interface);
|
|
91
|
+
font-weight:var(--sans-body-l-font-weight, Regular);
|
|
92
|
+
line-height:var(--sans-body-l-line-height, 24px);
|
|
93
|
+
font-size:var(--sans-body-l-font-size, 16px);
|
|
94
|
+
letter-spacing:var(--sans-body-l-letter-spacing, 0.1px);
|
|
95
|
+
paragraph-spacing:var(--sans-body-l-paragraph-spacing, 8.8px);
|
|
96
|
+
}
|
|
97
|
+
.content[data-size=l] .caption{
|
|
98
|
+
font-family:var(--sans-body-m-font-family, SB Sans Interface);
|
|
99
|
+
font-weight:var(--sans-body-m-font-weight, Regular);
|
|
100
|
+
line-height:var(--sans-body-m-line-height, 20px);
|
|
101
|
+
font-size:var(--sans-body-m-font-size, 14px);
|
|
102
|
+
letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
|
|
103
|
+
paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
|
|
104
|
+
}
|
|
105
|
+
.content[data-size=l] .description{
|
|
106
|
+
font-family:var(--sans-body-m-font-family, SB Sans Interface);
|
|
107
|
+
font-weight:var(--sans-body-m-font-weight, Regular);
|
|
108
|
+
line-height:var(--sans-body-m-line-height, 20px);
|
|
109
|
+
font-size:var(--sans-body-m-font-size, 14px);
|
|
110
|
+
letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
|
|
111
|
+
paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
|
|
112
|
+
}
|
|
113
|
+
.content[data-disabled] .label,
|
|
114
|
+
.content[data-disabled] .description,
|
|
115
|
+
.content[data-disabled] .caption{
|
|
116
|
+
color:var(--sys-neutral-text-disabled, #b3b6bf);
|
|
117
|
+
}
|
|
@@ -9,6 +9,6 @@ export type ListEmptyState = {
|
|
|
9
9
|
loading?: boolean;
|
|
10
10
|
dataError?: boolean;
|
|
11
11
|
dataFiltered?: boolean;
|
|
12
|
-
|
|
12
|
+
hasNoItems: boolean;
|
|
13
13
|
};
|
|
14
|
-
export declare function ListEmptyState({ dataError, dataFiltered,
|
|
14
|
+
export declare function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyStates, loading }: ListEmptyState): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { InfoBlock } from '@snack-uikit/info-block';
|
|
3
3
|
import styles from './styles.module.css';
|
|
4
|
-
export function ListEmptyState({ dataError, dataFiltered,
|
|
5
|
-
if (
|
|
4
|
+
export function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyStates, loading }) {
|
|
5
|
+
if (loading) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
if (dataError) {
|
|
9
|
+
return (_jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.errorDataState, { size: 's', align: 'vertical' })) }));
|
|
10
|
+
}
|
|
11
|
+
if (dataFiltered && hasNoItems) {
|
|
12
|
+
return (_jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.noResultsState, { size: 's', align: 'vertical', "data-test-id": 'list__no-results' })) }));
|
|
13
|
+
}
|
|
14
|
+
if (!dataFiltered && hasNoItems) {
|
|
15
|
+
return (_jsx("div", { className: styles.listEmptyStateWrapper, children: _jsx(InfoBlock, Object.assign({}, emptyStates.noDataState, { size: 's', align: 'vertical', "data-test-id": 'list__no-data' })) }));
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
9
18
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ForwardedRef, MouseEvent } from 'react';
|
|
1
2
|
import { TruncateStringProps } from '@snack-uikit/truncate-string';
|
|
2
3
|
export type SeparatorProps = {
|
|
3
4
|
label?: string;
|
|
@@ -6,6 +7,11 @@ export type SeparatorProps = {
|
|
|
6
7
|
};
|
|
7
8
|
mode?: 'primary' | 'secondary';
|
|
8
9
|
divider?: boolean;
|
|
9
|
-
|
|
10
|
+
selectButton?: {
|
|
11
|
+
onClick?(e: MouseEvent<HTMLElement>): void;
|
|
12
|
+
indeterminate?: boolean;
|
|
13
|
+
checked?: boolean;
|
|
14
|
+
itemRef?: ForwardedRef<HTMLElement>;
|
|
15
|
+
};
|
|
10
16
|
};
|
|
11
|
-
export declare function Separator({ label, truncate, divider, mode,
|
|
17
|
+
export declare function Separator({ label, truncate, divider, mode, selectButton }: SeparatorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { ButtonFunction } from '@snack-uikit/button';
|
|
2
4
|
import { Divider } from '@snack-uikit/divider';
|
|
5
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
3
6
|
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
7
|
+
import { useNewListContext } from '../../components/Lists/contexts';
|
|
8
|
+
import { SELECT_BUTTON_SIZE_MAP } from './constants';
|
|
4
9
|
import styles from './styles.module.css';
|
|
5
|
-
export function Separator({ label, truncate, divider, mode = 'secondary',
|
|
10
|
+
export function Separator({ label, truncate, divider, mode = 'secondary', selectButton }) {
|
|
11
|
+
const { size = 's' } = useNewListContext();
|
|
12
|
+
const { t } = useLocale('List');
|
|
13
|
+
const selectButtonJSX = useMemo(() => {
|
|
14
|
+
if (!selectButton) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const { onClick, checked, itemRef } = selectButton;
|
|
18
|
+
return (_jsx("span", { className: styles.selectButton, "data-size": size, "data-weight": (divider && mode) || undefined, children: _jsx(ButtonFunction, { size: SELECT_BUTTON_SIZE_MAP[size], tabIndex: 0, onClick: e => {
|
|
19
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
e.stopPropagation();
|
|
22
|
+
}, onFocus: e => {
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
}, ref: itemRef, label: checked ? t('groupSelectButton.reset') : t('groupSelectButton.select') }) }));
|
|
25
|
+
}, [divider, mode, selectButton, size, t]);
|
|
6
26
|
if (label) {
|
|
7
|
-
return (_jsxs("div", { className: styles.separatorWithLabel, "data-size": size, children: [_jsx("span", { className: styles.label, "data-mode": mode, children: _jsx(TruncateString, { variant: truncate === null || truncate === void 0 ? void 0 : truncate.variant, text: label, maxLines: 1 }) }), divider && _jsx(Divider, { weight: mode === 'primary' ? 'regular' : 'light', className: styles.divider })] }));
|
|
27
|
+
return (_jsxs("div", { className: styles.separatorWithLabel, "data-size": size, children: [_jsx("span", { className: styles.label, "data-mode": mode, children: _jsx(TruncateString, { variant: truncate === null || truncate === void 0 ? void 0 : truncate.variant, text: label, maxLines: 1 }) }), _jsxs("div", { style: { flex: 1 }, children: [selectButtonJSX, divider && _jsx(Divider, { weight: mode === 'primary' ? 'regular' : 'light', className: styles.divider })] })] }));
|
|
8
28
|
}
|
|
9
29
|
if (divider) {
|
|
10
30
|
return (_jsx("div", { className: styles.separatorWithoutLabel, "data-size": size, children: _jsx(Divider, { weight: 'regular' }) }));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
.separatorWithLabel{
|
|
2
|
-
overflow:hidden;
|
|
3
2
|
display:flex;
|
|
4
3
|
gap:var(--dimension-1m, 8px);
|
|
5
4
|
align-items:flex-end;
|
|
@@ -119,4 +118,24 @@ hr.divider{
|
|
|
119
118
|
flex:1;
|
|
120
119
|
width:auto;
|
|
121
120
|
min-width:0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.selectButton{
|
|
124
|
+
display:flex;
|
|
125
|
+
justify-content:flex-end;
|
|
126
|
+
}
|
|
127
|
+
.selectButton[data-weight=primary]{
|
|
128
|
+
--divider-height:1px;
|
|
129
|
+
}
|
|
130
|
+
.selectButton[data-weight=secondary]{
|
|
131
|
+
--divider-height:0.5px;
|
|
132
|
+
}
|
|
133
|
+
.selectButton[data-size=s]{
|
|
134
|
+
transform:translateY(calc((var(--size-button-xs, 24px) - var(--sans-label-s-line-height, 14px)) / 2 - var(--divider-height, 0)));
|
|
135
|
+
}
|
|
136
|
+
.selectButton[data-size=m]{
|
|
137
|
+
transform:translateY(calc((var(--size-button-s, 32px) - var(--sans-label-m-line-height, 16px)) / 2 - var(--divider-height, 0)));
|
|
138
|
+
}
|
|
139
|
+
.selectButton[data-size=l]{
|
|
140
|
+
transform:translateY(calc((var(--size-button-m, 40px) - var(--sans-label-l-line-height, 20px)) / 2 - var(--divider-height, 0)));
|
|
122
141
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './components';
|
|
2
|
-
export { useFuzzySearch } from './hooks';
|
|
3
2
|
export type { SearchState } from './types';
|
|
4
|
-
export {
|
|
3
|
+
export { kindFlattenItems } from './components/Items';
|
|
4
|
+
export * from './helperComponents/ItemContent';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './components';
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
2
|
+
export { kindFlattenItems } from './components/Items';
|
|
3
|
+
export * from './helperComponents/ItemContent';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
export type SearchState = {
|
|
3
3
|
placeholder?: string;
|
|
4
|
+
loading?: boolean;
|
|
4
5
|
value?: string;
|
|
5
6
|
onChange(value: string): void;
|
|
6
|
-
loading?: boolean;
|
|
7
7
|
};
|
|
8
8
|
export type ScrollProps = {
|
|
9
9
|
/** Включить ли скролл для основной части списка */
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "List",
|
|
7
|
-
"version": "0.11.1
|
|
7
|
+
"version": "0.11.1",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,27 +32,22 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/
|
|
36
|
-
"@snack-uikit/
|
|
35
|
+
"@snack-uikit/button": "0.17.1",
|
|
36
|
+
"@snack-uikit/divider": "3.0.3",
|
|
37
|
+
"@snack-uikit/dropdown": "0.2.2",
|
|
37
38
|
"@snack-uikit/icons": "0.20.1",
|
|
38
|
-
"@snack-uikit/info-block": "0.3.
|
|
39
|
-
"@snack-uikit/loaders": "0.5.
|
|
40
|
-
"@snack-uikit/
|
|
41
|
-
"@snack-uikit/
|
|
42
|
-
"@snack-uikit/
|
|
43
|
-
"@snack-uikit/
|
|
44
|
-
"@snack-uikit/
|
|
45
|
-
"@snack-uikit/utils": "3.2.0",
|
|
39
|
+
"@snack-uikit/info-block": "0.3.4",
|
|
40
|
+
"@snack-uikit/loaders": "0.5.2",
|
|
41
|
+
"@snack-uikit/scroll": "0.5.3",
|
|
42
|
+
"@snack-uikit/search-private": "0.2.0",
|
|
43
|
+
"@snack-uikit/toggles": "0.9.8",
|
|
44
|
+
"@snack-uikit/truncate-string": "0.4.13",
|
|
45
|
+
"@snack-uikit/utils": "3.3.0",
|
|
46
46
|
"classnames": "2.5.1",
|
|
47
|
-
"
|
|
48
|
-
"merge-refs": "1.2.2",
|
|
49
|
-
"uncontrollable": "8.0.4"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@types/fuzzy-search": "2.1.5"
|
|
47
|
+
"merge-refs": "1.2.2"
|
|
53
48
|
},
|
|
54
49
|
"peerDependencies": {
|
|
55
50
|
"@snack-uikit/locale": "*"
|
|
56
51
|
},
|
|
57
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "bf1e1f3cfabccc1ee288c18722e33009bd001798"
|
|
58
53
|
}
|