@alfalab/core-components-select 10.2.3 → 10.4.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.
Files changed (187) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/Component.d.ts +1 -1
  3. package/dist/Component.js +2 -1
  4. package/dist/components/arrow/Component.js +1 -1
  5. package/dist/components/arrow/index.css +3 -3
  6. package/dist/components/base-select/Component.js +26 -23
  7. package/dist/components/base-select/index.css +7 -7
  8. package/dist/components/base-select/index.js +1 -1
  9. package/dist/components/checkmark/Component.d.ts +1 -1
  10. package/dist/components/checkmark/Component.js +11 -5
  11. package/dist/components/checkmark/index.css +21 -9
  12. package/dist/components/checkmark/index.js +1 -0
  13. package/dist/components/field/Component.d.ts +1 -1
  14. package/dist/components/field/Component.js +3 -3
  15. package/dist/components/field/index.css +9 -9
  16. package/dist/components/field/index.js +1 -1
  17. package/dist/components/index.js +2 -1
  18. package/dist/components/native-select/Component.js +1 -1
  19. package/dist/components/native-select/index.js +1 -1
  20. package/dist/components/optgroup/Component.js +1 -1
  21. package/dist/components/optgroup/index.css +6 -6
  22. package/dist/components/option/Component.js +7 -5
  23. package/dist/components/option/index.css +20 -20
  24. package/dist/components/option/index.js +2 -1
  25. package/dist/components/options-list/Component.js +13 -8
  26. package/dist/components/options-list/index.css +9 -5
  27. package/dist/components/options-list/index.js +1 -0
  28. package/dist/components/virtual-options-list/Component.d.ts +1 -1
  29. package/dist/components/virtual-options-list/Component.js +22 -18
  30. package/dist/components/virtual-options-list/index.css +15 -12
  31. package/dist/components/virtual-options-list/index.js +1 -0
  32. package/dist/cssm/Component.d.ts +1 -1
  33. package/dist/cssm/Component.js +1 -0
  34. package/dist/cssm/components/base-select/Component.js +24 -21
  35. package/dist/cssm/components/checkmark/Component.d.ts +1 -1
  36. package/dist/cssm/components/checkmark/Component.js +10 -4
  37. package/dist/cssm/components/checkmark/index.js +1 -0
  38. package/dist/cssm/components/checkmark/index.module.css +19 -7
  39. package/dist/cssm/components/field/Component.d.ts +1 -1
  40. package/dist/cssm/components/field/Component.js +1 -1
  41. package/dist/cssm/components/index.js +1 -0
  42. package/dist/cssm/components/option/Component.js +5 -3
  43. package/dist/cssm/components/option/index.js +1 -0
  44. package/dist/cssm/components/options-list/Component.js +12 -7
  45. package/dist/cssm/components/options-list/index.js +1 -0
  46. package/dist/cssm/components/options-list/index.module.css +4 -0
  47. package/dist/cssm/components/virtual-options-list/Component.d.ts +1 -1
  48. package/dist/cssm/components/virtual-options-list/Component.js +21 -17
  49. package/dist/cssm/components/virtual-options-list/index.js +1 -0
  50. package/dist/cssm/components/virtual-options-list/index.module.css +4 -1
  51. package/dist/cssm/hook-3b9bd559.d.ts +12 -0
  52. package/dist/cssm/hook-3b9bd559.js +147 -0
  53. package/dist/cssm/hook-f5b8fe4f.d.ts +61 -0
  54. package/dist/cssm/index.js +8 -1
  55. package/dist/cssm/intersection-observer-8c55e13a.d.ts +1 -0
  56. package/dist/cssm/intersection-observer-8c55e13a.js +893 -0
  57. package/dist/cssm/presets/index.d.ts +1 -0
  58. package/dist/cssm/presets/index.js +30 -1
  59. package/dist/cssm/presets/useLazyLoading/hook.js +2 -892
  60. package/dist/cssm/presets/useSelectWithApply/hook.d.ts +0 -0
  61. package/dist/cssm/presets/useSelectWithApply/hook.js +46 -0
  62. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  63. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/Component.js +45 -0
  64. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  65. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.js +45 -0
  66. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.module.css +38 -0
  67. package/dist/cssm/presets/useSelectWithLoading/hook.js +1 -0
  68. package/dist/cssm/typings.d.ts +55 -6
  69. package/dist/esm/Component.d.ts +1 -1
  70. package/dist/esm/Component.js +2 -1
  71. package/dist/esm/components/arrow/Component.js +1 -1
  72. package/dist/esm/components/arrow/index.css +3 -3
  73. package/dist/esm/components/base-select/Component.js +26 -23
  74. package/dist/esm/components/base-select/index.css +7 -7
  75. package/dist/esm/components/base-select/index.js +1 -1
  76. package/dist/esm/components/checkmark/Component.d.ts +1 -1
  77. package/dist/esm/components/checkmark/Component.js +12 -6
  78. package/dist/esm/components/checkmark/index.css +21 -9
  79. package/dist/esm/components/checkmark/index.js +1 -0
  80. package/dist/esm/components/field/Component.d.ts +1 -1
  81. package/dist/esm/components/field/Component.js +3 -3
  82. package/dist/esm/components/field/index.css +9 -9
  83. package/dist/esm/components/field/index.js +1 -1
  84. package/dist/esm/components/index.js +2 -1
  85. package/dist/esm/components/native-select/Component.js +1 -1
  86. package/dist/esm/components/native-select/index.js +1 -1
  87. package/dist/esm/components/optgroup/Component.js +1 -1
  88. package/dist/esm/components/optgroup/index.css +6 -6
  89. package/dist/esm/components/option/Component.js +7 -5
  90. package/dist/esm/components/option/index.css +20 -20
  91. package/dist/esm/components/option/index.js +2 -1
  92. package/dist/esm/components/options-list/Component.js +14 -9
  93. package/dist/esm/components/options-list/index.css +9 -5
  94. package/dist/esm/components/options-list/index.js +1 -0
  95. package/dist/esm/components/virtual-options-list/Component.d.ts +1 -1
  96. package/dist/esm/components/virtual-options-list/Component.js +22 -18
  97. package/dist/esm/components/virtual-options-list/index.css +15 -12
  98. package/dist/esm/components/virtual-options-list/index.js +1 -0
  99. package/dist/esm/hook-3514e1ff.d.ts +12 -0
  100. package/dist/esm/hook-3514e1ff.js +131 -0
  101. package/dist/esm/hook-f5b8fe4f.d.ts +61 -0
  102. package/dist/esm/index.js +5 -1
  103. package/dist/esm/intersection-observer-228b670b.d.ts +1 -0
  104. package/dist/esm/intersection-observer-228b670b.js +891 -0
  105. package/dist/esm/presets/index.d.ts +1 -0
  106. package/dist/esm/presets/index.js +21 -1
  107. package/dist/esm/presets/useLazyLoading/hook.js +4 -894
  108. package/dist/esm/presets/useLazyLoading/index.css +2 -2
  109. package/dist/esm/presets/useSelectWithApply/hook.d.ts +0 -0
  110. package/dist/esm/presets/useSelectWithApply/hook.js +26 -0
  111. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  112. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/Component.js +26 -0
  113. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
  114. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  115. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.js +26 -0
  116. package/dist/esm/presets/useSelectWithLoading/hook.js +3 -2
  117. package/dist/esm/presets/useSelectWithLoading/index.css +2 -2
  118. package/dist/esm/{tslib.es6-e401d952.d.ts → tslib.es6-f688174c.d.ts} +0 -0
  119. package/dist/esm/{tslib.es6-e401d952.js → tslib.es6-f688174c.js} +0 -0
  120. package/dist/esm/typings.d.ts +55 -6
  121. package/dist/hook-6f1602ae.d.ts +12 -0
  122. package/dist/hook-6f1602ae.js +140 -0
  123. package/dist/hook-f5b8fe4f.d.ts +61 -0
  124. package/dist/index.js +7 -1
  125. package/dist/intersection-observer-6dcf2d59.d.ts +1 -0
  126. package/dist/intersection-observer-6dcf2d59.js +893 -0
  127. package/dist/modern/Component.d.ts +1 -1
  128. package/dist/modern/Component.js +1 -0
  129. package/dist/modern/components/arrow/Component.js +1 -1
  130. package/dist/modern/components/arrow/index.css +3 -3
  131. package/dist/modern/components/base-select/Component.js +20 -15
  132. package/dist/modern/components/base-select/index.css +7 -7
  133. package/dist/modern/components/checkmark/Component.d.ts +1 -1
  134. package/dist/modern/components/checkmark/Component.js +12 -4
  135. package/dist/modern/components/checkmark/index.css +21 -9
  136. package/dist/modern/components/checkmark/index.js +1 -0
  137. package/dist/modern/components/field/Component.d.ts +1 -1
  138. package/dist/modern/components/field/Component.js +2 -2
  139. package/dist/modern/components/field/index.css +9 -9
  140. package/dist/modern/components/index.js +1 -0
  141. package/dist/modern/components/optgroup/Component.js +1 -1
  142. package/dist/modern/components/optgroup/index.css +6 -6
  143. package/dist/modern/components/option/Component.js +6 -4
  144. package/dist/modern/components/option/index.css +20 -20
  145. package/dist/modern/components/option/index.js +1 -0
  146. package/dist/modern/components/options-list/Component.js +11 -7
  147. package/dist/modern/components/options-list/index.css +9 -5
  148. package/dist/modern/components/virtual-options-list/Component.d.ts +1 -1
  149. package/dist/modern/components/virtual-options-list/Component.js +20 -17
  150. package/dist/modern/components/virtual-options-list/index.css +15 -12
  151. package/dist/modern/hook-d9110e41.d.ts +12 -0
  152. package/dist/modern/hook-d9110e41.js +132 -0
  153. package/dist/modern/hook-f5b8fe4f.d.ts +61 -0
  154. package/dist/modern/index.js +4 -0
  155. package/dist/modern/intersection-observer-228b670b.d.ts +1 -0
  156. package/dist/modern/intersection-observer-228b670b.js +891 -0
  157. package/dist/modern/presets/index.d.ts +1 -0
  158. package/dist/modern/presets/index.js +20 -0
  159. package/dist/modern/presets/useLazyLoading/hook.js +3 -893
  160. package/dist/modern/presets/useLazyLoading/index.css +2 -2
  161. package/dist/modern/presets/useSelectWithApply/hook.d.ts +0 -0
  162. package/dist/modern/presets/useSelectWithApply/hook.js +25 -0
  163. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  164. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/Component.js +25 -0
  165. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
  166. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  167. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.js +25 -0
  168. package/dist/modern/presets/useSelectWithLoading/hook.js +2 -1
  169. package/dist/modern/presets/useSelectWithLoading/index.css +2 -2
  170. package/dist/modern/typings.d.ts +55 -6
  171. package/dist/presets/index.d.ts +1 -0
  172. package/dist/presets/index.js +23 -1
  173. package/dist/presets/useLazyLoading/hook.js +4 -894
  174. package/dist/presets/useLazyLoading/index.css +2 -2
  175. package/dist/presets/useSelectWithApply/hook.d.ts +0 -0
  176. package/dist/presets/useSelectWithApply/hook.js +35 -0
  177. package/dist/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  178. package/dist/presets/useSelectWithApply/options-list-with-apply/Component.js +34 -0
  179. package/dist/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
  180. package/dist/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  181. package/dist/presets/useSelectWithApply/options-list-with-apply/index.js +34 -0
  182. package/dist/presets/useSelectWithLoading/hook.js +3 -2
  183. package/dist/presets/useSelectWithLoading/index.css +2 -2
  184. package/dist/{tslib.es6-ba995fc6.d.ts → tslib.es6-b1b1a51e.d.ts} +0 -0
  185. package/dist/{tslib.es6-ba995fc6.js → tslib.es6-b1b1a51e.js} +0 -0
  186. package/dist/typings.d.ts +55 -6
  187. package/package.json +5 -3
