@snack-uikit/list 0.10.0 → 0.10.1-preview-69abc1d3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +56 -24
  2. package/dist/components/Items/AccordionItem/AccordionItem.d.ts +4 -2
  3. package/dist/components/Items/AccordionItem/AccordionItem.js +18 -16
  4. package/dist/components/Items/BaseItem/BaseItem.d.ts +8 -4
  5. package/dist/components/Items/BaseItem/BaseItem.js +20 -14
  6. package/dist/components/Items/BaseItem/styles.module.css +9 -122
  7. package/dist/components/Items/GroupItem/GroupItem.d.ts +5 -1
  8. package/dist/components/Items/GroupItem/GroupItem.js +1 -3
  9. package/dist/components/Items/GroupSelectItem/GroupSelectItem.d.ts +4 -0
  10. package/dist/components/Items/GroupSelectItem/GroupSelectItem.js +18 -0
  11. package/dist/components/Items/GroupSelectItem/index.d.ts +1 -0
  12. package/dist/components/Items/GroupSelectItem/index.js +1 -0
  13. package/dist/components/Items/NextListItem/NextListItem.d.ts +6 -2
  14. package/dist/components/Items/NextListItem/NextListItem.js +53 -45
  15. package/dist/components/Items/NextListItem/constants.d.ts +2 -0
  16. package/dist/components/Items/NextListItem/constants.js +10 -0
  17. package/dist/components/Items/SearchItem/SearchItem.d.ts +3 -1
  18. package/dist/components/Items/SearchItem/SearchItem.js +5 -8
  19. package/dist/components/Items/hooks.d.ts +11 -10
  20. package/dist/components/Items/hooks.js +64 -46
  21. package/dist/components/Items/index.d.ts +1 -5
  22. package/dist/components/Items/index.js +1 -5
  23. package/dist/components/Items/types.d.ts +68 -34
  24. package/dist/components/Items/utils.d.ts +33 -16
  25. package/dist/components/Items/utils.js +132 -37
  26. package/dist/components/Lists/Droplist/DropList.d.ts +1 -1
  27. package/dist/components/Lists/Droplist/DropList.js +73 -50
  28. package/dist/components/Lists/List/List.d.ts +5 -9
  29. package/dist/components/Lists/List/List.js +56 -54
  30. package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +6 -20
  31. package/dist/components/Lists/ListPrivate/ListPrivate.js +9 -8
  32. package/dist/components/Lists/ListPrivate/styles.module.css +1 -0
  33. package/dist/components/Lists/contexts/CollapseProvider.d.ts +13 -1
  34. package/dist/components/Lists/contexts/CollapseProvider.js +2 -0
  35. package/dist/components/Lists/contexts/FocusListProvider.d.ts +9 -0
  36. package/dist/components/Lists/contexts/FocusListProvider.js +5 -0
  37. package/dist/components/Lists/contexts/NewListProvider.d.ts +32 -0
  38. package/dist/components/Lists/contexts/{ListProvider.js → NewListProvider.js} +10 -5
  39. package/dist/components/Lists/contexts/SelectionProvider.d.ts +25 -15
  40. package/dist/components/Lists/contexts/SelectionProvider.js +17 -13
  41. package/dist/components/Lists/contexts/index.d.ts +2 -2
  42. package/dist/components/Lists/contexts/index.js +2 -2
  43. package/dist/components/Lists/hooks.d.ts +10 -12
  44. package/dist/components/Lists/hooks.js +73 -40
  45. package/dist/components/Lists/types.d.ts +12 -14
  46. package/dist/components/index.d.ts +2 -2
  47. package/dist/components/index.js +1 -1
  48. package/dist/helperComponents/ItemContent/ItemContent.d.ts +15 -0
  49. package/dist/helperComponents/ItemContent/ItemContent.js +23 -0
  50. package/dist/helperComponents/ItemContent/index.d.ts +1 -0
  51. package/dist/helperComponents/ItemContent/index.js +1 -0
  52. package/dist/helperComponents/ItemContent/styles.module.css +117 -0
  53. package/dist/helperComponents/ListEmptyState/ListEmptyState.d.ts +2 -2
  54. package/dist/helperComponents/ListEmptyState/ListEmptyState.js +13 -4
  55. package/dist/helperComponents/Separator/Separator.d.ts +8 -2
  56. package/dist/helperComponents/Separator/Separator.js +22 -2
  57. package/dist/helperComponents/Separator/constants.d.ts +2 -0
  58. package/dist/helperComponents/Separator/constants.js +5 -0
  59. package/dist/helperComponents/Separator/styles.module.css +20 -1
  60. package/dist/helperComponents/index.d.ts +1 -0
  61. package/dist/helperComponents/index.js +1 -0
  62. package/dist/hooks.d.ts +1 -1
  63. package/dist/hooks.js +15 -10
  64. package/dist/index.d.ts +3 -2
  65. package/dist/index.js +3 -2
  66. package/dist/legacy/components/Items/hooks.d.ts +12 -0
  67. package/dist/legacy/components/Items/hooks.js +33 -0
  68. package/dist/legacy/components/index.d.ts +1 -0
  69. package/dist/legacy/components/index.js +1 -0
  70. package/dist/legacy/hooks.d.ts +5 -0
  71. package/dist/legacy/hooks.js +15 -0
  72. package/dist/legacy/index.d.ts +3 -0
  73. package/dist/legacy/index.js +3 -0
  74. package/dist/{utils.d.ts → legacy/utils.d.ts} +2 -3
  75. package/dist/{utils.js → legacy/utils.js} +4 -12
  76. package/dist/types.d.ts +1 -1
  77. package/package.json +14 -14
  78. package/src/components/Items/AccordionItem/AccordionItem.tsx +24 -20
  79. package/src/components/Items/BaseItem/BaseItem.tsx +48 -43
  80. package/src/components/Items/BaseItem/styles.module.scss +8 -70
  81. package/src/components/Items/GroupItem/GroupItem.tsx +5 -5
  82. package/src/components/Items/GroupSelectItem/GroupSelectItem.tsx +44 -0
  83. package/src/components/Items/GroupSelectItem/index.ts +1 -0
  84. package/src/components/Items/NextListItem/NextListItem.tsx +86 -85
  85. package/src/components/Items/NextListItem/constants.ts +12 -0
  86. package/src/components/Items/SearchItem/SearchItem.tsx +6 -8
  87. package/src/components/Items/hooks.tsx +86 -66
  88. package/src/components/Items/index.ts +1 -5
  89. package/src/components/Items/types.ts +91 -42
  90. package/src/components/Items/utils.ts +193 -52
  91. package/src/components/Lists/Droplist/DropList.tsx +151 -98
  92. package/src/components/Lists/List/List.tsx +124 -104
  93. package/src/components/Lists/ListPrivate/ListPrivate.tsx +19 -20
  94. package/src/components/Lists/ListPrivate/styles.module.scss +1 -0
  95. package/src/components/Lists/contexts/CollapseProvider.tsx +22 -0
  96. package/src/components/Lists/contexts/FocusListProvider.tsx +16 -0
  97. package/src/components/Lists/contexts/NewListProvider.tsx +54 -0
  98. package/src/components/Lists/contexts/SelectionProvider.tsx +56 -39
  99. package/src/components/Lists/contexts/index.ts +3 -2
  100. package/src/components/Lists/hooks.ts +124 -75
  101. package/src/components/Lists/types.ts +20 -24
  102. package/src/components/index.ts +16 -2
  103. package/src/helperComponents/ItemContent/ItemContent.tsx +63 -0
  104. package/src/helperComponents/ItemContent/index.ts +1 -0
  105. package/src/helperComponents/ItemContent/styles.module.scss +78 -0
  106. package/src/helperComponents/ListEmptyState/ListEmptyState.tsx +26 -12
  107. package/src/helperComponents/Separator/Separator.tsx +49 -3
  108. package/src/helperComponents/Separator/constants.ts +7 -0
  109. package/src/helperComponents/Separator/styles.module.scss +41 -1
  110. package/src/helperComponents/index.ts +1 -0
  111. package/src/hooks.ts +21 -15
  112. package/src/index.ts +5 -2
  113. package/src/legacy/components/Items/hooks.tsx +53 -0
  114. package/src/legacy/components/index.ts +1 -0
  115. package/src/legacy/hooks.ts +27 -0
  116. package/src/legacy/index.ts +3 -0
  117. package/src/{utils.ts → legacy/utils.ts} +4 -13
  118. package/src/types.ts +1 -1
  119. package/dist/components/Items/NextListItem/hooks.d.ts +0 -19
  120. package/dist/components/Items/NextListItem/hooks.js +0 -80
  121. package/dist/components/Lists/contexts/ListProvider.d.ts +0 -17
  122. package/dist/components/Lists/contexts/ParentListProvider.d.ts +0 -18
  123. package/dist/components/Lists/contexts/ParentListProvider.js +0 -12
  124. package/src/components/Items/NextListItem/hooks.ts +0 -105
  125. package/src/components/Lists/contexts/CollapseProvider.ts +0 -9
  126. package/src/components/Lists/contexts/ListProvider.tsx +0 -28
  127. package/src/components/Lists/contexts/ParentListProvider.tsx +0 -35
