@rescui/select 0.1.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 (41) hide show
  1. package/LICENSE.txt +202 -0
  2. package/README.md +3 -0
  3. package/lib/common-prop-types.d.ts +25 -0
  4. package/lib/common-prop-types.js +18 -0
  5. package/lib/index.css +742 -0
  6. package/lib/index.d.ts +3 -0
  7. package/lib/index.js +4 -0
  8. package/lib/key-codes.d.ts +7 -0
  9. package/lib/key-codes.js +8 -0
  10. package/lib/parts/common-select.module.pcss.js +4 -0
  11. package/lib/parts/foldable.d.ts +34 -0
  12. package/lib/parts/foldable.js +297 -0
  13. package/lib/parts/form-trigger-wrapper.d.ts +13 -0
  14. package/lib/parts/form-trigger-wrapper.js +87 -0
  15. package/lib/parts/form-trigger.module.pcss.js +9 -0
  16. package/lib/parts/multiselect.d.ts +80 -0
  17. package/lib/parts/multiselect.js +399 -0
  18. package/lib/parts/native-select.d.ts +29 -0
  19. package/lib/parts/native-select.js +282 -0
  20. package/lib/parts/native-select.module.pcss.js +9 -0
  21. package/lib/parts/trigger.d.ts +37 -0
  22. package/lib/parts/trigger.js +307 -0
  23. package/lib/parts/trigger.module.pcss.js +30 -0
  24. package/lib/select.d.ts +86 -0
  25. package/lib/select.js +391 -0
  26. package/lib/state/multiselect/actions.d.ts +36 -0
  27. package/lib/state/multiselect/actions.js +45 -0
  28. package/lib/state/multiselect/reducer.d.ts +21 -0
  29. package/lib/state/multiselect/reducer.js +203 -0
  30. package/lib/state/multiselect/selectors.d.ts +6 -0
  31. package/lib/state/multiselect/selectors.js +39 -0
  32. package/lib/state/select/actions.d.ts +81 -0
  33. package/lib/state/select/actions.js +87 -0
  34. package/lib/state/select/reducer.d.ts +22 -0
  35. package/lib/state/select/reducer.js +199 -0
  36. package/lib/state/select/selectors.d.ts +20 -0
  37. package/lib/state/select/selectors.js +114 -0
  38. package/lib/types.d.ts +51 -0
  39. package/lib/utils.d.ts +8 -0
  40. package/lib/utils.js +102 -0
  41. package/package.json +46 -0
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import { Theme } from '@rescui/ui-contexts';
3
+ import type { SelectOption, NoOptionsMessage, SelectOptionOrGroup, SelectSize, SelectMode } from './types';
4
+ export interface CustomTriggerOptions {
5
+ selectedLabel?: string;
6
+ selectedValue: string;
7
+ placeholder?: string;
8
+ hovered: boolean;
9
+ }
10
+ export interface SelectProps {
11
+ /**
12
+ * Additional class name
13
+ */
14
+ className?: string;
15
+ /**
16
+ * Array of options or option groups
17
+ */
18
+ options: SelectOptionOrGroup[];
19
+ /**
20
+ * Default value for select state
21
+ */
22
+ defaultValue?: SelectOption;
23
+ /**
24
+ * Is select supports clear the value
25
+ */
26
+ isClearable?: boolean;
27
+ /**
28
+ * Is select supports inplace filtering
29
+ */
30
+ isSearchable?: boolean;
31
+ /**
32
+ * Is select has been disabled
33
+ */
34
+ isDisabled?: boolean;
35
+ /**
36
+ * Is loader displayed inside select
37
+ */
38
+ isLoading?: boolean;
39
+ /**
40
+ * Input name attribute
41
+ */
42
+ placeholder?: string;
43
+ /**
44
+ * Size
45
+ */
46
+ size?: SelectSize;
47
+ /**
48
+ * Appearance mode
49
+ */
50
+ mode?: SelectMode;
51
+ /**
52
+ * Appearance theme
53
+ */
54
+ theme?: Theme;
55
+ /**
56
+ * Value of the select
57
+ */
58
+ value?: SelectOption;
59
+ /**
60
+ * Change value callback. `value => ...`
61
+ */
62
+ onChange?: (newValue: SelectOption) => void;
63
+ /**
64
+ * Error state flag or React.ReactNode (use with forms)
65
+ */
66
+ error?: boolean | React.ReactNode;
67
+ /**
68
+ * Label element upper then Select element (use with forms)
69
+ */
70
+ label?: React.ReactNode;
71
+ /**
72
+ * Placement of dropdown element
73
+ */
74
+ placement?: 'auto-start' | 'auto' | 'auto-end' | 'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-end' | 'bottom' | 'bottom-start' | 'left-end' | 'left' | 'left-start';
75
+ /**
76
+ * Note element below then Select element (use with forms)
77
+ */
78
+ note?: React.ReactNode;
79
+ id?: string;
80
+ /**
81
+ * Text to display when there are no options
82
+ */
83
+ noOptionsMessage?: NoOptionsMessage;
84
+ }
85
+ declare const Select: React.FC<SelectProps>;
86
+ export default Select;
package/lib/select.js ADDED
@@ -0,0 +1,391 @@
1
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
+ import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["options", "size", "mode", "theme", "className", "defaultValue", "value", "onChange", "placeholder", "isClearable", "isLoading", "isDisabled", "isSearchable", "noOptionsMessage", "placement"];
4
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
5
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
6
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
7
+ import "core-js/modules/es.array.join.js";
8
+ import "core-js/modules/es.regexp.constructor.js";
9
+ import "core-js/modules/es.regexp.exec.js";
10
+ import "core-js/modules/es.regexp.to-string.js";
11
+ import React, { useRef, useState, useReducer, useEffect, useCallback } from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import scrollIntoView from 'scroll-into-view-if-needed';
14
+ import Dropdown from '@rescui/dropdown';
15
+ import { Menu, MenuItem, Divider, GroupHeader } from '@rescui/menu';
16
+ import { useTheme } from '@rescui/ui-contexts';
17
+ import SelectTrigger from './parts/trigger.js';
18
+ import FormTriggerWrapper from './parts/form-trigger-wrapper.js';
19
+ import { optionType, optionsGroupType, noOptionsMessageConfigType } from './common-prop-types.js';
20
+ import { selectReducer, getInitialState } from './state/select/reducer.js';
21
+ import { setGroups, setSelectedValue, setSelectedIndex, closeMenu, setSearchString, clearSelectedAndCloseMenu, openMenu, setCursorIndex, cursorMovedDown, cursorMovedUp } from './state/select/actions.js';
22
+ import { getSelected, isEmpty, getPlainOptions, withoutGroupsLabel, OptionGroupTypes, getOptionValue, getSelectedValue, isIndexMatchCursor, getGroups, getCursorIndex } from './state/select/selectors.js';
23
+ import { convertToOptionGroupsIfNeeded, reverseTheme, getEmptyMessage, escapeRegex, shouldOpenSelect, calculateMaxHeight } from './utils.js';
24
+ import { ESCAPE, BACKSPACE, ARROW_DOWN, ARROW_UP, ENTER, SPACE, TAB } from './key-codes.js';
25
+ import styles from './parts/common-select.module.pcss.js'; // eslint-disable-next-line complexity
26
+
27
+ var Option = function Option(_ref) {
28
+ var state = _ref.state,
29
+ size = _ref.size,
30
+ item = _ref.item,
31
+ isLastItem = _ref.isLastItem,
32
+ highlightedItemRef = _ref.highlightedItemRef,
33
+ handleSelectIndex = _ref.handleSelectIndex,
34
+ handleHighlightIndex = _ref.handleHighlightIndex;
35
+ var marginInPx = withoutGroupsLabel(state) ? 0 : {
36
+ l: 12,
37
+ m: 6,
38
+ s: 0
39
+ }[size];
40
+
41
+ if (item.type === OptionGroupTypes.OPTION) {
42
+ var _context;
43
+
44
+ var index = item.index,
45
+ label = item.label;
46
+ var value = getOptionValue(item);
47
+ var isSelected = value === getSelectedValue(state);
48
+ var isHighlighted = isIndexMatchCursor(state, index);
49
+ return /*#__PURE__*/React.createElement(MenuItem, {
50
+ selected: isSelected,
51
+ highlighted: isHighlighted,
52
+ ref: isHighlighted ? highlightedItemRef : null,
53
+ onMouseMove: function onMouseMove() {
54
+ return handleHighlightIndex(index);
55
+ },
56
+ onClick: function onClick() {
57
+ return handleSelectIndex(index);
58
+ },
59
+ style: {
60
+ marginBottom: isLastItem ? "".concat(marginInPx, "px") : ''
61
+ },
62
+ "data-test": _filterInstanceProperty(_context = ['select-menu-item', isHighlighted && 'select-menu-item-highlighted', isSelected && 'select-menu-item-selected']).call(_context, Boolean).join(' ')
63
+ }, label);
64
+ }
65
+
66
+ if (item.type === OptionGroupTypes.DIVIDER) {
67
+ return /*#__PURE__*/React.createElement(Divider, {
68
+ style: {
69
+ marginTop: "".concat(marginInPx, "px")
70
+ }
71
+ });
72
+ }
73
+
74
+ if (item.type === OptionGroupTypes.HEADER) {
75
+ var _label = item.label;
76
+ return /*#__PURE__*/React.createElement(GroupHeader, {
77
+ text: _label
78
+ });
79
+ }
80
+
81
+ return null;
82
+ };
83
+
84
+ var getOptionKey = function getOptionKey(item, i) {
85
+ if (item.type === OptionGroupTypes.OPTION) {
86
+ var _context2;
87
+
88
+ var value = getOptionValue(item);
89
+ return _concatInstanceProperty(_context2 = "".concat(value, "_")).call(_context2, item.index[0]);
90
+ } else if (item.type === OptionGroupTypes.DIVIDER) {
91
+ return "divider".concat(i);
92
+ } else if (item.type === OptionGroupTypes.HEADER) {
93
+ return "header".concat(i);
94
+ }
95
+
96
+ return null;
97
+ }; // eslint-disable-next-line complexity
98
+
99
+
100
+ var Select = function Select(_ref2) {
101
+ var _context3;
102
+
103
+ var options = _ref2.options,
104
+ _ref2$size = _ref2.size,
105
+ size = _ref2$size === void 0 ? 'm' : _ref2$size,
106
+ _ref2$mode = _ref2.mode,
107
+ mode = _ref2$mode === void 0 ? 'classic' : _ref2$mode,
108
+ themeFromProps = _ref2.theme,
109
+ _ref2$className = _ref2.className,
110
+ className = _ref2$className === void 0 ? null : _ref2$className,
111
+ _ref2$defaultValue = _ref2.defaultValue,
112
+ defaultValue = _ref2$defaultValue === void 0 ? null : _ref2$defaultValue,
113
+ _ref2$value = _ref2.value,
114
+ value = _ref2$value === void 0 ? undefined : _ref2$value,
115
+ onChange = _ref2.onChange,
116
+ _ref2$placeholder = _ref2.placeholder,
117
+ placeholder = _ref2$placeholder === void 0 ? 'Placeholder' : _ref2$placeholder,
118
+ _ref2$isClearable = _ref2.isClearable,
119
+ isClearable = _ref2$isClearable === void 0 ? false : _ref2$isClearable,
120
+ _ref2$isLoading = _ref2.isLoading,
121
+ isLoading = _ref2$isLoading === void 0 ? false : _ref2$isLoading,
122
+ _ref2$isDisabled = _ref2.isDisabled,
123
+ isDisabled = _ref2$isDisabled === void 0 ? false : _ref2$isDisabled,
124
+ _ref2$isSearchable = _ref2.isSearchable,
125
+ isSearchable = _ref2$isSearchable === void 0 ? false : _ref2$isSearchable,
126
+ noOptionsMessage = _ref2.noOptionsMessage,
127
+ _ref2$placement = _ref2.placement,
128
+ placement = _ref2$placement === void 0 ? 'bottom' : _ref2$placement,
129
+ restProps = _objectWithoutProperties(_ref2, _excluded);
130
+
131
+ var theme = useTheme(themeFromProps);
132
+ var dropdownRef = useRef(null);
133
+ var highlightedItemRef = /*#__PURE__*/React.createRef();
134
+
135
+ var _useState = useState(false),
136
+ _useState2 = _slicedToArray(_useState, 2),
137
+ isKeyboardNavigating = _useState2[0],
138
+ setIsKeyboardNavigating = _useState2[1];
139
+
140
+ var skipScrollingRef = useRef(false);
141
+
142
+ var _useReducer = useReducer(selectReducer, getInitialState(convertToOptionGroupsIfNeeded(options), defaultValue)),
143
+ _useReducer2 = _slicedToArray(_useReducer, 2),
144
+ state = _useReducer2[0],
145
+ dispatch = _useReducer2[1];
146
+
147
+ useEffect(function () {
148
+ dispatch(setGroups(convertToOptionGroupsIfNeeded(options)));
149
+ }, [options]);
150
+ useEffect(function () {
151
+ dispatch(setSelectedValue(value));
152
+ }, [value]);
153
+ var selected = value ? value : getSelected(state);
154
+ var isEmptyMenu = isEmpty(state);
155
+ var menuIsOpen = state.menuIsOpen;
156
+
157
+ var handleSelectIndex = function handleSelectIndex(index) {
158
+ var selectedOption = getGroups(state)[index[0]].options[index[1]];
159
+ dispatch(setSelectedIndex(index));
160
+ setIsKeyboardNavigating(false);
161
+
162
+ if (onChange) {
163
+ onChange(selectedOption);
164
+ }
165
+ };
166
+
167
+ useEffect(function () {
168
+ if (dropdownRef.current) {
169
+ dropdownRef.current.scheduleUpdate();
170
+ }
171
+ }, [state.searchString]);
172
+ var handleMouseMove = useCallback(function () {
173
+ return setIsKeyboardNavigating(false);
174
+ }, []);
175
+ useEffect(function () {
176
+ if (isKeyboardNavigating) {
177
+ document.addEventListener('mousemove', handleMouseMove);
178
+ }
179
+
180
+ return function () {
181
+ return document.removeEventListener('mousemove', handleMouseMove);
182
+ };
183
+ }, [handleMouseMove, isKeyboardNavigating]);
184
+ useEffect(function () {
185
+ if (isKeyboardNavigating && highlightedItemRef.current) {
186
+ if (skipScrollingRef.current) {
187
+ skipScrollingRef.current = false;
188
+ } else {
189
+ var elementToScrollTo = highlightedItemRef.current;
190
+
191
+ if (state.cursorIndex[0] === 0 && state.cursorIndex[1] === 0) {
192
+ var groupHeader = highlightedItemRef.current.previousSibling;
193
+
194
+ if (groupHeader) {
195
+ elementToScrollTo = groupHeader;
196
+ }
197
+ }
198
+
199
+ scrollIntoView(elementToScrollTo, {
200
+ behavior: 'instant',
201
+ scrollMode: 'if-needed',
202
+ block: 'nearest',
203
+ inline: 'nearest'
204
+ });
205
+ }
206
+ }
207
+ }, [highlightedItemRef, state.cursorIndex, isKeyboardNavigating]);
208
+
209
+ var handleClose = function handleClose() {
210
+ dispatch(closeMenu());
211
+ setIsKeyboardNavigating(false);
212
+ }; // eslint-disable-next-line complexity
213
+
214
+
215
+ var handleKeyNavigation = function handleKeyNavigation(e) {
216
+ if (e.key === ARROW_DOWN || e.key === ARROW_UP) {
217
+ var isDownDirection = e.key === ARROW_DOWN;
218
+ dispatch(isDownDirection ? cursorMovedDown() : cursorMovedUp());
219
+ setIsKeyboardNavigating(true);
220
+ e.preventDefault();
221
+ }
222
+
223
+ if (e.key === ENTER || !isSearchable && e.key === SPACE) {
224
+ var cursorIndex = getCursorIndex(state);
225
+
226
+ if (cursorIndex !== null) {
227
+ handleSelectIndex(cursorIndex);
228
+ } else {
229
+ handleClose();
230
+ }
231
+
232
+ e.preventDefault();
233
+ }
234
+
235
+ if (e.key === TAB) {
236
+ handleClose();
237
+ }
238
+ };
239
+
240
+ var handleClick = function handleClick() {
241
+ if (isDisabled) {
242
+ return;
243
+ }
244
+
245
+ var action = menuIsOpen ? closeMenu() : openMenu();
246
+ dispatch(action);
247
+ };
248
+
249
+ var handleSearchInputChange = function handleSearchInputChange(searchValue) {
250
+ var filter = new RegExp("(?:^|\\s)".concat(escapeRegex(searchValue)), 'i');
251
+ dispatch(setSearchString(searchValue, function (_ref3) {
252
+ var label = _ref3.label;
253
+ return filter.test(label);
254
+ }));
255
+ };
256
+
257
+ var handleClearClick = function handleClearClick() {
258
+ dispatch(clearSelectedAndCloseMenu());
259
+
260
+ if (onChange) {
261
+ onChange(null);
262
+ }
263
+ }; // eslint-disable-next-line complexity
264
+
265
+
266
+ var handleTriggerKeyDown = function handleTriggerKeyDown(e) {
267
+ if (e.key === ESCAPE) {
268
+ handleClose();
269
+ e.preventDefault();
270
+ }
271
+
272
+ if (isDisabled) {
273
+ return;
274
+ }
275
+
276
+ if (menuIsOpen) {
277
+ handleKeyNavigation(e);
278
+ } else {
279
+ var target = e.target;
280
+ var trigger = target.closest('[data-target="trigger"]');
281
+ var isTriggerTarget = trigger === target;
282
+
283
+ if (shouldOpenSelect(e.key, isTriggerTarget)) {
284
+ dispatch(openMenu());
285
+ setIsKeyboardNavigating(true);
286
+ skipScrollingRef.current = true;
287
+ trigger.focus();
288
+ e.preventDefault();
289
+ }
290
+
291
+ if (e.key === BACKSPACE && isClearable) {
292
+ handleClearClick();
293
+ trigger.focus();
294
+ e.preventDefault();
295
+ }
296
+ }
297
+ };
298
+
299
+ var handleHighlightIndex = function handleHighlightIndex(index) {
300
+ if (!isIndexMatchCursor(state, index)) {
301
+ dispatch(setCursorIndex(index));
302
+ }
303
+ };
304
+
305
+ var maxHeight = calculateMaxHeight(size);
306
+ return /*#__PURE__*/React.createElement(Dropdown, {
307
+ theme: theme,
308
+ onRequestClose: handleClose,
309
+ placement: placement,
310
+ mode: mode,
311
+ ref: dropdownRef,
312
+ cancelCloseAnimation: true,
313
+ minWidth: "trigger",
314
+ maxWidth: "trigger",
315
+ maxHeight: maxHeight,
316
+ leastMaxHeight: maxHeight,
317
+ trigger: function trigger(_ref4) {
318
+ var ref = _ref4.ref;
319
+ return /*#__PURE__*/React.createElement(FormTriggerWrapper, {
320
+ className: className,
321
+ theme: theme,
322
+ size: size,
323
+ error: restProps.error,
324
+ label: restProps.label,
325
+ note: restProps.note
326
+ }, /*#__PURE__*/React.createElement(SelectTrigger, {
327
+ theme: theme,
328
+ mode: mode,
329
+ size: size,
330
+ isOpen: menuIsOpen,
331
+ triggerRef: ref,
332
+ onKeyDown: handleTriggerKeyDown,
333
+ selected: selected,
334
+ placeholder: placeholder,
335
+ isClearable: isClearable,
336
+ isLoading: isLoading,
337
+ isDisabled: isDisabled,
338
+ searchInput: state.searchString,
339
+ isSearchable: isSearchable,
340
+ onSearchChange: handleSearchInputChange,
341
+ onClick: handleClick,
342
+ onClearClick: handleClearClick,
343
+ error: Boolean(restProps.error),
344
+ id: restProps.id,
345
+ "data-target": "trigger"
346
+ }));
347
+ },
348
+ isOpen: menuIsOpen
349
+ }, /*#__PURE__*/React.createElement(Menu, {
350
+ size: size,
351
+ theme: mode === 'rock' ? reverseTheme(theme) : theme,
352
+ disableCursor: isKeyboardNavigating,
353
+ className: styles.menu
354
+ }, !isEmptyMenu ? _mapInstanceProperty(_context3 = getPlainOptions(state)).call(_context3, function (item, i, collection) {
355
+ return /*#__PURE__*/React.createElement(Option, {
356
+ item: item,
357
+ isLastItem: i === collection.length - 1,
358
+ key: getOptionKey(item, i),
359
+ state: state,
360
+ size: size,
361
+ highlightedItemRef: highlightedItemRef,
362
+ handleSelectIndex: handleSelectIndex,
363
+ handleHighlightIndex: handleHighlightIndex
364
+ });
365
+ }) : /*#__PURE__*/React.createElement(MenuItem, {
366
+ disabled: true
367
+ }, getEmptyMessage(isLoading, isSearchable && state.searchString.length > 0, noOptionsMessage))));
368
+ };
369
+
370
+ Select.propTypes = {
371
+ className: PropTypes.string,
372
+ options: PropTypes.oneOfType([PropTypes.arrayOf(optionType), PropTypes.arrayOf(optionsGroupType)]),
373
+ defaultValue: optionType,
374
+ value: optionType,
375
+ onChange: PropTypes.func,
376
+ size: PropTypes.oneOf(['l', 'm', 's']),
377
+ mode: PropTypes.oneOf(['classic', 'rock']),
378
+ theme: PropTypes.oneOf(['light', 'dark']),
379
+ placeholder: PropTypes.string,
380
+ isClearable: PropTypes.bool,
381
+ isSearchable: PropTypes.bool,
382
+ isDisabled: PropTypes.bool,
383
+ isLoading: PropTypes.bool,
384
+ error: PropTypes.oneOfType([PropTypes.bool, PropTypes.node]),
385
+ label: PropTypes.node,
386
+ id: PropTypes.string,
387
+ note: PropTypes.node,
388
+ noOptionsMessage: PropTypes.oneOfType([PropTypes.string, noOptionsMessageConfigType]),
389
+ placement: PropTypes.oneOf(['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start'])
390
+ };
391
+ export default Select;
@@ -0,0 +1,36 @@
1
+ import { Index, SelectOption } from '../../types';
2
+ export declare function addSelectedIndex(index: Index): {
3
+ type: string;
4
+ index: Index;
5
+ };
6
+ export declare namespace addSelectedIndex {
7
+ var type: string;
8
+ }
9
+ export declare function removeSelectedIndex(index: Index): {
10
+ type: string;
11
+ index: Index;
12
+ };
13
+ export declare namespace removeSelectedIndex {
14
+ var type: string;
15
+ }
16
+ export declare function setHideSelected(hideSelected: boolean): {
17
+ type: string;
18
+ hideSelected: boolean;
19
+ };
20
+ export declare namespace setHideSelected {
21
+ var type: string;
22
+ }
23
+ export declare function removeSelectedOption(unselectedOption: SelectOption): {
24
+ type: string;
25
+ unselectedOption: SelectOption;
26
+ };
27
+ export declare namespace removeSelectedOption {
28
+ var type: string;
29
+ }
30
+ export declare function setSelectedValue(selected: SelectOption[]): {
31
+ type: string;
32
+ selected: SelectOption[];
33
+ };
34
+ export declare namespace setSelectedValue {
35
+ var type: string;
36
+ }
@@ -0,0 +1,45 @@
1
+ function addSelectedIndex(index) {
2
+ return {
3
+ type: addSelectedIndex.type,
4
+ index: index
5
+ };
6
+ }
7
+
8
+ addSelectedIndex.type = 'ADD_SELECTED_BY_INDEX';
9
+
10
+ function removeSelectedIndex(index) {
11
+ return {
12
+ type: removeSelectedIndex.type,
13
+ index: index
14
+ };
15
+ }
16
+
17
+ removeSelectedIndex.type = 'REMOVE_SELECTED_BY_INDEX';
18
+
19
+ function setHideSelected(hideSelected) {
20
+ return {
21
+ type: setHideSelected.type,
22
+ hideSelected: hideSelected
23
+ };
24
+ }
25
+
26
+ setHideSelected.type = 'SET_HIDE_SELECTED';
27
+
28
+ function removeSelectedOption(unselectedOption) {
29
+ return {
30
+ type: removeSelectedOption.type,
31
+ unselectedOption: unselectedOption
32
+ };
33
+ }
34
+
35
+ removeSelectedOption.type = 'REMOVE_SELECTED_OPTION';
36
+
37
+ function setSelectedValue(selected) {
38
+ return {
39
+ type: setSelectedValue.type,
40
+ selected: selected
41
+ };
42
+ }
43
+
44
+ setSelectedValue.type = 'SET_SELECTED_VALUE';
45
+ export { addSelectedIndex, removeSelectedIndex, removeSelectedOption, setHideSelected, setSelectedValue };
@@ -0,0 +1,21 @@
1
+ import type { SelectOption, State, Index, Groups, Action } from '../../types';
2
+ export declare function getInitialState(groups: Groups, defaultSelected?: SelectOption[], hideSelected?: boolean): State;
3
+ export declare function multiselectReducer(state: State, action: Action): {
4
+ cursorIndex: any;
5
+ groups: Groups;
6
+ menuIsOpen: boolean;
7
+ selected: SelectOption | SelectOption[];
8
+ searchString: string;
9
+ filteredGroups: Groups;
10
+ hideSelected?: boolean;
11
+ groupsWithoutSelected?: Groups;
12
+ } | {
13
+ selected: any;
14
+ groups: Groups;
15
+ menuIsOpen: boolean;
16
+ searchString: string;
17
+ filteredGroups: Groups;
18
+ cursorIndex: Index;
19
+ hideSelected?: boolean;
20
+ groupsWithoutSelected?: Groups;
21
+ };