@alfalab/core-components-select 10.3.0 → 10.4.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 (170) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/Component.d.ts +1 -1
  3. package/dist/Component.js +1 -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 +23 -22
  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.js +2 -2
  10. package/dist/components/checkmark/index.css +7 -7
  11. package/dist/components/field/Component.d.ts +1 -1
  12. package/dist/components/field/Component.js +3 -3
  13. package/dist/components/field/index.css +9 -9
  14. package/dist/components/field/index.js +1 -1
  15. package/dist/components/index.js +1 -1
  16. package/dist/components/native-select/Component.js +1 -1
  17. package/dist/components/native-select/index.js +1 -1
  18. package/dist/components/optgroup/Component.js +1 -1
  19. package/dist/components/optgroup/index.css +6 -6
  20. package/dist/components/option/Component.js +2 -2
  21. package/dist/components/option/index.css +20 -20
  22. package/dist/components/option/index.js +1 -1
  23. package/dist/components/options-list/Component.js +13 -8
  24. package/dist/components/options-list/index.css +9 -5
  25. package/dist/components/options-list/index.js +1 -0
  26. package/dist/components/virtual-options-list/Component.d.ts +1 -1
  27. package/dist/components/virtual-options-list/Component.js +22 -18
  28. package/dist/components/virtual-options-list/index.css +15 -12
  29. package/dist/components/virtual-options-list/index.js +1 -0
  30. package/dist/cssm/Component.d.ts +1 -1
  31. package/dist/cssm/components/base-select/Component.js +21 -20
  32. package/dist/cssm/components/checkmark/Component.js +1 -1
  33. package/dist/cssm/components/field/Component.d.ts +1 -1
  34. package/dist/cssm/components/field/Component.js +1 -1
  35. package/dist/cssm/components/options-list/Component.js +12 -7
  36. package/dist/cssm/components/options-list/index.js +1 -0
  37. package/dist/cssm/components/options-list/index.module.css +4 -0
  38. package/dist/cssm/components/virtual-options-list/Component.d.ts +1 -1
  39. package/dist/cssm/components/virtual-options-list/Component.js +21 -17
  40. package/dist/cssm/components/virtual-options-list/index.js +1 -0
  41. package/dist/cssm/components/virtual-options-list/index.module.css +4 -1
  42. package/dist/cssm/hook-45e5f3a8.d.ts +12 -0
  43. package/dist/cssm/hook-45e5f3a8.js +147 -0
  44. package/dist/cssm/hook-f5b8fe4f.d.ts +61 -0
  45. package/dist/cssm/index.js +7 -1
  46. package/dist/cssm/intersection-observer-8c55e13a.d.ts +1 -0
  47. package/dist/cssm/intersection-observer-8c55e13a.js +893 -0
  48. package/dist/cssm/presets/index.d.ts +1 -0
  49. package/dist/cssm/presets/index.js +29 -1
  50. package/dist/cssm/presets/useLazyLoading/hook.js +1 -892
  51. package/dist/cssm/presets/useSelectWithApply/hook.d.ts +0 -0
  52. package/dist/cssm/presets/useSelectWithApply/hook.js +46 -0
  53. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  54. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/Component.js +45 -0
  55. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  56. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.js +45 -0
  57. package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.module.css +38 -0
  58. package/dist/cssm/typings.d.ts +39 -6
  59. package/dist/esm/Component.d.ts +1 -1
  60. package/dist/esm/Component.js +1 -1
  61. package/dist/esm/components/arrow/Component.js +1 -1
  62. package/dist/esm/components/arrow/index.css +3 -3
  63. package/dist/esm/components/base-select/Component.js +23 -22
  64. package/dist/esm/components/base-select/index.css +7 -7
  65. package/dist/esm/components/base-select/index.js +1 -1
  66. package/dist/esm/components/checkmark/Component.js +2 -2
  67. package/dist/esm/components/checkmark/index.css +7 -7
  68. package/dist/esm/components/field/Component.d.ts +1 -1
  69. package/dist/esm/components/field/Component.js +3 -3
  70. package/dist/esm/components/field/index.css +9 -9
  71. package/dist/esm/components/field/index.js +1 -1
  72. package/dist/esm/components/index.js +1 -1
  73. package/dist/esm/components/native-select/Component.js +1 -1
  74. package/dist/esm/components/native-select/index.js +1 -1
  75. package/dist/esm/components/optgroup/Component.js +1 -1
  76. package/dist/esm/components/optgroup/index.css +6 -6
  77. package/dist/esm/components/option/Component.js +2 -2
  78. package/dist/esm/components/option/index.css +20 -20
  79. package/dist/esm/components/option/index.js +1 -1
  80. package/dist/esm/components/options-list/Component.js +14 -9
  81. package/dist/esm/components/options-list/index.css +9 -5
  82. package/dist/esm/components/options-list/index.js +1 -0
  83. package/dist/esm/components/virtual-options-list/Component.d.ts +1 -1
  84. package/dist/esm/components/virtual-options-list/Component.js +22 -18
  85. package/dist/esm/components/virtual-options-list/index.css +15 -12
  86. package/dist/esm/components/virtual-options-list/index.js +1 -0
  87. package/dist/esm/hook-a01ac265.d.ts +12 -0
  88. package/dist/esm/hook-a01ac265.js +131 -0
  89. package/dist/esm/hook-f5b8fe4f.d.ts +61 -0
  90. package/dist/esm/index.js +4 -1
  91. package/dist/esm/intersection-observer-2080f60e.d.ts +1 -0
  92. package/dist/esm/intersection-observer-2080f60e.js +891 -0
  93. package/dist/esm/presets/index.d.ts +1 -0
  94. package/dist/esm/presets/index.js +20 -1
  95. package/dist/esm/presets/useLazyLoading/hook.js +3 -894
  96. package/dist/esm/presets/useLazyLoading/index.css +2 -2
  97. package/dist/esm/presets/useSelectWithApply/hook.d.ts +0 -0
  98. package/dist/esm/presets/useSelectWithApply/hook.js +26 -0
  99. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  100. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/Component.js +26 -0
  101. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
  102. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  103. package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.js +26 -0
  104. package/dist/esm/presets/useSelectWithLoading/hook.js +2 -2
  105. package/dist/esm/presets/useSelectWithLoading/index.css +2 -2
  106. package/dist/esm/{tslib.es6-5a8a0ede.d.ts → tslib.es6-11a0bbd3.d.ts} +0 -0
  107. package/dist/esm/{tslib.es6-5a8a0ede.js → tslib.es6-11a0bbd3.js} +0 -0
  108. package/dist/esm/typings.d.ts +39 -6
  109. package/dist/hook-4f9a90b8.d.ts +12 -0
  110. package/dist/hook-4f9a90b8.js +140 -0
  111. package/dist/hook-f5b8fe4f.d.ts +61 -0
  112. package/dist/index.js +6 -1
  113. package/dist/intersection-observer-c983b2d1.d.ts +1 -0
  114. package/dist/intersection-observer-c983b2d1.js +893 -0
  115. package/dist/modern/Component.d.ts +1 -1
  116. package/dist/modern/components/arrow/Component.js +1 -1
  117. package/dist/modern/components/arrow/index.css +3 -3
  118. package/dist/modern/components/base-select/Component.js +17 -14
  119. package/dist/modern/components/base-select/index.css +7 -7
  120. package/dist/modern/components/checkmark/Component.js +2 -2
  121. package/dist/modern/components/checkmark/index.css +7 -7
  122. package/dist/modern/components/field/Component.d.ts +1 -1
  123. package/dist/modern/components/field/Component.js +2 -2
  124. package/dist/modern/components/field/index.css +9 -9
  125. package/dist/modern/components/optgroup/Component.js +1 -1
  126. package/dist/modern/components/optgroup/index.css +6 -6
  127. package/dist/modern/components/option/Component.js +1 -1
  128. package/dist/modern/components/option/index.css +20 -20
  129. package/dist/modern/components/options-list/Component.js +11 -7
  130. package/dist/modern/components/options-list/index.css +9 -5
  131. package/dist/modern/components/virtual-options-list/Component.d.ts +1 -1
  132. package/dist/modern/components/virtual-options-list/Component.js +20 -17
  133. package/dist/modern/components/virtual-options-list/index.css +15 -12
  134. package/dist/modern/hook-cdda7a62.d.ts +12 -0
  135. package/dist/modern/hook-cdda7a62.js +132 -0
  136. package/dist/modern/hook-f5b8fe4f.d.ts +61 -0
  137. package/dist/modern/index.js +3 -0
  138. package/dist/modern/intersection-observer-2080f60e.d.ts +1 -0
  139. package/dist/modern/intersection-observer-2080f60e.js +891 -0
  140. package/dist/modern/presets/index.d.ts +1 -0
  141. package/dist/modern/presets/index.js +19 -0
  142. package/dist/modern/presets/useLazyLoading/hook.js +2 -893
  143. package/dist/modern/presets/useLazyLoading/index.css +2 -2
  144. package/dist/modern/presets/useSelectWithApply/hook.d.ts +0 -0
  145. package/dist/modern/presets/useSelectWithApply/hook.js +25 -0
  146. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  147. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/Component.js +25 -0
  148. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
  149. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  150. package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.js +25 -0
  151. package/dist/modern/presets/useSelectWithLoading/hook.js +1 -1
  152. package/dist/modern/presets/useSelectWithLoading/index.css +2 -2
  153. package/dist/modern/typings.d.ts +39 -6
  154. package/dist/presets/index.d.ts +1 -0
  155. package/dist/presets/index.js +22 -1
  156. package/dist/presets/useLazyLoading/hook.js +3 -894
  157. package/dist/presets/useLazyLoading/index.css +2 -2
  158. package/dist/presets/useSelectWithApply/hook.d.ts +0 -0
  159. package/dist/presets/useSelectWithApply/hook.js +35 -0
  160. package/dist/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
  161. package/dist/presets/useSelectWithApply/options-list-with-apply/Component.js +34 -0
  162. package/dist/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
  163. package/dist/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
  164. package/dist/presets/useSelectWithApply/options-list-with-apply/index.js +34 -0
  165. package/dist/presets/useSelectWithLoading/hook.js +2 -2
  166. package/dist/presets/useSelectWithLoading/index.css +2 -2
  167. package/dist/{tslib.es6-f6070e97.d.ts → tslib.es6-edfcd771.d.ts} +0 -0
  168. package/dist/{tslib.es6-f6070e97.js → tslib.es6-edfcd771.js} +0 -0
  169. package/dist/typings.d.ts +39 -6
  170. package/package.json +3 -2