@@ -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
- itemsLength: number;
12
+ hasNoItems: boolean;
13
13
  };
14
- export declare function ListEmptyState({ dataError, dataFiltered, itemsLength, emptyStates, loading }: ListEmptyState): import("react/jsx-runtime").JSX.Element | null;
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, jsxs as _jsxs } from "react/jsx-runtime";
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, itemsLength, emptyStates, loading }) {
5
- if (itemsLength || loading) {
4
+ export function ListEmptyState({ dataError, dataFiltered, hasNoItems, emptyStates, loading }) {
5
+ if (loading) {
6
6
  return null;
7
7
  }
8
- return (_jsxs("div", { className: styles.listEmptyStateWrapper, children: [dataError && _jsx(InfoBlock, Object.assign({}, emptyStates.errorDataState, { size: 's', align: 'vertical' })), !dataError && dataFiltered && (_jsx(InfoBlock, Object.assign({}, emptyStates.noResultsState, { size: 's', align: 'vertical', "data-test-id": 'list__no-results' }))), !dataError && !dataFiltered && (_jsx(InfoBlock, Object.assign({}, emptyStates.noDataState, { size: 's', align: 'vertical', "data-test-id": 'list__no-data' })))] }));
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
- size?: 's' | 'm' | 'l';
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, size }: SeparatorProps): import("react/jsx-runtime").JSX.Element | null;
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', size = 's' }) {
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' }) }));
@@ -0,0 +1,2 @@
1
+ import { ButtonFunctionProps } from '@snack-uikit/button';
2
+ export declare const SELECT_BUTTON_SIZE_MAP: Record<string, ButtonFunctionProps['size']>;
@@ -0,0 +1,5 @@
1
+ export const SELECT_BUTTON_SIZE_MAP = {
2
+ s: 'xs',
3
+ m: 's',
4
+ l: 'm',
5
+ };
@@ -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
  }
