@snack-uikit/list 0.4.2-preview-1d9347a7.0 → 0.4.2-preview-3bc93fc3.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 +25 -0
- package/dist/components/Items/BaseItem/BaseItem.d.ts +1 -1
- package/dist/components/Items/BaseItem/BaseItem.js +2 -2
- package/dist/components/Items/types.d.ts +0 -2
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +1 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +4 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +25 -0
- package/package.json +3 -3
- package/src/components/Items/BaseItem/BaseItem.tsx +0 -2
- package/src/components/Items/types.ts +0 -2
- package/src/components/index.ts +2 -1
- package/src/hooks.ts +5 -23
- package/src/index.ts +1 -1
- package/src/utils.ts +35 -0
package/README.md
CHANGED
|
@@ -8,11 +8,36 @@
|
|
|
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
|
+
|------|------|---------------|-------------|
|
|
11
16
|
## extractChildIds
|
|
12
17
|
### Props
|
|
13
18
|
| name | type | default value | description |
|
|
14
19
|
|------|------|---------------|-------------|
|
|
15
20
|
| items* | `ItemProps[]` | - | |
|
|
21
|
+
## flattenItems
|
|
22
|
+
`flattenItems`
|
|
23
|
+
|
|
24
|
+
Функция разворачивает массив айтемов в плоский список
|
|
25
|
+
## isAccordionItemProps
|
|
26
|
+
### Props
|
|
27
|
+
| name | type | default value | description |
|
|
28
|
+
|------|------|---------------|-------------|
|
|
29
|
+
## isBaseItemProps
|
|
30
|
+
### Props
|
|
31
|
+
| name | type | default value | description |
|
|
32
|
+
|------|------|---------------|-------------|
|
|
33
|
+
## isGroupItemProps
|
|
34
|
+
### Props
|
|
35
|
+
| name | type | default value | description |
|
|
36
|
+
|------|------|---------------|-------------|
|
|
37
|
+
## isNextListItemProps
|
|
38
|
+
### Props
|
|
39
|
+
| name | type | default value | description |
|
|
40
|
+
|------|------|---------------|-------------|
|
|
16
41
|
## useGroupItemSelection
|
|
17
42
|
### Props
|
|
18
43
|
| name | type | default value | description |
|
|
@@ -5,5 +5,5 @@ type AllBaseItemProps = BaseItemProps & BaseItemPrivateProps & {
|
|
|
5
5
|
onSelect?(): void;
|
|
6
6
|
isParentNode?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare function BaseItem({ beforeContent, afterContent, content, onClick,
|
|
8
|
+
export declare function BaseItem({ beforeContent, afterContent, content, onClick, 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
9
|
export {};
|
|
@@ -19,7 +19,7 @@ import commonStyles from '../styles.module.css';
|
|
|
19
19
|
import { CHECKBOX_SIZE_MAP } from './constants';
|
|
20
20
|
import styles from './styles.module.css';
|
|
21
21
|
export function BaseItem(_a) {
|
|
22
|
-
var { beforeContent, afterContent, content, onClick,
|
|
22
|
+
var { beforeContent, afterContent, content, onClick, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "onSelect", "isParentNode", "className", "inactive", "itemWrapRender"]);
|
|
23
23
|
const { option, caption, description } = content || {};
|
|
24
24
|
const interactive = !inactive;
|
|
25
25
|
const { parentResetActiveFocusIndex } = useParentListContext();
|
|
@@ -70,7 +70,7 @@ export function BaseItem(_a) {
|
|
|
70
70
|
e.stopPropagation();
|
|
71
71
|
};
|
|
72
72
|
const props = extractSupportProps(rest);
|
|
73
|
-
const item = (_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,
|
|
73
|
+
const item = (_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, 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, { text: option, maxLines: 1 }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: 2 }) }))] }), 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 })] }));
|
|
74
74
|
if (!itemWrapRender) {
|
|
75
75
|
return item;
|
|
76
76
|
}
|
|
@@ -26,8 +26,6 @@ export type BaseItemProps = WithSupportProps<{
|
|
|
26
26
|
content: ItemContentProps;
|
|
27
27
|
/** Колбек обработки клика */
|
|
28
28
|
onClick?(e: MouseEvent<HTMLElement>): void;
|
|
29
|
-
/** Колбек обработки нажатия кнопки мыши */
|
|
30
|
-
onMouseDown?(e: MouseEvent<HTMLElement>): void;
|
|
31
29
|
/** Колбек обработки нажатия клавиши */
|
|
32
30
|
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
33
31
|
/** Колбек обработки фокуса */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from './Lists';
|
|
2
|
-
export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items
|
|
2
|
+
export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
|
|
3
|
+
export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
|
|
3
4
|
export { useGroupItemSelection } from './Items/hooks';
|
package/dist/components/index.js
CHANGED
package/dist/hooks.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { ItemProps } from './components/Items';
|
|
2
|
+
/**
|
|
3
|
+
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
4
|
+
*/
|
|
2
5
|
export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => ItemProps[];
|
package/dist/hooks.js
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import FuzzySearch from 'fuzzy-search';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
function flattenItems(items) {
|
|
5
|
-
const flattenedItems = [];
|
|
6
|
-
function flatten(item) {
|
|
7
|
-
if (!isGroupItemProps(item)) {
|
|
8
|
-
flattenedItems.push(item);
|
|
9
|
-
}
|
|
10
|
-
if ('items' in item) {
|
|
11
|
-
for (const nestedItem of item.items) {
|
|
12
|
-
flatten(nestedItem);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
for (const item of items) {
|
|
17
|
-
flatten(item);
|
|
18
|
-
}
|
|
19
|
-
return flattenedItems;
|
|
20
|
-
}
|
|
3
|
+
import { flattenItems } from './utils';
|
|
21
4
|
const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
|
|
5
|
+
/**
|
|
6
|
+
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
7
|
+
*/
|
|
22
8
|
export function useFuzzySearch(items, minSearchInputLength) {
|
|
23
9
|
return useCallback((search) => {
|
|
24
10
|
const searcher = new FuzzySearch(flattenItems(items), ['content.option', 'content.caption', 'content.description', 'label'], {});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import { ItemProps } from './components/Items';
|
|
2
|
+
import { AccordionItemProps, BaseItemProps, ItemProps, NextListItemProps } from './components/Items';
|
|
3
3
|
type WithCollapsedItemsProps = {
|
|
4
4
|
items: ItemProps[];
|
|
5
5
|
openCollapsedItems: Array<number | string>;
|
|
@@ -11,6 +11,10 @@ export declare function withCollapsedItems({ items, openCollapsedItems }: WithCo
|
|
|
11
11
|
expandedIds: (string | number)[];
|
|
12
12
|
};
|
|
13
13
|
export declare function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[];
|
|
14
|
+
/**
|
|
15
|
+
* Функция возвращает массив id дочерних items
|
|
16
|
+
* @function extractItemIds
|
|
17
|
+
*/
|
|
14
18
|
export declare function extractItemIds(items: ItemProps[]): Array<string | number>;
|
|
15
19
|
export declare function extractChildIds({ items }: {
|
|
16
20
|
items: ItemProps[];
|
|
@@ -18,4 +22,9 @@ export declare function extractChildIds({ items }: {
|
|
|
18
22
|
export declare function extractAllChildIds({ items }: {
|
|
19
23
|
items: ItemProps[];
|
|
20
24
|
}): Array<string | number>;
|
|
25
|
+
/**
|
|
26
|
+
* Функция разворачивает массив айтемов в плоский список
|
|
27
|
+
* @function flattenItems
|
|
28
|
+
*/
|
|
29
|
+
export declare function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[];
|
|
21
30
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -46,6 +46,10 @@ export function extractItemRefs(items) {
|
|
|
46
46
|
return item.itemRef ? prev.concat([item.itemRef]) : prev;
|
|
47
47
|
}, []);
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Функция возвращает массив id дочерних items
|
|
51
|
+
* @function extractItemIds
|
|
52
|
+
*/
|
|
49
53
|
export function extractItemIds(items) {
|
|
50
54
|
return items.reduce((prev, item) => {
|
|
51
55
|
if (isGroupItemProps(item)) {
|
|
@@ -88,3 +92,24 @@ export function extractAllChildIds({ items }) {
|
|
|
88
92
|
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
89
93
|
}, []);
|
|
90
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Функция разворачивает массив айтемов в плоский список
|
|
97
|
+
* @function flattenItems
|
|
98
|
+
*/
|
|
99
|
+
export function flattenItems(items) {
|
|
100
|
+
const flattenedItems = [];
|
|
101
|
+
function flatten(item) {
|
|
102
|
+
if (!isGroupItemProps(item)) {
|
|
103
|
+
flattenedItems.push(item);
|
|
104
|
+
}
|
|
105
|
+
if ('items' in item) {
|
|
106
|
+
for (const nestedItem of item.items) {
|
|
107
|
+
flatten(nestedItem);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const item of items) {
|
|
112
|
+
flatten(item);
|
|
113
|
+
}
|
|
114
|
+
return flattenedItems;
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "List",
|
|
7
|
-
"version": "0.4.2-preview-
|
|
7
|
+
"version": "0.4.2-preview-3bc93fc3.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/divider": "3.0.
|
|
35
|
+
"@snack-uikit/divider": "3.0.2-preview-3bc93fc3.0",
|
|
36
36
|
"@snack-uikit/dropdown": "0.2.0",
|
|
37
37
|
"@snack-uikit/icons": "0.20.1",
|
|
38
38
|
"@snack-uikit/info-block": "0.3.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@snack-uikit/locale": "*"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a2fa7717157c8a23fa1fc6b64c67c7b2d9dfc39c"
|
|
58
58
|
}
|
|
@@ -19,7 +19,6 @@ export function BaseItem({
|
|
|
19
19
|
afterContent,
|
|
20
20
|
content,
|
|
21
21
|
onClick,
|
|
22
|
-
onMouseDown,
|
|
23
22
|
id,
|
|
24
23
|
expandIcon,
|
|
25
24
|
disabled,
|
|
@@ -108,7 +107,6 @@ export function BaseItem({
|
|
|
108
107
|
className={cn(commonStyles.listItem, styles.droplistItem, className)}
|
|
109
108
|
data-size={size}
|
|
110
109
|
onClick={handleItemClick}
|
|
111
|
-
onMouseDown={onMouseDown}
|
|
112
110
|
tabIndex={-1}
|
|
113
111
|
data-non-pointer={inactive && !onClick}
|
|
114
112
|
data-inactive={inactive || undefined}
|
|
@@ -32,8 +32,6 @@ export type BaseItemProps = WithSupportProps<{
|
|
|
32
32
|
|
|
33
33
|
/** Колбек обработки клика */
|
|
34
34
|
onClick?(e: MouseEvent<HTMLElement>): void;
|
|
35
|
-
/** Колбек обработки нажатия кнопки мыши */
|
|
36
|
-
onMouseDown?(e: MouseEvent<HTMLElement>): void;
|
|
37
35
|
/** Колбек обработки нажатия клавиши */
|
|
38
36
|
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
39
37
|
/** Колбек обработки фокуса */
|
package/src/components/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './Lists';
|
|
2
2
|
|
|
3
|
-
export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items
|
|
3
|
+
export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
|
|
4
|
+
export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
|
|
4
5
|
|
|
5
6
|
export { useGroupItemSelection } from './Items/hooks';
|
package/src/hooks.ts
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import FuzzySearch from 'fuzzy-search';
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
function flattenItems(items: ItemProps[]): ItemProps[] {
|
|
7
|
-
const flattenedItems: ItemProps[] = [];
|
|
8
|
-
|
|
9
|
-
function flatten(item: ItemProps) {
|
|
10
|
-
if (!isGroupItemProps(item)) {
|
|
11
|
-
flattenedItems.push(item);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if ('items' in item) {
|
|
15
|
-
for (const nestedItem of item.items) {
|
|
16
|
-
flatten(nestedItem);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
for (const item of items) {
|
|
22
|
-
flatten(item);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return flattenedItems;
|
|
26
|
-
}
|
|
4
|
+
import { ItemProps } from './components/Items';
|
|
5
|
+
import { flattenItems } from './utils';
|
|
27
6
|
|
|
28
7
|
const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
|
|
29
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
11
|
+
*/
|
|
30
12
|
export function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number) {
|
|
31
13
|
return useCallback(
|
|
32
14
|
(search: string) => {
|
package/src/index.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
AccordionItemProps,
|
|
5
|
+
BaseItemProps,
|
|
4
6
|
isAccordionItemProps,
|
|
5
7
|
isBaseItemProps,
|
|
6
8
|
isGroupItemProps,
|
|
7
9
|
isNextListItemProps,
|
|
8
10
|
ItemProps,
|
|
11
|
+
NextListItemProps,
|
|
9
12
|
} from './components/Items';
|
|
10
13
|
|
|
11
14
|
type WithCollapsedItemsProps = {
|
|
@@ -77,6 +80,11 @@ export function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[] {
|
|
|
77
80
|
}, [] as RefObject<HTMLElement>[]);
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Функция возвращает массив id дочерних items
|
|
85
|
+
* @function extractItemIds
|
|
86
|
+
*/
|
|
87
|
+
|
|
80
88
|
export function extractItemIds(items: ItemProps[]): Array<string | number> {
|
|
81
89
|
return items.reduce(
|
|
82
90
|
(prev: Array<string | number>, item: ItemProps) => {
|
|
@@ -138,3 +146,30 @@ export function extractAllChildIds({ items }: { items: ItemProps[] }): Array<str
|
|
|
138
146
|
[] as Array<string | number>,
|
|
139
147
|
);
|
|
140
148
|
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Функция разворачивает массив айтемов в плоский список
|
|
152
|
+
* @function flattenItems
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
export function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[] {
|
|
156
|
+
const flattenedItems: (BaseItemProps | AccordionItemProps | NextListItemProps)[] = [];
|
|
157
|
+
|
|
158
|
+
function flatten(item: ItemProps) {
|
|
159
|
+
if (!isGroupItemProps(item)) {
|
|
160
|
+
flattenedItems.push(item);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if ('items' in item) {
|
|
164
|
+
for (const nestedItem of item.items) {
|
|
165
|
+
flatten(nestedItem);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const item of items) {
|
|
171
|
+
flatten(item);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return flattenedItems;
|
|
175
|
+
}
|