@@ -1,5 +1,5 @@
1
- /* hash: wk5ga */
2
- .select__skeleton_1mtny {
1
+ /* hash: 1nsdr */
2
+ .select__skeleton_8v2uk {
3
3
  position: absolute;
4
4
  top: 50%;
5
5
  transform: translateY(-50%);
File without changes
@@ -0,0 +1,26 @@
1
+ import '../../tslib.es6-11a0bbd3.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-2080f60e.js';
25
+ import '@alfalab/core-components-button/dist/esm';
26
+ export { S as SELECT_ALL_KEY, u as useSelectWithApply } from '../../hook-a01ac265.js';
@@ -0,0 +1,26 @@
1
+ import '../../../tslib.es6-11a0bbd3.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-2080f60e.js';
25
+ import '@alfalab/core-components-button/dist/esm';
26
+ export { O as OptionsListWithApply } from '../../../hook-a01ac265.js';
@@ -0,0 +1,39 @@
1
+ /* hash: c23yc */
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_1lf9t {
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_1lf9t > * + * {
35
+ margin-left: var(--gap-xs);
36
+ }
37
+ .select__withBorder_1lf9t {
38
+ box-shadow: inset 0 1px 0 var(--color-light-border-secondary);
39
+ }
@@ -0,0 +1 @@
1
+ export * from "../../../hook-a01ac265";
@@ -0,0 +1,26 @@
1
+ import '../../../tslib.es6-11a0bbd3.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-2080f60e.js';
25
+ import '@alfalab/core-components-button/dist/esm';
26
+ export { O as OptionsListWithApply } from '../../../hook-a01ac265.js';
@@ -1,4 +1,4 @@
1
- import { a as __assign } from '../../tslib.es6-5a8a0ede.js';
1
+ import { a as __assign } from '../../tslib.es6-11a0bbd3.js';
2
2
  import React, { useCallback } from 'react';
3
3
  import 'classnames';
4
4
  import '@alfalab/core-components-checkbox/dist/esm';
@@ -6,7 +6,7 @@ import '../../components/checkmark/Component.js';
6
6
  import { Option } from '../../components/option/Component.js';
7
7
  import { Skeleton } from '@alfalab/core-components-skeleton/dist/esm';
8
8
 
9
- var styles = {"skeleton":"select__skeleton_q8641"};
9
+ var styles = {"skeleton":"select__skeleton_17vdg"};
10
10
  require('./index.css')
11
11
 
12
12
  function useSelectWithLoading(_a) {
@@ -1,5 +1,5 @@
1
- /* hash: 1jbkv */
2
- .select__skeleton_q8641 {
1
+ /* hash: 16om0 */
2
+ .select__skeleton_17vdg {
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
  /**
@@ -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-edfcd771.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-c983b2d1.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_1lf9t","withBorder":"select__withBorder_1lf9t"};
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-f6070e97.js');
5
+ require('./tslib.es6-edfcd771.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('@alfalab/hooks');
@@ -27,7 +27,10 @@ require('react-virtual');
27
27
  var components_virtualOptionsList_Component = require('./components/virtual-options-list/Component.js');
28
28
  require('@alfalab/core-components-skeleton');
29
29
  var presets_useSelectWithLoading_hook = require('./presets/useSelectWithLoading/hook.js');
30
+ require('./intersection-observer-c983b2d1.js');
30
31
  var presets_useLazyLoading_hook = require('./presets/useLazyLoading/hook.js');
32
+ require('@alfalab/core-components-button');
33
+ var presets_useSelectWithApply_optionsListWithApply_Component = require('./hook-4f9a90b8.js');
31
34
 
32
35
 
33
36
 
@@ -48,3 +51,5 @@ exports.Select = Component.Select;
48
51
  exports.VirtualOptionsList = components_virtualOptionsList_Component.VirtualOptionsList;
49
52
  exports.useSelectWithLoading = presets_useSelectWithLoading_hook.useSelectWithLoading;
50
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 {};