@@ -2,3 +2,4 @@ export * from './CollapseBlockPrivate';
2
2
  export * from './Separator';
3
3
  export * from './HiddenTabButton';
4
4
  export * from './ListEmptyState';
5
+ export * from './ItemContent';
@@ -2,3 +2,4 @@ export * from './CollapseBlockPrivate';
2
2
  export * from './Separator';
3
3
  export * from './HiddenTabButton';
4
4
  export * from './ListEmptyState';
5
+ export * from './ItemContent';
package/dist/hooks.d.ts CHANGED
@@ -2,4 +2,4 @@ import { ItemProps } from './components/Items';
2
2
  /**
3
3
  * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
4
4
  */
5
- export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => ItemProps[];
5
+ export declare function useFuzzySearch(items: ItemProps[]): () => import("./components/Items").Item[];
package/dist/hooks.js CHANGED
@@ -1,15 +1,20 @@
1
- import FuzzySearch from 'fuzzy-search';
1
+ // import FuzzySearch from 'fuzzy-search';
2
2
  import { useCallback } from 'react';
3
- import { flattenItems } from './utils';
4
- const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
3
+ // import { flattenItems } from './utils';
4
+ // const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
5
5
  /**
6
6
  * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
7
7
  */
8
- export function useFuzzySearch(items, minSearchInputLength) {
9
- return useCallback((search) => {
10
- const searcher = new FuzzySearch(flattenItems(items), ['content.option', 'content.caption', 'content.description', 'label'], {});
11
- return search.length > (minSearchInputLength !== null && minSearchInputLength !== void 0 ? minSearchInputLength : DEFAULT_MIN_SEARCH_INPUT_LENGTH)
12
- ? searcher.search(search)
13
- : items;
14
- }, [items, minSearchInputLength]);
8
+ export function useFuzzySearch(items) {
9
+ return useCallback(() =>
10
+ // (search: string) =>
11
+ // const searcher = new FuzzySearch(
12
+ // // flattenItems(items),
13
+ // ['content.option', 'content.caption', 'content.description', 'label'],
14
+ // {},
15
+ // );
16
+ // return search.length > (minSearchInputLength ?? DEFAULT_MIN_SEARCH_INPUT_LENGTH)
17
+ // ? searcher.search(search)
18
+ // : items;
19
+ items, [items]);
15
20
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './components';
2
- export { useFuzzySearch } from './hooks';
3
2
  export type { SearchState } from './types';
4
- export { extractChildIds, flattenItems } from './utils';
3
+ export { kindFlattenItems } from './components/Items';
4
+ export * from './helperComponents/ItemContent';
5
+ export * from './legacy';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
- export { useFuzzySearch } from './hooks';
3
- export { extractChildIds, flattenItems } from './utils';
2
+ export { kindFlattenItems } from './components/Items';
3
+ export * from './helperComponents/ItemContent';
4
+ export * from './legacy';
@@ -0,0 +1,12 @@
1
+ import { ItemProps } from '../../../components';
2
+ type UseGroupItemSelectionProps = {
3
+ items: ItemProps[];
4
+ id?: string | number;
5
+ disabled?: boolean;
6
+ };
7
+ export declare function useLegacyGroupItemSelection({ id, items, disabled }: UseGroupItemSelectionProps): {
8
+ checked: boolean | undefined;
9
+ isIndeterminate: boolean;
10
+ handleOnSelect: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,33 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { useSelectionContext } from '../../../components/Lists/contexts';
3
+ import { extractAllChildIds, extractChildIds } from '../../utils';
4
+ export function useLegacyGroupItemSelection({ id = '', items, disabled }) {
5
+ const { value, setValue, isSelectionMultiple } = useSelectionContext();
6
+ const { childIds, allChildIds } = useMemo(() => ({ childIds: extractChildIds({ items }), allChildIds: extractAllChildIds({ items }) }), [items]);
7
+ const isIndeterminate = isSelectionMultiple
8
+ ? allChildIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
9
+ : allChildIds.includes(value !== null && value !== void 0 ? value : '');
10
+ const checked = isSelectionMultiple ? allChildIds.every(childId => value === null || value === void 0 ? void 0 : value.includes(childId)) : undefined;
11
+ useEffect(() => {
12
+ if (isSelectionMultiple) {
13
+ if (checked && !(value === null || value === void 0 ? void 0 : value.includes(id))) {
14
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([id !== null && id !== void 0 ? id : '']));
15
+ }
16
+ if (!checked && (value === null || value === void 0 ? void 0 : value.includes(id))) {
17
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id));
18
+ }
19
+ }
20
+ }, [checked, disabled, id, isSelectionMultiple, setValue, value]);
21
+ const handleOnSelect = () => {
22
+ if (checked) {
23
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !childIds.includes(itemId)));
24
+ return;
25
+ }
26
+ if (isIndeterminate) {
27
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...childIds, id])));
28
+ return;
29
+ }
30
+ setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([...childIds, id !== null && id !== void 0 ? id : '']));
31
+ };
32
+ return { checked, isIndeterminate, handleOnSelect };
33
+ }
@@ -0,0 +1 @@
1
+ export { useLegacyGroupItemSelection } from './Items/hooks';
@@ -0,0 +1 @@
1
+ export { useLegacyGroupItemSelection } from './Items/hooks';
@@ -0,0 +1,5 @@
1
+ import { ItemProps } from '../components';
2
+ /**
3
+ * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
4
+ */
5
+ export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => import("../components/Items").Item[];
@@ -0,0 +1,15 @@
1
+ import FuzzySearch from 'fuzzy-search';
2
+ import { useCallback } from 'react';
3
+ import { flattenItems } from './utils';
4
+ const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
5
+ /**
6
+ * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
7
+ */
8
+ export function useFuzzySearch(items, minSearchInputLength) {
9
+ return useCallback((search) => {
10
+ const searcher = new FuzzySearch(flattenItems(items), ['content.option', 'content.caption', 'content.description', 'label'], {});
11
+ return search.length > (minSearchInputLength !== null && minSearchInputLength !== void 0 ? minSearchInputLength : DEFAULT_MIN_SEARCH_INPUT_LENGTH)
12
+ ? searcher.search(search)
13
+ : items;
14
+ }, [items, minSearchInputLength]);
15
+ }
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { useFuzzySearch } from './hooks';
3
+ export { extractChildIds, flattenItems } from './utils';
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { useFuzzySearch } from './hooks';
3
+ export { extractChildIds, flattenItems } from './utils';
@@ -1,16 +1,15 @@
1
1
  import { RefObject } from 'react';
