@deephaven/components 0.5.2-beta.0 → 0.6.1-demo.8

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 (119) hide show
  1. package/dist/AutoCompleteInput.js +410 -448
  2. package/dist/AutoCompleteInput.js.map +1 -1
  3. package/dist/AutoResizeTextarea.js +17 -46
  4. package/dist/AutoResizeTextarea.js.map +1 -1
  5. package/dist/BasicModal.js +18 -19
  6. package/dist/BasicModal.js.map +1 -1
  7. package/dist/Button.js +30 -21
  8. package/dist/Button.js.map +1 -1
  9. package/dist/ButtonGroup.js +6 -4
  10. package/dist/ButtonGroup.js.map +1 -1
  11. package/dist/ButtonOld.js +10 -8
  12. package/dist/ButtonOld.js.map +1 -1
  13. package/dist/CardFlip.js +10 -8
  14. package/dist/CardFlip.js.map +1 -1
  15. package/dist/Checkbox.js +18 -31
  16. package/dist/Checkbox.js.map +1 -1
  17. package/dist/Collapse.js +65 -105
  18. package/dist/Collapse.js.map +1 -1
  19. package/dist/ComboBox.js +432 -460
  20. package/dist/ComboBox.js.map +1 -1
  21. package/dist/CustomTimeSelect.js +485 -517
  22. package/dist/CustomTimeSelect.js.map +1 -1
  23. package/dist/DebouncedSearchInput.js +61 -91
  24. package/dist/DebouncedSearchInput.js.map +1 -1
  25. package/dist/DeephavenSpinner.js +6 -6
  26. package/dist/DeephavenSpinner.js.map +1 -1
  27. package/dist/DragUtils.js +65 -113
  28. package/dist/DragUtils.js.map +1 -1
  29. package/dist/DraggableItemList.d.ts +1 -0
  30. package/dist/DraggableItemList.d.ts.map +1 -1
  31. package/dist/DraggableItemList.js +219 -257
  32. package/dist/DraggableItemList.js.map +1 -1
  33. package/dist/HierarchicalCheckboxMenu.js +160 -227
  34. package/dist/HierarchicalCheckboxMenu.js.map +1 -1
  35. package/dist/ItemList.d.ts +4 -2
  36. package/dist/ItemList.d.ts.map +1 -1
  37. package/dist/ItemList.js +595 -598
  38. package/dist/ItemList.js.map +1 -1
  39. package/dist/ItemListItem.js +194 -215
  40. package/dist/ItemListItem.js.map +1 -1
  41. package/dist/LoadingOverlay.js +9 -10
  42. package/dist/LoadingOverlay.js.map +1 -1
  43. package/dist/LoadingSpinner.js +4 -3
  44. package/dist/LoadingSpinner.js.map +1 -1
  45. package/dist/MaskedInput.js +59 -70
  46. package/dist/MaskedInput.js.map +1 -1
  47. package/dist/Option.js +5 -3
  48. package/dist/Option.js.map +1 -1
  49. package/dist/RadioGroup.js +16 -34
  50. package/dist/RadioGroup.js.map +1 -1
  51. package/dist/RadioItem.js +14 -33
  52. package/dist/RadioItem.js.map +1 -1
  53. package/dist/SearchInput.js +42 -75
  54. package/dist/SearchInput.js.map +1 -1
  55. package/dist/Select.js +10 -8
  56. package/dist/Select.js.map +1 -1
  57. package/dist/SelectValueList.js +97 -134
  58. package/dist/SelectValueList.js.map +1 -1
  59. package/dist/SocketedButton.js +13 -11
  60. package/dist/SocketedButton.js.map +1 -1
  61. package/dist/ThemeExport.js.map +1 -1
  62. package/dist/TimeInput.js +16 -53
  63. package/dist/TimeInput.js.map +1 -1
  64. package/dist/TimeSlider.js +62 -88
  65. package/dist/TimeSlider.js.map +1 -1
  66. package/dist/ToastNotification.js +14 -13
  67. package/dist/ToastNotification.js.map +1 -1
  68. package/dist/UISwitch.js +9 -8
  69. package/dist/UISwitch.js.map +1 -1
  70. package/dist/context-actions/ContextActionUtils.js +173 -231
  71. package/dist/context-actions/ContextActionUtils.js.map +1 -1
  72. package/dist/context-actions/ContextActions.js +135 -177
  73. package/dist/context-actions/ContextActions.js.map +1 -1
  74. package/dist/context-actions/ContextMenu.js +509 -543
  75. package/dist/context-actions/ContextMenu.js.map +1 -1
  76. package/dist/context-actions/ContextMenuItem.js +32 -22
  77. package/dist/context-actions/ContextMenuItem.js.map +1 -1
  78. package/dist/context-actions/ContextMenuRoot.js +112 -152
  79. package/dist/context-actions/ContextMenuRoot.js.map +1 -1
  80. package/dist/context-actions/GlobalContextAction.js +49 -84
  81. package/dist/context-actions/GlobalContextAction.js.map +1 -1
  82. package/dist/context-actions/GlobalContextActions.js +25 -57
  83. package/dist/context-actions/GlobalContextActions.js.map +1 -1
  84. package/dist/context-actions/index.js +4 -4
  85. package/dist/context-actions/index.js.map +1 -1
  86. package/dist/index.js +39 -39
  87. package/dist/index.js.map +1 -1
  88. package/dist/menu-actions/DropdownMenu.js +126 -159
  89. package/dist/menu-actions/DropdownMenu.js.map +1 -1
  90. package/dist/menu-actions/Menu.js +215 -245
  91. package/dist/menu-actions/Menu.js.map +1 -1
  92. package/dist/menu-actions/index.js +1 -1
  93. package/dist/menu-actions/index.js.map +1 -1
  94. package/dist/navigation/Menu.js +14 -18
  95. package/dist/navigation/Menu.js.map +1 -1
  96. package/dist/navigation/MenuItem.js +15 -14
  97. package/dist/navigation/MenuItem.js.map +1 -1
  98. package/dist/navigation/Page.js +7 -5
  99. package/dist/navigation/Page.js.map +1 -1
  100. package/dist/navigation/Stack.js +14 -39
  101. package/dist/navigation/Stack.js.map +1 -1
  102. package/dist/navigation/index.js +4 -4
  103. package/dist/navigation/index.js.map +1 -1
  104. package/dist/popper/Popper.js +209 -235
  105. package/dist/popper/Popper.js.map +1 -1
  106. package/dist/popper/Tooltip.js +227 -257
  107. package/dist/popper/Tooltip.js.map +1 -1
  108. package/dist/popper/index.js +2 -2
  109. package/dist/popper/index.js.map +1 -1
  110. package/dist/shortcuts/GlobalShortcuts.js +2 -2
  111. package/dist/shortcuts/GlobalShortcuts.js.map +1 -1
  112. package/dist/shortcuts/Shortcut.js +263 -291
  113. package/dist/shortcuts/Shortcut.js.map +1 -1
  114. package/dist/shortcuts/ShortcutRegistry.js +48 -71
  115. package/dist/shortcuts/ShortcutRegistry.js.map +1 -1
  116. package/dist/shortcuts/index.js +4 -4
  117. package/dist/shortcuts/index.js.map +1 -1
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +30 -54
package/dist/ComboBox.js CHANGED
@@ -1,29 +1,7 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
2
 