@@ -1,5 +1,5 @@
1
- /* hash: 1ghd3 */
2
- .select__skeleton_1gpi6 {
1
+ /* hash: 1isnn */
2
+ .select__skeleton_7dbzt {
3
3
  position: absolute;
4
4
  top: 50%;
5
5
  transform: translateY(-50%);
File without changes
@@ -0,0 +1,26 @@
1
+ import '../../tslib.es6-f688174c.js';
2
+ import 'react';
3
+ import 'classnames';
4
+ import '@alfalab/hooks';
5
+ import '@alfalab/core-components-form-control/dist/esm';
6
+ import '../../utils.js';
7
+ import '../../components/field/Component.js';
8
+ import '@alfalab/icons-glyph/ChevronDownMIcon';
9
+ import '../../components/arrow/Component.js';
10
+ import 'react-merge-refs';
11
+ import '../../components/optgroup/Component.js';
12
+ import '../../components/options-list/Component.js';
13
+ import '@alfalab/core-components-checkbox/dist/esm';
14
+ import '../../components/checkmark/Component.js';
15
+ import '../../components/option/Component.js';
16
+ import 'resize-observer';
17
+ import '@alfalab/core-components-popover/dist/esm';
18
+ import 'downshift';
19
+ import '../../components/native-select/Component.js';
20
+ import '../../components/base-select/Component.js';
21
+ import '../../Component.js';
22
+ import 'react-virtual';
23
+ import '@alfalab/core-components-skeleton/dist/esm';
24
+ import '../../intersection-observer-228b670b.js';
25
+ import '@alfalab/core-components-button/dist/esm';
26
+ export { S as SELECT_ALL_KEY, u as useSelectWithApply } from '../../hook-3514e1ff.js';
@@ -0,0 +1,26 @@
1
+ import '../../../tslib.es6-f688174c.js';
2
+ import 'react';
3
+ import 'classnames';
4
+ import '@alfalab/hooks';
5
+ import '@alfalab/core-components-form-control/dist/esm';
6
+ import '../../../utils.js';
7
+ import '../../../components/field/Component.js';
8
+ import '@alfalab/icons-glyph/ChevronDownMIcon';
9
+ import '../../../components/arrow/Component.js';
10
+ import 'react-merge-refs';
11
+ import '../../../components/optgroup/Component.js';
12
+ import '../../../components/options-list/Component.js';
13
+ import '@alfalab/core-components-checkbox/dist/esm';
14
+ import '../../../components/checkmark/Component.js';
15
+ import '../../../components/option/Component.js';
16
+ import 'resize-observer';
17
+ import '@alfalab/core-components-popover/dist/esm';
18
+ import 'downshift';
19
+ import '../../../components/native-select/Component.js';
20
+ import '../../../components/base-select/Component.js';
21
+ import '../../../Component.js';
22
+ import 'react-virtual';
23
+ import '@alfalab/core-components-skeleton/dist/esm';
24
+ import '../../../intersection-observer-228b670b.js';
25
+ import '@alfalab/core-components-button/dist/esm';
26
+ export { O as OptionsListWithApply } from '../../../hook-3514e1ff.js';
@@ -0,0 +1,39 @@
1
+ /* hash: 5k2jg */
2
+ :root {
3
+ --color-light-bg-primary: #fff;
4
+ --color-light-border-secondary: #e7e9eb;
5
+ }
6
+ :root {
7
+
8
+ /* Hard */
9
+
10
+ /* Up */
11
+
12
+ /* Hard up */
13
+ }
14
+ :root {
15
+ --gap-xs: 8px;
16
+ --gap-s: 12px;
17
+ --gap-m: 16px;
18
+ }
19
+ :root {
20
+
21
+ /* options list */
22
+
23
+ /* option */
24
+
25
+ /* checkmark */
26
+
27
+ /* optgroup */
28
+ }
29
+ .select__footer_xitdb {
30
+ background: var(--color-light-bg-primary);
31
+ padding: var(--gap-s) var(--gap-s) var(--gap-m);
32
+ outline: none
33
+ }
34
+ .select__footer_xitdb > * + * {
35
+ margin-left: var(--gap-xs);
36
+ }
37
+ .select__withBorder_xitdb {
38
+ box-shadow: inset 0 1px 0 var(--color-light-border-secondary);
39
+ }
@@ -0,0 +1 @@
1
+ export * from "../../../hook-3514e1ff";
@@ -0,0 +1,26 @@
1
+ import '../../../tslib.es6-f688174c.js';
2
+ import 'react';
3
+ import 'classnames';
4
+ import '@alfalab/hooks';
5
+ import '@alfalab/core-components-form-control/dist/esm';
6
+ import '../../../utils.js';
7
+ import '../../../components/field/Component.js';
8
+ import '@alfalab/icons-glyph/ChevronDownMIcon';
9
+ import '../../../components/arrow/Component.js';
10
+ import 'react-merge-refs';
11
+ import '../../../components/optgroup/Component.js';
12
+ import '../../../components/options-list/Component.js';
13
+ import '@alfalab/core-components-checkbox/dist/esm';
14
+ import '../../../components/checkmark/Component.js';
15
+ import '../../../components/option/Component.js';
16
+ import 'resize-observer';
17
+ import '@alfalab/core-components-popover/dist/esm';
18
+ import 'downshift';
19
+ import '../../../components/native-select/Component.js';
20
+ import '../../../components/base-select/Component.js';
21
+ import '../../../Component.js';
22
+ import 'react-virtual';
23
+ import '@alfalab/core-components-skeleton/dist/esm';
24
+ import '../../../intersection-observer-228b670b.js';
25
+ import '@alfalab/core-components-button/dist/esm';
26
+ export { O as OptionsListWithApply } from '../../../hook-3514e1ff.js';
@@ -1,11 +1,12 @@
1
- import { a as __assign } from '../../tslib.es6-e401d952.js';
1
+ import { a as __assign } from '../../tslib.es6-f688174c.js';
2
2
  import React, { useCallback } from 'react';
3
3
  import 'classnames';
4
+ import '@alfalab/core-components-checkbox/dist/esm';
4
5
  import '../../components/checkmark/Component.js';
5
6
  import { Option } from '../../components/option/Component.js';
6
7
  import { Skeleton } from '@alfalab/core-components-skeleton/dist/esm';
7
8
 
8
- var styles = {"skeleton":"select__skeleton_1bo8s"};
9
+ var styles = {"skeleton":"select__skeleton_1p9wx"};
9
10
  require('./index.css')
10
11
 
11
12
  function useSelectWithLoading(_a) {
@@ -1,5 +1,5 @@
1
- /* hash: 1bu7m */
2
- .select__skeleton_1bo8s {
1
+ /* hash: 1hktt */
2
+ .select__skeleton_1p9wx {
3
3
  position: absolute;
4
4
  top: 50%;
5
5
  transform: translateY(-50%);
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { ReactNode, FC, RefAttributes, AriaAttributes, FocusEvent, MouseEvent, ReactElement } from 'react';
3
2
  import { PopoverProps } from "@alfalab/core-components-popover";
4
3
  import { InputProps } from "@alfalab/core-components-input";
@@ -51,6 +50,10 @@ type BaseSelectProps = {
51
50
  * Дополнительный класс для пункта меню
52
51
  */
53
52
  optionClassName?: string;
53
+ /**
54
+ * Дополнительный класс для поповера
55
+ */
56
+ popperClassName?: string;
54
57
  /**
55
58
  * Список вариантов выбора
56
59
  */
@@ -194,6 +197,7 @@ type BaseSelectProps = {
194
197
  onChange?: (payload: {
195
198
  selected: OptionShape | null;
196
199
  selectedMultiple: OptionShape[];
200
+ initiator: OptionShape | null;
197
201
  name?: string;
198
202
  }) => void;
199
203
  /**
@@ -245,6 +249,14 @@ type FieldProps = {
245
249
  * Список выбранных пунктов
246
250
  */
247
251
  selectedMultiple?: OptionShape[];
252
+ /**
253
+ * Метод для ручной установки выбранных пунктов
254
+ */
255
+ setSelectedItems: (selected: OptionShape[]) => void;
256
+ /**
257
+ * Метод переключающий видимость выпадающего списка
258
+ */
259
+ toggleMenu: () => void;
248
260
  /**
249
261
  * Флаг, можно ли выбрать несколько значений
250
262
  */
@@ -322,10 +334,31 @@ type OptionsListProps = {
322
334
  /**
323
335
  * Компонент пункта меню
324
336
  */
325
- Option: (props: {
326
- option: OptionShape;
327
- index: number;
328
- }) => JSX.Element | null;
337
+ Option: FC<OptionProps>;
338
+ /**
339
+ * Функция для получения пропсов для ячейки
340
+ */
341
+ getOptionProps: (option: OptionShape, index: number) => OptionProps;
342
+ /**
343
+ * Список выбранных пунктов
344
+ */
345
+ selectedItems?: OptionShape[];
346
+ /**
347
+ * Метод для ручной установки выбранных пунктов
348
+ */
349
+ setSelectedItems: (selected: OptionShape[]) => void;
350
+ /**
351
+ * Метод переключающий видимость выпадающего списка
352
+ */
353
+ toggleMenu: () => void;
354
+ /**
355
+ * Контент шапки
356
+ */
357
+ header?: ReactNode;
358
+ /**
359
+ * Контент футера
360
+ */
361
+ footer?: ReactNode;
329
362
  /**
330
363
  * Список вариантов выбора
331
364
  */
@@ -399,7 +432,7 @@ type OptionProps = {
399
432
  */
400
433
  option: OptionShape;
401
434
  /**
402
- * Индект пункта
435
+ * Индекс пункта
403
436
  */
404
437
  index: number;
405
438
  /**
@@ -414,6 +447,10 @@ type OptionProps = {
414
447
  * Флаг, заблокирован ли данный пункт
415
448
  */
416
449
  disabled?: boolean;
450
+ /**
451
+ * Флаг множественного выбора
452
+ */
453
+ multiple?: boolean;
417
454
  /**
418
455
  * Компонент пункта меню
419
456
  */
@@ -438,5 +475,17 @@ type CheckmarkProps = {
438
475
  * Флаг, данный пункт выбран
439
476
  */
440
477
  selected?: boolean;
478
+ /**
479
+ * Дополнительный класс
480
+ */
481
+ className?: string;
482
+ /**
483
+ * Флаг множественного выбора
484
+ */
485
+ multiple?: boolean;
486
+ /**
487
+ * Расположение отметки
488
+ */
489
+ position?: 'before' | 'after';
441
490
  };
442
491
  export { OptionShape, GroupShape, BaseSelectProps, FieldProps, ArrowProps, OptionsListProps, OptgroupProps, OptionProps, CheckmarkProps };
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import React from 'react';
3
+ import { OptionShape, OptionsListProps } from "./typings";
4
+ declare const OptionsListWithApply: React.ForwardRefExoticComponent<OptionsListProps & {
5
+ showClear?: boolean | undefined;
6
+ onApply?: (() => void) | undefined;
7
+ onClear?: (() => void) | undefined;
8
+ onClose?: (() => void) | undefined;
9
+ selectedDraft?: OptionShape[] | undefined;
10
+ OptionsList?: React.FC<OptionsListProps & React.RefAttributes<unknown>> | undefined;
11
+ } & React.RefAttributes<unknown>>;
12
+ export { OptionsListWithApply };
@@ -0,0 +1,140 @@
1
+ 'use strict';
2
+
3
+ var tslib_es6 = require('./tslib.es6-b1b1a51e.js');
4
+ var React = require('react');
5
+ var cn = require('classnames');
6
+ require('@alfalab/hooks');
7
+ require('@alfalab/core-components-form-control');
8
+ var utils = require('./utils.js');
9
+ require('@alfalab/icons-glyph/ChevronDownMIcon');
10
+ var components_optionsList_Component = require('./components/options-list/Component.js');
11
+ require('@alfalab/core-components-checkbox');
12
+ require('./components/base-select/Component.js');
13
+ require('./Component.js');
14
+ require('react-virtual');
15
+ require('@alfalab/core-components-skeleton');
16
+ require('./intersection-observer-6dcf2d59.js');
17
+ var coreComponentsButton = require('@alfalab/core-components-button');
18
+
19
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
+
21
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
22
+ var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
23
+
24
+ var styles = {"footer":"select__footer_xitdb","withBorder":"select__withBorder_xitdb"};
25
+ require('./presets/useSelectWithApply/options-list-with-apply/index.css')
26
+
27
+ var OptionsListWithApply = React.forwardRef(function (_a, ref) {
28
+ var _b;
29
+ var toggleMenu = _a.toggleMenu, _c = _a.OptionsList, OptionsList = _c === void 0 ? components_optionsList_Component.OptionsList : _c, defaultGetOptionProps = _a.getOptionProps, _d = _a.showClear, showClear = _d === void 0 ? true : _d, _e = _a.selectedDraft, selectedDraft = _e === void 0 ? [] : _e, _f = _a.flatOptions, flatOptions = _f === void 0 ? [] : _f, _g = _a.onApply, onApply = _g === void 0 ? function () { return null; } : _g, _h = _a.onClear, onClear = _h === void 0 ? function () { return null; } : _h, _j = _a.onClose, onClose = _j === void 0 ? function () { return null; } : _j, _k = _a.visibleOptions, visibleOptions = _k === void 0 ? 5 : _k, restProps = tslib_es6.__rest(_a, ["toggleMenu", "OptionsList", "getOptionProps", "showClear", "selectedDraft", "flatOptions", "onApply", "onClear", "onClose", "visibleOptions"]);
30
+ var footerRef = React.useRef(null);
31
+ var getOptionProps = React.useCallback(function (option, index) {
32
+ var optionProps = defaultGetOptionProps(option, index);
33
+ var selected = option.key === SELECT_ALL_KEY
34
+ ? selectedDraft.length === flatOptions.length - 1
35
+ : selectedDraft.includes(option);
36
+ return tslib_es6.__assign(tslib_es6.__assign({}, optionProps), { selected: selected });
37
+ }, [defaultGetOptionProps, flatOptions.length, selectedDraft]);
38
+ var handleApply = React.useCallback(function () {
39
+ onApply();
40
+ toggleMenu();
41
+ }, [onApply, toggleMenu]);
42
+ var handleClear = React.useCallback(function () {
43
+ onClear();
44
+ toggleMenu();
45
+ }, [onClear, toggleMenu]);
46
+ React.useEffect(function () {
47
+ var activeElement = document.activeElement;
48
+ setTimeout(function () {
49
+ if (footerRef.current) {
50
+ footerRef.current.focus();
51
+ }
52
+ }, 0);
53
+ return function () {
54
+ onClose();
55
+ if (activeElement) {
56
+ activeElement.focus();
57
+ }
58
+ };
59
+ // eslint-disable-next-line react-hooks/exhaustive-deps
60
+ }, []);
61
+ return (React__default['default'].createElement(OptionsList, tslib_es6.__assign({}, restProps, { ref: ref, visibleOptions: visibleOptions, toggleMenu: toggleMenu, flatOptions: flatOptions, getOptionProps: getOptionProps, footer: React__default['default'].createElement("div", {
62
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
63
+ tabIndex: 0, className: cn__default['default'](styles.footer, (_b = {},
64
+ _b[styles.withBorder] = visibleOptions && flatOptions.length > visibleOptions,
65
+ _b)), ref: footerRef },
66
+ React__default['default'].createElement(coreComponentsButton.Button, { size: 'xxs', view: 'primary', onClick: handleApply }, "\u041F\u0440\u0438\u043C\u0435\u043D\u0438\u0442\u044C"),
67
+ showClear && (React__default['default'].createElement(coreComponentsButton.Button, { size: 'xxs', view: 'secondary', onClick: handleClear }, "\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C"))) })));
68
+ });
69
+
70
+ var SELECT_ALL_KEY = 'select_all';
71
+ var selectAllOption = { key: SELECT_ALL_KEY, content: 'Выбрать все' };
72
+ function useSelectWithApply(_a) {
73
+ var options = _a.options, selected = _a.selected, _b = _a.onChange, onChange = _b === void 0 ? function () { return null; } : _b, OptionsList = _a.OptionsList, _c = _a.showClear, showClear = _c === void 0 ? true : _c, _d = _a.showSelectAll, showSelectAll = _d === void 0 ? false : _d;
74
+ var _e = React.useMemo(function () { return utils.processOptions(options, selected); }, [
75
+ options,
76
+ selected,
77
+ ]), flatOptions = _e.flatOptions, selectedOptions = _e.selectedOptions;
78
+ var _f = React.useState(selectedOptions), selectedDraft = _f[0], setSelectedDraft = _f[1];
79
+ var selectedOptionsRef = React.useRef(selectedOptions);
80
+ var handleApply = React.useCallback(function () {
81
+ onChange({
82
+ selected: selectedDraft[0],
83
+ selectedMultiple: selectedDraft,
84
+ initiator: null,
85
+ });
86
+ }, [onChange, selectedDraft]);
87
+ var handleClear = React.useCallback(function () {
88
+ setSelectedDraft([]);
89
+ onChange({
90
+ selected: null,
91
+ selectedMultiple: [],
92
+ initiator: null,
93
+ });
94
+ }, [onChange]);
95
+ var handleChange = React.useCallback(function (_a) {
96
+ var initiator = _a.initiator, restArgs = tslib_es6.__rest(_a, ["initiator"]);
97
+ if (!initiator) {
98
+ onChange(tslib_es6.__assign({ initiator: null }, restArgs));
99
+ return;
100
+ }
101
+ var initiatorSelected = selectedDraft.includes(initiator) ||
102
+ (initiator.key === SELECT_ALL_KEY && selectedDraft.length === flatOptions.length);
103
+ if (initiator.key === SELECT_ALL_KEY) {
104
+ setSelectedDraft(initiatorSelected ? [] : flatOptions);
105
+ }
106
+ else {
107
+ setSelectedDraft(initiatorSelected
108
+ ? selectedDraft.filter(function (o) { return o !== initiator; })
109
+ : selectedDraft.concat(initiator));
110
+ }
111
+ }, [flatOptions, onChange, selectedDraft]);
112
+ var handleClose = React.useCallback(function () {
113
+ setSelectedDraft(selectedOptionsRef.current);
114
+ }, []);
115
+ React.useEffect(function () {
116
+ setSelectedDraft(selectedOptions);
117
+ selectedOptionsRef.current = selectedOptions;
118
+ }, [selectedOptions]);
119
+ var memoizedOptions = React.useMemo(function () { return (showSelectAll ? tslib_es6.__spreadArrays([selectAllOption], options) : options); }, [options, showSelectAll]);
120
+ return {
121
+ OptionsList: OptionsListWithApply,
122
+ optionsListProps: {
123
+ OptionsList: OptionsList,
124
+ showClear: showClear && (selectedDraft.length > 0 || selectedOptions.length > 0),
125
+ onClear: handleClear,
126
+ onApply: handleApply,
127
+ onClose: handleClose,
128
+ selectedDraft: selectedDraft,
129
+ },
130
+ allowUnselect: true,
131
+ multiple: true,
132
+ options: memoizedOptions,
133
+ onChange: handleChange,
134
+ selected: selected,
135
+ };
136
+ }
137
+
138
+ exports.OptionsListWithApply = OptionsListWithApply;
139
+ exports.SELECT_ALL_KEY = SELECT_ALL_KEY;
140
+ exports.useSelectWithApply = useSelectWithApply;
@@ -0,0 +1,61 @@
1
+ /// <reference types="react" />
2
+ import { OptionShape, BaseSelectProps } from "./index";
3
+ type useSelectWithApplyProps = {
4
+ /**
5
+ * Список выбранных пунктов
6
+ */
7
+ selected: BaseSelectProps['selected'];
8
+ /**
9
+ * Список вариантов выбора
10
+ */
11
+ options: BaseSelectProps['options'];
12
+ /**
13
+ * Обработчик выбора
14
+ */
15
+ onChange: BaseSelectProps['onChange'];
16
+ /**
17
+ * Компонент выпадающего меню
18
+ */
19
+ OptionsList?: BaseSelectProps['OptionsList'];
20
+ /**
21
+ * Показывать кнопку очистки
22
+ */
23
+ showClear?: boolean;
24
+ /**
25
+ * Показывать пункт "Выбрать все"
26
+ */
27
+ showSelectAll?: boolean;
28
+ };
29
+ declare const SELECT_ALL_KEY = "select_all";
30
+ declare function useSelectWithApply({ options, selected, onChange, OptionsList, showClear, showSelectAll, }: useSelectWithApplyProps): {
31
+ OptionsList: import("react").ForwardRefExoticComponent<import("./index").OptionsListProps & {
32
+ showClear?: boolean | undefined;
33
+ onApply?: (() => void) | undefined;
34
+ onClear?: (() => void) | undefined;
35
+ onClose?: (() => void) | undefined;
36
+ selectedDraft?: OptionShape[] | undefined;
37
+ OptionsList?: import("react").FC<import("./index").OptionsListProps & import("react").RefAttributes<unknown>> | undefined;
38
+ } & import("react").RefAttributes<unknown>>;
39
+ optionsListProps: {
40
+ OptionsList: import("react").FC<import("./index").OptionsListProps> | undefined;
41
+ showClear: boolean;
42
+ onClear: () => void;
43
+ onApply: () => void;
44
+ onClose: () => void;
45
+ selectedDraft: OptionShape[];
46
+ };
47
+ allowUnselect: boolean;
48
+ multiple: boolean;
49
+ options: (OptionShape | import("./index").GroupShape | {
50
+ key: string;
51
+ content: string;
52
+ })[];
53
+ onChange: (payload: {
54
+ selected: OptionShape | null;
55
+ selectedMultiple: OptionShape[];
56
+ initiator: OptionShape | null;
57
+ name?: string | undefined;
58
+ }) => void;
59
+ selected: string | OptionShape | (string | OptionShape)[] | null | undefined;
60
+ };
61
+ export { SELECT_ALL_KEY, useSelectWithApply };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('./tslib.es6-ba995fc6.js');
5
+ require('./tslib.es6-b1b1a51e.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('@alfalab/hooks');
@@ -14,6 +14,7 @@ var components_arrow_Component = require('./components/arrow/Component.js');
14
14
  require('react-merge-refs');
15
15
  var components_optgroup_Component = require('./components/optgroup/Component.js');
16
16
  var components_optionsList_Component = require('./components/options-list/Component.js');
17
+ require('@alfalab/core-components-checkbox');
17
18
  require('./components/checkmark/Component.js');
18
19
  var components_option_Component = require('./components/option/Component.js');
19
20
  require('resize-observer');
@@ -26,7 +27,10 @@ require('react-virtual');
26
27
  var components_virtualOptionsList_Component = require('./components/virtual-options-list/Component.js');
27
28
  require('@alfalab/core-components-skeleton');
28
29
  var presets_useSelectWithLoading_hook = require('./presets/useSelectWithLoading/hook.js');
30
+ require('./intersection-observer-6dcf2d59.js');
29
31
  var presets_useLazyLoading_hook = require('./presets/useLazyLoading/hook.js');
32
+ require('@alfalab/core-components-button');
33
+ var presets_useSelectWithApply_optionsListWithApply_Component = require('./hook-6f1602ae.js');
30
34
 
31
35
 
32
36
 
@@ -47,3 +51,5 @@ exports.Select = Component.Select;
47
51
  exports.VirtualOptionsList = components_virtualOptionsList_Component.VirtualOptionsList;
48
52
  exports.useSelectWithLoading = presets_useSelectWithLoading_hook.useSelectWithLoading;
49
53
  exports.useLazyLoading = presets_useLazyLoading_hook.useLazyLoading;
54
+ exports.SELECT_ALL_KEY = presets_useSelectWithApply_optionsListWithApply_Component.SELECT_ALL_KEY;
55
+ exports.useSelectWithApply = presets_useSelectWithApply_optionsListWithApply_Component.useSelectWithApply;
@@ -0,0 +1 @@
1
+ export {};