2
- import { AccordionItemProps, BaseItemProps, ItemProps, NextListItemProps } 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>;
6
6
  };
7
7
  export declare function withCollapsedItems({ items, openCollapsedItems }: WithCollapsedItemsProps): {
8
- items: ItemProps[];
8
+ items: import("../components/Items").Item[];
9
9
  itemRefs: RefObject<HTMLElement>[];
10
10
  ids: (string | number)[];
11
11
  expandedIds: (string | number)[];
12
12
  };
13
- export declare function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[];
14
13
  /**
15
14
  * Функция возвращает массив id дочерних items
16
15
  * @function extractItemIds
@@ -1,4 +1,4 @@
1
- import { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps, } from './components/Items';
1
+ import { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps, } from '../components/Items';
2
2
  export function withCollapsedItems({ items, openCollapsedItems }) {
3
3
  let itemRefs = [];
4
4
  let newItems = [];
@@ -38,14 +38,6 @@ export function withCollapsedItems({ items, openCollapsedItems }) {
38
38
  });
39
39
  return { items, itemRefs, ids, expandedIds };
40
40
  }
41
- export function extractItemRefs(items) {
42
- return items.reduce((prev, item) => {
43
- if (isGroupItemProps(item)) {
44
- return prev.concat(extractItemRefs(item.items));
45
- }
46
- return item.itemRef ? prev.concat([item.itemRef]) : prev;
47
- }, []);
48
- }
49
41
  /**
50
42
  * Функция возвращает массив id дочерних items
51
43
  * @function extractItemIds
@@ -97,10 +89,10 @@ export function extractAllChildIds({ items }) {
97
89
  * @function flattenItems
98
90
  */