5
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
4
 
7
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
-
9
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
10
-
11
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
12
-
13
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
-
15
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
-
17
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
18
-
19
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
20
-
21
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22
-
23
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
24
-
25
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
-
27
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
6
 
29
7
  /**
@@ -46,8 +24,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
46
24
  import { vsTriangleDown } from '@deephaven/icons';
47
25
  import memoize from 'memoizee';
48
26
  import classNames from 'classnames';
49
- import SearchInput from './SearchInput';
50
- import { Popper } from './popper';
27
+ import SearchInput from "./SearchInput.js";
28
+ import { Popper } from "./popper/index.js";
51
29
  import "./ComboBox.css";
52
30
  var MENU_NAVIGATION_DIRECTION;
53
31
 
@@ -56,37 +34,25 @@ var MENU_NAVIGATION_DIRECTION;
56
34
  MENU_NAVIGATION_DIRECTION["DOWN"] = "DOWN";
57
35
  })(MENU_NAVIGATION_DIRECTION || (MENU_NAVIGATION_DIRECTION = {}));
58
36
 
59
- var ComboBox = /*#__PURE__*/function (_Component) {
60
- _inherits(ComboBox, _Component);
61
-
62
- var _super = _createSuper(ComboBox);
63
-
64
- function ComboBox(props) {
65
- var _this;
37
+ class ComboBox extends Component {
38
+ constructor(props) {
39
+ super(props);
66
40
 
67
- _classCallCheck(this, ComboBox);
41
+ _defineProperty(this, "popper", void 0);
68
42
 
69
- _this = _super.call(this, props);
43
+ _defineProperty(this, "cbContainer", void 0);
70
44
 
71
- _defineProperty(_assertThisInitialized(_this), "popper", void 0);
45
+ _defineProperty(this, "toggleButton", void 0);
72
46
 
73
- _defineProperty(_assertThisInitialized(_this), "cbContainer", void 0);
47
+ _defineProperty(this, "menuContainer", void 0);
74
48
 
75
- _defineProperty(_assertThisInitialized(_this), "toggleButton", void 0);
49
+ _defineProperty(this, "input", void 0);
76
50
 
77
- _defineProperty(_assertThisInitialized(_this), "menuContainer", void 0);
51
+ _defineProperty(this, "searchInput", void 0);
78
52
 
79
- _defineProperty(_assertThisInitialized(_this), "input", void 0);
53
+ _defineProperty(this, "getCachedFilteredOptions", memoize((options, input) => options.filter(option => option.title.toLowerCase().indexOf(input.toLowerCase()) >= 0 || option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0)));
80
54
 
81
- _defineProperty(_assertThisInitialized(_this), "searchInput", void 0);
82
-
83
- _defineProperty(_assertThisInitialized(_this), "getCachedFilteredOptions", memoize(function (options, input) {
84
- return options.filter(function (option) {
85
- return option.title.toLowerCase().indexOf(input.toLowerCase()) >= 0 || option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0;
86
- });
87
- }));
88
-
89
- _this.state = {
55
+ this.state = {
90
56
  value: '',
91
57
  filter: '',
92
58
  filteredOptions: props.options,
@@ -94,461 +60,464 @@ var ComboBox = /*#__PURE__*/function (_Component) {
94
60
  menuIsOpen: false,
95
61
  inputWidth: 100
96
62
  };
97
- _this.toggleMenu = _this.toggleMenu.bind(_assertThisInitialized(_this));
98
- _this.handleMenuKeyDown = _this.handleMenuKeyDown.bind(_assertThisInitialized(_this));
99
- _this.handleMenuBlur = _this.handleMenuBlur.bind(_assertThisInitialized(_this));
100
- _this.closeMenu = _this.closeMenu.bind(_assertThisInitialized(_this));
101
- _this.handleInputChange = _this.handleInputChange.bind(_assertThisInitialized(_this));
102
- _this.handleInputKeyDown = _this.handleInputKeyDown.bind(_assertThisInitialized(_this));
103
- _this.handleInputBlur = _this.handleInputBlur.bind(_assertThisInitialized(_this));
104
- _this.handleFilterChange = _this.handleFilterChange.bind(_assertThisInitialized(_this));
105
- _this.handleOptionClick = _this.handleOptionClick.bind(_assertThisInitialized(_this));
106
- _this.handleOptionFocus = _this.handleOptionFocus.bind(_assertThisInitialized(_this));
107
- _this.handleMenuOpened = _this.handleMenuOpened.bind(_assertThisInitialized(_this));
108
- _this.handleMenuExited = _this.handleMenuExited.bind(_assertThisInitialized(_this));
109
- _this.popper = /*#__PURE__*/React.createRef();
110
- _this.cbContainer = /*#__PURE__*/React.createRef();
111
- _this.toggleButton = /*#__PURE__*/React.createRef();
112
- _this.menuContainer = /*#__PURE__*/React.createRef();
113
- _this.input = /*#__PURE__*/React.createRef();
114
- _this.searchInput = /*#__PURE__*/React.createRef();
115
- return _this;
63
+ this.toggleMenu = this.toggleMenu.bind(this);
64
+ this.handleMenuKeyDown = this.handleMenuKeyDown.bind(this);
65
+ this.handleMenuBlur = this.handleMenuBlur.bind(this);
66
+ this.closeMenu = this.closeMenu.bind(this);
67
+ this.handleInputChange = this.handleInputChange.bind(this);
68
+ this.handleInputKeyDown = this.handleInputKeyDown.bind(this);
69
+ this.handleInputBlur = this.handleInputBlur.bind(this);
70
+ this.handleFilterChange = this.handleFilterChange.bind(this);
71
+ this.handleOptionClick = this.handleOptionClick.bind(this);
72
+ this.handleOptionFocus = this.handleOptionFocus.bind(this);
73
+ this.handleMenuOpened = this.handleMenuOpened.bind(this);
74
+ this.handleMenuExited = this.handleMenuExited.bind(this);
75
+ this.popper = /*#__PURE__*/React.createRef();
76
+ this.cbContainer = /*#__PURE__*/React.createRef();
77
+ this.toggleButton = /*#__PURE__*/React.createRef();
78
+ this.menuContainer = /*#__PURE__*/React.createRef();
79
+ this.input = /*#__PURE__*/React.createRef();
80
+ this.searchInput = /*#__PURE__*/React.createRef();
116
81
  }
117
82
 
118
- _createClass(ComboBox, [{
119
- key: "componentDidUpdate",
120
- value: function componentDidUpdate() {
121
- var _this$state = this.state,
122
- menuIsOpen = _this$state.menuIsOpen,
123
- keyboardOptionIndex = _this$state.keyboardOptionIndex;
83
+ componentDidUpdate() {
84
+ var {
85
+ menuIsOpen,
86
+ keyboardOptionIndex
87
+ } = this.state;
124
88
 
125
- if (menuIsOpen && keyboardOptionIndex >= 0) {
126
- this.scrollOptionIntoView();
127
- }
128
- }
129
- }, {
130
- key: "setInputWidth",
131
- value: function setInputWidth() {
132
- if (this.cbContainer.current) {
133
- this.setState({
134
- inputWidth: this.cbContainer.current.getBoundingClientRect().width
135
- });
136
- }
89
+ if (menuIsOpen && keyboardOptionIndex >= 0) {
90
+ this.scrollOptionIntoView();
137
91
  }
138
- }, {
139
- key: "focus",
140
- value: function focus() {
141
- var _this$input$current;
92
+ }
142
93
 
143
- (_this$input$current = this.input.current) === null || _this$input$current === void 0 ? void 0 : _this$input$current.focus();
144
- }
145
- }, {
146
- key: "resetValue",
147
- value: function resetValue() {
148
- this.setState({
149
- value: ''
150
- });
151
- }
152
- }, {
153
- key: "updateInputValue",
154
- value: function updateInputValue(value) {
155
- var onChange = this.props.onChange;
94
+ setInputWidth() {
95
+ if (this.cbContainer.current) {
156
96
  this.setState({
157
- value: value
97
+ inputWidth: this.cbContainer.current.getBoundingClientRect().width
158
98
  });
159
- onChange(value);
160
99
  }
161
- }, {
162
- key: "handleResize",
163
- value: function handleResize() {
164
- this.setInputWidth();
165
- }
166
- }, {
167
- key: "handleMenuKeyDown",
168
- value: function handleMenuKeyDown(event) {
169
- var _menuOptions$keyboard, _this$input$current2;
170
-
171
- var _this$state2 = this.state,
172
- filter = _this$state2.filter,
173
- filteredOptions = _this$state2.filteredOptions,
174
- keyboardOptionIndex = _this$state2.keyboardOptionIndex;
175
- var options = this.props.options;
176
- var menuOptions = filter ? filteredOptions : options;
177
-
178
- switch (event.key) {
179
- case 'Enter':
180
- if (((_menuOptions$keyboard = menuOptions[keyboardOptionIndex]) === null || _menuOptions$keyboard === void 0 ? void 0 : _menuOptions$keyboard.value) != null) {
181
- this.updateInputValue(menuOptions[keyboardOptionIndex].value);
182
- }
100
+ }
101
+
102
+ focus() {
103
+ var _this$input$current;
104
+
105
+ (_this$input$current = this.input.current) === null || _this$input$current === void 0 ? void 0 : _this$input$current.focus();
106
+ }
107
+
108
+ resetValue() {
109
+ this.setState({
110
+ value: ''
111
+ });
112
+ }
113
+
114
+ updateInputValue(value) {
115
+ var {
116
+ onChange
117
+ } = this.props;
118
+ this.setState({
119
+ value
120
+ });
121
+ onChange(value);
122
+ }
123
+
124
+ handleResize() {
125
+ this.setInputWidth();
126
+ }
127
+
128
+ handleMenuKeyDown(event) {
129
+ var _menuOptions$keyboard, _this$input$current2;
130
+
131
+ var {
132
+ filter,
133
+ filteredOptions,
134
+ keyboardOptionIndex
135
+ } = this.state;
136
+ var {
137
+ options
138
+ } = this.props;
139
+ var menuOptions = filter ? filteredOptions : options;
140
+
141
+ switch (event.key) {
142
+ case 'Enter':
143
+ if (((_menuOptions$keyboard = menuOptions[keyboardOptionIndex]) === null || _menuOptions$keyboard === void 0 ? void 0 : _menuOptions$keyboard.value) != null) {
144
+ this.updateInputValue(menuOptions[keyboardOptionIndex].value);
145
+ }
183
146
 
147
+ this.closeMenu();
148
+ (_this$input$current2 = this.input.current) === null || _this$input$current2 === void 0 ? void 0 : _this$input$current2.focus();
149
+ event.stopPropagation();
150
+ event.preventDefault();
151
+ break;
152
+
153
+ case 'ArrowUp':
154
+ this.handleMenuNavigation(ComboBox.MENU_NAVIGATION_DIRECTION.UP);
155
+ event.stopPropagation();
156
+ event.preventDefault();
157
+ break;
158
+
159
+ case 'ArrowDown':
160
+ this.handleMenuNavigation(ComboBox.MENU_NAVIGATION_DIRECTION.DOWN);
161
+ event.stopPropagation();
162
+ event.preventDefault();
163
+ break;
164
+
165
+ case 'Escape':
166
+ if (filter !== '') {
167
+ this.setState({
168
+ filter: ''
169
+ });
170
+ event.stopPropagation(); // Don't trigger blur on input element
171
+ } else {
184
172
  this.closeMenu();
185
- (_this$input$current2 = this.input.current) === null || _this$input$current2 === void 0 ? void 0 : _this$input$current2.focus();
186
- event.stopPropagation();
187
- event.preventDefault();
188
- break;
189
-
190
- case 'ArrowUp':
191
- this.handleMenuNavigation(ComboBox.MENU_NAVIGATION_DIRECTION.UP);
192
- event.stopPropagation();
193
- event.preventDefault();
194
- break;
195
-
196
- case 'ArrowDown':
197
- this.handleMenuNavigation(ComboBox.MENU_NAVIGATION_DIRECTION.DOWN);
198
- event.stopPropagation();
199
- event.preventDefault();
200
- break;
201
-
202
- case 'Escape':
203
- if (filter !== '') {
204
- this.setState({
205
- filter: ''
206
- });
207
- event.stopPropagation(); // Don't trigger blur on input element
208
- } else {
209
- this.closeMenu();
210
- }
211
-
212
- break;
213
-
214
- case 'Tab':
215
- if (!event.shiftKey && keyboardOptionIndex === menuOptions.length - 1) {
216
- this.closeMenu();
217
- }
218
-
219
- break;
220
-
221
- default:
222
- break;
223
- }
224
- }
225
- }, {
226
- key: "handleMenuNavigation",
227
- value: function handleMenuNavigation(direction) {
228
- var _this$state3 = this.state,
229
- filter = _this$state3.filter,
230
- filteredOptions = _this$state3.filteredOptions,
231
- keyboardOptionIndex = _this$state3.keyboardOptionIndex;
232
- var options = this.props.options;
233
- var menuOptions = filter ? filteredOptions : options;
234
- var menuOptionsLength = menuOptions.length;
235
- var delta = 0;
236
-
237
- switch (direction) {
238
- case ComboBox.MENU_NAVIGATION_DIRECTION.UP:
239
- delta = -1;
240
- break;
241
-
242
- case ComboBox.MENU_NAVIGATION_DIRECTION.DOWN:
243
- delta = 1;
244
- break;
245
- }
173
+ }
246
174
 
247
- if (delta !== 0) {
248
- this.setState({
249
- keyboardOptionIndex: (keyboardOptionIndex + delta + menuOptionsLength) % menuOptionsLength
250
- });
251
- }
252
- }
253
- }, {
254
- key: "handleInputKeyDown",
255
- value: function handleInputKeyDown(event) {
256
- var onEnter = this.props.onEnter;
257
- var menuIsOpen = this.state.menuIsOpen;
258
-
259
- if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
260
- if (!menuIsOpen) {
261
- this.openMenu();
175
+ break;
176
+
177
+ case 'Tab':
178
+ if (!event.shiftKey && keyboardOptionIndex === menuOptions.length - 1) {
179
+ this.closeMenu();
262
180
  }
263
- } else if (event.key === 'Enter') {
264
- onEnter();
265
- }
266
- }
267
- }, {
268
- key: "handleInputChange",
269
- value: function handleInputChange(event) {
270
- this.updateInputValue(event.target.value);
271
- }
272
- }, {
273
- key: "handleOptionClick",
274
- value: function handleOptionClick(event) {
275
- var _this$input$current3;
276
-
277
- var optionIndex = Number(event.currentTarget.value);
278
- var _this$state4 = this.state,
279
- filter = _this$state4.filter,
280
- filteredOptions = _this$state4.filteredOptions;
281
- var options = this.props.options;
282
- var menuOptions = filter ? filteredOptions : options;
283
- this.updateInputValue(menuOptions[optionIndex].value);
284
- this.closeMenu();
285
- (_this$input$current3 = this.input.current) === null || _this$input$current3 === void 0 ? void 0 : _this$input$current3.focus();
181
+
182
+ break;
183
+
184
+ default:
185
+ break;
286
186
  }
287
- }, {
288
- key: "handleOptionFocus",
289
- value: function handleOptionFocus(event) {
290
- this.setState({
291
- keyboardOptionIndex: Number(event.target.value)
292
- });
187
+ }
188
+
189
+ handleMenuNavigation(direction) {
190
+ var {
191
+ filter,
192
+ filteredOptions,
193
+ keyboardOptionIndex
194
+ } = this.state;
195
+ var {
196
+ options
197
+ } = this.props;
198
+ var menuOptions = filter ? filteredOptions : options;
199
+ var menuOptionsLength = menuOptions.length;
200
+ var delta = 0;
201
+
202
+ switch (direction) {
203
+ case ComboBox.MENU_NAVIGATION_DIRECTION.UP:
204
+ delta = -1;
205
+ break;
206
+
207
+ case ComboBox.MENU_NAVIGATION_DIRECTION.DOWN:
208
+ delta = 1;
209
+ break;
293
210
  }
294
- }, {
295
- key: "handleFilterChange",
296
- value: function handleFilterChange(event) {
297
- var _this$popper$current;
298
-
299
- var options = this.props.options;
300
- var filter = event.target.value;
301
- var filteredOptions = this.getCachedFilteredOptions(options, filter);
211
+
212
+ if (delta !== 0) {
302
213
  this.setState({
303
- filter: filter,
304
- filteredOptions: filteredOptions,
305
- keyboardOptionIndex: 0
214
+ keyboardOptionIndex: (keyboardOptionIndex + delta + menuOptionsLength) % menuOptionsLength
306
215
  });
307
- (_this$popper$current = this.popper.current) === null || _this$popper$current === void 0 ? void 0 : _this$popper$current.scheduleUpdate();
308
216
  }
309
- }, {
310
- key: "handleMenuBlur",
311
- value: function handleMenuBlur(event) {
312
- var _this$popper$current2;
313
-
314
- // close if menu blurs, unless its an internal option or the toggleButton which triggers close via click
315
- if (event.relatedTarget instanceof Element && (_this$popper$current2 = this.popper.current) !== null && _this$popper$current2 !== void 0 && _this$popper$current2.element.contains(event.relatedTarget) || event.relatedTarget === this.toggleButton.current) {
316
- return;
317
- }
217
+ }
318
218
 
319
- this.closeMenu(false);
219
+ handleInputKeyDown(event) {
220
+ var {
221
+ onEnter
222
+ } = this.props;
223
+ var {
224
+ menuIsOpen
225
+ } = this.state;
226
+
227
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
228
+ if (!menuIsOpen) {
229
+ this.openMenu();
230
+ }
231
+ } else if (event.key === 'Enter') {
232
+ onEnter();
320
233
  }
321
- }, {
322
- key: "handleInputBlur",
323
- value: function handleInputBlur(event) {
324
- var _this$popper$current3;
234
+ }
325
235
 
326
- // if blur event is caused by focusing on search input or open menu by keyboard, don't close the menu
327
- var menuIsOpen = this.state.menuIsOpen;
236
+ handleInputChange(event) {
237
+ this.updateInputValue(event.target.value);
238
+ }
328
239
 
329
- if (menuIsOpen && event.relatedTarget instanceof Element && (_this$popper$current3 = this.popper.current) !== null && _this$popper$current3 !== void 0 && _this$popper$current3.element.contains(event.relatedTarget)) {
330
- return;
331
- }
240
+ handleOptionClick(event) {
241
+ var _this$input$current3;
242
+
243
+ var optionIndex = Number(event.currentTarget.value);
244
+ var {
245
+ filter,
246
+ filteredOptions
247
+ } = this.state;
248
+ var {
249
+ options
250
+ } = this.props;
251
+ var menuOptions = filter ? filteredOptions : options;
252
+ this.updateInputValue(menuOptions[optionIndex].value);
253
+ this.closeMenu();
254
+ (_this$input$current3 = this.input.current) === null || _this$input$current3 === void 0 ? void 0 : _this$input$current3.focus();
255
+ }
256
+
257
+ handleOptionFocus(event) {
258
+ this.setState({
259
+ keyboardOptionIndex: Number(event.target.value)
260
+ });
261
+ }
262
+
263
+ handleFilterChange(event) {
264
+ var _this$popper$current;
265
+
266
+ var {
267
+ options
268
+ } = this.props;
269
+ var filter = event.target.value;
270
+ var filteredOptions = this.getCachedFilteredOptions(options, filter);
271
+ this.setState({
272
+ filter,
273
+ filteredOptions,
274
+ keyboardOptionIndex: 0
275
+ });
276
+ (_this$popper$current = this.popper.current) === null || _this$popper$current === void 0 ? void 0 : _this$popper$current.scheduleUpdate();
277
+ }
332
278
 
333
- this.closeMenu(false);
279
+ handleMenuBlur(event) {
280
+ var _this$popper$current2;
281
+
282
+ // close if menu blurs, unless its an internal option or the toggleButton which triggers close via click
283
+ if (event.relatedTarget instanceof Element && (_this$popper$current2 = this.popper.current) !== null && _this$popper$current2 !== void 0 && _this$popper$current2.element.contains(event.relatedTarget) || event.relatedTarget === this.toggleButton.current) {
284
+ return;
334
285
  }
335
- }, {
336
- key: "handleMenuOpened",
337
- value: function handleMenuOpened() {
338
- var _this$searchInput$cur;
339
286
 
340
- this.scrollOptionIntoView();
341
- (_this$searchInput$cur = this.searchInput.current) === null || _this$searchInput$cur === void 0 ? void 0 : _this$searchInput$cur.focus();
287
+ this.closeMenu(false);
288
+ }
289
+
290
+ handleInputBlur(event) {
291
+ var _this$popper$current3;
292
+
293
+ // if blur event is caused by focusing on search input or open menu by keyboard, don't close the menu
294
+ var {
295
+ menuIsOpen
296
+ } = this.state;
297
+
298
+ if (menuIsOpen && event.relatedTarget instanceof Element && (_this$popper$current3 = this.popper.current) !== null && _this$popper$current3 !== void 0 && _this$popper$current3.element.contains(event.relatedTarget)) {
299
+ return;
342
300
  }
343
- }, {
344
- key: "handleMenuExited",
345
- value: function handleMenuExited() {
346
- var menuIsOpen = this.state.menuIsOpen;
347
-
348
- if (menuIsOpen) {
349
- var _this$popper$current4;
350
-
351
- this.setState({
352
- menuIsOpen: false
353
- });
354
- (_this$popper$current4 = this.popper.current) === null || _this$popper$current4 === void 0 ? void 0 : _this$popper$current4.hide();
355
- }
301
+
302
+ this.closeMenu(false);
303
+ }
304
+
305
+ handleMenuOpened() {
306
+ var _this$searchInput$cur;
307
+
308
+ this.scrollOptionIntoView();
309
+ (_this$searchInput$cur = this.searchInput.current) === null || _this$searchInput$cur === void 0 ? void 0 : _this$searchInput$cur.focus();
310
+ }
311
+
312
+ handleMenuExited() {
313
+ var {
314
+ menuIsOpen
315
+ } = this.state;
316
+
317
+ if (menuIsOpen) {
318
+ var _this$popper$current4;
356
319
 
357
320
  this.setState({
358
- filter: ''
321
+ menuIsOpen: false
359
322
  });
323
+ (_this$popper$current4 = this.popper.current) === null || _this$popper$current4 === void 0 ? void 0 : _this$popper$current4.hide();
360
324
  }
361
- }, {
362
- key: "toggleMenu",
363
- value: function toggleMenu(event) {
364
- var menuIsOpen = this.state.menuIsOpen;
365
325
 
366
- if (menuIsOpen) {
367
- this.closeMenu();
368
- } else {
369
- this.openMenu();
370
- }
326
+ this.setState({
327
+ filter: ''
328
+ });
329
+ }
330
+
331
+ toggleMenu(event) {
332
+ var {
333
+ menuIsOpen
334
+ } = this.state;
371
335
 
372
- event.stopPropagation();
336
+ if (menuIsOpen) {
337
+ this.closeMenu();
338
+ } else {
339
+ this.openMenu();
373
340
  }
374
- }, {
375
- key: "openMenu",
376
- value: function openMenu() {
377
- var _this2 = this;
378
341
 
379
- this.updateKeyboardIndex();
380
- this.setInputWidth();
381
- this.setState({
382
- menuIsOpen: true
383
- });
384
- window.requestAnimationFrame(function () {
385
- var _this2$popper$current;
342
+ event.stopPropagation();
343
+ }
386
344
 
387
- (_this2$popper$current = _this2.popper.current) === null || _this2$popper$current === void 0 ? void 0 : _this2$popper$current.show();
388
- });
389
- }
390
- }, {
391
- key: "closeMenu",
392
- value: function closeMenu() {
345
+ openMenu() {
346
+ this.updateKeyboardIndex();
347
+ this.setInputWidth();
348
+ this.setState({
349
+ menuIsOpen: true
350
+ });
351
+ window.requestAnimationFrame(() => {
393
352
  var _this$popper$current5;
394
353
 
395
- var focusInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
396
- this.setState({
397
- menuIsOpen: false
398
- });
354
+ (_this$popper$current5 = this.popper.current) === null || _this$popper$current5 === void 0 ? void 0 : _this$popper$current5.show();
355
+ });
356
+ }
399
357
 
400
- if (focusInput) {
401
- var _this$input$current4;
358
+ closeMenu() {
359
+ var _this$popper$current6;
402
360
 
403
- (_this$input$current4 = this.input.current) === null || _this$input$current4 === void 0 ? void 0 : _this$input$current4.focus();
404
- }
361
+ var focusInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
362
+ this.setState({
363
+ menuIsOpen: false
364
+ });
405
365
 
406
- (_this$popper$current5 = this.popper.current) === null || _this$popper$current5 === void 0 ? void 0 : _this$popper$current5.hide();
407
- }
408
- }, {
409
- key: "updateKeyboardIndex",
410
- value: function updateKeyboardIndex() {
411
- var _this$state5 = this.state,
412
- value = _this$state5.value,
413
- filter = _this$state5.filter,
414
- filteredOptions = _this$state5.filteredOptions;
415
- var options = this.props.options;
416
- var menuOptions = filter ? filteredOptions : options;
417
- var valueIndex = menuOptions.findIndex(function (option) {
418
- return option.value === value;
419
- });
420
- this.setState({
421
- keyboardOptionIndex: valueIndex
422
- });
423
- }
424
- }, {
425
- key: "scrollOptionIntoView",
426
- value: function scrollOptionIntoView() {
427
- var _this$menuContainer$c;
428
-
429
- var activeOption = (_this$menuContainer$c = this.menuContainer.current) === null || _this$menuContainer$c === void 0 ? void 0 : _this$menuContainer$c.querySelector('.cb-option-btn.keyboard-active');
430
-
431
- if (activeOption instanceof HTMLElement) {
432
- activeOption.scrollIntoView({
433
- block: 'nearest',
434
- inline: 'nearest'
435
- });
436
- }
437
- }
438
- }, {
439
- key: "renderMenuElement",
440
- value: function renderMenuElement() {
441
- var searchPlaceholder = this.props.searchPlaceholder;
442
- var _this$state6 = this.state,
443
- filter = _this$state6.filter,
444
- inputWidth = _this$state6.inputWidth;
445
- return /*#__PURE__*/React.createElement("div", {
446
- className: "cb-menu-container",
447
- ref: this.menuContainer,
448
- role: "presentation",
449
- onKeyDown: this.handleMenuKeyDown,
450
- onClick: function onClick(event) {
451
- event.stopPropagation();
452
- },
453
- style: {
454
- width: inputWidth
455
- },
456
- onBlur: this.handleMenuBlur
457
- }, /*#__PURE__*/React.createElement("div", {
458
- className: "cb-search-input-container"
459
- }, /*#__PURE__*/React.createElement(SearchInput, {
460
- value: filter,
461
- ref: this.searchInput,
462
- onChange: this.handleFilterChange,
463
- className: "cb-search-input",
464
- placeholder: searchPlaceholder
465
- })), /*#__PURE__*/React.createElement("div", {
466
- className: "cb-options-container"
467
- }, /*#__PURE__*/React.createElement("div", {
468
- className: "cb-options"
469
- }, this.renderOptions())));
366
+ if (focusInput) {
367
+ var _this$input$current4;
368
+
369
+ (_this$input$current4 = this.input.current) === null || _this$input$current4 === void 0 ? void 0 : _this$input$current4.focus();
470
370
  }
471
- }, {
472
- key: "renderOptions",
473
- value: function renderOptions() {
474
- var _this3 = this;
475
-
476
- var options = this.props.options;
477
- var _this$state7 = this.state,
478
- keyboardOptionIndex = _this$state7.keyboardOptionIndex,
479
- filter = _this$state7.filter,
480
- filteredOptions = _this$state7.filteredOptions;
481
- var menuOptions = filter ? filteredOptions : options;
482
- return menuOptions.map(function (option, index) {
483
- var key = "option-".concat(index, "-").concat(option.value);
484
- return /*#__PURE__*/React.createElement("button", {
485
- key: key,
486
- type: "button",
487
- value: index,
488
- className: classNames('cb-option-btn', {
489
- 'keyboard-active': keyboardOptionIndex === index
490
- }),
491
- onClick: _this3.handleOptionClick,
492
- onFocus: _this3.handleOptionFocus
493
- }, option.title);
371
+
372
+ (_this$popper$current6 = this.popper.current) === null || _this$popper$current6 === void 0 ? void 0 : _this$popper$current6.hide();
373
+ }
374
+
375
+ updateKeyboardIndex() {
376
+ var {
377
+ value,
378
+ filter,
379
+ filteredOptions
380
+ } = this.state;
381
+ var {
382
+ options
383
+ } = this.props;
384
+ var menuOptions = filter ? filteredOptions : options;
385
+ var valueIndex = menuOptions.findIndex(option => option.value === value);
386
+ this.setState({
387
+ keyboardOptionIndex: valueIndex
388
+ });
389
+ }
390
+
391
+ scrollOptionIntoView() {
392
+ var _this$menuContainer$c;
393
+
394
+ var activeOption = (_this$menuContainer$c = this.menuContainer.current) === null || _this$menuContainer$c === void 0 ? void 0 : _this$menuContainer$c.querySelector('.cb-option-btn.keyboard-active');
395
+
396
+ if (activeOption instanceof HTMLElement) {
397
+ activeOption.scrollIntoView({
398
+ block: 'nearest',
399
+ inline: 'nearest'
494
400
  });
495
401
  }
496
- }, {
497
- key: "render",
498
- value: function render() {
499
- var _this$props = this.props,
500
- options = _this$props.options,
501
- inputPlaceholder = _this$props.inputPlaceholder,
502
- disabled = _this$props.disabled,
503
- className = _this$props.className,
504
- defaultValue = _this$props.defaultValue,
505
- spellCheck = _this$props.spellCheck;
506
- var value = this.state.value;
507
- var popperOptions = this.props.popperOptions;
508
- popperOptions = _objectSpread({
509
- placement: 'bottom-end',
510
- modifiers: {
511
- preventOverflow: {
512
- enabled: false
513
- }
514
- }
515
- }, popperOptions);
516
- return /*#__PURE__*/React.createElement("div", {
517
- className: "input-group cb-container",
518
- ref: this.cbContainer
519
- }, /*#__PURE__*/React.createElement("input", {
520
- value: value || defaultValue,
521
- className: classNames('form-control', className, 'cb-input'),
522
- ref: this.input,
523
- onChange: this.handleInputChange,
524
- placeholder: inputPlaceholder || options[0] && options[0].title,
525
- disabled: disabled,
526
- onBlur: this.handleInputBlur,
527
- onKeyDown: this.handleInputKeyDown,
528
- spellCheck: spellCheck
529
- }), /*#__PURE__*/React.createElement("div", {
530
- className: "input-group-append cb-dropdown"
531
- }, /*#__PURE__*/React.createElement("button", {
402
+ }
403
+
404
+ renderMenuElement() {
405
+ var {
406
+ searchPlaceholder
407
+ } = this.props;
408
+ var {
409
+ filter,
410
+ inputWidth
411
+ } = this.state;
412
+ return /*#__PURE__*/React.createElement("div", {
413
+ className: "cb-menu-container",
414
+ ref: this.menuContainer,
415
+ role: "presentation",
416
+ onKeyDown: this.handleMenuKeyDown,
417
+ onClick: event => {
418
+ event.stopPropagation();
419
+ },
420
+ style: {
421
+ width: inputWidth
422
+ },
423
+ onBlur: this.handleMenuBlur
424
+ }, /*#__PURE__*/React.createElement("div", {
425
+ className: "cb-search-input-container"
426
+ }, /*#__PURE__*/React.createElement(SearchInput, {
427
+ value: filter,
428
+ ref: this.searchInput,
429
+ onChange: this.handleFilterChange,
430
+ className: "cb-search-input",
431
+ placeholder: searchPlaceholder
432
+ })), /*#__PURE__*/React.createElement("div", {
433
+ className: "cb-options-container"
434
+ }, /*#__PURE__*/React.createElement("div", {
435
+ className: "cb-options"
436
+ }, this.renderOptions())));
437
+ }
438
+
439
+ renderOptions() {
440
+ var {
441
+ options
442
+ } = this.props;
443
+ var {
444
+ keyboardOptionIndex,
445
+ filter,
446
+ filteredOptions
447
+ } = this.state;
448
+ var menuOptions = filter ? filteredOptions : options;
449
+ return menuOptions.map((option, index) => {
450
+ var key = "option-".concat(index, "-").concat(option.value);
451
+ return /*#__PURE__*/React.createElement("button", {
452
+ key: key,
532
453
  type: "button",
533
- className: "btn cb-btn form-control",
534
- ref: this.toggleButton,
535
- onClick: this.toggleMenu,
536
- onKeyDown: this.handleInputKeyDown,
537
- disabled: disabled
538
- }, /*#__PURE__*/React.createElement(FontAwesomeIcon, {
539
- icon: vsTriangleDown
540
- }), /*#__PURE__*/React.createElement(Popper, {
541
- ref: this.popper,
542
- options: popperOptions,
543
- className: classNames('combobox interactive'),
544
- onEntered: this.handleMenuOpened,
545
- onExited: this.handleMenuExited
546
- }, this.renderMenuElement()))));
547
- }
548
- }]);
454
+ value: index,
455
+ className: classNames('cb-option-btn', {
456
+ 'keyboard-active': keyboardOptionIndex === index
457
+ }),
458
+ onClick: this.handleOptionClick,
459
+ onFocus: this.handleOptionFocus
460
+ }, option.title);
461
+ });
462
+ }
463
+
464
+ render() {
465
+ var {
466
+ options,
467
+ inputPlaceholder,
468
+ disabled,
469
+ className,
470
+ defaultValue,
471
+ spellCheck
472
+ } = this.props;
473
+ var {
474
+ value
475
+ } = this.state;
476
+ var {
477
+ popperOptions
478
+ } = this.props;
479
+ popperOptions = _objectSpread({
480
+ placement: 'bottom-end',
481
+ modifiers: {
482
+ preventOverflow: {
483
+ enabled: false
484
+ }
485
+ }
486
+ }, popperOptions);
487
+ return /*#__PURE__*/React.createElement("div", {
488
+ className: "input-group cb-container",
489
+ ref: this.cbContainer
490
+ }, /*#__PURE__*/React.createElement("input", {
491
+ value: value || defaultValue,
492
+ className: classNames('form-control', className, 'cb-input'),
493
+ ref: this.input,
494
+ onChange: this.handleInputChange,
495
+ placeholder: inputPlaceholder || options[0] && options[0].title,
496
+ disabled: disabled,
497
+ onBlur: this.handleInputBlur,
498
+ onKeyDown: this.handleInputKeyDown,
499
+ spellCheck: spellCheck
500
+ }), /*#__PURE__*/React.createElement("div", {
501
+ className: "input-group-append cb-dropdown"
502
+ }, /*#__PURE__*/React.createElement("button", {
503
+ type: "button",
504
+ className: "btn cb-btn form-control",
505
+ ref: this.toggleButton,
506
+ onClick: this.toggleMenu,
507
+ onKeyDown: this.handleInputKeyDown,
508
+ disabled: disabled
509
+ }, /*#__PURE__*/React.createElement(FontAwesomeIcon, {
510
+ icon: vsTriangleDown
511
+ }), /*#__PURE__*/React.createElement(Popper, {
512
+ ref: this.popper,
513
+ options: popperOptions,
514
+ className: classNames('combobox interactive'),
515
+ onEntered: this.handleMenuOpened,
516
+ onExited: this.handleMenuExited
517
+ }, this.renderMenuElement()))));
518
+ }
549
519
 
550
- return ComboBox;
551
- }(Component);
520
+ }
552
521
 
553
522
  _defineProperty(ComboBox, "MENU_NAVIGATION_DIRECTION", MENU_NAVIGATION_DIRECTION);
554
523
 
@@ -574,8 +543,9 @@ _defineProperty(ComboBox, "propTypes", {
574
543
  });
575
544
 
576
545
  _defineProperty(ComboBox, "defaultProps", {
577
- onChange: function onChange() {// no-op
546
+ onChange() {// no-op
578
547
  },
548
+
579
549
  inputPlaceholder: '',
580
550
  searchPlaceholder: 'Search',
581
551
  disabled: false,
@@ -583,8 +553,10 @@ _defineProperty(ComboBox, "defaultProps", {
583
553
  defaultValue: '',
584
554
  popperOptions: null,
585
555
  spellCheck: true,
586
- onEnter: function onEnter() {// no-op
556
+
557
+ onEnter() {// no-op
587
558
  }
559
+
588
560
  });
589
561
 
590
562
  export default ComboBox;