99
91
  export function flattenItems(items) {
100
- const flattenedItems = [];
92
+ const flattenItems = [];
101
93
  function flatten(item) {
102
94
  if (!isGroupItemProps(item)) {
103
- flattenedItems.push(item);
95
+ flattenItems.push(item);
104
96
  }
105
97
  if ('items' in item) {
106
98
  for (const nestedItem of item.items) {
@@ -111,5 +103,5 @@ export function flattenItems(items) {
111
103
  for (const item of items) {
112
104
  flatten(item);
113
105
  }
114
- return flattenedItems;
106
+ return flattenItems;
115
107
  }
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.10.0",
7
+ "version": "0.10.1-preview-69abc1d3.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,21 +32,21 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/divider": "3.0.2",
36
- "@snack-uikit/dropdown": "0.2.1",
35
+ "@snack-uikit/button": "0.17.1-preview-69abc1d3.0",
36
+ "@snack-uikit/divider": "3.0.3-preview-69abc1d3.0",
37
+ "@snack-uikit/dropdown": "0.2.2-preview-69abc1d3.0",
37
38
  "@snack-uikit/icons": "0.20.1",
38
- "@snack-uikit/info-block": "0.3.3",
39
- "@snack-uikit/loaders": "0.5.1",
40
- "@snack-uikit/locale": "0.6.0",
41
- "@snack-uikit/scroll": "0.5.2",
42
- "@snack-uikit/search-private": "0.1.5",
43
- "@snack-uikit/toggles": "0.9.7",
44
- "@snack-uikit/truncate-string": "0.4.12",
45
- "@snack-uikit/utils": "3.2.0",
39
+ "@snack-uikit/info-block": "0.3.4-preview-69abc1d3.0",
40
+ "@snack-uikit/loaders": "0.5.2-preview-69abc1d3.0",
41
+ "@snack-uikit/locale": "0.6.1-preview-69abc1d3.0",
42
+ "@snack-uikit/scroll": "0.5.3-preview-69abc1d3.0",
43
+ "@snack-uikit/search-private": "0.1.6-preview-69abc1d3.0",
44
+ "@snack-uikit/toggles": "0.9.8-preview-69abc1d3.0",
45
+ "@snack-uikit/truncate-string": "0.4.13-preview-69abc1d3.0",
46
+ "@snack-uikit/utils": "3.2.1-preview-69abc1d3.0",
46
47
  "classnames": "2.5.1",
47
48
  "fuzzy-search": "3.2.1",
48
- "merge-refs": "1.2.2",
49
- "uncontrollable": "8.0.4"
49
+ "merge-refs": "1.2.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/fuzzy-search": "2.1.5"
@@ -54,5 +54,5 @@
54
54
  "peerDependencies": {
55
55
  "@snack-uikit/locale": "*"
56
56
  },
57
- "gitHead": "381565b14f3e08082b29add05be8f982fa8f4c2f"
57
+ "gitHead": "f1afde301bcd6ae86662d45c89041e7a14cc7b98"
58
58
  }
@@ -1,33 +1,36 @@
1
- import { KeyboardEvent, MouseEvent } from 'react';
1
+ import { MouseEvent, useCallback } from 'react';
2
2
 
3
3
  import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
4
4
 
5
5
  import { CollapseBlockPrivate } from '../../../helperComponents';
6
- import { CollapseContext, useCollapseContext, useParentListContext } from '../../Lists/contexts';
6
+ import { CollapseLevelContext, useCollapseContext, useCollapseLevelContext } from '../../Lists/contexts';
7
7
  import { BaseItem } from '../BaseItem';
8
8
  import { useGroupItemSelection, useRenderItems } from '../hooks';
9
- import { AccordionItemProps } from '../types';
9
+ import { CommonFlattenProps, FlattenAccordionItem } from '../types';
10
10
 
11
- export function AccordionItem({ items: itemsProp, id, disabled, ...option }: AccordionItemProps) {
12
- const { level = 1 } = useCollapseContext();
13
- const { toggleOpenCollapsedItems, openCollapsedItems } = useParentListContext();
14
- const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items: itemsProp, id, disabled });
11
+ type AccordionItemProps = Omit<FlattenAccordionItem, 'type>'> & CommonFlattenProps;
15
12
 
16
- const isOpen = Boolean(openCollapsedItems?.includes(id ?? ''));
13
+ export function AccordionItem({ id, disabled, allChildIds, items, ...option }: AccordionItemProps) {
14
+ const { level = 1 } = useCollapseLevelContext();
15
+ const { openCollapseItems = [], toggleOpenCollapseItem } = useCollapseContext();
17
16
 
18
- const handleKeyDown = (e: KeyboardEvent<HTMLElement>) => {
19
- if (e.key === 'ArrowRight') {
20
- toggleOpenCollapsedItems?.(id ?? '');
17
+ const { indeterminate, checked, handleOnSelect } = useGroupItemSelection({
18
+ items,
19
+ id,
20
+ disabled,
21
+ allChildIds,
22
+ });
21
23
 
22
- e.preventDefault();
23
- e.stopPropagation();
24
- }
25
- };
24
+ const isOpen = Boolean(openCollapseItems.includes(id ?? ''));
25
+
26
+ const handleKeyDown = useCallback(() => {
27
+ toggleOpenCollapseItem?.(id ?? '');
28
+ }, [id, toggleOpenCollapseItem]);
26
29
 
27
- const itemsJSX = useRenderItems(itemsProp);
30
+ const itemsJSX = useRenderItems(items);
28
31
 
29
32
  const handleItemClick = (e: MouseEvent<HTMLElement>) => {
30
- toggleOpenCollapsedItems?.(id ?? '');
33
+ toggleOpenCollapseItem?.(id ?? '');
31
34
  option.onClick?.(e);
32
35
  };
33
36
 
@@ -41,15 +44,16 @@ export function AccordionItem({ items: itemsProp, id, disabled, ...option }: Acc
41
44
  expandIcon={isOpen ? <ChevronUpSVG /> : <ChevronDownSVG />}
42
45
  onClick={handleItemClick}
43
46
  isParentNode
44
- onKeyDown={handleKeyDown}
45
- indeterminate={isIndeterminate && !checked}
47
+ onOpenNestedList={handleKeyDown}
48
+ checked={checked}
49
+ indeterminate={indeterminate}
46
50
  onSelect={!disabled ? handleOnSelect : undefined}
47
51
  />
48
52
  }
49
53
  expanded={isOpen}
50
54
  data-test-id={`list__accordion-item-${id}`}
51
55
  >
52
- <CollapseContext.Provider value={{ level: level + 1 }}>{itemsJSX}</CollapseContext.Provider>
56
+ <CollapseLevelContext.Provider value={{ level: level + 1 }}>{itemsJSX}</CollapseLevelContext.Provider>
53
57
  </CollapseBlockPrivate>
54
58
  );
55
59
  }