@khanacademy/wonder-blocks-dropdown 2.3.19
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.
- package/LICENSE +21 -0
- package/dist/es/index.js +3403 -0
- package/dist/index.js +3966 -0
- package/dist/index.js.flow +2 -0
- package/docs.md +12 -0
- package/package.json +44 -0
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +4054 -0
- package/src/__tests__/generated-snapshot.test.js +1612 -0
- package/src/__tests__/index.test.js +23 -0
- package/src/components/__mocks__/dropdown-core-virtualized.js +40 -0
- package/src/components/__tests__/__snapshots__/action-item.test.js.snap +63 -0
- package/src/components/__tests__/action-item.test.js +43 -0
- package/src/components/__tests__/action-menu.test.js +544 -0
- package/src/components/__tests__/dropdown-core-virtualized.test.js +119 -0
- package/src/components/__tests__/dropdown-core.test.js +659 -0
- package/src/components/__tests__/multi-select.test.js +982 -0
- package/src/components/__tests__/search-text-input.test.js +144 -0
- package/src/components/__tests__/single-select.test.js +588 -0
- package/src/components/action-item.js +270 -0
- package/src/components/action-menu-opener-core.js +203 -0
- package/src/components/action-menu.js +300 -0
- package/src/components/action-menu.md +338 -0
- package/src/components/check.js +59 -0
- package/src/components/checkbox.js +111 -0
- package/src/components/dropdown-core-virtualized-item.js +62 -0
- package/src/components/dropdown-core-virtualized.js +246 -0
- package/src/components/dropdown-core.js +770 -0
- package/src/components/dropdown-opener.js +101 -0
- package/src/components/multi-select.js +597 -0
- package/src/components/multi-select.md +718 -0
- package/src/components/multi-select.stories.js +111 -0
- package/src/components/option-item.js +239 -0
- package/src/components/search-text-input.js +227 -0
- package/src/components/select-opener.js +297 -0
- package/src/components/separator-item.js +50 -0
- package/src/components/single-select.js +418 -0
- package/src/components/single-select.md +520 -0
- package/src/components/single-select.stories.js +107 -0
- package/src/index.js +20 -0
- package/src/util/constants.js +50 -0
- package/src/util/types.js +32 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3966 @@
|
|
|
1
|
+
module.exports =
|
|
2
|
+
/******/ (function(modules) { // webpackBootstrap
|
|
3
|
+
/******/ // The module cache
|
|
4
|
+
/******/ var installedModules = {};
|
|
5
|
+
/******/
|
|
6
|
+
/******/ // The require function
|
|
7
|
+
/******/ function __webpack_require__(moduleId) {
|
|
8
|
+
/******/
|
|
9
|
+
/******/ // Check if module is in cache
|
|
10
|
+
/******/ if(installedModules[moduleId]) {
|
|
11
|
+
/******/ return installedModules[moduleId].exports;
|
|
12
|
+
/******/ }
|
|
13
|
+
/******/ // Create a new module (and put it into the cache)
|
|
14
|
+
/******/ var module = installedModules[moduleId] = {
|
|
15
|
+
/******/ i: moduleId,
|
|
16
|
+
/******/ l: false,
|
|
17
|
+
/******/ exports: {}
|
|
18
|
+
/******/ };
|
|
19
|
+
/******/
|
|
20
|
+
/******/ // Execute the module function
|
|
21
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
22
|
+
/******/
|
|
23
|
+
/******/ // Flag the module as loaded
|
|
24
|
+
/******/ module.l = true;
|
|
25
|
+
/******/
|
|
26
|
+
/******/ // Return the exports of the module
|
|
27
|
+
/******/ return module.exports;
|
|
28
|
+
/******/ }
|
|
29
|
+
/******/
|
|
30
|
+
/******/
|
|
31
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
32
|
+
/******/ __webpack_require__.m = modules;
|
|
33
|
+
/******/
|
|
34
|
+
/******/ // expose the module cache
|
|
35
|
+
/******/ __webpack_require__.c = installedModules;
|
|
36
|
+
/******/
|
|
37
|
+
/******/ // define getter function for harmony exports
|
|
38
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
39
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
40
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ };
|
|
43
|
+
/******/
|
|
44
|
+
/******/ // define __esModule on exports
|
|
45
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
46
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
47
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
48
|
+
/******/ }
|
|
49
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
50
|
+
/******/ };
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // create a fake namespace object
|
|
53
|
+
/******/ // mode & 1: value is a module id, require it
|
|
54
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
55
|
+
/******/ // mode & 4: return value when already ns object
|
|
56
|
+
/******/ // mode & 8|1: behave like require
|
|
57
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
58
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
59
|
+
/******/ if(mode & 8) return value;
|
|
60
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
61
|
+
/******/ var ns = Object.create(null);
|
|
62
|
+
/******/ __webpack_require__.r(ns);
|
|
63
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
64
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
65
|
+
/******/ return ns;
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/
|
|
68
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
69
|
+
/******/ __webpack_require__.n = function(module) {
|
|
70
|
+
/******/ var getter = module && module.__esModule ?
|
|
71
|
+
/******/ function getDefault() { return module['default']; } :
|
|
72
|
+
/******/ function getModuleExports() { return module; };
|
|
73
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
74
|
+
/******/ return getter;
|
|
75
|
+
/******/ };
|
|
76
|
+
/******/
|
|
77
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
78
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
79
|
+
/******/
|
|
80
|
+
/******/ // __webpack_public_path__
|
|
81
|
+
/******/ __webpack_require__.p = "";
|
|
82
|
+
/******/
|
|
83
|
+
/******/
|
|
84
|
+
/******/ // Load entry module and return exports
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 18);
|
|
86
|
+
/******/ })
|
|
87
|
+
/************************************************************************/
|
|
88
|
+
/******/ ([
|
|
89
|
+
/* 0 */
|
|
90
|
+
/***/ (function(module, exports) {
|
|
91
|
+
|
|
92
|
+
module.exports = require("react");
|
|
93
|
+
|
|
94
|
+
/***/ }),
|
|
95
|
+
/* 1 */
|
|
96
|
+
/***/ (function(module, exports) {
|
|
97
|
+
|
|
98
|
+
module.exports = require("@khanacademy/wonder-blocks-color");
|
|
99
|
+
|
|
100
|
+
/***/ }),
|
|
101
|
+
/* 2 */
|
|
102
|
+
/***/ (function(module, exports) {
|
|
103
|
+
|
|
104
|
+
module.exports = require("@khanacademy/wonder-blocks-spacing");
|
|
105
|
+
|
|
106
|
+
/***/ }),
|
|
107
|
+
/* 3 */
|
|
108
|
+
/***/ (function(module, exports) {
|
|
109
|
+
|
|
110
|
+
module.exports = require("aphrodite");
|
|
111
|
+
|
|
112
|
+
/***/ }),
|
|
113
|
+
/* 4 */
|
|
114
|
+
/***/ (function(module, exports) {
|
|
115
|
+
|
|
116
|
+
module.exports = require("@khanacademy/wonder-blocks-core");
|
|
117
|
+
|
|
118
|
+
/***/ }),
|
|
119
|
+
/* 5 */
|
|
120
|
+
/***/ (function(module, exports) {
|
|
121
|
+
|
|
122
|
+
module.exports = require("@khanacademy/wonder-blocks-icon");
|
|
123
|
+
|
|
124
|
+
/***/ }),
|
|
125
|
+
/* 6 */
|
|
126
|
+
/***/ (function(module, exports) {
|
|
127
|
+
|
|
128
|
+
module.exports = require("@khanacademy/wonder-blocks-typography");
|
|
129
|
+
|
|
130
|
+
/***/ }),
|
|
131
|
+
/* 7 */
|
|
132
|
+
/***/ (function(module, exports) {
|
|
133
|
+
|
|
134
|
+
module.exports = require("react-dom");
|
|
135
|
+
|
|
136
|
+
/***/ }),
|
|
137
|
+
/* 8 */
|
|
138
|
+
/***/ (function(module, exports) {
|
|
139
|
+
|
|
140
|
+
module.exports = require("@khanacademy/wonder-blocks-clickable");
|
|
141
|
+
|
|
142
|
+
/***/ }),
|
|
143
|
+
/* 9 */
|
|
144
|
+
/***/ (function(module, exports) {
|
|
145
|
+
|
|
146
|
+
module.exports = require("prop-types");
|
|
147
|
+
|
|
148
|
+
/***/ }),
|
|
149
|
+
/* 10 */
|
|
150
|
+
/***/ (function(module, exports) {
|
|
151
|
+
|
|
152
|
+
module.exports = require("@khanacademy/wonder-blocks-timing");
|
|
153
|
+
|
|
154
|
+
/***/ }),
|
|
155
|
+
/* 11 */
|
|
156
|
+
/***/ (function(module, exports) {
|
|
157
|
+
|
|
158
|
+
module.exports = require("react-window");
|
|
159
|
+
|
|
160
|
+
/***/ }),
|
|
161
|
+
/* 12 */
|
|
162
|
+
/***/ (function(module, exports) {
|
|
163
|
+
|
|
164
|
+
module.exports = require("react-router-dom");
|
|
165
|
+
|
|
166
|
+
/***/ }),
|
|
167
|
+
/* 13 */
|
|
168
|
+
/***/ (function(module, exports) {
|
|
169
|
+
|
|
170
|
+
module.exports = require("react-popper");
|
|
171
|
+
|
|
172
|
+
/***/ }),
|
|
173
|
+
/* 14 */
|
|
174
|
+
/***/ (function(module, exports) {
|
|
175
|
+
|
|
176
|
+
module.exports = require("@khanacademy/wonder-blocks-modal");
|
|
177
|
+
|
|
178
|
+
/***/ }),
|
|
179
|
+
/* 15 */
|
|
180
|
+
/***/ (function(module, exports) {
|
|
181
|
+
|
|
182
|
+
module.exports = require("popper.js");
|
|
183
|
+
|
|
184
|
+
/***/ }),
|
|
185
|
+
/* 16 */
|
|
186
|
+
/***/ (function(module, exports) {
|
|
187
|
+
|
|
188
|
+
module.exports = require("@khanacademy/wonder-blocks-icon-button");
|
|
189
|
+
|
|
190
|
+
/***/ }),
|
|
191
|
+
/* 17 */
|
|
192
|
+
/***/ (function(module, exports) {
|
|
193
|
+
|
|
194
|
+
module.exports = require("@khanacademy/wonder-blocks-layout");
|
|
195
|
+
|
|
196
|
+
/***/ }),
|
|
197
|
+
/* 18 */
|
|
198
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
199
|
+
|
|
200
|
+
"use strict";
|
|
201
|
+
// ESM COMPAT FLAG
|
|
202
|
+
__webpack_require__.r(__webpack_exports__);
|
|
203
|
+
|
|
204
|
+
// EXPORTS
|
|
205
|
+
__webpack_require__.d(__webpack_exports__, "ActionItem", function() { return /* reexport */ action_item_ActionItem; });
|
|
206
|
+
__webpack_require__.d(__webpack_exports__, "OptionItem", function() { return /* reexport */ option_item_OptionItem; });
|
|
207
|
+
__webpack_require__.d(__webpack_exports__, "SeparatorItem", function() { return /* reexport */ separator_item_SeparatorItem; });
|
|
208
|
+
__webpack_require__.d(__webpack_exports__, "ActionMenu", function() { return /* reexport */ action_menu_ActionMenu; });
|
|
209
|
+
__webpack_require__.d(__webpack_exports__, "SingleSelect", function() { return /* reexport */ single_select_SingleSelect; });
|
|
210
|
+
__webpack_require__.d(__webpack_exports__, "MultiSelect", function() { return /* reexport */ multi_select_MultiSelect; });
|
|
211
|
+
|
|
212
|
+
// EXTERNAL MODULE: external "react"
|
|
213
|
+
var external_react_ = __webpack_require__(0);
|
|
214
|
+
|
|
215
|
+
// EXTERNAL MODULE: external "aphrodite"
|
|
216
|
+
var external_aphrodite_ = __webpack_require__(3);
|
|
217
|
+
|
|
218
|
+
// EXTERNAL MODULE: external "react-router-dom"
|
|
219
|
+
var external_react_router_dom_ = __webpack_require__(12);
|
|
220
|
+
|
|
221
|
+
// EXTERNAL MODULE: external "prop-types"
|
|
222
|
+
var external_prop_types_ = __webpack_require__(9);
|
|
223
|
+
|
|
224
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-color"
|
|
225
|
+
var wonder_blocks_color_ = __webpack_require__(1);
|
|
226
|
+
var wonder_blocks_color_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_color_);
|
|
227
|
+
|
|
228
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-spacing"
|
|
229
|
+
var wonder_blocks_spacing_ = __webpack_require__(2);
|
|
230
|
+
var wonder_blocks_spacing_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_spacing_);
|
|
231
|
+
|
|
232
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-typography"
|
|
233
|
+
var wonder_blocks_typography_ = __webpack_require__(6);
|
|
234
|
+
|
|
235
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-clickable"
|
|
236
|
+
var wonder_blocks_clickable_ = __webpack_require__(8);
|
|
237
|
+
|
|
238
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
|
|
239
|
+
var wonder_blocks_core_ = __webpack_require__(4);
|
|
240
|
+
|
|
241
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/util/constants.js
|
|
242
|
+
|
|
243
|
+
var keyCodes = {
|
|
244
|
+
tab: 9,
|
|
245
|
+
enter: 13,
|
|
246
|
+
escape: 27,
|
|
247
|
+
space: 32,
|
|
248
|
+
up: 38,
|
|
249
|
+
down: 40
|
|
250
|
+
};
|
|
251
|
+
var selectDropdownStyle = {
|
|
252
|
+
marginTop: wonder_blocks_spacing_default.a.xSmall_8,
|
|
253
|
+
marginBottom: wonder_blocks_spacing_default.a.xSmall_8
|
|
254
|
+
}; // Filterable dropdown has minimum dimensions requested from Design.
|
|
255
|
+
// Note that these can be overridden by the provided style if needed.
|
|
256
|
+
|
|
257
|
+
var filterableDropdownStyle = {
|
|
258
|
+
minHeight: 100,
|
|
259
|
+
maxHeight: 384
|
|
260
|
+
};
|
|
261
|
+
var searchInputStyle = {
|
|
262
|
+
margin: wonder_blocks_spacing_default.a.xSmall_8,
|
|
263
|
+
marginTop: wonder_blocks_spacing_default.a.xxxSmall_4
|
|
264
|
+
}; // The default item height
|
|
265
|
+
|
|
266
|
+
var DROPDOWN_ITEM_HEIGHT = 40;
|
|
267
|
+
var SEPARATOR_ITEM_HEIGHT = 9;
|
|
268
|
+
var SEARCH_ITEM_HEIGHT = DROPDOWN_ITEM_HEIGHT + searchInputStyle.margin + searchInputStyle.marginTop; // The default labels that will be used by different components
|
|
269
|
+
|
|
270
|
+
var defaultLabels = {
|
|
271
|
+
clearSearch: "Clear search",
|
|
272
|
+
filter: "Filter",
|
|
273
|
+
noResults: "No results",
|
|
274
|
+
selectNoneLabel: "Select none",
|
|
275
|
+
selectAllLabel: function selectAllLabel(numOptions) {
|
|
276
|
+
return "Select all (".concat(numOptions, ")");
|
|
277
|
+
},
|
|
278
|
+
noneSelected: "0 items",
|
|
279
|
+
someSelected: function someSelected(numSelectedValues) {
|
|
280
|
+
return "".concat(numSelectedValues, " items");
|
|
281
|
+
},
|
|
282
|
+
allSelected: "All items"
|
|
283
|
+
};
|
|
284
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/action-item.js
|
|
285
|
+
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); }
|
|
286
|
+
|
|
287
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
288
|
+
|
|
289
|
+
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; }
|
|
290
|
+
|
|
291
|
+
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; }
|
|
292
|
+
|
|
293
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
294
|
+
|
|
295
|
+
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); } }
|
|
296
|
+
|
|
297
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
298
|
+
|
|
299
|
+
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); }
|
|
300
|
+
|
|
301
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
302
|
+
|
|
303
|
+
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); }; }
|
|
304
|
+
|
|
305
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
306
|
+
|
|
307
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
308
|
+
|
|
309
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
310
|
+
|
|
311
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
312
|
+
|
|
313
|
+
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; }
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
var blue = wonder_blocks_color_default.a.blue,
|
|
326
|
+
white = wonder_blocks_color_default.a.white,
|
|
327
|
+
offBlack = wonder_blocks_color_default.a.offBlack,
|
|
328
|
+
action_item_offBlack32 = wonder_blocks_color_default.a.offBlack32;
|
|
329
|
+
var StyledAnchor = Object(wonder_blocks_core_["addStyle"])("a");
|
|
330
|
+
var StyledButton = Object(wonder_blocks_core_["addStyle"])("button");
|
|
331
|
+
var StyledLink = Object(wonder_blocks_core_["addStyle"])(external_react_router_dom_["Link"]);
|
|
332
|
+
/**
|
|
333
|
+
* The action item trigger actions, such as navigating to a different page or
|
|
334
|
+
* opening a modal. Supply the href and/or onClick props. Used as a child of
|
|
335
|
+
* ActionMenu.
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
var action_item_ActionItem = /*#__PURE__*/function (_React$Component) {
|
|
339
|
+
_inherits(ActionItem, _React$Component);
|
|
340
|
+
|
|
341
|
+
var _super = _createSuper(ActionItem);
|
|
342
|
+
|
|
343
|
+
function ActionItem() {
|
|
344
|
+
_classCallCheck(this, ActionItem);
|
|
345
|
+
|
|
346
|
+
return _super.apply(this, arguments);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
_createClass(ActionItem, [{
|
|
350
|
+
key: "render",
|
|
351
|
+
value: function render() {
|
|
352
|
+
var _this$props = this.props,
|
|
353
|
+
skipClientNav = _this$props.skipClientNav,
|
|
354
|
+
disabled = _this$props.disabled,
|
|
355
|
+
href = _this$props.href,
|
|
356
|
+
target = _this$props.target,
|
|
357
|
+
indent = _this$props.indent,
|
|
358
|
+
label = _this$props.label,
|
|
359
|
+
onClick = _this$props.onClick,
|
|
360
|
+
role = _this$props.role,
|
|
361
|
+
style = _this$props.style,
|
|
362
|
+
testId = _this$props.testId;
|
|
363
|
+
var router = this.context.router;
|
|
364
|
+
var ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])(href, skipClientNav, router);
|
|
365
|
+
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
366
|
+
disabled: disabled,
|
|
367
|
+
onClick: onClick,
|
|
368
|
+
href: href,
|
|
369
|
+
role: role,
|
|
370
|
+
target: target
|
|
371
|
+
}, function (state, childrenProps) {
|
|
372
|
+
var pressed = state.pressed,
|
|
373
|
+
hovered = state.hovered,
|
|
374
|
+
focused = state.focused;
|
|
375
|
+
var defaultStyle = [styles.shared, disabled && styles.disabled, !disabled && (pressed ? styles.active : (hovered || focused) && styles.focus), // pass optional styles from react-window (if applies)
|
|
376
|
+
style];
|
|
377
|
+
|
|
378
|
+
var props = _objectSpread({
|
|
379
|
+
"data-test-id": testId,
|
|
380
|
+
disabled: disabled,
|
|
381
|
+
role: role,
|
|
382
|
+
style: [defaultStyle]
|
|
383
|
+
}, childrenProps);
|
|
384
|
+
|
|
385
|
+
var children = /*#__PURE__*/external_react_["createElement"](external_react_["Fragment"], null, /*#__PURE__*/external_react_["createElement"](wonder_blocks_typography_["LabelMedium"], {
|
|
386
|
+
style: [indent && styles.indent, styles.label]
|
|
387
|
+
}, label));
|
|
388
|
+
|
|
389
|
+
if (href && !disabled) {
|
|
390
|
+
return router && !skipClientNav && Object(wonder_blocks_clickable_["isClientSideUrl"])(href) ? /*#__PURE__*/external_react_["createElement"](StyledLink, _extends({}, props, {
|
|
391
|
+
to: href
|
|
392
|
+
}), children) : /*#__PURE__*/external_react_["createElement"](StyledAnchor, _extends({}, props, {
|
|
393
|
+
href: href,
|
|
394
|
+
target: target
|
|
395
|
+
}), children);
|
|
396
|
+
} else {
|
|
397
|
+
return /*#__PURE__*/external_react_["createElement"](StyledButton, _extends({
|
|
398
|
+
type: "button"
|
|
399
|
+
}, props, {
|
|
400
|
+
disabled: disabled
|
|
401
|
+
}), children);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}], [{
|
|
406
|
+
key: "isClassOf",
|
|
407
|
+
value: function isClassOf(instance) {
|
|
408
|
+
return instance && instance.type && instance.type.__IS_ACTION_ITEM__;
|
|
409
|
+
}
|
|
410
|
+
}]);
|
|
411
|
+
|
|
412
|
+
return ActionItem;
|
|
413
|
+
}(external_react_["Component"]);
|
|
414
|
+
|
|
415
|
+
_defineProperty(action_item_ActionItem, "contextTypes", {
|
|
416
|
+
router: external_prop_types_["any"]
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
_defineProperty(action_item_ActionItem, "defaultProps", {
|
|
420
|
+
disabled: false,
|
|
421
|
+
indent: false,
|
|
422
|
+
role: "menuitem"
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
_defineProperty(action_item_ActionItem, "__IS_ACTION_ITEM__", true);
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
var styles = external_aphrodite_["StyleSheet"].create({
|
|
429
|
+
shared: {
|
|
430
|
+
background: white,
|
|
431
|
+
color: offBlack,
|
|
432
|
+
textDecoration: "none",
|
|
433
|
+
border: "none",
|
|
434
|
+
outline: "none",
|
|
435
|
+
flexDirection: "row",
|
|
436
|
+
alignItems: "center",
|
|
437
|
+
display: "flex",
|
|
438
|
+
height: DROPDOWN_ITEM_HEIGHT,
|
|
439
|
+
minHeight: DROPDOWN_ITEM_HEIGHT,
|
|
440
|
+
paddingLeft: wonder_blocks_spacing_default.a.medium_16,
|
|
441
|
+
paddingRight: wonder_blocks_spacing_default.a.medium_16,
|
|
442
|
+
// This removes the 300ms click delay on mobile browsers by indicating that
|
|
443
|
+
// "double-tap to zoom" shouldn't be used on this element.
|
|
444
|
+
touchAction: "manipulation"
|
|
445
|
+
},
|
|
446
|
+
label: {
|
|
447
|
+
whiteSpace: "nowrap",
|
|
448
|
+
userSelect: "none"
|
|
449
|
+
},
|
|
450
|
+
indent: {
|
|
451
|
+
marginLeft: wonder_blocks_spacing_default.a.medium_16
|
|
452
|
+
},
|
|
453
|
+
// hover and focus states
|
|
454
|
+
focus: {
|
|
455
|
+
color: white,
|
|
456
|
+
background: blue
|
|
457
|
+
},
|
|
458
|
+
// active and pressed states
|
|
459
|
+
active: {
|
|
460
|
+
color: Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(blue, 0.32), white),
|
|
461
|
+
background: Object(wonder_blocks_color_["mix"])(action_item_offBlack32, blue)
|
|
462
|
+
},
|
|
463
|
+
// disabled state
|
|
464
|
+
disabled: {
|
|
465
|
+
color: action_item_offBlack32,
|
|
466
|
+
cursor: "default"
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-icon"
|
|
470
|
+
var wonder_blocks_icon_ = __webpack_require__(5);
|
|
471
|
+
var wonder_blocks_icon_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_icon_);
|
|
472
|
+
|
|
473
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/check.js
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
var check_offBlack = wonder_blocks_color_default.a.offBlack,
|
|
479
|
+
check_offBlack32 = wonder_blocks_color_default.a.offBlack32,
|
|
480
|
+
check_white = wonder_blocks_color_default.a.white;
|
|
481
|
+
/**
|
|
482
|
+
* Props describing the state of the OptionItem, shared by the checkbox
|
|
483
|
+
* component,
|
|
484
|
+
*/
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* The check component used by OptionItem.
|
|
488
|
+
*/
|
|
489
|
+
function Check(props) {
|
|
490
|
+
var disabled = props.disabled,
|
|
491
|
+
selected = props.selected,
|
|
492
|
+
pressed = props.pressed,
|
|
493
|
+
hovered = props.hovered,
|
|
494
|
+
focused = props.focused;
|
|
495
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
496
|
+
icon: wonder_blocks_icon_["icons"].check,
|
|
497
|
+
size: "small",
|
|
498
|
+
color: disabled ? check_offBlack32 : pressed || hovered || focused ? check_white : check_offBlack,
|
|
499
|
+
style: [check_styles.bounds, !selected && check_styles.hide]
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
var check_styles = external_aphrodite_["StyleSheet"].create({
|
|
503
|
+
bounds: {
|
|
504
|
+
// Semantically, this are the constants for a small-sized icon
|
|
505
|
+
minHeight: 16,
|
|
506
|
+
minWidth: 16
|
|
507
|
+
},
|
|
508
|
+
hide: {
|
|
509
|
+
visibility: "hidden"
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/checkbox.js
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
// NOTE(sophie): This is a smaller check specifically for use in checkboxes.
|
|
519
|
+
// Please don't copy it automatically and check with designers before using.
|
|
520
|
+
// If the intended icon is a check without a checkbox, you should be using
|
|
521
|
+
// icons.check from the Wonder Blocks Icon package.
|
|
522
|
+
var checkboxCheck = {
|
|
523
|
+
small: "M11.263 4.324a1 1 0 1 1 1.474 1.352l-5.5 6a1 1 0 0 1-1.505-.036l-2.5-3a1 1 0 1 1 1.536-1.28L6.536 9.48l4.727-5.157z"
|
|
524
|
+
};
|
|
525
|
+
var checkbox_blue = wonder_blocks_color_default.a.blue,
|
|
526
|
+
checkbox_white = wonder_blocks_color_default.a.white,
|
|
527
|
+
offBlack16 = wonder_blocks_color_default.a.offBlack16,
|
|
528
|
+
checkbox_offBlack32 = wonder_blocks_color_default.a.offBlack32,
|
|
529
|
+
offBlack50 = wonder_blocks_color_default.a.offBlack50,
|
|
530
|
+
offWhite = wonder_blocks_color_default.a.offWhite;
|
|
531
|
+
/**
|
|
532
|
+
* Props describing the state of the OptionItem, shared by the check
|
|
533
|
+
* component,
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* The checkbox component used by OptionItem.
|
|
538
|
+
*/
|
|
539
|
+
function Checkbox(props) {
|
|
540
|
+
var disabled = props.disabled,
|
|
541
|
+
selected = props.selected,
|
|
542
|
+
pressed = props.pressed,
|
|
543
|
+
hovered = props.hovered,
|
|
544
|
+
focused = props.focused;
|
|
545
|
+
var activeBlue = Object(wonder_blocks_color_["mix"])(checkbox_offBlack32, checkbox_blue);
|
|
546
|
+
var clickInteraction = pressed || hovered || focused;
|
|
547
|
+
var bgColor = disabled ? offWhite : selected && !clickInteraction ? checkbox_blue : checkbox_white;
|
|
548
|
+
var checkColor = disabled ? checkbox_offBlack32 : clickInteraction ? pressed ? activeBlue : checkbox_blue : checkbox_white;
|
|
549
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], {
|
|
550
|
+
style: [checkbox_styles.checkbox, (clickInteraction || selected && !disabled) && checkbox_styles.noBorder, disabled && checkbox_styles.disabledCheckbox, {
|
|
551
|
+
backgroundColor: bgColor
|
|
552
|
+
}]
|
|
553
|
+
}, selected && /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
554
|
+
icon: checkboxCheck,
|
|
555
|
+
size: "small",
|
|
556
|
+
color: checkColor,
|
|
557
|
+
style: [disabled && selected && checkbox_styles.disabledCheckFormatting]
|
|
558
|
+
}));
|
|
559
|
+
}
|
|
560
|
+
var checkbox_styles = external_aphrodite_["StyleSheet"].create({
|
|
561
|
+
checkbox: {
|
|
562
|
+
// Semantically, this are the constants for a small-sized icon
|
|
563
|
+
minHeight: 16,
|
|
564
|
+
minWidth: 16,
|
|
565
|
+
borderRadius: 3,
|
|
566
|
+
borderWidth: 1,
|
|
567
|
+
borderStyle: "solid",
|
|
568
|
+
borderColor: offBlack50
|
|
569
|
+
},
|
|
570
|
+
noBorder: {
|
|
571
|
+
borderWidth: 0
|
|
572
|
+
},
|
|
573
|
+
disabledCheckbox: {
|
|
574
|
+
borderColor: offBlack16,
|
|
575
|
+
backgroundColor: offWhite
|
|
576
|
+
},
|
|
577
|
+
// The border of 1px on the selected, disabled checkbox pushes the check out
|
|
578
|
+
// of place. Move it back.
|
|
579
|
+
disabledCheckFormatting: {
|
|
580
|
+
position: "absolute",
|
|
581
|
+
top: -1,
|
|
582
|
+
left: -1
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/option-item.js
|
|
586
|
+
function option_item_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { option_item_typeof = function _typeof(obj) { return typeof obj; }; } else { option_item_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return option_item_typeof(obj); }
|
|
587
|
+
|
|
588
|
+
function option_item_extends() { option_item_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return option_item_extends.apply(this, arguments); }
|
|
589
|
+
|
|
590
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
591
|
+
|
|
592
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
593
|
+
|
|
594
|
+
function option_item_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
595
|
+
|
|
596
|
+
function option_item_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); } }
|
|
597
|
+
|
|
598
|
+
function option_item_createClass(Constructor, protoProps, staticProps) { if (protoProps) option_item_defineProperties(Constructor.prototype, protoProps); if (staticProps) option_item_defineProperties(Constructor, staticProps); return Constructor; }
|
|
599
|
+
|
|
600
|
+
function option_item_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) option_item_setPrototypeOf(subClass, superClass); }
|
|
601
|
+
|
|
602
|
+
function option_item_setPrototypeOf(o, p) { option_item_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return option_item_setPrototypeOf(o, p); }
|
|
603
|
+
|
|
604
|
+
function option_item_createSuper(Derived) { var hasNativeReflectConstruct = option_item_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = option_item_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = option_item_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return option_item_possibleConstructorReturn(this, result); }; }
|
|
605
|
+
|
|
606
|
+
function option_item_possibleConstructorReturn(self, call) { if (call && (option_item_typeof(call) === "object" || typeof call === "function")) { return call; } return option_item_assertThisInitialized(self); }
|
|
607
|
+
|
|
608
|
+
function option_item_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
609
|
+
|
|
610
|
+
function option_item_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
611
|
+
|
|
612
|
+
function option_item_getPrototypeOf(o) { option_item_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return option_item_getPrototypeOf(o); }
|
|
613
|
+
|
|
614
|
+
function option_item_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; }
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* For option items that can be selected in a dropdown, selection denoted either
|
|
630
|
+
* with a check ✔️ or a checkbox ☑️. Use as children in SingleSelect or
|
|
631
|
+
* MultiSelect.
|
|
632
|
+
*/
|
|
633
|
+
var option_item_OptionItem = /*#__PURE__*/function (_React$Component) {
|
|
634
|
+
option_item_inherits(OptionItem, _React$Component);
|
|
635
|
+
|
|
636
|
+
var _super = option_item_createSuper(OptionItem);
|
|
637
|
+
|
|
638
|
+
function OptionItem() {
|
|
639
|
+
var _this;
|
|
640
|
+
|
|
641
|
+
option_item_classCallCheck(this, OptionItem);
|
|
642
|
+
|
|
643
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
644
|
+
args[_key] = arguments[_key];
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
648
|
+
|
|
649
|
+
option_item_defineProperty(option_item_assertThisInitialized(_this), "handleClick", function () {
|
|
650
|
+
var _this$props = _this.props,
|
|
651
|
+
onClick = _this$props.onClick,
|
|
652
|
+
onToggle = _this$props.onToggle,
|
|
653
|
+
value = _this$props.value;
|
|
654
|
+
onToggle(value);
|
|
655
|
+
|
|
656
|
+
if (onClick) {
|
|
657
|
+
onClick();
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
return _this;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
option_item_createClass(OptionItem, [{
|
|
665
|
+
key: "getCheckComponent",
|
|
666
|
+
value: function getCheckComponent() {
|
|
667
|
+
if (this.props.variant === "check") {
|
|
668
|
+
return Check;
|
|
669
|
+
} else {
|
|
670
|
+
return Checkbox;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}, {
|
|
674
|
+
key: "render",
|
|
675
|
+
value: function render() {
|
|
676
|
+
var _this$props2 = this.props,
|
|
677
|
+
disabled = _this$props2.disabled,
|
|
678
|
+
label = _this$props2.label,
|
|
679
|
+
role = _this$props2.role,
|
|
680
|
+
selected = _this$props2.selected,
|
|
681
|
+
testId = _this$props2.testId,
|
|
682
|
+
style = _this$props2.style,
|
|
683
|
+
value = _this$props2.value,
|
|
684
|
+
onClick = _this$props2.onClick,
|
|
685
|
+
onToggle = _this$props2.onToggle,
|
|
686
|
+
variant = _this$props2.variant,
|
|
687
|
+
sharedProps = _objectWithoutProperties(_this$props2, ["disabled", "label", "role", "selected", "testId", "style", "value", "onClick", "onToggle", "variant"]);
|
|
688
|
+
|
|
689
|
+
var ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])();
|
|
690
|
+
var CheckComponent = this.getCheckComponent();
|
|
691
|
+
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
692
|
+
disabled: disabled,
|
|
693
|
+
onClick: this.handleClick,
|
|
694
|
+
role: role
|
|
695
|
+
}, function (state, childrenProps) {
|
|
696
|
+
var pressed = state.pressed,
|
|
697
|
+
hovered = state.hovered,
|
|
698
|
+
focused = state.focused;
|
|
699
|
+
var defaultStyle = [option_item_styles.itemContainer, pressed ? option_item_styles.active : (hovered || focused) && option_item_styles.focus, disabled && option_item_styles.disabled, // pass optional styles from react-window (if applies)
|
|
700
|
+
style];
|
|
701
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], option_item_extends({}, sharedProps, {
|
|
702
|
+
testId: testId,
|
|
703
|
+
style: defaultStyle,
|
|
704
|
+
"aria-selected": selected ? "true" : "false",
|
|
705
|
+
role: role
|
|
706
|
+
}, childrenProps), /*#__PURE__*/external_react_["createElement"](CheckComponent, {
|
|
707
|
+
disabled: disabled,
|
|
708
|
+
selected: selected,
|
|
709
|
+
pressed: pressed,
|
|
710
|
+
hovered: hovered,
|
|
711
|
+
focused: focused
|
|
712
|
+
}), /*#__PURE__*/external_react_["createElement"](wonder_blocks_typography_["LabelMedium"], {
|
|
713
|
+
style: option_item_styles.label
|
|
714
|
+
}, label));
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
}], [{
|
|
718
|
+
key: "isClassOf",
|
|
719
|
+
value: function isClassOf(instance) {
|
|
720
|
+
return instance && instance.type && instance.type.__IS_OPTION_ITEM__;
|
|
721
|
+
}
|
|
722
|
+
}]);
|
|
723
|
+
|
|
724
|
+
return OptionItem;
|
|
725
|
+
}(external_react_["Component"]);
|
|
726
|
+
|
|
727
|
+
option_item_defineProperty(option_item_OptionItem, "contextTypes", {
|
|
728
|
+
router: external_prop_types_["any"]
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
option_item_defineProperty(option_item_OptionItem, "defaultProps", {
|
|
732
|
+
disabled: false,
|
|
733
|
+
onToggle: function onToggle() {
|
|
734
|
+
return void 0;
|
|
735
|
+
},
|
|
736
|
+
role: "option",
|
|
737
|
+
selected: false
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
option_item_defineProperty(option_item_OptionItem, "__IS_OPTION_ITEM__", true);
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
var option_item_blue = wonder_blocks_color_default.a.blue,
|
|
744
|
+
option_item_white = wonder_blocks_color_default.a.white,
|
|
745
|
+
option_item_offBlack = wonder_blocks_color_default.a.offBlack,
|
|
746
|
+
option_item_offBlack32 = wonder_blocks_color_default.a.offBlack32;
|
|
747
|
+
var option_item_styles = external_aphrodite_["StyleSheet"].create({
|
|
748
|
+
itemContainer: {
|
|
749
|
+
flexDirection: "row",
|
|
750
|
+
backgroundColor: option_item_white,
|
|
751
|
+
color: option_item_offBlack,
|
|
752
|
+
alignItems: "center",
|
|
753
|
+
height: DROPDOWN_ITEM_HEIGHT,
|
|
754
|
+
minHeight: DROPDOWN_ITEM_HEIGHT,
|
|
755
|
+
border: 0,
|
|
756
|
+
outline: 0,
|
|
757
|
+
paddingLeft: wonder_blocks_spacing_default.a.xSmall_8,
|
|
758
|
+
paddingRight: wonder_blocks_spacing_default.a.medium_16,
|
|
759
|
+
whiteSpace: "nowrap",
|
|
760
|
+
cursor: "default"
|
|
761
|
+
},
|
|
762
|
+
focus: {
|
|
763
|
+
color: option_item_white,
|
|
764
|
+
background: option_item_blue
|
|
765
|
+
},
|
|
766
|
+
active: {
|
|
767
|
+
color: Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(option_item_blue, 0.32), option_item_white),
|
|
768
|
+
background: Object(wonder_blocks_color_["mix"])(option_item_offBlack32, option_item_blue)
|
|
769
|
+
},
|
|
770
|
+
disabled: {
|
|
771
|
+
color: option_item_offBlack32,
|
|
772
|
+
background: option_item_white
|
|
773
|
+
},
|
|
774
|
+
label: {
|
|
775
|
+
whiteSpace: "nowrap",
|
|
776
|
+
userSelect: "none",
|
|
777
|
+
marginLeft: wonder_blocks_spacing_default.a.xSmall_8,
|
|
778
|
+
// added to truncate strings that are longer than expected
|
|
779
|
+
overflow: "hidden",
|
|
780
|
+
textOverflow: "ellipsis"
|
|
781
|
+
},
|
|
782
|
+
hide: {
|
|
783
|
+
visibility: "hidden"
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/separator-item.js
|
|
787
|
+
function separator_item_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { separator_item_typeof = function _typeof(obj) { return typeof obj; }; } else { separator_item_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return separator_item_typeof(obj); }
|
|
788
|
+
|
|
789
|
+
function separator_item_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
790
|
+
|
|
791
|
+
function separator_item_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); } }
|
|
792
|
+
|
|
793
|
+
function separator_item_createClass(Constructor, protoProps, staticProps) { if (protoProps) separator_item_defineProperties(Constructor.prototype, protoProps); if (staticProps) separator_item_defineProperties(Constructor, staticProps); return Constructor; }
|
|
794
|
+
|
|
795
|
+
function separator_item_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) separator_item_setPrototypeOf(subClass, superClass); }
|
|
796
|
+
|
|
797
|
+
function separator_item_setPrototypeOf(o, p) { separator_item_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return separator_item_setPrototypeOf(o, p); }
|
|
798
|
+
|
|
799
|
+
function separator_item_createSuper(Derived) { var hasNativeReflectConstruct = separator_item_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = separator_item_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = separator_item_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return separator_item_possibleConstructorReturn(this, result); }; }
|
|
800
|
+
|
|
801
|
+
function separator_item_possibleConstructorReturn(self, call) { if (call && (separator_item_typeof(call) === "object" || typeof call === "function")) { return call; } return separator_item_assertThisInitialized(self); }
|
|
802
|
+
|
|
803
|
+
function separator_item_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
804
|
+
|
|
805
|
+
function separator_item_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
806
|
+
|
|
807
|
+
function separator_item_getPrototypeOf(o) { separator_item_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return separator_item_getPrototypeOf(o); }
|
|
808
|
+
|
|
809
|
+
function separator_item_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; }
|
|
810
|
+
|
|
811
|
+
// Separator item in a dropdown, used to denote a semantic break.
|
|
812
|
+
// Actualized as a horizontal line with surrounding whitespace. -----
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* A separator used in a dropdown menu.
|
|
821
|
+
*/
|
|
822
|
+
var separator_item_SeparatorItem = /*#__PURE__*/function (_React$Component) {
|
|
823
|
+
separator_item_inherits(SeparatorItem, _React$Component);
|
|
824
|
+
|
|
825
|
+
var _super = separator_item_createSuper(SeparatorItem);
|
|
826
|
+
|
|
827
|
+
function SeparatorItem() {
|
|
828
|
+
separator_item_classCallCheck(this, SeparatorItem);
|
|
829
|
+
|
|
830
|
+
return _super.apply(this, arguments);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
separator_item_createClass(SeparatorItem, [{
|
|
834
|
+
key: "render",
|
|
835
|
+
value: function render() {
|
|
836
|
+
return (
|
|
837
|
+
/*#__PURE__*/
|
|
838
|
+
// pass optional styles from react-window (if applies)
|
|
839
|
+
external_react_["createElement"](wonder_blocks_core_["View"], {
|
|
840
|
+
style: [separator_item_styles.separator, this.props.style],
|
|
841
|
+
"aria-hidden": "true"
|
|
842
|
+
})
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
}], [{
|
|
846
|
+
key: "isClassOf",
|
|
847
|
+
value: function isClassOf(instance) {
|
|
848
|
+
return instance && instance.type && instance.type.__IS_SEPARATOR_ITEM__;
|
|
849
|
+
}
|
|
850
|
+
}]);
|
|
851
|
+
|
|
852
|
+
return SeparatorItem;
|
|
853
|
+
}(external_react_["Component"]);
|
|
854
|
+
|
|
855
|
+
separator_item_defineProperty(separator_item_SeparatorItem, "__IS_SEPARATOR_ITEM__", true);
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
var separator_item_styles = external_aphrodite_["StyleSheet"].create({
|
|
859
|
+
separator: {
|
|
860
|
+
boxShadow: "0 -1px ".concat(wonder_blocks_color_default.a.offBlack16),
|
|
861
|
+
height: 1,
|
|
862
|
+
minHeight: 1,
|
|
863
|
+
marginTop: wonder_blocks_spacing_default.a.xxxSmall_4,
|
|
864
|
+
marginBottom: wonder_blocks_spacing_default.a.xxxSmall_4
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
// EXTERNAL MODULE: external "react-dom"
|
|
868
|
+
var external_react_dom_ = __webpack_require__(7);
|
|
869
|
+
var external_react_dom_default = /*#__PURE__*/__webpack_require__.n(external_react_dom_);
|
|
870
|
+
|
|
871
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/dropdown-opener.js
|
|
872
|
+
function dropdown_opener_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { dropdown_opener_typeof = function _typeof(obj) { return typeof obj; }; } else { dropdown_opener_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return dropdown_opener_typeof(obj); }
|
|
873
|
+
|
|
874
|
+
function dropdown_opener_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; }
|
|
875
|
+
|
|
876
|
+
function dropdown_opener_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { dropdown_opener_ownKeys(Object(source), true).forEach(function (key) { dropdown_opener_defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { dropdown_opener_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
877
|
+
|
|
878
|
+
function dropdown_opener_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
879
|
+
|
|
880
|
+
function dropdown_opener_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); } }
|
|
881
|
+
|
|
882
|
+
function dropdown_opener_createClass(Constructor, protoProps, staticProps) { if (protoProps) dropdown_opener_defineProperties(Constructor.prototype, protoProps); if (staticProps) dropdown_opener_defineProperties(Constructor, staticProps); return Constructor; }
|
|
883
|
+
|
|
884
|
+
function dropdown_opener_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) dropdown_opener_setPrototypeOf(subClass, superClass); }
|
|
885
|
+
|
|
886
|
+
function dropdown_opener_setPrototypeOf(o, p) { dropdown_opener_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return dropdown_opener_setPrototypeOf(o, p); }
|
|
887
|
+
|
|
888
|
+
function dropdown_opener_createSuper(Derived) { var hasNativeReflectConstruct = dropdown_opener_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = dropdown_opener_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = dropdown_opener_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return dropdown_opener_possibleConstructorReturn(this, result); }; }
|
|
889
|
+
|
|
890
|
+
function dropdown_opener_possibleConstructorReturn(self, call) { if (call && (dropdown_opener_typeof(call) === "object" || typeof call === "function")) { return call; } return dropdown_opener_assertThisInitialized(self); }
|
|
891
|
+
|
|
892
|
+
function dropdown_opener_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
893
|
+
|
|
894
|
+
function dropdown_opener_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
895
|
+
|
|
896
|
+
function dropdown_opener_getPrototypeOf(o) { dropdown_opener_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return dropdown_opener_getPrototypeOf(o); }
|
|
897
|
+
|
|
898
|
+
function dropdown_opener_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; }
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
var dropdown_opener_DropdownOpener = /*#__PURE__*/function (_React$Component) {
|
|
904
|
+
dropdown_opener_inherits(DropdownOpener, _React$Component);
|
|
905
|
+
|
|
906
|
+
var _super = dropdown_opener_createSuper(DropdownOpener);
|
|
907
|
+
|
|
908
|
+
function DropdownOpener() {
|
|
909
|
+
var _this;
|
|
910
|
+
|
|
911
|
+
dropdown_opener_classCallCheck(this, DropdownOpener);
|
|
912
|
+
|
|
913
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
914
|
+
args[_key] = arguments[_key];
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
918
|
+
|
|
919
|
+
dropdown_opener_defineProperty(dropdown_opener_assertThisInitialized(_this), "getTestIdFromProps", function (childrenProps) {
|
|
920
|
+
return childrenProps.testId || childrenProps["data-test-id"];
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
return _this;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
dropdown_opener_createClass(DropdownOpener, [{
|
|
927
|
+
key: "renderAnchorChildren",
|
|
928
|
+
value: function renderAnchorChildren(eventState, clickableChildrenProps) {
|
|
929
|
+
var _this$props = this.props,
|
|
930
|
+
disabled = _this$props.disabled,
|
|
931
|
+
testId = _this$props.testId,
|
|
932
|
+
text = _this$props.text;
|
|
933
|
+
var renderedChildren = this.props.children(dropdown_opener_objectSpread(dropdown_opener_objectSpread({}, eventState), {}, {
|
|
934
|
+
text: text
|
|
935
|
+
}));
|
|
936
|
+
var childrenProps = renderedChildren.props;
|
|
937
|
+
var childrenTestId = this.getTestIdFromProps(childrenProps);
|
|
938
|
+
return external_react_["cloneElement"](renderedChildren, dropdown_opener_objectSpread(dropdown_opener_objectSpread({}, clickableChildrenProps), {}, {
|
|
939
|
+
disabled: disabled,
|
|
940
|
+
onClick: childrenProps.onClick ? function (e) {
|
|
941
|
+
// This is done to avoid overriding a
|
|
942
|
+
// custom onClick handler inside the
|
|
943
|
+
// children node
|
|
944
|
+
childrenProps.onClick(e);
|
|
945
|
+
clickableChildrenProps.onClick(e);
|
|
946
|
+
} : clickableChildrenProps.onClick,
|
|
947
|
+
// try to get the testId from the child element
|
|
948
|
+
// If it's not set, try to fallback to the parent's testId
|
|
949
|
+
"data-test-id": childrenTestId || testId
|
|
950
|
+
}));
|
|
951
|
+
}
|
|
952
|
+
}, {
|
|
953
|
+
key: "render",
|
|
954
|
+
value: function render() {
|
|
955
|
+
var _this2 = this;
|
|
956
|
+
|
|
957
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_clickable_["ClickableBehavior"], {
|
|
958
|
+
onClick: this.props.onClick,
|
|
959
|
+
disabled: this.props.disabled
|
|
960
|
+
}, function (eventState, handlers) {
|
|
961
|
+
return _this2.renderAnchorChildren(eventState, handlers);
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
}]);
|
|
965
|
+
|
|
966
|
+
return DropdownOpener;
|
|
967
|
+
}(external_react_["Component"]);
|
|
968
|
+
|
|
969
|
+
dropdown_opener_defineProperty(dropdown_opener_DropdownOpener, "defaultProps", {
|
|
970
|
+
disabled: false
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
/* harmony default export */ var dropdown_opener = (dropdown_opener_DropdownOpener);
|
|
974
|
+
// EXTERNAL MODULE: external "react-popper"
|
|
975
|
+
var external_react_popper_ = __webpack_require__(13);
|
|
976
|
+
|
|
977
|
+
// EXTERNAL MODULE: external "react-window"
|
|
978
|
+
var external_react_window_ = __webpack_require__(11);
|
|
979
|
+
|
|
980
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-modal"
|
|
981
|
+
var wonder_blocks_modal_ = __webpack_require__(14);
|
|
982
|
+
|
|
983
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-timing"
|
|
984
|
+
var wonder_blocks_timing_ = __webpack_require__(10);
|
|
985
|
+
|
|
986
|
+
// EXTERNAL MODULE: external "popper.js"
|
|
987
|
+
var external_popper_js_ = __webpack_require__(15);
|
|
988
|
+
var external_popper_js_default = /*#__PURE__*/__webpack_require__.n(external_popper_js_);
|
|
989
|
+
|
|
990
|
+
// CONCATENATED MODULE: ./shared-unpackaged/get-edges.js
|
|
991
|
+
var EmptySizes = Object.freeze({
|
|
992
|
+
top: 0,
|
|
993
|
+
left: 0,
|
|
994
|
+
bottom: 0,
|
|
995
|
+
right: 0
|
|
996
|
+
});
|
|
997
|
+
/**
|
|
998
|
+
* Get the margin, padding, and border edges for a given element.
|
|
999
|
+
*/
|
|
1000
|
+
|
|
1001
|
+
function getEdges(element, withoutEdges) {
|
|
1002
|
+
if (!withoutEdges && element instanceof Element) {
|
|
1003
|
+
var style = element.currentStyle || window.getComputedStyle(element);
|
|
1004
|
+
return {
|
|
1005
|
+
margin: {
|
|
1006
|
+
left: parseFloat(style.marginLeft),
|
|
1007
|
+
top: parseFloat(style.marginTop),
|
|
1008
|
+
right: parseFloat(style.marginRight),
|
|
1009
|
+
bottom: parseFloat(style.marginBottom)
|
|
1010
|
+
},
|
|
1011
|
+
padding: {
|
|
1012
|
+
left: parseFloat(style.paddingLeft),
|
|
1013
|
+
top: parseFloat(style.paddingTop),
|
|
1014
|
+
right: parseFloat(style.paddingRight),
|
|
1015
|
+
bottom: parseFloat(style.paddingBottom)
|
|
1016
|
+
},
|
|
1017
|
+
border: {
|
|
1018
|
+
left: parseFloat(style.borderLeftWidth),
|
|
1019
|
+
top: parseFloat(style.borderTopWidth),
|
|
1020
|
+
right: parseFloat(style.borderRightWidth),
|
|
1021
|
+
bottom: parseFloat(style.borderBottomWidth)
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
return {
|
|
1027
|
+
margin: EmptySizes,
|
|
1028
|
+
padding: EmptySizes,
|
|
1029
|
+
border: EmptySizes
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
// CONCATENATED MODULE: ./shared-unpackaged/get-bounds.js
|
|
1033
|
+
|
|
1034
|
+
function getBounds(element) {
|
|
1035
|
+
var withoutEdges = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1036
|
+
var elementRect = element.getBoundingClientRect();
|
|
1037
|
+
var edges = getEdges(element, withoutEdges);
|
|
1038
|
+
return {
|
|
1039
|
+
left: elementRect.left + edges.margin.left + edges.padding.left + edges.border.left,
|
|
1040
|
+
top: elementRect.top + edges.margin.top + edges.padding.top + edges.border.top,
|
|
1041
|
+
right: elementRect.right - edges.margin.right - edges.padding.right - edges.border.right,
|
|
1042
|
+
bottom: elementRect.bottom - edges.margin.bottom - edges.padding.bottom - edges.border.bottom
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
// CONCATENATED MODULE: ./shared-unpackaged/get-axis-intersection.js
|
|
1046
|
+
function getAxisIntersection(intersectingRect, boundsRect, axis) {
|
|
1047
|
+
var start = function start(rect) {
|
|
1048
|
+
return axis === "horizontal" ? rect.left : rect.top;
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
var end = function end(rect) {
|
|
1052
|
+
return axis === "horizontal" ? rect.right : rect.bottom;
|
|
1053
|
+
};
|
|
1054
|
+
|
|
1055
|
+
if (end(intersectingRect) <= start(boundsRect)) {
|
|
1056
|
+
return "before";
|
|
1057
|
+
} else if (start(intersectingRect) >= end(boundsRect)) {
|
|
1058
|
+
return "after";
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
return "within";
|
|
1062
|
+
}
|
|
1063
|
+
// CONCATENATED MODULE: ./shared-unpackaged/get-intersection.js
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Determine how one rectangle intersects another.
|
|
1067
|
+
*
|
|
1068
|
+
* The intersection should be interpreted as whether the first rectangle is
|
|
1069
|
+
* within the second.
|
|
1070
|
+
*/
|
|
1071
|
+
|
|
1072
|
+
function getIntersection(intersectingRect, boundsRect) {
|
|
1073
|
+
var horizontal = getAxisIntersection(intersectingRect, boundsRect, "horizontal");
|
|
1074
|
+
var vertical = getAxisIntersection(intersectingRect, boundsRect, "vertical");
|
|
1075
|
+
return {
|
|
1076
|
+
horizontal: horizontal,
|
|
1077
|
+
vertical: vertical
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
// CONCATENATED MODULE: ./shared-unpackaged/is-obscured.js
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Determine if an element is obscured by other elements.
|
|
1085
|
+
*
|
|
1086
|
+
* This uses document.elementFromPoint to see if the given element is being
|
|
1087
|
+
* overdrawn by another element. Note that this won't work if the given element
|
|
1088
|
+
* has `pointer-events: none`.
|
|
1089
|
+
*/
|
|
1090
|
+
|
|
1091
|
+
function isObscured(anchorElement, popperElement) {
|
|
1092
|
+
// TODO(somewhatabstract): We should be smarter in this algorithm and
|
|
1093
|
+
// actually look at the intersection of the elements doing the obscuring
|
|
1094
|
+
// just as we already do with our scroll parent intersections. That way we
|
|
1095
|
+
// can not only check that the entire element is obscured, but think about
|
|
1096
|
+
// partial obscurement so we can move the tooltip bubble when it's anchor
|
|
1097
|
+
// point is not visible.
|
|
1098
|
+
// Before we assume we're visible let's check to see if something else
|
|
1099
|
+
// is obscuring us. Here we check a variety of points of the element
|
|
1100
|
+
// like topleft, bottomright, and center to see if they are covered by
|
|
1101
|
+
// something, and if so, assume we're not visible.
|
|
1102
|
+
// There are ways that this can still not work, such as different
|
|
1103
|
+
// elements only covering those points and the remainder being visible,
|
|
1104
|
+
// or if some covering element has none for pointer-events style, but
|
|
1105
|
+
// those edge cases shouldn't bother the main usages for this method.
|
|
1106
|
+
// NOTE: If the anchor element has `pointer-events: none`, we're always
|
|
1107
|
+
// going to end up hiding, so, you know, probably don't do that.
|
|
1108
|
+
// We're not explicitly checking for that CSS since it's a corner-case and
|
|
1109
|
+
// would impact perf of the regular cases if we were always checking it.
|
|
1110
|
+
// TODO(somewhatabstract, WB-300): Need to cater to the case where the
|
|
1111
|
+
// viewport is zoomed such that both corners are off screen but the rest
|
|
1112
|
+
// isn't. In this case some browsers don't return the element from
|
|
1113
|
+
// `elementFromPoint` then doesn't return the element.
|
|
1114
|
+
// Also, consider how we might mitigate the pointer-events issue and make
|
|
1115
|
+
// this call more robust.
|
|
1116
|
+
var bounds = getBounds(anchorElement); // This method does the main work, taking some coordinates and determining
|
|
1117
|
+
// if our element is visible at that point or not.
|
|
1118
|
+
|
|
1119
|
+
var isVisible = function isVisible(x, y) {
|
|
1120
|
+
var elAtPoint = document.elementFromPoint(x, y);
|
|
1121
|
+
|
|
1122
|
+
if (elAtPoint != null && (elAtPoint === popperElement || popperElement.contains(elAtPoint))) {
|
|
1123
|
+
// Oh no, we're being obscured by our own popper.
|
|
1124
|
+
// We need to look behind it. Shenanigans time.
|
|
1125
|
+
var pointerEventsStyle = elAtPoint.style.pointerEvents; // Remove pointer events so that we can look through it.
|
|
1126
|
+
|
|
1127
|
+
elAtPoint.style.pointerEvents = "none";
|
|
1128
|
+
|
|
1129
|
+
try {
|
|
1130
|
+
var visible = isVisible(x, y);
|
|
1131
|
+
return visible;
|
|
1132
|
+
} finally {
|
|
1133
|
+
// Make sure we put things back the way we found them. :)
|
|
1134
|
+
elAtPoint.style.pointerEvents = pointerEventsStyle;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if (anchorElement instanceof Element) {
|
|
1139
|
+
// If we are working with an element, then we can do some decendency checks
|
|
1140
|
+
// to ensure we're not just hitting a child. We're ok with saying that
|
|
1141
|
+
// we're visible if we hit a parent because we check them for visibility
|
|
1142
|
+
// elsewhere.
|
|
1143
|
+
return elAtPoint != null && (anchorElement.contains(elAtPoint) || elAtPoint.contains(anchorElement));
|
|
1144
|
+
} // If element is a reference object, all we have to work with is
|
|
1145
|
+
// intersection for checking obscurity. Since this doesn't cover
|
|
1146
|
+
// parent/child relationships in the DOM, it's not really effective
|
|
1147
|
+
// on its own and is possibly about as good as just returning `true`.
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
var intersection = elAtPoint && getIntersection(bounds, getBounds(elAtPoint, true));
|
|
1151
|
+
return (intersection === null || intersection === void 0 ? void 0 : intersection.horizontal) !== "within" || (intersection === null || intersection === void 0 ? void 0 : intersection.vertical) !== "within";
|
|
1152
|
+
}; // NOTE: We are using functions here so that we only do as much work
|
|
1153
|
+
// as we need to, short-circuiting as soon as we have a definitive
|
|
1154
|
+
// answer.
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
var isTopLeftVisible = function isTopLeftVisible() {
|
|
1158
|
+
return isVisible(bounds.left, bounds.top);
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1161
|
+
var isBottomRightVisible = function isBottomRightVisible() {
|
|
1162
|
+
return isVisible(bounds.right, bounds.bottom);
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
var isCenterVisible = function isCenterVisible() {
|
|
1166
|
+
return isVisible(bounds.left + (bounds.right - bounds.left) / 2, bounds.top + (bounds.bottom - bounds.top) / 2);
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
return !isTopLeftVisible() && !isBottomRightVisible() && !isCenterVisible();
|
|
1170
|
+
}
|
|
1171
|
+
// CONCATENATED MODULE: ./shared-unpackaged/visibility-modifier.js
|
|
1172
|
+
var _PopperJS$Defaults$mo, _PopperJS$Defaults$mo2;
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* A modifier for use with popper.js or react-popper.
|
|
1176
|
+
*
|
|
1177
|
+
* This looks at the scroll parents of the reference element to determine
|
|
1178
|
+
* overall visibility.
|
|
1179
|
+
*
|
|
1180
|
+
* See https://popper.js.org/popper-documentation.html#modifiers for more
|
|
1181
|
+
* details on popper.js modifiers.
|
|
1182
|
+
*/
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* The function that implements the modifier.
|
|
1188
|
+
*/
|
|
1189
|
+
|
|
1190
|
+
function visibilityModifierFn(data) {
|
|
1191
|
+
var anchorElement = data.instance.reference; // First, we see how the element intersects with its scroll parents.
|
|
1192
|
+
// If it doesn't, then we should hide it.
|
|
1193
|
+
// Otherwise, we check to see if anything else obscures the component (like
|
|
1194
|
+
// a fixed or absolute positioned element).
|
|
1195
|
+
|
|
1196
|
+
var _getElementIntersecti = Object(wonder_blocks_core_["getElementIntersection"])(anchorElement),
|
|
1197
|
+
horizontal = _getElementIntersecti.horizontal,
|
|
1198
|
+
vertical = _getElementIntersecti.vertical;
|
|
1199
|
+
|
|
1200
|
+
var hide = horizontal !== "within" || vertical !== "within" || isObscured(anchorElement, data.instance.popper); // If we're hidden, we mimic what the built-in hide method does,
|
|
1201
|
+
// and set the hide flag and the OOB attribute with appropriate
|
|
1202
|
+
// short-circuiting.
|
|
1203
|
+
// https://github.com/FezVrasta/popper.js/blob/08c5d6010346bf9df06e9f81a54fa6c2c51e3639/packages/popper/src/modifiers/hide.js#L29-L42
|
|
1204
|
+
|
|
1205
|
+
if (hide) {
|
|
1206
|
+
if (data.hide) {
|
|
1207
|
+
return data;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
data.hide = true;
|
|
1211
|
+
data.attributes["x-out-of-boundaries"] = "";
|
|
1212
|
+
} else {
|
|
1213
|
+
// Avoid unnecessary DOM access if visibility hasn't changed
|
|
1214
|
+
if (!data.hide) {
|
|
1215
|
+
return data;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
data.hide = false;
|
|
1219
|
+
data.attributes["x-out-of-boundaries"] = false;
|
|
1220
|
+
} // Always have to return the data object to ensure the modifier chain
|
|
1221
|
+
// in popper.js is unbroken.
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
return data;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Default configuration that sets things up how usually want them.
|
|
1228
|
+
* Usage:
|
|
1229
|
+
* ```js
|
|
1230
|
+
* import visibilityModifier from "visibility-modifier.js";
|
|
1231
|
+
* const modifiers = [
|
|
1232
|
+
* wbvisibility: visibilityModifier,
|
|
1233
|
+
* ];
|
|
1234
|
+
* ```
|
|
1235
|
+
*
|
|
1236
|
+
* Where `wbvisibility` is a unique name to give the modifier entry,
|
|
1237
|
+
* and `modifiers` is the popper.js or react-popper modifiers array.
|
|
1238
|
+
*/
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
/* harmony default export */ var visibility_modifier = ({
|
|
1242
|
+
enabled: true,
|
|
1243
|
+
// We want this to run after the "hide" modifier, by default.
|
|
1244
|
+
order: (((_PopperJS$Defaults$mo = external_popper_js_default.a.Defaults.modifiers) === null || _PopperJS$Defaults$mo === void 0 ? void 0 : (_PopperJS$Defaults$mo2 = _PopperJS$Defaults$mo.hide) === null || _PopperJS$Defaults$mo2 === void 0 ? void 0 : _PopperJS$Defaults$mo2.order) || 0) + 1,
|
|
1245
|
+
fn: visibilityModifierFn
|
|
1246
|
+
});
|
|
1247
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/dropdown-core-virtualized-item.js
|
|
1248
|
+
function dropdown_core_virtualized_item_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { dropdown_core_virtualized_item_typeof = function _typeof(obj) { return typeof obj; }; } else { dropdown_core_virtualized_item_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return dropdown_core_virtualized_item_typeof(obj); }
|
|
1249
|
+
|
|
1250
|
+
function dropdown_core_virtualized_item_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; }
|
|
1251
|
+
|
|
1252
|
+
function dropdown_core_virtualized_item_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { dropdown_core_virtualized_item_ownKeys(Object(source), true).forEach(function (key) { dropdown_core_virtualized_item_defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { dropdown_core_virtualized_item_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1253
|
+
|
|
1254
|
+
function dropdown_core_virtualized_item_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; }
|
|
1255
|
+
|
|
1256
|
+
function dropdown_core_virtualized_item_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1257
|
+
|
|
1258
|
+
function dropdown_core_virtualized_item_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); } }
|
|
1259
|
+
|
|
1260
|
+
function dropdown_core_virtualized_item_createClass(Constructor, protoProps, staticProps) { if (protoProps) dropdown_core_virtualized_item_defineProperties(Constructor.prototype, protoProps); if (staticProps) dropdown_core_virtualized_item_defineProperties(Constructor, staticProps); return Constructor; }
|
|
1261
|
+
|
|
1262
|
+
function dropdown_core_virtualized_item_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) dropdown_core_virtualized_item_setPrototypeOf(subClass, superClass); }
|
|
1263
|
+
|
|
1264
|
+
function dropdown_core_virtualized_item_setPrototypeOf(o, p) { dropdown_core_virtualized_item_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return dropdown_core_virtualized_item_setPrototypeOf(o, p); }
|
|
1265
|
+
|
|
1266
|
+
function dropdown_core_virtualized_item_createSuper(Derived) { var hasNativeReflectConstruct = dropdown_core_virtualized_item_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = dropdown_core_virtualized_item_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = dropdown_core_virtualized_item_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return dropdown_core_virtualized_item_possibleConstructorReturn(this, result); }; }
|
|
1267
|
+
|
|
1268
|
+
function dropdown_core_virtualized_item_possibleConstructorReturn(self, call) { if (call && (dropdown_core_virtualized_item_typeof(call) === "object" || typeof call === "function")) { return call; } return dropdown_core_virtualized_item_assertThisInitialized(self); }
|
|
1269
|
+
|
|
1270
|
+
function dropdown_core_virtualized_item_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1271
|
+
|
|
1272
|
+
function dropdown_core_virtualized_item_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
1273
|
+
|
|
1274
|
+
function dropdown_core_virtualized_item_getPrototypeOf(o) { dropdown_core_virtualized_item_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return dropdown_core_virtualized_item_getPrototypeOf(o); }
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* A virtualized list item - It's created by decorating the DropdownItem
|
|
1281
|
+
* (ActionItem, OptionItem, SeparatorItem) with custom styles to let
|
|
1282
|
+
* react-window make its own calculations.
|
|
1283
|
+
*/
|
|
1284
|
+
var dropdown_core_virtualized_item_DropdownVirtualizedItem = /*#__PURE__*/function (_React$Component) {
|
|
1285
|
+
dropdown_core_virtualized_item_inherits(DropdownVirtualizedItem, _React$Component);
|
|
1286
|
+
|
|
1287
|
+
var _super = dropdown_core_virtualized_item_createSuper(DropdownVirtualizedItem);
|
|
1288
|
+
|
|
1289
|
+
function DropdownVirtualizedItem() {
|
|
1290
|
+
dropdown_core_virtualized_item_classCallCheck(this, DropdownVirtualizedItem);
|
|
1291
|
+
|
|
1292
|
+
return _super.apply(this, arguments);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
dropdown_core_virtualized_item_createClass(DropdownVirtualizedItem, [{
|
|
1296
|
+
key: "render",
|
|
1297
|
+
value: function render() {
|
|
1298
|
+
var _this$props = this.props,
|
|
1299
|
+
data = _this$props.data,
|
|
1300
|
+
index = _this$props.index,
|
|
1301
|
+
style = _this$props.style;
|
|
1302
|
+
var item = data[index];
|
|
1303
|
+
|
|
1304
|
+
if (separator_item_SeparatorItem.isClassOf(item.component)) {
|
|
1305
|
+
// add react-window style to the separator to preserve the correct
|
|
1306
|
+
// position
|
|
1307
|
+
return external_react_["cloneElement"](item.component, {
|
|
1308
|
+
style: style
|
|
1309
|
+
});
|
|
1310
|
+
} else {
|
|
1311
|
+
var component = item.component,
|
|
1312
|
+
populatedProps = item.populatedProps,
|
|
1313
|
+
onClick = item.onClick,
|
|
1314
|
+
role = item.role,
|
|
1315
|
+
ref = item.ref;
|
|
1316
|
+
return external_react_["cloneElement"](component, dropdown_core_virtualized_item_objectSpread(dropdown_core_virtualized_item_objectSpread({
|
|
1317
|
+
style: style
|
|
1318
|
+
}, populatedProps), {}, {
|
|
1319
|
+
key: index,
|
|
1320
|
+
onClick: onClick,
|
|
1321
|
+
ref: item.focusable && ref,
|
|
1322
|
+
role: role
|
|
1323
|
+
}));
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}]);
|
|
1327
|
+
|
|
1328
|
+
return DropdownVirtualizedItem;
|
|
1329
|
+
}(external_react_["Component"]);
|
|
1330
|
+
|
|
1331
|
+
/* harmony default export */ var dropdown_core_virtualized_item = (dropdown_core_virtualized_item_DropdownVirtualizedItem);
|
|
1332
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-icon-button"
|
|
1333
|
+
var wonder_blocks_icon_button_ = __webpack_require__(16);
|
|
1334
|
+
var wonder_blocks_icon_button_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_icon_button_);
|
|
1335
|
+
|
|
1336
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/search-text-input.js
|
|
1337
|
+
function search_text_input_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { search_text_input_typeof = function _typeof(obj) { return typeof obj; }; } else { search_text_input_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return search_text_input_typeof(obj); }
|
|
1338
|
+
|
|
1339
|
+
function search_text_input_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; }
|
|
1340
|
+
|
|
1341
|
+
function search_text_input_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { search_text_input_ownKeys(Object(source), true).forEach(function (key) { search_text_input_defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { search_text_input_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1342
|
+
|
|
1343
|
+
function search_text_input_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1344
|
+
|
|
1345
|
+
function search_text_input_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); } }
|
|
1346
|
+
|
|
1347
|
+
function search_text_input_createClass(Constructor, protoProps, staticProps) { if (protoProps) search_text_input_defineProperties(Constructor.prototype, protoProps); if (staticProps) search_text_input_defineProperties(Constructor, staticProps); return Constructor; }
|
|
1348
|
+
|
|
1349
|
+
function search_text_input_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) search_text_input_setPrototypeOf(subClass, superClass); }
|
|
1350
|
+
|
|
1351
|
+
function search_text_input_setPrototypeOf(o, p) { search_text_input_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return search_text_input_setPrototypeOf(o, p); }
|
|
1352
|
+
|
|
1353
|
+
function search_text_input_createSuper(Derived) { var hasNativeReflectConstruct = search_text_input_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = search_text_input_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = search_text_input_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return search_text_input_possibleConstructorReturn(this, result); }; }
|
|
1354
|
+
|
|
1355
|
+
function search_text_input_possibleConstructorReturn(self, call) { if (call && (search_text_input_typeof(call) === "object" || typeof call === "function")) { return call; } return search_text_input_assertThisInitialized(self); }
|
|
1356
|
+
|
|
1357
|
+
function search_text_input_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1358
|
+
|
|
1359
|
+
function search_text_input_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
1360
|
+
|
|
1361
|
+
function search_text_input_getPrototypeOf(o) { search_text_input_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return search_text_input_getPrototypeOf(o); }
|
|
1362
|
+
|
|
1363
|
+
function search_text_input_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; }
|
|
1364
|
+
|
|
1365
|
+
// A TextField with a search icon on its left side and X icon on its right side
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
var search_text_input_SearchTextInput = /*#__PURE__*/function (_React$Component) {
|
|
1377
|
+
search_text_input_inherits(SearchTextInput, _React$Component);
|
|
1378
|
+
|
|
1379
|
+
var _super = search_text_input_createSuper(SearchTextInput);
|
|
1380
|
+
|
|
1381
|
+
function SearchTextInput() {
|
|
1382
|
+
var _this;
|
|
1383
|
+
|
|
1384
|
+
search_text_input_classCallCheck(this, SearchTextInput);
|
|
1385
|
+
|
|
1386
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1387
|
+
args[_key] = arguments[_key];
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
1391
|
+
|
|
1392
|
+
search_text_input_defineProperty(search_text_input_assertThisInitialized(_this), "state", {
|
|
1393
|
+
focused: false,
|
|
1394
|
+
labels: search_text_input_objectSpread({
|
|
1395
|
+
clearSearch: defaultLabels.clearSearch,
|
|
1396
|
+
filter: defaultLabels.filter
|
|
1397
|
+
}, _this.props.labels)
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
search_text_input_defineProperty(search_text_input_assertThisInitialized(_this), "handleChange", function (e) {
|
|
1401
|
+
e.preventDefault();
|
|
1402
|
+
|
|
1403
|
+
_this.props.onChange(e.target.value);
|
|
1404
|
+
});
|
|
1405
|
+
|
|
1406
|
+
search_text_input_defineProperty(search_text_input_assertThisInitialized(_this), "handleDismiss", function () {
|
|
1407
|
+
var _this$props = _this.props,
|
|
1408
|
+
onClick = _this$props.onClick,
|
|
1409
|
+
onChange = _this$props.onChange; // Empty the search text and focus the SearchTextInput
|
|
1410
|
+
|
|
1411
|
+
onChange("");
|
|
1412
|
+
|
|
1413
|
+
if (onClick) {
|
|
1414
|
+
onClick();
|
|
1415
|
+
}
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1418
|
+
search_text_input_defineProperty(search_text_input_assertThisInitialized(_this), "handleBlur", function (e) {
|
|
1419
|
+
_this.setState({
|
|
1420
|
+
focused: false
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
search_text_input_defineProperty(search_text_input_assertThisInitialized(_this), "handleFocus", function (e) {
|
|
1425
|
+
_this.setState({
|
|
1426
|
+
focused: true
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
return _this;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
search_text_input_createClass(SearchTextInput, [{
|
|
1434
|
+
key: "componentDidUpdate",
|
|
1435
|
+
value: function componentDidUpdate(prevProps) {
|
|
1436
|
+
if (this.props.labels !== prevProps.labels) {
|
|
1437
|
+
// eslint-disable-next-line react/no-did-update-set-state
|
|
1438
|
+
this.setState({
|
|
1439
|
+
labels: search_text_input_objectSpread(search_text_input_objectSpread({}, this.state.labels), this.props.labels)
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}, {
|
|
1444
|
+
key: "maybeRenderDismissIconButton",
|
|
1445
|
+
value: function maybeRenderDismissIconButton() {
|
|
1446
|
+
var searchText = this.props.searchText;
|
|
1447
|
+
var clearSearch = this.state.labels.clearSearch;
|
|
1448
|
+
|
|
1449
|
+
if (searchText.length > 0) {
|
|
1450
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_button_default.a, {
|
|
1451
|
+
icon: wonder_blocks_icon_["icons"].dismiss,
|
|
1452
|
+
kind: "tertiary",
|
|
1453
|
+
onClick: this.handleDismiss,
|
|
1454
|
+
style: search_text_input_styles.dismissIcon,
|
|
1455
|
+
"aria-label": clearSearch
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
return null;
|
|
1460
|
+
}
|
|
1461
|
+
}, {
|
|
1462
|
+
key: "render",
|
|
1463
|
+
value: function render() {
|
|
1464
|
+
var _this$props2 = this.props,
|
|
1465
|
+
onClick = _this$props2.onClick,
|
|
1466
|
+
itemRef = _this$props2.itemRef,
|
|
1467
|
+
searchText = _this$props2.searchText,
|
|
1468
|
+
style = _this$props2.style,
|
|
1469
|
+
testId = _this$props2.testId;
|
|
1470
|
+
var filter = this.state.labels.filter;
|
|
1471
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], {
|
|
1472
|
+
onClick: onClick,
|
|
1473
|
+
style: [search_text_input_styles.inputContainer, this.state.focused && search_text_input_styles.focused, style]
|
|
1474
|
+
}, /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
1475
|
+
icon: wonder_blocks_icon_["icons"].search,
|
|
1476
|
+
size: "medium",
|
|
1477
|
+
color: wonder_blocks_color_default.a.offBlack64,
|
|
1478
|
+
style: search_text_input_styles.searchIcon,
|
|
1479
|
+
"aria-hidden": "true"
|
|
1480
|
+
}), /*#__PURE__*/external_react_["createElement"]("input", {
|
|
1481
|
+
type: "text",
|
|
1482
|
+
onChange: this.handleChange,
|
|
1483
|
+
onFocus: this.handleFocus,
|
|
1484
|
+
onBlur: this.handleBlur,
|
|
1485
|
+
ref: itemRef,
|
|
1486
|
+
placeholder: filter,
|
|
1487
|
+
value: searchText,
|
|
1488
|
+
className: Object(external_aphrodite_["css"])(search_text_input_styles.inputStyleReset, wonder_blocks_typography_["styles"].LabelMedium),
|
|
1489
|
+
"data-test-id": testId
|
|
1490
|
+
}), this.maybeRenderDismissIconButton());
|
|
1491
|
+
}
|
|
1492
|
+
}], [{
|
|
1493
|
+
key: "isClassOf",
|
|
1494
|
+
value: function isClassOf(instance) {
|
|
1495
|
+
return instance && instance.type && instance.type.__IS_SEARCH_TEXT_INPUT__;
|
|
1496
|
+
}
|
|
1497
|
+
}]);
|
|
1498
|
+
|
|
1499
|
+
return SearchTextInput;
|
|
1500
|
+
}(external_react_["Component"]);
|
|
1501
|
+
|
|
1502
|
+
search_text_input_defineProperty(search_text_input_SearchTextInput, "defaultProps", {
|
|
1503
|
+
labels: {
|
|
1504
|
+
clearSearch: defaultLabels.clearSearch,
|
|
1505
|
+
filter: defaultLabels.filter
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
search_text_input_defineProperty(search_text_input_SearchTextInput, "__IS_SEARCH_TEXT_INPUT__", true);
|
|
1510
|
+
|
|
1511
|
+
|
|
1512
|
+
var search_text_input_styles = external_aphrodite_["StyleSheet"].create({
|
|
1513
|
+
inputContainer: {
|
|
1514
|
+
flexDirection: "row",
|
|
1515
|
+
border: "1px solid ".concat(wonder_blocks_color_default.a.offBlack16),
|
|
1516
|
+
borderRadius: wonder_blocks_spacing_default.a.xxxSmall_4,
|
|
1517
|
+
alignItems: "center",
|
|
1518
|
+
// The height of the text input is 40 in design spec and we need to
|
|
1519
|
+
// specify the height as well as minHeight to make sure the search text
|
|
1520
|
+
// input takes enough height to render. (otherwise, it will get
|
|
1521
|
+
// squashed)
|
|
1522
|
+
height: DROPDOWN_ITEM_HEIGHT,
|
|
1523
|
+
minHeight: DROPDOWN_ITEM_HEIGHT
|
|
1524
|
+
},
|
|
1525
|
+
focused: {
|
|
1526
|
+
border: "1px solid ".concat(wonder_blocks_color_default.a.blue)
|
|
1527
|
+
},
|
|
1528
|
+
searchIcon: {
|
|
1529
|
+
marginLeft: wonder_blocks_spacing_default.a.xSmall_8,
|
|
1530
|
+
marginRight: wonder_blocks_spacing_default.a.xSmall_8
|
|
1531
|
+
},
|
|
1532
|
+
dismissIcon: {
|
|
1533
|
+
margin: 0,
|
|
1534
|
+
":hover": {
|
|
1535
|
+
border: "none"
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
inputStyleReset: {
|
|
1539
|
+
display: "flex",
|
|
1540
|
+
flex: 1,
|
|
1541
|
+
background: "inherit",
|
|
1542
|
+
border: "none",
|
|
1543
|
+
outline: "none",
|
|
1544
|
+
"::placeholder": {
|
|
1545
|
+
color: wonder_blocks_color_default.a.offBlack64
|
|
1546
|
+
},
|
|
1547
|
+
width: "100%",
|
|
1548
|
+
color: "inherit"
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/dropdown-core-virtualized.js
|
|
1552
|
+
function dropdown_core_virtualized_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { dropdown_core_virtualized_typeof = function _typeof(obj) { return typeof obj; }; } else { dropdown_core_virtualized_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return dropdown_core_virtualized_typeof(obj); }
|
|
1553
|
+
|
|
1554
|
+
function dropdown_core_virtualized_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1555
|
+
|
|
1556
|
+
function dropdown_core_virtualized_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); } }
|
|
1557
|
+
|
|
1558
|
+
function dropdown_core_virtualized_createClass(Constructor, protoProps, staticProps) { if (protoProps) dropdown_core_virtualized_defineProperties(Constructor.prototype, protoProps); if (staticProps) dropdown_core_virtualized_defineProperties(Constructor, staticProps); return Constructor; }
|
|
1559
|
+
|
|
1560
|
+
function dropdown_core_virtualized_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) dropdown_core_virtualized_setPrototypeOf(subClass, superClass); }
|
|
1561
|
+
|
|
1562
|
+
function dropdown_core_virtualized_setPrototypeOf(o, p) { dropdown_core_virtualized_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return dropdown_core_virtualized_setPrototypeOf(o, p); }
|
|
1563
|
+
|
|
1564
|
+
function dropdown_core_virtualized_createSuper(Derived) { var hasNativeReflectConstruct = dropdown_core_virtualized_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = dropdown_core_virtualized_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = dropdown_core_virtualized_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return dropdown_core_virtualized_possibleConstructorReturn(this, result); }; }
|
|
1565
|
+
|
|
1566
|
+
function dropdown_core_virtualized_possibleConstructorReturn(self, call) { if (call && (dropdown_core_virtualized_typeof(call) === "object" || typeof call === "function")) { return call; } return dropdown_core_virtualized_assertThisInitialized(self); }
|
|
1567
|
+
|
|
1568
|
+
function dropdown_core_virtualized_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1569
|
+
|
|
1570
|
+
function dropdown_core_virtualized_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
1571
|
+
|
|
1572
|
+
function dropdown_core_virtualized_getPrototypeOf(o) { dropdown_core_virtualized_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return dropdown_core_virtualized_getPrototypeOf(o); }
|
|
1573
|
+
|
|
1574
|
+
function dropdown_core_virtualized_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; }
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
|
|
1585
|
+
/**
|
|
1586
|
+
* Maximum visible items inside the dropdown list
|
|
1587
|
+
*/
|
|
1588
|
+
var MAX_VISIBLE_ITEMS = 10;
|
|
1589
|
+
/**
|
|
1590
|
+
* A react-window's List wrapper that instantiates the virtualized list and
|
|
1591
|
+
* dynamically calculates the item height depending on the type
|
|
1592
|
+
*/
|
|
1593
|
+
|
|
1594
|
+
var dropdown_core_virtualized_DropdownCoreVirtualized = /*#__PURE__*/function (_React$Component) {
|
|
1595
|
+
dropdown_core_virtualized_inherits(DropdownCoreVirtualized, _React$Component);
|
|
1596
|
+
|
|
1597
|
+
var _super = dropdown_core_virtualized_createSuper(DropdownCoreVirtualized);
|
|
1598
|
+
|
|
1599
|
+
function DropdownCoreVirtualized() {
|
|
1600
|
+
var _this;
|
|
1601
|
+
|
|
1602
|
+
dropdown_core_virtualized_classCallCheck(this, DropdownCoreVirtualized);
|
|
1603
|
+
|
|
1604
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1605
|
+
args[_key] = arguments[_key];
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
1609
|
+
|
|
1610
|
+
dropdown_core_virtualized_defineProperty(dropdown_core_virtualized_assertThisInitialized(_this), "state", {
|
|
1611
|
+
height: _this.getHeight(),
|
|
1612
|
+
width: _this.props.width
|
|
1613
|
+
});
|
|
1614
|
+
|
|
1615
|
+
dropdown_core_virtualized_defineProperty(dropdown_core_virtualized_assertThisInitialized(_this), "getItemSize", function (index) {
|
|
1616
|
+
// get the current item in the list
|
|
1617
|
+
var item = _this.props.data[index];
|
|
1618
|
+
|
|
1619
|
+
if (separator_item_SeparatorItem.isClassOf(item.component)) {
|
|
1620
|
+
// this is the separator's height (1px) + vertical margin (8px)
|
|
1621
|
+
return SEPARATOR_ITEM_HEIGHT;
|
|
1622
|
+
} else if (search_text_input_SearchTextInput.isClassOf(item.component)) {
|
|
1623
|
+
// search text input height
|
|
1624
|
+
return SEARCH_ITEM_HEIGHT;
|
|
1625
|
+
} else {
|
|
1626
|
+
// default dropdown item height
|
|
1627
|
+
return DROPDOWN_ITEM_HEIGHT;
|
|
1628
|
+
}
|
|
1629
|
+
});
|
|
1630
|
+
|
|
1631
|
+
return _this;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
dropdown_core_virtualized_createClass(DropdownCoreVirtualized, [{
|
|
1635
|
+
key: "componentDidMount",
|
|
1636
|
+
value: function componentDidMount() {
|
|
1637
|
+
var _this2 = this;
|
|
1638
|
+
|
|
1639
|
+
var schedule = this.props.schedule; // Wait for styles to be applied. This way, we can get a more precise
|
|
1640
|
+
// value of the container dimensions.
|
|
1641
|
+
|
|
1642
|
+
schedule.animationFrame(function () {
|
|
1643
|
+
_this2.setWidth();
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
}, {
|
|
1647
|
+
key: "componentDidUpdate",
|
|
1648
|
+
value: function componentDidUpdate(prevProps) {
|
|
1649
|
+
var _this$props = this.props,
|
|
1650
|
+
data = _this$props.data,
|
|
1651
|
+
listRef = _this$props.listRef; // if the items size has changed, then recalculate each item position
|
|
1652
|
+
|
|
1653
|
+
if (prevProps.data.length !== data.length) {
|
|
1654
|
+
this.setHeight();
|
|
1655
|
+
|
|
1656
|
+
if (listRef && listRef.current) {
|
|
1657
|
+
// the ref can't associate this instance method
|
|
1658
|
+
// $FlowIgnore
|
|
1659
|
+
listRef.current.resetAfterIndex(1);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Update container width
|
|
1665
|
+
*/
|
|
1666
|
+
|
|
1667
|
+
}, {
|
|
1668
|
+
key: "setWidth",
|
|
1669
|
+
value: function setWidth() {
|
|
1670
|
+
var rootNode = external_react_dom_default.a.findDOMNode(this);
|
|
1671
|
+
var parentNode = rootNode === null || rootNode === void 0 ? void 0 : rootNode.parentElement; // after the non-virtualized items are rendered, we get the container
|
|
1672
|
+
// width to pass it to react-window's List
|
|
1673
|
+
|
|
1674
|
+
if (parentNode) {
|
|
1675
|
+
var width = parentNode.getBoundingClientRect().width;
|
|
1676
|
+
this.setState({
|
|
1677
|
+
width: width
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Update container height
|
|
1683
|
+
*/
|
|
1684
|
+
|
|
1685
|
+
}, {
|
|
1686
|
+
key: "setHeight",
|
|
1687
|
+
value: function setHeight() {
|
|
1688
|
+
// calculate dropdown's height depending on the type of items
|
|
1689
|
+
var height = this.getHeight();
|
|
1690
|
+
this.setState({
|
|
1691
|
+
height: height
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
/**
|
|
1695
|
+
* The list height that is automatically calculated depending on the
|
|
1696
|
+
* component's type of each item (e.g. Separator, Option, Search, etc)
|
|
1697
|
+
*/
|
|
1698
|
+
|
|
1699
|
+
}, {
|
|
1700
|
+
key: "getHeight",
|
|
1701
|
+
value: function getHeight() {
|
|
1702
|
+
// calculate using the first 10 items on the array as we want to display
|
|
1703
|
+
// this number of elements in the visible area
|
|
1704
|
+
return this.props.data.slice(0, MAX_VISIBLE_ITEMS).reduce(function (sum, item) {
|
|
1705
|
+
if (separator_item_SeparatorItem.isClassOf(item.component)) {
|
|
1706
|
+
return sum + SEPARATOR_ITEM_HEIGHT;
|
|
1707
|
+
} else if (search_text_input_SearchTextInput.isClassOf(item.component)) {
|
|
1708
|
+
// search text input height
|
|
1709
|
+
return sum + SEARCH_ITEM_HEIGHT;
|
|
1710
|
+
} else {
|
|
1711
|
+
return sum + DROPDOWN_ITEM_HEIGHT;
|
|
1712
|
+
}
|
|
1713
|
+
}, 0);
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Calculates item height
|
|
1717
|
+
*/
|
|
1718
|
+
|
|
1719
|
+
}, {
|
|
1720
|
+
key: "renderInitialItems",
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* render non virtualized items to calculate the container max-width that
|
|
1724
|
+
* will be used by DropdownCoreVirtualized
|
|
1725
|
+
*/
|
|
1726
|
+
value: function renderInitialItems() {
|
|
1727
|
+
var data = this.props.data;
|
|
1728
|
+
var allComponents = data.map(function (e) {
|
|
1729
|
+
return e.component;
|
|
1730
|
+
}); // 1. get the children opaque data structure to sort each item by its
|
|
1731
|
+
// label length
|
|
1732
|
+
|
|
1733
|
+
var longestItems = external_react_["Children"].toArray(allComponents).filter(Boolean).sort(function (a, b) {
|
|
1734
|
+
// 2. only sort elements that contain a `label` prop
|
|
1735
|
+
if (b.props.label && a.props.label) {
|
|
1736
|
+
return b.props.label.length - a.props.label.length;
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
return -1;
|
|
1740
|
+
}) // 3. only render the possible visible items to minimize layout
|
|
1741
|
+
// jumps
|
|
1742
|
+
.slice(0, MAX_VISIBLE_ITEMS); // Append longest items to calculate the container width.
|
|
1743
|
+
// We need to hide these sorted elements to avoid any FOUC.
|
|
1744
|
+
|
|
1745
|
+
return longestItems.map(function (item) {
|
|
1746
|
+
return external_react_["cloneElement"](item, {
|
|
1747
|
+
style: {
|
|
1748
|
+
visibility: "hidden"
|
|
1749
|
+
}
|
|
1750
|
+
});
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
}, {
|
|
1754
|
+
key: "renderVirtualizedList",
|
|
1755
|
+
value: function renderVirtualizedList() {
|
|
1756
|
+
var _this$props2 = this.props,
|
|
1757
|
+
data = _this$props2.data,
|
|
1758
|
+
listRef = _this$props2.listRef;
|
|
1759
|
+
var _this$state = this.state,
|
|
1760
|
+
height = _this$state.height,
|
|
1761
|
+
width = _this$state.width;
|
|
1762
|
+
return (
|
|
1763
|
+
/*#__PURE__*/
|
|
1764
|
+
// react-window has some issues for typing lists when passing refs
|
|
1765
|
+
// $FlowIgnore
|
|
1766
|
+
external_react_["createElement"](external_react_window_["VariableSizeList"] // react-window doesn't accept maybe numbers. It wants numbers
|
|
1767
|
+
// or strings.
|
|
1768
|
+
// $FlowFixMe
|
|
1769
|
+
, {
|
|
1770
|
+
height: height,
|
|
1771
|
+
itemCount: data.length,
|
|
1772
|
+
itemSize: this.getItemSize,
|
|
1773
|
+
itemData: data,
|
|
1774
|
+
style: {
|
|
1775
|
+
overflowX: "hidden"
|
|
1776
|
+
} // react-window doesn't accept maybe numbers. It wants numbers
|
|
1777
|
+
// or strings.
|
|
1778
|
+
// $FlowFixMe
|
|
1779
|
+
,
|
|
1780
|
+
width: width,
|
|
1781
|
+
overscanCount: 5,
|
|
1782
|
+
ref: listRef
|
|
1783
|
+
}, dropdown_core_virtualized_item)
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1786
|
+
}, {
|
|
1787
|
+
key: "render",
|
|
1788
|
+
value: function render() {
|
|
1789
|
+
if (this.state.width === undefined) {
|
|
1790
|
+
// if we don't pass a fixed value, then we need to render
|
|
1791
|
+
// non-virtualized items to calculate width
|
|
1792
|
+
return this.renderInitialItems();
|
|
1793
|
+
} else {
|
|
1794
|
+
// width has been provided, then render the virtualized list
|
|
1795
|
+
return this.renderVirtualizedList();
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
}]);
|
|
1799
|
+
|
|
1800
|
+
return DropdownCoreVirtualized;
|
|
1801
|
+
}(external_react_["Component"]);
|
|
1802
|
+
|
|
1803
|
+
/* harmony default export */ var dropdown_core_virtualized = (Object(wonder_blocks_timing_["withActionScheduler"])(dropdown_core_virtualized_DropdownCoreVirtualized));
|
|
1804
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/dropdown-core.js
|
|
1805
|
+
function dropdown_core_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { dropdown_core_typeof = function _typeof(obj) { return typeof obj; }; } else { dropdown_core_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return dropdown_core_typeof(obj); }
|
|
1806
|
+
|
|
1807
|
+
function dropdown_core_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = dropdown_core_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
1808
|
+
|
|
1809
|
+
function dropdown_core_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1810
|
+
|
|
1811
|
+
function dropdown_core_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; }
|
|
1812
|
+
|
|
1813
|
+
function dropdown_core_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { dropdown_core_ownKeys(Object(source), true).forEach(function (key) { dropdown_core_defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { dropdown_core_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1814
|
+
|
|
1815
|
+
function dropdown_core_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1816
|
+
|
|
1817
|
+
function dropdown_core_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); } }
|
|
1818
|
+
|
|
1819
|
+
function dropdown_core_createClass(Constructor, protoProps, staticProps) { if (protoProps) dropdown_core_defineProperties(Constructor.prototype, protoProps); if (staticProps) dropdown_core_defineProperties(Constructor, staticProps); return Constructor; }
|
|
1820
|
+
|
|
1821
|
+
function dropdown_core_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) dropdown_core_setPrototypeOf(subClass, superClass); }
|
|
1822
|
+
|
|
1823
|
+
function dropdown_core_setPrototypeOf(o, p) { dropdown_core_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return dropdown_core_setPrototypeOf(o, p); }
|
|
1824
|
+
|
|
1825
|
+
function dropdown_core_createSuper(Derived) { var hasNativeReflectConstruct = dropdown_core_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = dropdown_core_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = dropdown_core_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return dropdown_core_possibleConstructorReturn(this, result); }; }
|
|
1826
|
+
|
|
1827
|
+
function dropdown_core_possibleConstructorReturn(self, call) { if (call && (dropdown_core_typeof(call) === "object" || typeof call === "function")) { return call; } return dropdown_core_assertThisInitialized(self); }
|
|
1828
|
+
|
|
1829
|
+
function dropdown_core_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1830
|
+
|
|
1831
|
+
function dropdown_core_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
1832
|
+
|
|
1833
|
+
function dropdown_core_getPrototypeOf(o) { dropdown_core_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return dropdown_core_getPrototypeOf(o); }
|
|
1834
|
+
|
|
1835
|
+
function dropdown_core_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; }
|
|
1836
|
+
|
|
1837
|
+
// A menu that consists of action items
|
|
1838
|
+
|
|
1839
|
+
|
|
1840
|
+
|
|
1841
|
+
|
|
1842
|
+
|
|
1843
|
+
|
|
1844
|
+
|
|
1845
|
+
|
|
1846
|
+
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
// NOTE(jeff): Here we share some code for use with PopperJS. Long term,
|
|
1850
|
+
// we should either contribute this code to the PopperJS component, or its
|
|
1851
|
+
// own non-wonder-blocks package.
|
|
1852
|
+
// $FlowIgnore
|
|
1853
|
+
// eslint-disable-line import/no-restricted-paths
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* A core dropdown component that takes an opener and children to display as
|
|
1862
|
+
* part of the dropdown menu. Renders the dropdown as a portal to avoid clipping
|
|
1863
|
+
* in overflow: auto containers.
|
|
1864
|
+
*/
|
|
1865
|
+
var dropdown_core_DropdownCore = /*#__PURE__*/function (_React$Component) {
|
|
1866
|
+
dropdown_core_inherits(DropdownCore, _React$Component);
|
|
1867
|
+
|
|
1868
|
+
var _super = dropdown_core_createSuper(DropdownCore);
|
|
1869
|
+
|
|
1870
|
+
dropdown_core_createClass(DropdownCore, null, [{
|
|
1871
|
+
key: "sameItemsFocusable",
|
|
1872
|
+
// Keeps track of the index of the focused item, out of a list of focusable items
|
|
1873
|
+
// Keeps track of the index of the focused item in the context of all the
|
|
1874
|
+
// items contained by this menu, whether focusable or not, used for figuring
|
|
1875
|
+
// out focus correctly when the items have changed in terms of whether
|
|
1876
|
+
// they're focusable or not
|
|
1877
|
+
// Whether any items have been selected since the menu was opened
|
|
1878
|
+
// Keeps a reference of the virtualized list instance
|
|
1879
|
+
// Figure out if the same items are focusable. If an item has been added or
|
|
1880
|
+
// removed, this method will return false.
|
|
1881
|
+
value: function sameItemsFocusable(prevItems, currentItems) {
|
|
1882
|
+
if (prevItems.length !== currentItems.length) {
|
|
1883
|
+
return false;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
for (var i = 0; i < prevItems.length; i++) {
|
|
1887
|
+
if (prevItems[i].focusable !== currentItems[i].focusable) {
|
|
1888
|
+
return false;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
return true;
|
|
1893
|
+
}
|
|
1894
|
+
}, {
|
|
1895
|
+
key: "getDerivedStateFromProps",
|
|
1896
|
+
// This is here to avoid calling React.createRef on each rerender. Instead,
|
|
1897
|
+
// we create the itemRefs only if it's the first time or if the set of items
|
|
1898
|
+
// that are focusable has changed.
|
|
1899
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
1900
|
+
if (state.itemRefs.length === 0 && props.open || !DropdownCore.sameItemsFocusable(state.prevItems, props.items)) {
|
|
1901
|
+
var itemRefs = [];
|
|
1902
|
+
|
|
1903
|
+
for (var i = 0; i < props.items.length; i++) {
|
|
1904
|
+
if (props.items[i].focusable) {
|
|
1905
|
+
var ref = external_react_["createRef"]();
|
|
1906
|
+
itemRefs.push({
|
|
1907
|
+
ref: ref,
|
|
1908
|
+
originalIndex: i
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
return {
|
|
1914
|
+
itemRefs: itemRefs,
|
|
1915
|
+
prevItems: props.items,
|
|
1916
|
+
sameItemsFocusable: false
|
|
1917
|
+
};
|
|
1918
|
+
} else {
|
|
1919
|
+
return {
|
|
1920
|
+
prevItems: props.items,
|
|
1921
|
+
sameItemsFocusable: true
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}]);
|
|
1926
|
+
|
|
1927
|
+
function DropdownCore(props) {
|
|
1928
|
+
var _this;
|
|
1929
|
+
|
|
1930
|
+
dropdown_core_classCallCheck(this, DropdownCore);
|
|
1931
|
+
|
|
1932
|
+
_this = _super.call(this, props);
|
|
1933
|
+
|
|
1934
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "focusedIndex", void 0);
|
|
1935
|
+
|
|
1936
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "focusedOriginalIndex", void 0);
|
|
1937
|
+
|
|
1938
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "itemsClicked", void 0);
|
|
1939
|
+
|
|
1940
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "popperElement", void 0);
|
|
1941
|
+
|
|
1942
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "listRef", void 0);
|
|
1943
|
+
|
|
1944
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "handleInteract", function (event) {
|
|
1945
|
+
var _this$props = _this.props,
|
|
1946
|
+
open = _this$props.open,
|
|
1947
|
+
onOpenChanged = _this$props.onOpenChanged;
|
|
1948
|
+
var target = event.target;
|
|
1949
|
+
var thisElement = external_react_dom_default.a.findDOMNode(dropdown_core_assertThisInitialized(_this));
|
|
1950
|
+
|
|
1951
|
+
if (open && thisElement && !thisElement.contains(target) && _this.popperElement && !_this.popperElement.contains(target)) {
|
|
1952
|
+
onOpenChanged(false);
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1955
|
+
|
|
1956
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "handleKeyDown", function (event) {
|
|
1957
|
+
var _this$props2 = _this.props,
|
|
1958
|
+
onOpenChanged = _this$props2.onOpenChanged,
|
|
1959
|
+
open = _this$props2.open,
|
|
1960
|
+
onSearchTextChanged = _this$props2.onSearchTextChanged,
|
|
1961
|
+
searchText = _this$props2.searchText;
|
|
1962
|
+
var keyCode = event.which || event.keyCode; // If menu isn't open and user presses down, open the menu
|
|
1963
|
+
|
|
1964
|
+
if (!open) {
|
|
1965
|
+
if (keyCode === keyCodes.down) {
|
|
1966
|
+
event.preventDefault();
|
|
1967
|
+
onOpenChanged(true);
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
var showSearchTextInput = !!onSearchTextChanged && typeof searchText === "string"; // Handle all other key behavior
|
|
1975
|
+
|
|
1976
|
+
switch (keyCode) {
|
|
1977
|
+
case keyCodes.tab:
|
|
1978
|
+
// When we show SearchTextInput and that is focused and the
|
|
1979
|
+
// searchText is entered at least one character, dismiss button
|
|
1980
|
+
// is displayed. When user presses tab, we should move focus
|
|
1981
|
+
// to the dismiss button.
|
|
1982
|
+
if (showSearchTextInput && _this.focusedIndex === 0 && searchText) {
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
_this.restoreTabOrder();
|
|
1987
|
+
|
|
1988
|
+
onOpenChanged(false);
|
|
1989
|
+
return;
|
|
1990
|
+
|
|
1991
|
+
case keyCodes.space:
|
|
1992
|
+
// When we display SearchTextInput and the focus is on it,
|
|
1993
|
+
// we should let the user type space.
|
|
1994
|
+
if (showSearchTextInput && _this.focusedIndex === 0) {
|
|
1995
|
+
return;
|
|
1996
|
+
} // Prevent space from scrolling down the page
|
|
1997
|
+
|
|
1998
|
+
|
|
1999
|
+
event.preventDefault();
|
|
2000
|
+
return;
|
|
2001
|
+
|
|
2002
|
+
case keyCodes.up:
|
|
2003
|
+
event.preventDefault();
|
|
2004
|
+
|
|
2005
|
+
_this.focusPreviousItem();
|
|
2006
|
+
|
|
2007
|
+
return;
|
|
2008
|
+
|
|
2009
|
+
case keyCodes.down:
|
|
2010
|
+
event.preventDefault();
|
|
2011
|
+
|
|
2012
|
+
_this.focusNextItem();
|
|
2013
|
+
|
|
2014
|
+
return;
|
|
2015
|
+
}
|
|
2016
|
+
});
|
|
2017
|
+
|
|
2018
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "handleKeyUp", function (event) {
|
|
2019
|
+
var _this$props3 = _this.props,
|
|
2020
|
+
onOpenChanged = _this$props3.onOpenChanged,
|
|
2021
|
+
open = _this$props3.open,
|
|
2022
|
+
onSearchTextChanged = _this$props3.onSearchTextChanged,
|
|
2023
|
+
searchText = _this$props3.searchText;
|
|
2024
|
+
var keyCode = event.which || event.keyCode;
|
|
2025
|
+
var showSearchTextInput = !!onSearchTextChanged && typeof searchText === "string";
|
|
2026
|
+
|
|
2027
|
+
switch (keyCode) {
|
|
2028
|
+
case keyCodes.space:
|
|
2029
|
+
// When we display SearchTextInput and the focus is on it,
|
|
2030
|
+
// we should let the user type space.
|
|
2031
|
+
if (showSearchTextInput && _this.focusedIndex === 0) {
|
|
2032
|
+
return;
|
|
2033
|
+
} // Prevent space from scrolling down the page
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
event.preventDefault();
|
|
2037
|
+
return;
|
|
2038
|
+
|
|
2039
|
+
case keyCodes.escape:
|
|
2040
|
+
// Close only the dropdown, not other elements that are
|
|
2041
|
+
// listening for an escape press
|
|
2042
|
+
if (open) {
|
|
2043
|
+
event.stopPropagation();
|
|
2044
|
+
|
|
2045
|
+
_this.restoreTabOrder();
|
|
2046
|
+
|
|
2047
|
+
onOpenChanged(false);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
return;
|
|
2051
|
+
}
|
|
2052
|
+
});
|
|
2053
|
+
|
|
2054
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "handleClickFocus", function (index) {
|
|
2055
|
+
// Turn itemsClicked on so pressing up or down would focus the
|
|
2056
|
+
// appropriate item in handleKeyDown
|
|
2057
|
+
_this.itemsClicked = true;
|
|
2058
|
+
_this.focusedIndex = index;
|
|
2059
|
+
_this.focusedOriginalIndex = _this.state.itemRefs[_this.focusedIndex].originalIndex;
|
|
2060
|
+
});
|
|
2061
|
+
|
|
2062
|
+
dropdown_core_defineProperty(dropdown_core_assertThisInitialized(_this), "handleDropdownMouseUp", function (event) {
|
|
2063
|
+
// $FlowIgnore[method-unbinding]
|
|
2064
|
+
if (event.nativeEvent.stopImmediatePropagation) {
|
|
2065
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
2066
|
+
} else {
|
|
2067
|
+
// Workaround for jsdom
|
|
2068
|
+
event.stopPropagation();
|
|
2069
|
+
}
|
|
2070
|
+
});
|
|
2071
|
+
|
|
2072
|
+
_this.focusedIndex = _this.props.initialFocusedIndex;
|
|
2073
|
+
_this.state = {
|
|
2074
|
+
prevItems: _this.props.items,
|
|
2075
|
+
itemRefs: [],
|
|
2076
|
+
sameItemsFocusable: false,
|
|
2077
|
+
labels: dropdown_core_objectSpread({
|
|
2078
|
+
noResults: defaultLabels.noResults
|
|
2079
|
+
}, props.labels)
|
|
2080
|
+
};
|
|
2081
|
+
_this.listRef = external_react_["createRef"]();
|
|
2082
|
+
return _this;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
dropdown_core_createClass(DropdownCore, [{
|
|
2086
|
+
key: "componentDidMount",
|
|
2087
|
+
value: function componentDidMount() {
|
|
2088
|
+
this.updateEventListeners();
|
|
2089
|
+
this.initialFocusItem();
|
|
2090
|
+
}
|
|
2091
|
+
}, {
|
|
2092
|
+
key: "componentDidUpdate",
|
|
2093
|
+
value: function componentDidUpdate(prevProps) {
|
|
2094
|
+
var _this2 = this;
|
|
2095
|
+
|
|
2096
|
+
var open = this.props.open;
|
|
2097
|
+
|
|
2098
|
+
if (prevProps.open !== open) {
|
|
2099
|
+
this.updateEventListeners();
|
|
2100
|
+
this.initialFocusItem();
|
|
2101
|
+
} // If the menu changed, but from open to open, figure out if we need
|
|
2102
|
+
// to recalculate the focus somehow.
|
|
2103
|
+
else if (open) {
|
|
2104
|
+
var _this$state = this.state,
|
|
2105
|
+
itemRefs = _this$state.itemRefs,
|
|
2106
|
+
sameItemsFocusable = _this$state.sameItemsFocusable; // Check if the same items are focused by comparing the items at
|
|
2107
|
+
// each index and seeing if the {focusable} property is the same.
|
|
2108
|
+
// Very rarely do the set of focusable items change if the menu
|
|
2109
|
+
// hasn't been re-opened. This is for cases like a {Select all}
|
|
2110
|
+
// option that becomes disabled iff all the options are selected.
|
|
2111
|
+
|
|
2112
|
+
if (sameItemsFocusable) {
|
|
2113
|
+
return;
|
|
2114
|
+
} else {
|
|
2115
|
+
// If the set of items that was focusabled changed, it's very
|
|
2116
|
+
// likely that the previously focused item no longer has the
|
|
2117
|
+
// same index relative to the list of focusable items. Instead,
|
|
2118
|
+
// use the focusedOriginalIndex to find the new index of the
|
|
2119
|
+
// last item that was focused before this change
|
|
2120
|
+
var newFocusableIndex = itemRefs.findIndex(function (ref) {
|
|
2121
|
+
return ref.originalIndex === _this2.focusedOriginalIndex;
|
|
2122
|
+
});
|
|
2123
|
+
|
|
2124
|
+
if (newFocusableIndex === -1) {
|
|
2125
|
+
// Can't find the originally focused item, return focus to
|
|
2126
|
+
// the first item that IS focusable
|
|
2127
|
+
this.focusedIndex = 0; // Reset the knowlege that things had been clicked
|
|
2128
|
+
|
|
2129
|
+
this.itemsClicked = false;
|
|
2130
|
+
this.scheduleToFocusCurrentItem();
|
|
2131
|
+
} else {
|
|
2132
|
+
this.focusedIndex = newFocusableIndex;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
if (this.props.labels !== prevProps.labels) {
|
|
2137
|
+
// eslint-disable-next-line react/no-did-update-set-state
|
|
2138
|
+
this.setState({
|
|
2139
|
+
labels: dropdown_core_objectSpread(dropdown_core_objectSpread({}, this.state.labels), this.props.labels)
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
}, {
|
|
2145
|
+
key: "componentWillUnmount",
|
|
2146
|
+
value: function componentWillUnmount() {
|
|
2147
|
+
this.removeEventListeners();
|
|
2148
|
+
} // Figure out focus states for the dropdown after it has changed from open
|
|
2149
|
+
// to closed or vice versa
|
|
2150
|
+
|
|
2151
|
+
}, {
|
|
2152
|
+
key: "initialFocusItem",
|
|
2153
|
+
value: function initialFocusItem() {
|
|
2154
|
+
var _this$props4 = this.props,
|
|
2155
|
+
initialFocusedIndex = _this$props4.initialFocusedIndex,
|
|
2156
|
+
open = _this$props4.open;
|
|
2157
|
+
|
|
2158
|
+
if (open) {
|
|
2159
|
+
// Reset focused index
|
|
2160
|
+
this.focusedIndex = initialFocusedIndex;
|
|
2161
|
+
this.scheduleToFocusCurrentItem();
|
|
2162
|
+
} else if (!open) {
|
|
2163
|
+
this.itemsClicked = false;
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
}, {
|
|
2167
|
+
key: "updateEventListeners",
|
|
2168
|
+
value: function updateEventListeners() {
|
|
2169
|
+
if (this.props.open) {
|
|
2170
|
+
this.addEventListeners();
|
|
2171
|
+
} else {
|
|
2172
|
+
this.removeEventListeners();
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}, {
|
|
2176
|
+
key: "addEventListeners",
|
|
2177
|
+
value: function addEventListeners() {
|
|
2178
|
+
document.addEventListener("mouseup", this.handleInteract);
|
|
2179
|
+
document.addEventListener("touchend", this.handleInteract);
|
|
2180
|
+
}
|
|
2181
|
+
}, {
|
|
2182
|
+
key: "removeEventListeners",
|
|
2183
|
+
value: function removeEventListeners() {
|
|
2184
|
+
document.removeEventListener("mouseup", this.handleInteract);
|
|
2185
|
+
document.removeEventListener("touchend", this.handleInteract);
|
|
2186
|
+
}
|
|
2187
|
+
}, {
|
|
2188
|
+
key: "scheduleToFocusCurrentItem",
|
|
2189
|
+
value: function scheduleToFocusCurrentItem() {
|
|
2190
|
+
var _this3 = this;
|
|
2191
|
+
|
|
2192
|
+
// wait for windowed items to be recalculated
|
|
2193
|
+
this.props.schedule.animationFrame(function () {
|
|
2194
|
+
return _this3.focusCurrentItem();
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
}, {
|
|
2198
|
+
key: "focusCurrentItem",
|
|
2199
|
+
value: function focusCurrentItem() {
|
|
2200
|
+
var node = external_react_dom_default.a.findDOMNode(this.state.itemRefs[this.focusedIndex].ref.current);
|
|
2201
|
+
|
|
2202
|
+
if (node) {
|
|
2203
|
+
node.focus(); // Keep track of the original index of the newly focused item.
|
|
2204
|
+
// To be used if the set of focusable items in the menu changes
|
|
2205
|
+
|
|
2206
|
+
this.focusedOriginalIndex = this.state.itemRefs[this.focusedIndex].originalIndex;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
}, {
|
|
2210
|
+
key: "focusPreviousItem",
|
|
2211
|
+
value: function focusPreviousItem() {
|
|
2212
|
+
if (this.focusedIndex === 0) {
|
|
2213
|
+
this.focusedIndex = this.state.itemRefs.length - 1;
|
|
2214
|
+
} else {
|
|
2215
|
+
this.focusedIndex -= 1;
|
|
2216
|
+
} // force react-window to scroll on the correct position
|
|
2217
|
+
|
|
2218
|
+
|
|
2219
|
+
if (this.listRef.current) {
|
|
2220
|
+
this.listRef.current.scrollToItem(this.focusedIndex);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
this.scheduleToFocusCurrentItem();
|
|
2224
|
+
}
|
|
2225
|
+
}, {
|
|
2226
|
+
key: "focusNextItem",
|
|
2227
|
+
value: function focusNextItem() {
|
|
2228
|
+
if (this.focusedIndex === this.state.itemRefs.length - 1) {
|
|
2229
|
+
this.focusedIndex = 0;
|
|
2230
|
+
} else {
|
|
2231
|
+
this.focusedIndex += 1;
|
|
2232
|
+
} // force react-window to scroll on the correct position
|
|
2233
|
+
|
|
2234
|
+
|
|
2235
|
+
if (this.listRef.current) {
|
|
2236
|
+
this.listRef.current.scrollToItem(this.focusedIndex);
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
this.scheduleToFocusCurrentItem();
|
|
2240
|
+
}
|
|
2241
|
+
}, {
|
|
2242
|
+
key: "restoreTabOrder",
|
|
2243
|
+
value: function restoreTabOrder() {
|
|
2244
|
+
// NOTE: Because the dropdown is portalled out of its natural
|
|
2245
|
+
// position in the DOM, we need to manually return focus to the
|
|
2246
|
+
// opener element before we let the natural propagation of tab
|
|
2247
|
+
// shift the focus to the next element in the tab order.
|
|
2248
|
+
if (this.props.openerElement) {
|
|
2249
|
+
this.props.openerElement.focus();
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
}, {
|
|
2253
|
+
key: "getItemRole",
|
|
2254
|
+
value: function getItemRole() {
|
|
2255
|
+
var role = this.props.role;
|
|
2256
|
+
|
|
2257
|
+
switch (role) {
|
|
2258
|
+
case "listbox":
|
|
2259
|
+
return "option";
|
|
2260
|
+
|
|
2261
|
+
case "menu":
|
|
2262
|
+
return "menuitem";
|
|
2263
|
+
|
|
2264
|
+
default:
|
|
2265
|
+
throw new Error("Expected \"listbox\" or \"menu\" for role, but receieved \"".concat(role, "\" instead."));
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
}, {
|
|
2269
|
+
key: "maybeRenderNoResults",
|
|
2270
|
+
value: function maybeRenderNoResults() {
|
|
2271
|
+
var _this$props5 = this.props,
|
|
2272
|
+
items = _this$props5.items,
|
|
2273
|
+
onSearchTextChanged = _this$props5.onSearchTextChanged,
|
|
2274
|
+
searchText = _this$props5.searchText,
|
|
2275
|
+
noResults = _this$props5.labels.noResults;
|
|
2276
|
+
var showSearchTextInput = !!onSearchTextChanged && typeof searchText === "string";
|
|
2277
|
+
var includeSearchCount = showSearchTextInput ? 1 : 0; // Verify if there are items to be rendered or not
|
|
2278
|
+
|
|
2279
|
+
var numResults = items.length - includeSearchCount;
|
|
2280
|
+
|
|
2281
|
+
if (numResults === 0) {
|
|
2282
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_typography_["LabelMedium"], {
|
|
2283
|
+
style: dropdown_core_styles.noResult,
|
|
2284
|
+
testId: "dropdown-core-no-results"
|
|
2285
|
+
}, noResults);
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
return null;
|
|
2289
|
+
}
|
|
2290
|
+
/**
|
|
2291
|
+
* Process the items and wrap them into an array that react-window can
|
|
2292
|
+
* interpret
|
|
2293
|
+
*/
|
|
2294
|
+
|
|
2295
|
+
}, {
|
|
2296
|
+
key: "parseItemsList",
|
|
2297
|
+
value: function parseItemsList() {
|
|
2298
|
+
var _this4 = this;
|
|
2299
|
+
|
|
2300
|
+
var focusCounter = 0;
|
|
2301
|
+
var itemRole = this.getItemRole();
|
|
2302
|
+
return this.props.items.map(function (item, index) {
|
|
2303
|
+
if (!separator_item_SeparatorItem.isClassOf(item.component) && item.focusable) {
|
|
2304
|
+
focusCounter += 1;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
var focusIndex = focusCounter - 1;
|
|
2308
|
+
|
|
2309
|
+
if (search_text_input_SearchTextInput.isClassOf(item.component)) {
|
|
2310
|
+
return dropdown_core_objectSpread(dropdown_core_objectSpread({}, item), {}, {
|
|
2311
|
+
// override to avoid losing focus when pressing a key
|
|
2312
|
+
onClick: function onClick() {
|
|
2313
|
+
_this4.handleClickFocus(0);
|
|
2314
|
+
|
|
2315
|
+
_this4.focusCurrentItem();
|
|
2316
|
+
},
|
|
2317
|
+
populatedProps: {
|
|
2318
|
+
style: searchInputStyle,
|
|
2319
|
+
// pass the current ref down to the input element
|
|
2320
|
+
itemRef: _this4.state.itemRefs[focusIndex] ? _this4.state.itemRefs[focusIndex].ref : null
|
|
2321
|
+
}
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
return dropdown_core_objectSpread(dropdown_core_objectSpread({}, item), {}, {
|
|
2326
|
+
role: itemRole,
|
|
2327
|
+
ref: item.focusable ? _this4.state.itemRefs[focusIndex] ? _this4.state.itemRefs[focusIndex].ref : null : null,
|
|
2328
|
+
onClick: function onClick() {
|
|
2329
|
+
_this4.handleClickFocus(focusIndex);
|
|
2330
|
+
|
|
2331
|
+
if (item.component.props.onClick) {
|
|
2332
|
+
item.component.props.onClick();
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
if (item.populatedProps.onClick) {
|
|
2336
|
+
item.populatedProps.onClick();
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
}, {
|
|
2343
|
+
key: "renderItems",
|
|
2344
|
+
value: function renderItems(outOfBoundaries) {
|
|
2345
|
+
var _this$props6 = this.props,
|
|
2346
|
+
dropdownStyle = _this$props6.dropdownStyle,
|
|
2347
|
+
light = _this$props6.light,
|
|
2348
|
+
openerElement = _this$props6.openerElement; // The dropdown width is at least the width of the opener.
|
|
2349
|
+
// It's only used if the element exists in the DOM
|
|
2350
|
+
|
|
2351
|
+
var openerStyle = openerElement && window.getComputedStyle(openerElement);
|
|
2352
|
+
var minDropdownWidth = openerStyle ? openerStyle.getPropertyValue("width") : 0; // preprocess items data to pass it to the renderer
|
|
2353
|
+
|
|
2354
|
+
var itemsList = this.parseItemsList();
|
|
2355
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"] // Stop propagation to prevent the mouseup listener on the
|
|
2356
|
+
// document from closing the menu.
|
|
2357
|
+
, {
|
|
2358
|
+
onMouseUp: this.handleDropdownMouseUp,
|
|
2359
|
+
role: this.props.role,
|
|
2360
|
+
style: [dropdown_core_styles.dropdown, light && dropdown_core_styles.light, outOfBoundaries && dropdown_core_styles.hidden, {
|
|
2361
|
+
minWidth: minDropdownWidth
|
|
2362
|
+
}, dropdownStyle]
|
|
2363
|
+
}, /*#__PURE__*/external_react_["createElement"](dropdown_core_virtualized, {
|
|
2364
|
+
data: itemsList,
|
|
2365
|
+
listRef: this.listRef
|
|
2366
|
+
}), this.maybeRenderNoResults());
|
|
2367
|
+
}
|
|
2368
|
+
}, {
|
|
2369
|
+
key: "renderDropdown",
|
|
2370
|
+
value: function renderDropdown() {
|
|
2371
|
+
var _this5 = this;
|
|
2372
|
+
|
|
2373
|
+
var _this$props7 = this.props,
|
|
2374
|
+
alignment = _this$props7.alignment,
|
|
2375
|
+
openerElement = _this$props7.openerElement; // If we are in a modal, we find where we should be portalling the menu
|
|
2376
|
+
// by using the helper function from the modal package on the opener
|
|
2377
|
+
// element.
|
|
2378
|
+
// If we are not in a modal, we use body as the location to portal to.
|
|
2379
|
+
|
|
2380
|
+
var modalHost = Object(wonder_blocks_modal_["maybeGetPortalMountedModalHostElement"])(openerElement) || document.querySelector("body");
|
|
2381
|
+
|
|
2382
|
+
if (modalHost) {
|
|
2383
|
+
return external_react_dom_default.a.createPortal( /*#__PURE__*/external_react_["createElement"](external_react_popper_["Popper"], {
|
|
2384
|
+
innerRef: function innerRef(node) {
|
|
2385
|
+
if (node) {
|
|
2386
|
+
_this5.popperElement = node;
|
|
2387
|
+
}
|
|
2388
|
+
},
|
|
2389
|
+
referenceElement: this.props.openerElement,
|
|
2390
|
+
placement: alignment === "left" ? "bottom-start" : "bottom-end",
|
|
2391
|
+
modifiers: {
|
|
2392
|
+
wbVisibility: visibility_modifier,
|
|
2393
|
+
preventOverflow: {
|
|
2394
|
+
boundariesElement: "viewport",
|
|
2395
|
+
escapeWithReference: true
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
}, function (_ref) {
|
|
2399
|
+
var placement = _ref.placement,
|
|
2400
|
+
ref = _ref.ref,
|
|
2401
|
+
style = _ref.style,
|
|
2402
|
+
outOfBoundaries = _ref.outOfBoundaries;
|
|
2403
|
+
|
|
2404
|
+
// For some reason react-popper includes `pointerEvents: "none"`
|
|
2405
|
+
// in the `style` it passes to us, but only when running the tests.
|
|
2406
|
+
var _ = style.pointerEvents,
|
|
2407
|
+
restStyle = dropdown_core_objectWithoutProperties(style, ["pointerEvents"]);
|
|
2408
|
+
|
|
2409
|
+
return /*#__PURE__*/external_react_["createElement"]("div", {
|
|
2410
|
+
ref: ref,
|
|
2411
|
+
style: restStyle,
|
|
2412
|
+
"data-placement": placement
|
|
2413
|
+
}, _this5.renderItems(outOfBoundaries));
|
|
2414
|
+
}), modalHost);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
return null;
|
|
2418
|
+
}
|
|
2419
|
+
}, {
|
|
2420
|
+
key: "render",
|
|
2421
|
+
value: function render() {
|
|
2422
|
+
var _this$props8 = this.props,
|
|
2423
|
+
open = _this$props8.open,
|
|
2424
|
+
opener = _this$props8.opener,
|
|
2425
|
+
style = _this$props8.style,
|
|
2426
|
+
className = _this$props8.className;
|
|
2427
|
+
return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], {
|
|
2428
|
+
onKeyDown: this.handleKeyDown,
|
|
2429
|
+
onKeyUp: this.handleKeyUp,
|
|
2430
|
+
style: [dropdown_core_styles.menuWrapper, style],
|
|
2431
|
+
className: className
|
|
2432
|
+
}, opener, open && this.renderDropdown());
|
|
2433
|
+
}
|
|
2434
|
+
}]);
|
|
2435
|
+
|
|
2436
|
+
return DropdownCore;
|
|
2437
|
+
}(external_react_["Component"]);
|
|
2438
|
+
|
|
2439
|
+
dropdown_core_defineProperty(dropdown_core_DropdownCore, "defaultProps", {
|
|
2440
|
+
alignment: "left",
|
|
2441
|
+
initialFocusedIndex: 0,
|
|
2442
|
+
labels: {
|
|
2443
|
+
noResults: defaultLabels.noResults
|
|
2444
|
+
},
|
|
2445
|
+
light: false
|
|
2446
|
+
});
|
|
2447
|
+
|
|
2448
|
+
var dropdown_core_styles = external_aphrodite_["StyleSheet"].create({
|
|
2449
|
+
menuWrapper: {
|
|
2450
|
+
width: "fit-content"
|
|
2451
|
+
},
|
|
2452
|
+
dropdown: {
|
|
2453
|
+
backgroundColor: wonder_blocks_color_default.a.white,
|
|
2454
|
+
borderRadius: 4,
|
|
2455
|
+
paddingTop: wonder_blocks_spacing_default.a.xxxSmall_4,
|
|
2456
|
+
paddingBottom: wonder_blocks_spacing_default.a.xxxSmall_4,
|
|
2457
|
+
border: "solid 1px ".concat(wonder_blocks_color_default.a.offBlack16),
|
|
2458
|
+
boxShadow: "0px 8px 8px 0px ".concat(Object(wonder_blocks_color_["fade"])(wonder_blocks_color_default.a.offBlack, 0.1)),
|
|
2459
|
+
overflowY: "auto"
|
|
2460
|
+
},
|
|
2461
|
+
light: {
|
|
2462
|
+
// Pretty much just remove the border
|
|
2463
|
+
border: "none"
|
|
2464
|
+
},
|
|
2465
|
+
hidden: {
|
|
2466
|
+
visibility: "hidden"
|
|
2467
|
+
},
|
|
2468
|
+
noResult: {
|
|
2469
|
+
color: wonder_blocks_color_default.a.offBlack64,
|
|
2470
|
+
alignSelf: "center",
|
|
2471
|
+
marginTop: wonder_blocks_spacing_default.a.xxSmall_6
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
/* harmony default export */ var dropdown_core = (Object(wonder_blocks_timing_["withActionScheduler"])(dropdown_core_DropdownCore));
|
|
2475
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-layout"
|
|
2476
|
+
var wonder_blocks_layout_ = __webpack_require__(17);
|
|
2477
|
+
|
|
2478
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/action-menu-opener-core.js
|
|
2479
|
+
function action_menu_opener_core_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { action_menu_opener_core_typeof = function _typeof(obj) { return typeof obj; }; } else { action_menu_opener_core_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return action_menu_opener_core_typeof(obj); }
|
|
2480
|
+
|
|
2481
|
+
function action_menu_opener_core_extends() { action_menu_opener_core_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return action_menu_opener_core_extends.apply(this, arguments); }
|
|
2482
|
+
|
|
2483
|
+
function action_menu_opener_core_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = action_menu_opener_core_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
2484
|
+
|
|
2485
|
+
function action_menu_opener_core_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2486
|
+
|
|
2487
|
+
function action_menu_opener_core_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2488
|
+
|
|
2489
|
+
function action_menu_opener_core_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); } }
|
|
2490
|
+
|
|
2491
|
+
function action_menu_opener_core_createClass(Constructor, protoProps, staticProps) { if (protoProps) action_menu_opener_core_defineProperties(Constructor.prototype, protoProps); if (staticProps) action_menu_opener_core_defineProperties(Constructor, staticProps); return Constructor; }
|
|
2492
|
+
|
|
2493
|
+
function action_menu_opener_core_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) action_menu_opener_core_setPrototypeOf(subClass, superClass); }
|
|
2494
|
+
|
|
2495
|
+
function action_menu_opener_core_setPrototypeOf(o, p) { action_menu_opener_core_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return action_menu_opener_core_setPrototypeOf(o, p); }
|
|
2496
|
+
|
|
2497
|
+
function action_menu_opener_core_createSuper(Derived) { var hasNativeReflectConstruct = action_menu_opener_core_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = action_menu_opener_core_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = action_menu_opener_core_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return action_menu_opener_core_possibleConstructorReturn(this, result); }; }
|
|
2498
|
+
|
|
2499
|
+
function action_menu_opener_core_possibleConstructorReturn(self, call) { if (call && (action_menu_opener_core_typeof(call) === "object" || typeof call === "function")) { return call; } return action_menu_opener_core_assertThisInitialized(self); }
|
|
2500
|
+
|
|
2501
|
+
function action_menu_opener_core_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
2502
|
+
|
|
2503
|
+
function action_menu_opener_core_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
2504
|
+
|
|
2505
|
+
function action_menu_opener_core_getPrototypeOf(o) { action_menu_opener_core_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return action_menu_opener_core_getPrototypeOf(o); }
|
|
2506
|
+
|
|
2507
|
+
function action_menu_opener_core_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; }
|
|
2508
|
+
|
|
2509
|
+
|
|
2510
|
+
|
|
2511
|
+
|
|
2512
|
+
|
|
2513
|
+
|
|
2514
|
+
|
|
2515
|
+
|
|
2516
|
+
|
|
2517
|
+
|
|
2518
|
+
|
|
2519
|
+
var action_menu_opener_core_StyledButton = Object(wonder_blocks_core_["addStyle"])("button");
|
|
2520
|
+
/**
|
|
2521
|
+
* Although this component shares a lot with ButtonCore there are a couple
|
|
2522
|
+
* of differences:
|
|
2523
|
+
* - the down caret icon appears on the right instead of the left
|
|
2524
|
+
* - the down caret icon is smaller that the one that would be used by ButtonCore
|
|
2525
|
+
*/
|
|
2526
|
+
|
|
2527
|
+
var action_menu_opener_core_ActionMenuOpenerCore = /*#__PURE__*/function (_React$Component) {
|
|
2528
|
+
action_menu_opener_core_inherits(ActionMenuOpenerCore, _React$Component);
|
|
2529
|
+
|
|
2530
|
+
var _super = action_menu_opener_core_createSuper(ActionMenuOpenerCore);
|
|
2531
|
+
|
|
2532
|
+
function ActionMenuOpenerCore() {
|
|
2533
|
+
action_menu_opener_core_classCallCheck(this, ActionMenuOpenerCore);
|
|
2534
|
+
|
|
2535
|
+
return _super.apply(this, arguments);
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
action_menu_opener_core_createClass(ActionMenuOpenerCore, [{
|
|
2539
|
+
key: "render",
|
|
2540
|
+
value: function render() {
|
|
2541
|
+
var _this$props = this.props,
|
|
2542
|
+
children = _this$props.children,
|
|
2543
|
+
disabledProp = _this$props.disabled,
|
|
2544
|
+
focused = _this$props.focused,
|
|
2545
|
+
hovered = _this$props.hovered,
|
|
2546
|
+
pressed = _this$props.pressed,
|
|
2547
|
+
_ = _this$props.waiting,
|
|
2548
|
+
testId = _this$props.testId,
|
|
2549
|
+
opened = _this$props.opened,
|
|
2550
|
+
ariaLabel = _this$props["aria-label"],
|
|
2551
|
+
restProps = action_menu_opener_core_objectWithoutProperties(_this$props, ["children", "disabled", "focused", "hovered", "pressed", "waiting", "testId", "opened", "aria-label"]);
|
|
2552
|
+
|
|
2553
|
+
var buttonColor = wonder_blocks_color_["SemanticColor"].controlDefault;
|
|
2554
|
+
|
|
2555
|
+
var buttonStyles = action_menu_opener_core_generateStyles(buttonColor);
|
|
2556
|
+
|
|
2557
|
+
var disabled = disabledProp;
|
|
2558
|
+
var defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && pressed && buttonStyles.active];
|
|
2559
|
+
var label = /*#__PURE__*/external_react_["createElement"](wonder_blocks_typography_["LabelLarge"], {
|
|
2560
|
+
style: sharedStyles.text
|
|
2561
|
+
}, children);
|
|
2562
|
+
return /*#__PURE__*/external_react_["createElement"](action_menu_opener_core_StyledButton, action_menu_opener_core_extends({
|
|
2563
|
+
"aria-expanded": opened ? "true" : "false",
|
|
2564
|
+
"aria-haspopup": "menu",
|
|
2565
|
+
"aria-label": ariaLabel,
|
|
2566
|
+
disabled: disabled,
|
|
2567
|
+
style: defaultStyle,
|
|
2568
|
+
type: "button"
|
|
2569
|
+
}, restProps, {
|
|
2570
|
+
"data-test-id": testId
|
|
2571
|
+
}), /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], {
|
|
2572
|
+
style: !disabled && (hovered || focused) && buttonStyles.focus
|
|
2573
|
+
}, label), /*#__PURE__*/external_react_["createElement"](wonder_blocks_layout_["Strut"], {
|
|
2574
|
+
size: wonder_blocks_spacing_default.a.xxxSmall_4
|
|
2575
|
+
}), /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
2576
|
+
size: "small",
|
|
2577
|
+
color: "currentColor",
|
|
2578
|
+
icon: wonder_blocks_icon_["icons"].caretDown
|
|
2579
|
+
}));
|
|
2580
|
+
}
|
|
2581
|
+
}]);
|
|
2582
|
+
|
|
2583
|
+
return ActionMenuOpenerCore;
|
|
2584
|
+
}(external_react_["Component"]);
|
|
2585
|
+
|
|
2586
|
+
action_menu_opener_core_defineProperty(action_menu_opener_core_ActionMenuOpenerCore, "contextTypes", {
|
|
2587
|
+
router: external_prop_types_["any"]
|
|
2588
|
+
});
|
|
2589
|
+
|
|
2590
|
+
|
|
2591
|
+
var sharedStyles = external_aphrodite_["StyleSheet"].create({
|
|
2592
|
+
shared: {
|
|
2593
|
+
position: "relative",
|
|
2594
|
+
display: "inline-flex",
|
|
2595
|
+
alignItems: "center",
|
|
2596
|
+
justifyContent: "center",
|
|
2597
|
+
height: DROPDOWN_ITEM_HEIGHT,
|
|
2598
|
+
border: "none",
|
|
2599
|
+
borderRadius: wonder_blocks_spacing_default.a.xxxSmall_4,
|
|
2600
|
+
cursor: "pointer",
|
|
2601
|
+
outline: "none",
|
|
2602
|
+
textDecoration: "none",
|
|
2603
|
+
boxSizing: "border-box",
|
|
2604
|
+
// This removes the 300ms click delay on mobile browsers by indicating that
|
|
2605
|
+
// "double-tap to zoom" shouldn't be used on this element.
|
|
2606
|
+
touchAction: "manipulation",
|
|
2607
|
+
":focus": {
|
|
2608
|
+
// Mobile: Removes a blue highlight style shown when the user clicks a button
|
|
2609
|
+
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
2610
|
+
}
|
|
2611
|
+
},
|
|
2612
|
+
disabled: {
|
|
2613
|
+
cursor: "auto"
|
|
2614
|
+
},
|
|
2615
|
+
small: {
|
|
2616
|
+
height: wonder_blocks_spacing_default.a.xLarge_32
|
|
2617
|
+
},
|
|
2618
|
+
text: {
|
|
2619
|
+
textAlign: "left",
|
|
2620
|
+
display: "inline-block",
|
|
2621
|
+
alignItems: "center",
|
|
2622
|
+
fontWeight: "bold",
|
|
2623
|
+
userSelect: "none",
|
|
2624
|
+
whiteSpace: "nowrap",
|
|
2625
|
+
overflow: "hidden",
|
|
2626
|
+
textOverflow: "ellipsis",
|
|
2627
|
+
pointerEvents: "none" // fix Safari bug where the browser was eating mouse events
|
|
2628
|
+
|
|
2629
|
+
},
|
|
2630
|
+
hiddenText: {
|
|
2631
|
+
visibility: "hidden"
|
|
2632
|
+
},
|
|
2633
|
+
spinner: {
|
|
2634
|
+
position: "absolute"
|
|
2635
|
+
}
|
|
2636
|
+
});
|
|
2637
|
+
var action_menu_opener_core_styles = {};
|
|
2638
|
+
|
|
2639
|
+
var action_menu_opener_core_generateStyles = function _generateStyles(color) {
|
|
2640
|
+
var buttonType = color;
|
|
2641
|
+
|
|
2642
|
+
if (action_menu_opener_core_styles[buttonType]) {
|
|
2643
|
+
return action_menu_opener_core_styles[buttonType];
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
var offBlack32 = wonder_blocks_color_default.a.offBlack32;
|
|
2647
|
+
var activeColor = Object(wonder_blocks_color_["mix"])(offBlack32, color);
|
|
2648
|
+
var newStyles = {};
|
|
2649
|
+
newStyles = {
|
|
2650
|
+
default: {
|
|
2651
|
+
background: "none",
|
|
2652
|
+
color: color
|
|
2653
|
+
},
|
|
2654
|
+
focus: {
|
|
2655
|
+
":after": {
|
|
2656
|
+
content: "''",
|
|
2657
|
+
position: "absolute",
|
|
2658
|
+
height: 2,
|
|
2659
|
+
left: 0,
|
|
2660
|
+
right: 0,
|
|
2661
|
+
bottom: -1,
|
|
2662
|
+
background: "currentColor",
|
|
2663
|
+
borderRadius: 2
|
|
2664
|
+
}
|
|
2665
|
+
},
|
|
2666
|
+
active: {
|
|
2667
|
+
color: activeColor
|
|
2668
|
+
},
|
|
2669
|
+
disabled: {
|
|
2670
|
+
color: offBlack32,
|
|
2671
|
+
cursor: "default"
|
|
2672
|
+
}
|
|
2673
|
+
};
|
|
2674
|
+
action_menu_opener_core_styles[buttonType] = external_aphrodite_["StyleSheet"].create(newStyles);
|
|
2675
|
+
return action_menu_opener_core_styles[buttonType];
|
|
2676
|
+
};
|
|
2677
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/action-menu.js
|
|
2678
|
+
function action_menu_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { action_menu_typeof = function _typeof(obj) { return typeof obj; }; } else { action_menu_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return action_menu_typeof(obj); }
|
|
2679
|
+
|
|
2680
|
+
function action_menu_extends() { action_menu_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return action_menu_extends.apply(this, arguments); }
|
|
2681
|
+
|
|
2682
|
+
function action_menu_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = action_menu_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
2683
|
+
|
|
2684
|
+
function action_menu_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2685
|
+
|
|
2686
|
+
function action_menu_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; }
|
|
2687
|
+
|
|
2688
|
+
function action_menu_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { action_menu_ownKeys(Object(source), true).forEach(function (key) { action_menu_defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { action_menu_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
2689
|
+
|
|
2690
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2691
|
+
|
|
2692
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
2693
|
+
|
|
2694
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
2695
|
+
|
|
2696
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
2697
|
+
|
|
2698
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
2699
|
+
|
|
2700
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
2701
|
+
|
|
2702
|
+
function action_menu_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2703
|
+
|
|
2704
|
+
function action_menu_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); } }
|
|
2705
|
+
|
|
2706
|
+
function action_menu_createClass(Constructor, protoProps, staticProps) { if (protoProps) action_menu_defineProperties(Constructor.prototype, protoProps); if (staticProps) action_menu_defineProperties(Constructor, staticProps); return Constructor; }
|
|
2707
|
+
|
|
2708
|
+
function action_menu_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) action_menu_setPrototypeOf(subClass, superClass); }
|
|
2709
|
+
|
|
2710
|
+
function action_menu_setPrototypeOf(o, p) { action_menu_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return action_menu_setPrototypeOf(o, p); }
|
|
2711
|
+
|
|
2712
|
+
function action_menu_createSuper(Derived) { var hasNativeReflectConstruct = action_menu_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = action_menu_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = action_menu_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return action_menu_possibleConstructorReturn(this, result); }; }
|
|
2713
|
+
|
|
2714
|
+
function action_menu_possibleConstructorReturn(self, call) { if (call && (action_menu_typeof(call) === "object" || typeof call === "function")) { return call; } return action_menu_assertThisInitialized(self); }
|
|
2715
|
+
|
|
2716
|
+
function action_menu_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
2717
|
+
|
|
2718
|
+
function action_menu_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
2719
|
+
|
|
2720
|
+
function action_menu_getPrototypeOf(o) { action_menu_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return action_menu_getPrototypeOf(o); }
|
|
2721
|
+
|
|
2722
|
+
function action_menu_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; }
|
|
2723
|
+
|
|
2724
|
+
|
|
2725
|
+
|
|
2726
|
+
|
|
2727
|
+
|
|
2728
|
+
|
|
2729
|
+
|
|
2730
|
+
|
|
2731
|
+
|
|
2732
|
+
|
|
2733
|
+
/**
|
|
2734
|
+
* A menu that consists of various types of items.
|
|
2735
|
+
*/
|
|
2736
|
+
var action_menu_ActionMenu = /*#__PURE__*/function (_React$Component) {
|
|
2737
|
+
action_menu_inherits(ActionMenu, _React$Component);
|
|
2738
|
+
|
|
2739
|
+
var _super = action_menu_createSuper(ActionMenu);
|
|
2740
|
+
|
|
2741
|
+
function ActionMenu() {
|
|
2742
|
+
var _this;
|
|
2743
|
+
|
|
2744
|
+
action_menu_classCallCheck(this, ActionMenu);
|
|
2745
|
+
|
|
2746
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2747
|
+
args[_key] = arguments[_key];
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
2751
|
+
|
|
2752
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "openerElement", void 0);
|
|
2753
|
+
|
|
2754
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "state", {
|
|
2755
|
+
opened: false
|
|
2756
|
+
});
|
|
2757
|
+
|
|
2758
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "handleItemSelected", function () {
|
|
2759
|
+
// close menu
|
|
2760
|
+
_this.handleOpenChanged(false); // Bring focus back to the opener element.
|
|
2761
|
+
|
|
2762
|
+
|
|
2763
|
+
if (_this.openerElement) {
|
|
2764
|
+
_this.openerElement.focus();
|
|
2765
|
+
}
|
|
2766
|
+
});
|
|
2767
|
+
|
|
2768
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "handleOpenChanged", function (opened) {
|
|
2769
|
+
_this.setState({
|
|
2770
|
+
opened: opened
|
|
2771
|
+
});
|
|
2772
|
+
|
|
2773
|
+
if (_this.props.onToggle) {
|
|
2774
|
+
_this.props.onToggle(opened);
|
|
2775
|
+
}
|
|
2776
|
+
});
|
|
2777
|
+
|
|
2778
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "handleOptionSelected", function (selectedValue) {
|
|
2779
|
+
var _this$props = _this.props,
|
|
2780
|
+
onChange = _this$props.onChange,
|
|
2781
|
+
selectedValues = _this$props.selectedValues; // If either of these are not defined, return.
|
|
2782
|
+
|
|
2783
|
+
if (!onChange || !selectedValues) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
if (selectedValues.includes(selectedValue)) {
|
|
2788
|
+
var index = selectedValues.indexOf(selectedValue);
|
|
2789
|
+
var updatedSelection = [].concat(_toConsumableArray(selectedValues.slice(0, index)), _toConsumableArray(selectedValues.slice(index + 1)));
|
|
2790
|
+
onChange(updatedSelection);
|
|
2791
|
+
} else {
|
|
2792
|
+
// Item was newly selected
|
|
2793
|
+
onChange([].concat(_toConsumableArray(selectedValues), [selectedValue]));
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
_this.handleItemSelected();
|
|
2797
|
+
});
|
|
2798
|
+
|
|
2799
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "handleOpenerRef", function (node) {
|
|
2800
|
+
_this.openerElement = external_react_dom_default.a.findDOMNode(node);
|
|
2801
|
+
});
|
|
2802
|
+
|
|
2803
|
+
action_menu_defineProperty(action_menu_assertThisInitialized(_this), "handleClick", function (e) {
|
|
2804
|
+
_this.handleOpenChanged(!_this.state.opened);
|
|
2805
|
+
});
|
|
2806
|
+
|
|
2807
|
+
return _this;
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
action_menu_createClass(ActionMenu, [{
|
|
2811
|
+
key: "getMenuItems",
|
|
2812
|
+
value: function getMenuItems() {
|
|
2813
|
+
var _this2 = this;
|
|
2814
|
+
|
|
2815
|
+
var _this$props2 = this.props,
|
|
2816
|
+
children = _this$props2.children,
|
|
2817
|
+
selectedValues = _this$props2.selectedValues;
|
|
2818
|
+
var allChildren = external_react_["Children"].toArray(children).filter(Boolean); // verify if there's at least one OptionItem element to indent the
|
|
2819
|
+
// possible Action items
|
|
2820
|
+
|
|
2821
|
+
var isOptionItemIncluded = allChildren.some(function (item) {
|
|
2822
|
+
return option_item_OptionItem.isClassOf(item);
|
|
2823
|
+
});
|
|
2824
|
+
return allChildren.map(function (item) {
|
|
2825
|
+
var _item$props = item.props,
|
|
2826
|
+
value = _item$props.value,
|
|
2827
|
+
disabled = _item$props.disabled;
|
|
2828
|
+
var itemObject = {
|
|
2829
|
+
component: item,
|
|
2830
|
+
focusable: action_item_ActionItem.isClassOf(item) || option_item_OptionItem.isClassOf(item) ? !disabled : false,
|
|
2831
|
+
populatedProps: {}
|
|
2832
|
+
};
|
|
2833
|
+
|
|
2834
|
+
if (action_item_ActionItem.isClassOf(item)) {
|
|
2835
|
+
return action_menu_objectSpread(action_menu_objectSpread({}, itemObject), {}, {
|
|
2836
|
+
populatedProps: {
|
|
2837
|
+
indent: isOptionItemIncluded,
|
|
2838
|
+
onClick: _this2.handleItemSelected
|
|
2839
|
+
}
|
|
2840
|
+
});
|
|
2841
|
+
} else if (option_item_OptionItem.isClassOf(item)) {
|
|
2842
|
+
return action_menu_objectSpread(action_menu_objectSpread({}, itemObject), {}, {
|
|
2843
|
+
populatedProps: {
|
|
2844
|
+
onToggle: _this2.handleOptionSelected,
|
|
2845
|
+
selected: selectedValues ? selectedValues.includes(value) : false,
|
|
2846
|
+
variant: "check"
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
} else {
|
|
2850
|
+
return itemObject;
|
|
2851
|
+
}
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
}, {
|
|
2855
|
+
key: "renderOpener",
|
|
2856
|
+
value: function renderOpener(numItems) {
|
|
2857
|
+
var _this$props3 = this.props,
|
|
2858
|
+
disabled = _this$props3.disabled,
|
|
2859
|
+
menuText = _this$props3.menuText,
|
|
2860
|
+
opened = _this$props3.opened,
|
|
2861
|
+
opener = _this$props3.opener,
|
|
2862
|
+
testId = _this$props3.testId;
|
|
2863
|
+
return /*#__PURE__*/external_react_["createElement"](dropdown_opener, {
|
|
2864
|
+
onClick: this.handleClick,
|
|
2865
|
+
disabled: numItems === 0 || disabled,
|
|
2866
|
+
text: menuText,
|
|
2867
|
+
ref: this.handleOpenerRef,
|
|
2868
|
+
testId: opener ? undefined : testId
|
|
2869
|
+
}, opener ? opener : function (openerProps) {
|
|
2870
|
+
var text = openerProps.text,
|
|
2871
|
+
eventState = action_menu_objectWithoutProperties(openerProps, ["text"]);
|
|
2872
|
+
|
|
2873
|
+
return /*#__PURE__*/external_react_["createElement"](action_menu_opener_core_ActionMenuOpenerCore, action_menu_extends({}, eventState, {
|
|
2874
|
+
disabled: disabled,
|
|
2875
|
+
opened: !!opened,
|
|
2876
|
+
testId: testId
|
|
2877
|
+
}), menuText);
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2880
|
+
}, {
|
|
2881
|
+
key: "render",
|
|
2882
|
+
value: function render() {
|
|
2883
|
+
var _this$props4 = this.props,
|
|
2884
|
+
alignment = _this$props4.alignment,
|
|
2885
|
+
dropdownStyle = _this$props4.dropdownStyle,
|
|
2886
|
+
style = _this$props4.style,
|
|
2887
|
+
className = _this$props4.className;
|
|
2888
|
+
var items = this.getMenuItems();
|
|
2889
|
+
var dropdownOpener = this.renderOpener(items.length);
|
|
2890
|
+
return /*#__PURE__*/external_react_["createElement"](dropdown_core, {
|
|
2891
|
+
role: "menu",
|
|
2892
|
+
style: style,
|
|
2893
|
+
className: className,
|
|
2894
|
+
opener: dropdownOpener,
|
|
2895
|
+
alignment: alignment,
|
|
2896
|
+
open: this.state.opened,
|
|
2897
|
+
items: items,
|
|
2898
|
+
openerElement: this.openerElement,
|
|
2899
|
+
onOpenChanged: this.handleOpenChanged,
|
|
2900
|
+
dropdownStyle: [action_menu_styles.menuTopSpace, dropdownStyle]
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
}], [{
|
|
2904
|
+
key: "getDerivedStateFromProps",
|
|
2905
|
+
|
|
2906
|
+
/**
|
|
2907
|
+
* Used to sync the `opened` state when this component acts as a controlled
|
|
2908
|
+
* component
|
|
2909
|
+
*/
|
|
2910
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
2911
|
+
return {
|
|
2912
|
+
opened: typeof props.opened === "boolean" ? props.opened : state.opened
|
|
2913
|
+
};
|
|
2914
|
+
}
|
|
2915
|
+
}]);
|
|
2916
|
+
|
|
2917
|
+
return ActionMenu;
|
|
2918
|
+
}(external_react_["Component"]);
|
|
2919
|
+
|
|
2920
|
+
action_menu_defineProperty(action_menu_ActionMenu, "defaultProps", {
|
|
2921
|
+
alignment: "left",
|
|
2922
|
+
disabled: false
|
|
2923
|
+
});
|
|
2924
|
+
|
|
2925
|
+
|
|
2926
|
+
var action_menu_styles = external_aphrodite_["StyleSheet"].create({
|
|
2927
|
+
caret: {
|
|
2928
|
+
marginLeft: 4
|
|
2929
|
+
},
|
|
2930
|
+
// The design calls for additional offset around the opener.
|
|
2931
|
+
opener: {
|
|
2932
|
+
whiteSpace: "nowrap",
|
|
2933
|
+
userSelect: "none",
|
|
2934
|
+
overflow: "hidden",
|
|
2935
|
+
textOverflow: "ellipsis"
|
|
2936
|
+
},
|
|
2937
|
+
// This is to adjust the space between the menu and the opener.
|
|
2938
|
+
menuTopSpace: {
|
|
2939
|
+
top: -4
|
|
2940
|
+
}
|
|
2941
|
+
});
|
|
2942
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/select-opener.js
|
|
2943
|
+
function select_opener_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { select_opener_typeof = function _typeof(obj) { return typeof obj; }; } else { select_opener_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return select_opener_typeof(obj); }
|
|
2944
|
+
|
|
2945
|
+
function select_opener_extends() { select_opener_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return select_opener_extends.apply(this, arguments); }
|
|
2946
|
+
|
|
2947
|
+
function select_opener_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = select_opener_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
2948
|
+
|
|
2949
|
+
function select_opener_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2950
|
+
|
|
2951
|
+
function select_opener_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2952
|
+
|
|
2953
|
+
function select_opener_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); } }
|
|
2954
|
+
|
|
2955
|
+
function select_opener_createClass(Constructor, protoProps, staticProps) { if (protoProps) select_opener_defineProperties(Constructor.prototype, protoProps); if (staticProps) select_opener_defineProperties(Constructor, staticProps); return Constructor; }
|
|
2956
|
+
|
|
2957
|
+
function select_opener_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) select_opener_setPrototypeOf(subClass, superClass); }
|
|
2958
|
+
|
|
2959
|
+
function select_opener_setPrototypeOf(o, p) { select_opener_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return select_opener_setPrototypeOf(o, p); }
|
|
2960
|
+
|
|
2961
|
+
function select_opener_createSuper(Derived) { var hasNativeReflectConstruct = select_opener_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = select_opener_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = select_opener_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return select_opener_possibleConstructorReturn(this, result); }; }
|
|
2962
|
+
|
|
2963
|
+
function select_opener_possibleConstructorReturn(self, call) { if (call && (select_opener_typeof(call) === "object" || typeof call === "function")) { return call; } return select_opener_assertThisInitialized(self); }
|
|
2964
|
+
|
|
2965
|
+
function select_opener_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
2966
|
+
|
|
2967
|
+
function select_opener_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
2968
|
+
|
|
2969
|
+
function select_opener_getPrototypeOf(o) { select_opener_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return select_opener_getPrototypeOf(o); }
|
|
2970
|
+
|
|
2971
|
+
function select_opener_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; }
|
|
2972
|
+
|
|
2973
|
+
|
|
2974
|
+
|
|
2975
|
+
|
|
2976
|
+
|
|
2977
|
+
|
|
2978
|
+
|
|
2979
|
+
|
|
2980
|
+
|
|
2981
|
+
|
|
2982
|
+
|
|
2983
|
+
var select_opener_StyledButton = Object(wonder_blocks_core_["addStyle"])("button");
|
|
2984
|
+
var select_opener_blue = wonder_blocks_color_default.a.blue,
|
|
2985
|
+
select_opener_white = wonder_blocks_color_default.a.white,
|
|
2986
|
+
white50 = wonder_blocks_color_default.a.white50,
|
|
2987
|
+
select_opener_offBlack = wonder_blocks_color_default.a.offBlack,
|
|
2988
|
+
select_opener_offBlack16 = wonder_blocks_color_default.a.offBlack16,
|
|
2989
|
+
select_opener_offBlack32 = wonder_blocks_color_default.a.offBlack32,
|
|
2990
|
+
offBlack64 = wonder_blocks_color_default.a.offBlack64;
|
|
2991
|
+
|
|
2992
|
+
/**
|
|
2993
|
+
* An opener that opens select boxes.
|
|
2994
|
+
*/
|
|
2995
|
+
var select_opener_SelectOpener = /*#__PURE__*/function (_React$Component) {
|
|
2996
|
+
select_opener_inherits(SelectOpener, _React$Component);
|
|
2997
|
+
|
|
2998
|
+
var _super = select_opener_createSuper(SelectOpener);
|
|
2999
|
+
|
|
3000
|
+
function SelectOpener() {
|
|
3001
|
+
var _this;
|
|
3002
|
+
|
|
3003
|
+
select_opener_classCallCheck(this, SelectOpener);
|
|
3004
|
+
|
|
3005
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3006
|
+
args[_key] = arguments[_key];
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
3010
|
+
|
|
3011
|
+
select_opener_defineProperty(select_opener_assertThisInitialized(_this), "handleClick", function (e) {
|
|
3012
|
+
var open = _this.props.open;
|
|
3013
|
+
|
|
3014
|
+
_this.props.onOpenChanged(!open);
|
|
3015
|
+
});
|
|
3016
|
+
|
|
3017
|
+
return _this;
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
select_opener_createClass(SelectOpener, [{
|
|
3021
|
+
key: "render",
|
|
3022
|
+
value: function render() {
|
|
3023
|
+
var _this$props = this.props,
|
|
3024
|
+
children = _this$props.children,
|
|
3025
|
+
disabled = _this$props.disabled,
|
|
3026
|
+
id = _this$props.id,
|
|
3027
|
+
isPlaceholder = _this$props.isPlaceholder,
|
|
3028
|
+
light = _this$props.light,
|
|
3029
|
+
open = _this$props.open,
|
|
3030
|
+
testId = _this$props.testId,
|
|
3031
|
+
onOpenChanged = _this$props.onOpenChanged,
|
|
3032
|
+
sharedProps = select_opener_objectWithoutProperties(_this$props, ["children", "disabled", "id", "isPlaceholder", "light", "open", "testId", "onOpenChanged"]);
|
|
3033
|
+
|
|
3034
|
+
var ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])(this.context.router);
|
|
3035
|
+
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
3036
|
+
disabled: disabled,
|
|
3037
|
+
onClick: this.handleClick
|
|
3038
|
+
}, function (state, childrenProps) {
|
|
3039
|
+
var stateStyles = select_opener_generateStyles(light, isPlaceholder);
|
|
3040
|
+
|
|
3041
|
+
var hovered = state.hovered,
|
|
3042
|
+
focused = state.focused,
|
|
3043
|
+
pressed = state.pressed; // The icon colors are kind of fickle. This is just logic
|
|
3044
|
+
// based on the zeplin design.
|
|
3045
|
+
|
|
3046
|
+
var iconColor = light ? disabled || pressed ? "currentColor" : select_opener_white : disabled ? select_opener_offBlack32 : offBlack64;
|
|
3047
|
+
var style = [select_opener_styles.shared, stateStyles.default, disabled && stateStyles.disabled, !disabled && (pressed ? stateStyles.active : (hovered || focused) && stateStyles.focus)];
|
|
3048
|
+
return /*#__PURE__*/external_react_["createElement"](select_opener_StyledButton, select_opener_extends({}, sharedProps, {
|
|
3049
|
+
"aria-expanded": open ? "true" : "false",
|
|
3050
|
+
"aria-haspopup": "listbox",
|
|
3051
|
+
"data-test-id": testId,
|
|
3052
|
+
disabled: disabled,
|
|
3053
|
+
id: id,
|
|
3054
|
+
style: style,
|
|
3055
|
+
type: "button"
|
|
3056
|
+
}, childrenProps), /*#__PURE__*/external_react_["createElement"](wonder_blocks_typography_["LabelMedium"], {
|
|
3057
|
+
style: select_opener_styles.text
|
|
3058
|
+
}, children), /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
3059
|
+
icon: wonder_blocks_icon_["icons"].caretDown,
|
|
3060
|
+
color: iconColor,
|
|
3061
|
+
size: "small",
|
|
3062
|
+
style: select_opener_styles.caret,
|
|
3063
|
+
"aria-hidden": "true"
|
|
3064
|
+
}));
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
}]);
|
|
3068
|
+
|
|
3069
|
+
return SelectOpener;
|
|
3070
|
+
}(external_react_["Component"]);
|
|
3071
|
+
|
|
3072
|
+
select_opener_defineProperty(select_opener_SelectOpener, "contextTypes", {
|
|
3073
|
+
router: external_prop_types_["any"]
|
|
3074
|
+
});
|
|
3075
|
+
|
|
3076
|
+
select_opener_defineProperty(select_opener_SelectOpener, "defaultProps", {
|
|
3077
|
+
disabled: false,
|
|
3078
|
+
light: false,
|
|
3079
|
+
isPlaceholder: false
|
|
3080
|
+
});
|
|
3081
|
+
|
|
3082
|
+
|
|
3083
|
+
var buttonRadius = 4;
|
|
3084
|
+
var select_opener_styles = external_aphrodite_["StyleSheet"].create({
|
|
3085
|
+
// TODO: Dedupe with Button styles
|
|
3086
|
+
shared: {
|
|
3087
|
+
position: "relative",
|
|
3088
|
+
display: "inline-flex",
|
|
3089
|
+
alignItems: "center",
|
|
3090
|
+
justifyContent: "space-between",
|
|
3091
|
+
color: select_opener_offBlack,
|
|
3092
|
+
height: DROPDOWN_ITEM_HEIGHT,
|
|
3093
|
+
// This asymmetry arises from the Icon on the right side, which has
|
|
3094
|
+
// extra padding built in. To have the component look more balanced,
|
|
3095
|
+
// we need to take off some paddingRight here.
|
|
3096
|
+
paddingLeft: 16,
|
|
3097
|
+
paddingRight: 12,
|
|
3098
|
+
borderWidth: 0,
|
|
3099
|
+
borderRadius: buttonRadius,
|
|
3100
|
+
borderStyle: "solid",
|
|
3101
|
+
outline: "none",
|
|
3102
|
+
textDecoration: "none",
|
|
3103
|
+
boxSizing: "border-box",
|
|
3104
|
+
whiteSpace: "nowrap",
|
|
3105
|
+
// This removes the 300ms click delay on mobile browsers by indicating that
|
|
3106
|
+
// "double-tap to zoom" shouldn't be used on this element.
|
|
3107
|
+
touchAction: "manipulation"
|
|
3108
|
+
},
|
|
3109
|
+
text: {
|
|
3110
|
+
marginRight: wonder_blocks_spacing_default.a.xSmall_8,
|
|
3111
|
+
whiteSpace: "nowrap",
|
|
3112
|
+
userSelect: "none",
|
|
3113
|
+
overflow: "hidden",
|
|
3114
|
+
textOverflow: "ellipsis"
|
|
3115
|
+
},
|
|
3116
|
+
caret: {
|
|
3117
|
+
minWidth: 16
|
|
3118
|
+
}
|
|
3119
|
+
}); // These values are default padding (16 and 12) minus 1, because
|
|
3120
|
+
// changing the borderWidth to 2 messes up the button width
|
|
3121
|
+
// and causes it to move a couple pixels. This fixes that.
|
|
3122
|
+
|
|
3123
|
+
var adjustedPaddingLeft = 16 - 1;
|
|
3124
|
+
var adjustedPaddingRight = 12 - 1;
|
|
3125
|
+
var select_opener_stateStyles = {};
|
|
3126
|
+
|
|
3127
|
+
var select_opener_generateStyles = function _generateStyles(light, placeholder) {
|
|
3128
|
+
// "hash" the parameters
|
|
3129
|
+
var styleKey = "".concat(String(light), "-").concat(String(placeholder));
|
|
3130
|
+
|
|
3131
|
+
if (select_opener_stateStyles[styleKey]) {
|
|
3132
|
+
return select_opener_stateStyles[styleKey];
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
var newStyles = {};
|
|
3136
|
+
|
|
3137
|
+
if (light) {
|
|
3138
|
+
newStyles = {
|
|
3139
|
+
default: {
|
|
3140
|
+
backgroundColor: "transparent",
|
|
3141
|
+
color: placeholder ? white50 : select_opener_white,
|
|
3142
|
+
borderColor: white50,
|
|
3143
|
+
borderWidth: 1
|
|
3144
|
+
},
|
|
3145
|
+
focus: {
|
|
3146
|
+
borderColor: select_opener_white,
|
|
3147
|
+
borderWidth: 2,
|
|
3148
|
+
paddingLeft: adjustedPaddingLeft,
|
|
3149
|
+
paddingRight: adjustedPaddingRight
|
|
3150
|
+
},
|
|
3151
|
+
active: {
|
|
3152
|
+
paddingLeft: adjustedPaddingLeft,
|
|
3153
|
+
paddingRight: adjustedPaddingRight,
|
|
3154
|
+
borderColor: Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(select_opener_blue, 0.32), select_opener_white),
|
|
3155
|
+
borderWidth: 2,
|
|
3156
|
+
color: placeholder ? Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(select_opener_white, 0.32), select_opener_blue) : Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(select_opener_blue, 0.32), select_opener_white),
|
|
3157
|
+
backgroundColor: Object(wonder_blocks_color_["mix"])(select_opener_offBlack32, select_opener_blue)
|
|
3158
|
+
},
|
|
3159
|
+
disabled: {
|
|
3160
|
+
borderColor: Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(select_opener_white, 0.32), select_opener_blue),
|
|
3161
|
+
color: Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(select_opener_white, 0.32), select_opener_blue),
|
|
3162
|
+
cursor: "auto"
|
|
3163
|
+
}
|
|
3164
|
+
};
|
|
3165
|
+
} else {
|
|
3166
|
+
newStyles = {
|
|
3167
|
+
default: {
|
|
3168
|
+
backgroundColor: select_opener_white,
|
|
3169
|
+
borderColor: select_opener_offBlack16,
|
|
3170
|
+
borderWidth: 1,
|
|
3171
|
+
color: placeholder ? offBlack64 : select_opener_offBlack
|
|
3172
|
+
},
|
|
3173
|
+
focus: {
|
|
3174
|
+
borderColor: select_opener_blue,
|
|
3175
|
+
borderWidth: 2,
|
|
3176
|
+
paddingLeft: adjustedPaddingLeft,
|
|
3177
|
+
paddingRight: adjustedPaddingRight
|
|
3178
|
+
},
|
|
3179
|
+
active: {
|
|
3180
|
+
background: Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(select_opener_blue, 0.32), select_opener_white),
|
|
3181
|
+
borderColor: Object(wonder_blocks_color_["mix"])(select_opener_offBlack32, select_opener_blue),
|
|
3182
|
+
borderWidth: 2,
|
|
3183
|
+
paddingLeft: adjustedPaddingLeft,
|
|
3184
|
+
paddingRight: adjustedPaddingRight
|
|
3185
|
+
},
|
|
3186
|
+
disabled: {
|
|
3187
|
+
backgroundColor: "transparent",
|
|
3188
|
+
borderColor: select_opener_offBlack16,
|
|
3189
|
+
color: offBlack64,
|
|
3190
|
+
cursor: "auto"
|
|
3191
|
+
}
|
|
3192
|
+
};
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
select_opener_stateStyles[styleKey] = external_aphrodite_["StyleSheet"].create(newStyles);
|
|
3196
|
+
return select_opener_stateStyles[styleKey];
|
|
3197
|
+
};
|
|
3198
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/single-select.js
|
|
3199
|
+
function single_select_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { single_select_typeof = function _typeof(obj) { return typeof obj; }; } else { single_select_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return single_select_typeof(obj); }
|
|
3200
|
+
|
|
3201
|
+
function single_select_toConsumableArray(arr) { return single_select_arrayWithoutHoles(arr) || single_select_iterableToArray(arr) || single_select_unsupportedIterableToArray(arr) || single_select_nonIterableSpread(); }
|
|
3202
|
+
|
|
3203
|
+
function single_select_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3204
|
+
|
|
3205
|
+
function single_select_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return single_select_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return single_select_arrayLikeToArray(o, minLen); }
|
|
3206
|
+
|
|
3207
|
+
function single_select_iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
3208
|
+
|
|
3209
|
+
function single_select_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return single_select_arrayLikeToArray(arr); }
|
|
3210
|
+
|
|
3211
|
+
function single_select_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
3212
|
+
|
|
3213
|
+
function single_select_extends() { single_select_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return single_select_extends.apply(this, arguments); }
|
|
3214
|
+
|
|
3215
|
+
function single_select_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = single_select_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3216
|
+
|
|
3217
|
+
function single_select_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
3218
|
+
|
|
3219
|
+
function single_select_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3220
|
+
|
|
3221
|
+
function single_select_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); } }
|
|
3222
|
+
|
|
3223
|
+
function single_select_createClass(Constructor, protoProps, staticProps) { if (protoProps) single_select_defineProperties(Constructor.prototype, protoProps); if (staticProps) single_select_defineProperties(Constructor, staticProps); return Constructor; }
|
|
3224
|
+
|
|
3225
|
+
function single_select_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) single_select_setPrototypeOf(subClass, superClass); }
|
|
3226
|
+
|
|
3227
|
+
function single_select_setPrototypeOf(o, p) { single_select_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return single_select_setPrototypeOf(o, p); }
|
|
3228
|
+
|
|
3229
|
+
function single_select_createSuper(Derived) { var hasNativeReflectConstruct = single_select_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = single_select_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = single_select_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return single_select_possibleConstructorReturn(this, result); }; }
|
|
3230
|
+
|
|
3231
|
+
function single_select_possibleConstructorReturn(self, call) { if (call && (single_select_typeof(call) === "object" || typeof call === "function")) { return call; } return single_select_assertThisInitialized(self); }
|
|
3232
|
+
|
|
3233
|
+
function single_select_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
3234
|
+
|
|
3235
|
+
function single_select_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
3236
|
+
|
|
3237
|
+
function single_select_getPrototypeOf(o) { single_select_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return single_select_getPrototypeOf(o); }
|
|
3238
|
+
|
|
3239
|
+
function single_select_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; }
|
|
3240
|
+
|
|
3241
|
+
|
|
3242
|
+
|
|
3243
|
+
|
|
3244
|
+
|
|
3245
|
+
|
|
3246
|
+
|
|
3247
|
+
|
|
3248
|
+
|
|
3249
|
+
/**
|
|
3250
|
+
* The single select allows the selection of one item. Clients are responsible
|
|
3251
|
+
* for keeping track of the selected item in the select.
|
|
3252
|
+
*
|
|
3253
|
+
* The single select dropdown closes after the selection of an item. If the same
|
|
3254
|
+
* item is selected, there is no callback.
|
|
3255
|
+
*
|
|
3256
|
+
* *NOTE:* The component automatically uses
|
|
3257
|
+
* [react-window](https://github.com/bvaughn/react-window) to improve
|
|
3258
|
+
* performance when rendering these elements and is capable of handling many
|
|
3259
|
+
* hundreds of items without performance problems.
|
|
3260
|
+
*
|
|
3261
|
+
*/
|
|
3262
|
+
var single_select_SingleSelect = /*#__PURE__*/function (_React$Component) {
|
|
3263
|
+
single_select_inherits(SingleSelect, _React$Component);
|
|
3264
|
+
|
|
3265
|
+
var _super = single_select_createSuper(SingleSelect);
|
|
3266
|
+
|
|
3267
|
+
function SingleSelect(props) {
|
|
3268
|
+
var _this;
|
|
3269
|
+
|
|
3270
|
+
single_select_classCallCheck(this, SingleSelect);
|
|
3271
|
+
|
|
3272
|
+
_this = _super.call(this, props);
|
|
3273
|
+
|
|
3274
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "selectedIndex", void 0);
|
|
3275
|
+
|
|
3276
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "handleOpenChanged", function (opened) {
|
|
3277
|
+
_this.setState({
|
|
3278
|
+
open: opened,
|
|
3279
|
+
searchText: ""
|
|
3280
|
+
});
|
|
3281
|
+
|
|
3282
|
+
if (_this.props.onToggle) {
|
|
3283
|
+
_this.props.onToggle(opened);
|
|
3284
|
+
}
|
|
3285
|
+
});
|
|
3286
|
+
|
|
3287
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "handleToggle", function (selectedValue) {
|
|
3288
|
+
// Call callback if selection changed.
|
|
3289
|
+
if (selectedValue !== _this.props.selectedValue) {
|
|
3290
|
+
_this.props.onChange(selectedValue);
|
|
3291
|
+
} // Bring focus back to the opener element.
|
|
3292
|
+
|
|
3293
|
+
|
|
3294
|
+
if (_this.state.open && _this.state.openerElement) {
|
|
3295
|
+
_this.state.openerElement.focus();
|
|
3296
|
+
}
|
|
3297
|
+
|
|
3298
|
+
_this.setState({
|
|
3299
|
+
open: false // close the menu upon selection
|
|
3300
|
+
|
|
3301
|
+
});
|
|
3302
|
+
|
|
3303
|
+
if (_this.props.onToggle) {
|
|
3304
|
+
_this.props.onToggle(false);
|
|
3305
|
+
}
|
|
3306
|
+
});
|
|
3307
|
+
|
|
3308
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "mapOptionItemsToDropdownItems", function (children) {
|
|
3309
|
+
// Figure out which index should receive focus when this select opens
|
|
3310
|
+
// Needs to exclude counting items that are disabled
|
|
3311
|
+
var indexCounter = 0;
|
|
3312
|
+
_this.selectedIndex = 0;
|
|
3313
|
+
return children.map(function (option) {
|
|
3314
|
+
var selectedValue = _this.props.selectedValue;
|
|
3315
|
+
var _option$props = option.props,
|
|
3316
|
+
disabled = _option$props.disabled,
|
|
3317
|
+
value = _option$props.value;
|
|
3318
|
+
var selected = selectedValue === value;
|
|
3319
|
+
|
|
3320
|
+
if (!disabled) {
|
|
3321
|
+
indexCounter += 1;
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
if (selected) {
|
|
3325
|
+
_this.selectedIndex = indexCounter;
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3328
|
+
return {
|
|
3329
|
+
component: option,
|
|
3330
|
+
focusable: !disabled,
|
|
3331
|
+
populatedProps: {
|
|
3332
|
+
onToggle: _this.handleToggle,
|
|
3333
|
+
selected: selected,
|
|
3334
|
+
variant: "check"
|
|
3335
|
+
}
|
|
3336
|
+
};
|
|
3337
|
+
});
|
|
3338
|
+
});
|
|
3339
|
+
|
|
3340
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "handleSearchTextChanged", function (searchText) {
|
|
3341
|
+
_this.setState({
|
|
3342
|
+
searchText: searchText
|
|
3343
|
+
});
|
|
3344
|
+
});
|
|
3345
|
+
|
|
3346
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "handleOpenerRef", function (node) {
|
|
3347
|
+
var openerElement = external_react_dom_default.a.findDOMNode(node);
|
|
3348
|
+
|
|
3349
|
+
_this.setState({
|
|
3350
|
+
openerElement: openerElement
|
|
3351
|
+
});
|
|
3352
|
+
});
|
|
3353
|
+
|
|
3354
|
+
single_select_defineProperty(single_select_assertThisInitialized(_this), "handleClick", function (e) {
|
|
3355
|
+
_this.handleOpenChanged(!_this.state.open);
|
|
3356
|
+
});
|
|
3357
|
+
|
|
3358
|
+
_this.selectedIndex = 0;
|
|
3359
|
+
_this.state = {
|
|
3360
|
+
open: false,
|
|
3361
|
+
searchText: "",
|
|
3362
|
+
openerElement: null
|
|
3363
|
+
};
|
|
3364
|
+
return _this;
|
|
3365
|
+
}
|
|
3366
|
+
/**
|
|
3367
|
+
* Used to sync the `opened` state when this component acts as a controlled
|
|
3368
|
+
* component
|
|
3369
|
+
*/
|
|
3370
|
+
|
|
3371
|
+
|
|
3372
|
+
single_select_createClass(SingleSelect, [{
|
|
3373
|
+
key: "filterChildren",
|
|
3374
|
+
value: function filterChildren(children) {
|
|
3375
|
+
var searchText = this.state.searchText;
|
|
3376
|
+
var lowercasedSearchText = searchText.toLowerCase(); // Filter the children with the searchText if any.
|
|
3377
|
+
|
|
3378
|
+
return children.filter(function (_ref) {
|
|
3379
|
+
var props = _ref.props;
|
|
3380
|
+
return !searchText || props.label.toLowerCase().indexOf(lowercasedSearchText) > -1;
|
|
3381
|
+
});
|
|
3382
|
+
}
|
|
3383
|
+
}, {
|
|
3384
|
+
key: "getMenuItems",
|
|
3385
|
+
value: function getMenuItems(children) {
|
|
3386
|
+
var isFilterable = this.props.isFilterable; // If it's not filterable, no need to do any extra besides mapping the
|
|
3387
|
+
// option items to dropdown items.
|
|
3388
|
+
|
|
3389
|
+
return this.mapOptionItemsToDropdownItems(isFilterable ? this.filterChildren(children) : children);
|
|
3390
|
+
}
|
|
3391
|
+
}, {
|
|
3392
|
+
key: "getSearchField",
|
|
3393
|
+
value: function getSearchField() {
|
|
3394
|
+
if (!this.props.isFilterable) {
|
|
3395
|
+
return null;
|
|
3396
|
+
}
|
|
3397
|
+
|
|
3398
|
+
return {
|
|
3399
|
+
component: /*#__PURE__*/external_react_["createElement"](search_text_input_SearchTextInput, {
|
|
3400
|
+
key: "search-text-input",
|
|
3401
|
+
onChange: this.handleSearchTextChanged,
|
|
3402
|
+
searchText: this.state.searchText,
|
|
3403
|
+
labels: {
|
|
3404
|
+
clearSearch: defaultLabels.clearSearch,
|
|
3405
|
+
filter: defaultLabels.filter
|
|
3406
|
+
}
|
|
3407
|
+
}),
|
|
3408
|
+
focusable: true,
|
|
3409
|
+
populatedProps: {}
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
}, {
|
|
3413
|
+
key: "renderOpener",
|
|
3414
|
+
value: function renderOpener(numItems) {
|
|
3415
|
+
var _this$props = this.props,
|
|
3416
|
+
children = _this$props.children,
|
|
3417
|
+
disabled = _this$props.disabled,
|
|
3418
|
+
id = _this$props.id,
|
|
3419
|
+
light = _this$props.light,
|
|
3420
|
+
opener = _this$props.opener,
|
|
3421
|
+
placeholder = _this$props.placeholder,
|
|
3422
|
+
selectedValue = _this$props.selectedValue,
|
|
3423
|
+
testId = _this$props.testId,
|
|
3424
|
+
alignment = _this$props.alignment,
|
|
3425
|
+
dropdownStyle = _this$props.dropdownStyle,
|
|
3426
|
+
isFilterable = _this$props.isFilterable,
|
|
3427
|
+
onChange = _this$props.onChange,
|
|
3428
|
+
onToggle = _this$props.onToggle,
|
|
3429
|
+
opened = _this$props.opened,
|
|
3430
|
+
style = _this$props.style,
|
|
3431
|
+
className = _this$props.className,
|
|
3432
|
+
sharedProps = single_select_objectWithoutProperties(_this$props, ["children", "disabled", "id", "light", "opener", "placeholder", "selectedValue", "testId", "alignment", "dropdownStyle", "isFilterable", "onChange", "onToggle", "opened", "style", "className"]);
|
|
3433
|
+
|
|
3434
|
+
var selectedItem = external_react_["Children"].toArray(children).find(function (option) {
|
|
3435
|
+
return option.props.value === selectedValue;
|
|
3436
|
+
}); // If nothing is selected, or if the selectedValue doesn't match any
|
|
3437
|
+
// item in the menu, use the placeholder.
|
|
3438
|
+
|
|
3439
|
+
var menuText = selectedItem ? selectedItem.props.label : placeholder;
|
|
3440
|
+
var dropdownOpener = opener ? /*#__PURE__*/external_react_["createElement"](dropdown_opener, {
|
|
3441
|
+
onClick: this.handleClick,
|
|
3442
|
+
disabled: numItems === 0 || disabled,
|
|
3443
|
+
ref: this.handleOpenerRef,
|
|
3444
|
+
text: menuText
|
|
3445
|
+
}, opener) : /*#__PURE__*/external_react_["createElement"](select_opener_SelectOpener, single_select_extends({}, sharedProps, {
|
|
3446
|
+
disabled: numItems === 0 || disabled,
|
|
3447
|
+
id: id,
|
|
3448
|
+
isPlaceholder: !selectedItem,
|
|
3449
|
+
light: light,
|
|
3450
|
+
onOpenChanged: this.handleOpenChanged,
|
|
3451
|
+
open: this.state.open,
|
|
3452
|
+
ref: this.handleOpenerRef,
|
|
3453
|
+
testId: testId
|
|
3454
|
+
}), menuText);
|
|
3455
|
+
return dropdownOpener;
|
|
3456
|
+
}
|
|
3457
|
+
}, {
|
|
3458
|
+
key: "render",
|
|
3459
|
+
value: function render() {
|
|
3460
|
+
var _this$props2 = this.props,
|
|
3461
|
+
alignment = _this$props2.alignment,
|
|
3462
|
+
children = _this$props2.children,
|
|
3463
|
+
dropdownStyle = _this$props2.dropdownStyle,
|
|
3464
|
+
isFilterable = _this$props2.isFilterable,
|
|
3465
|
+
light = _this$props2.light,
|
|
3466
|
+
style = _this$props2.style,
|
|
3467
|
+
className = _this$props2.className;
|
|
3468
|
+
var searchText = this.state.searchText;
|
|
3469
|
+
var allChildren = external_react_["Children"].toArray(children).filter(Boolean);
|
|
3470
|
+
var filteredItems = this.getMenuItems(allChildren);
|
|
3471
|
+
var opener = this.renderOpener(allChildren.length);
|
|
3472
|
+
var searchField = this.getSearchField();
|
|
3473
|
+
var items = searchField ? [searchField].concat(single_select_toConsumableArray(filteredItems)) : filteredItems;
|
|
3474
|
+
return /*#__PURE__*/external_react_["createElement"](dropdown_core, {
|
|
3475
|
+
role: "listbox",
|
|
3476
|
+
alignment: alignment,
|
|
3477
|
+
dropdownStyle: [isFilterable && filterableDropdownStyle, selectDropdownStyle, dropdownStyle],
|
|
3478
|
+
initialFocusedIndex: this.selectedIndex,
|
|
3479
|
+
items: items,
|
|
3480
|
+
light: light,
|
|
3481
|
+
onOpenChanged: this.handleOpenChanged,
|
|
3482
|
+
open: this.state.open,
|
|
3483
|
+
opener: opener,
|
|
3484
|
+
openerElement: this.state.openerElement,
|
|
3485
|
+
style: style,
|
|
3486
|
+
className: className,
|
|
3487
|
+
onSearchTextChanged: isFilterable ? this.handleSearchTextChanged : null,
|
|
3488
|
+
searchText: isFilterable ? searchText : ""
|
|
3489
|
+
});
|
|
3490
|
+
}
|
|
3491
|
+
}], [{
|
|
3492
|
+
key: "getDerivedStateFromProps",
|
|
3493
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
3494
|
+
return {
|
|
3495
|
+
open: typeof props.opened === "boolean" ? props.opened : state.open
|
|
3496
|
+
};
|
|
3497
|
+
}
|
|
3498
|
+
}]);
|
|
3499
|
+
|
|
3500
|
+
return SingleSelect;
|
|
3501
|
+
}(external_react_["Component"]);
|
|
3502
|
+
|
|
3503
|
+
single_select_defineProperty(single_select_SingleSelect, "defaultProps", {
|
|
3504
|
+
alignment: "left",
|
|
3505
|
+
disabled: false,
|
|
3506
|
+
light: false
|
|
3507
|
+
});
|
|
3508
|
+
|
|
3509
|
+
|
|
3510
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/components/multi-select.js
|
|
3511
|
+
function multi_select_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { multi_select_typeof = function _typeof(obj) { return typeof obj; }; } else { multi_select_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return multi_select_typeof(obj); }
|
|
3512
|
+
|
|
3513
|
+
function multi_select_extends() { multi_select_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return multi_select_extends.apply(this, arguments); }
|
|
3514
|
+
|
|
3515
|
+
function multi_select_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = multi_select_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3516
|
+
|
|
3517
|
+
function multi_select_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
3518
|
+
|
|
3519
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = multi_select_unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3520
|
+
|
|
3521
|
+
function multi_select_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; }
|
|
3522
|
+
|
|
3523
|
+
function multi_select_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { multi_select_ownKeys(Object(source), true).forEach(function (key) { multi_select_defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { multi_select_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3524
|
+
|
|
3525
|
+
function multi_select_toConsumableArray(arr) { return multi_select_arrayWithoutHoles(arr) || multi_select_iterableToArray(arr) || multi_select_unsupportedIterableToArray(arr) || multi_select_nonIterableSpread(); }
|
|
3526
|
+
|
|
3527
|
+
function multi_select_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3528
|
+
|
|
3529
|
+
function multi_select_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return multi_select_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return multi_select_arrayLikeToArray(o, minLen); }
|
|
3530
|
+
|
|
3531
|
+
function multi_select_iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
3532
|
+
|
|
3533
|
+
function multi_select_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return multi_select_arrayLikeToArray(arr); }
|
|
3534
|
+
|
|
3535
|
+
function multi_select_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
3536
|
+
|
|
3537
|
+
function multi_select_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3538
|
+
|
|
3539
|
+
function multi_select_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); } }
|
|
3540
|
+
|
|
3541
|
+
function multi_select_createClass(Constructor, protoProps, staticProps) { if (protoProps) multi_select_defineProperties(Constructor.prototype, protoProps); if (staticProps) multi_select_defineProperties(Constructor, staticProps); return Constructor; }
|
|
3542
|
+
|
|
3543
|
+
function multi_select_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) multi_select_setPrototypeOf(subClass, superClass); }
|
|
3544
|
+
|
|
3545
|
+
function multi_select_setPrototypeOf(o, p) { multi_select_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return multi_select_setPrototypeOf(o, p); }
|
|
3546
|
+
|
|
3547
|
+
function multi_select_createSuper(Derived) { var hasNativeReflectConstruct = multi_select_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = multi_select_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = multi_select_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return multi_select_possibleConstructorReturn(this, result); }; }
|
|
3548
|
+
|
|
3549
|
+
function multi_select_possibleConstructorReturn(self, call) { if (call && (multi_select_typeof(call) === "object" || typeof call === "function")) { return call; } return multi_select_assertThisInitialized(self); }
|
|
3550
|
+
|
|
3551
|
+
function multi_select_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
3552
|
+
|
|
3553
|
+
function multi_select_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
3554
|
+
|
|
3555
|
+
function multi_select_getPrototypeOf(o) { multi_select_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return multi_select_getPrototypeOf(o); }
|
|
3556
|
+
|
|
3557
|
+
function multi_select_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; }
|
|
3558
|
+
|
|
3559
|
+
|
|
3560
|
+
|
|
3561
|
+
|
|
3562
|
+
|
|
3563
|
+
|
|
3564
|
+
|
|
3565
|
+
|
|
3566
|
+
|
|
3567
|
+
|
|
3568
|
+
|
|
3569
|
+
/**
|
|
3570
|
+
* A dropdown that consists of multiple selection items. This select allows
|
|
3571
|
+
* multiple options to be selected. Clients are responsible for keeping track
|
|
3572
|
+
* of the selected items.
|
|
3573
|
+
*
|
|
3574
|
+
* The multi select stays open until closed by the user. The onChange callback
|
|
3575
|
+
* happens every time there is a change in the selection of the items.
|
|
3576
|
+
*/
|
|
3577
|
+
var multi_select_MultiSelect = /*#__PURE__*/function (_React$Component) {
|
|
3578
|
+
multi_select_inherits(MultiSelect, _React$Component);
|
|
3579
|
+
|
|
3580
|
+
var _super = multi_select_createSuper(MultiSelect);
|
|
3581
|
+
|
|
3582
|
+
function MultiSelect(props) {
|
|
3583
|
+
var _this;
|
|
3584
|
+
|
|
3585
|
+
multi_select_classCallCheck(this, MultiSelect);
|
|
3586
|
+
|
|
3587
|
+
_this = _super.call(this, props);
|
|
3588
|
+
|
|
3589
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "labels", void 0);
|
|
3590
|
+
|
|
3591
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleOpenChanged", function (opened) {
|
|
3592
|
+
_this.setState({
|
|
3593
|
+
open: opened,
|
|
3594
|
+
searchText: "",
|
|
3595
|
+
lastSelectedValues: _this.props.selectedValues
|
|
3596
|
+
});
|
|
3597
|
+
|
|
3598
|
+
if (_this.props.onToggle) {
|
|
3599
|
+
_this.props.onToggle(opened);
|
|
3600
|
+
}
|
|
3601
|
+
});
|
|
3602
|
+
|
|
3603
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleToggle", function (selectedValue) {
|
|
3604
|
+
var _this$props = _this.props,
|
|
3605
|
+
onChange = _this$props.onChange,
|
|
3606
|
+
selectedValues = _this$props.selectedValues;
|
|
3607
|
+
|
|
3608
|
+
if (selectedValues.includes(selectedValue)) {
|
|
3609
|
+
var index = selectedValues.indexOf(selectedValue);
|
|
3610
|
+
var updatedSelection = [].concat(multi_select_toConsumableArray(selectedValues.slice(0, index)), multi_select_toConsumableArray(selectedValues.slice(index + 1)));
|
|
3611
|
+
onChange(updatedSelection);
|
|
3612
|
+
} else {
|
|
3613
|
+
// Item was newly selected
|
|
3614
|
+
onChange([].concat(multi_select_toConsumableArray(selectedValues), [selectedValue]));
|
|
3615
|
+
}
|
|
3616
|
+
});
|
|
3617
|
+
|
|
3618
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleSelectAll", function () {
|
|
3619
|
+
var _this$props2 = _this.props,
|
|
3620
|
+
children = _this$props2.children,
|
|
3621
|
+
onChange = _this$props2.onChange;
|
|
3622
|
+
var selected = external_react_["Children"].toArray(children).filter(Boolean).map(function (option) {
|
|
3623
|
+
return option.props.value;
|
|
3624
|
+
});
|
|
3625
|
+
onChange(selected);
|
|
3626
|
+
});
|
|
3627
|
+
|
|
3628
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleSelectNone", function () {
|
|
3629
|
+
var onChange = _this.props.onChange;
|
|
3630
|
+
onChange([]);
|
|
3631
|
+
});
|
|
3632
|
+
|
|
3633
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "mapOptionItemToDropdownItem", function (option) {
|
|
3634
|
+
var selectedValues = _this.props.selectedValues;
|
|
3635
|
+
var _option$props = option.props,
|
|
3636
|
+
disabled = _option$props.disabled,
|
|
3637
|
+
value = _option$props.value;
|
|
3638
|
+
return {
|
|
3639
|
+
component: option,
|
|
3640
|
+
focusable: !disabled,
|
|
3641
|
+
populatedProps: {
|
|
3642
|
+
onToggle: _this.handleToggle,
|
|
3643
|
+
selected: selectedValues.includes(value),
|
|
3644
|
+
variant: "checkbox"
|
|
3645
|
+
}
|
|
3646
|
+
};
|
|
3647
|
+
});
|
|
3648
|
+
|
|
3649
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleOpenerRef", function (node) {
|
|
3650
|
+
var openerElement = external_react_dom_default.a.findDOMNode(node);
|
|
3651
|
+
|
|
3652
|
+
_this.setState({
|
|
3653
|
+
openerElement: openerElement
|
|
3654
|
+
});
|
|
3655
|
+
});
|
|
3656
|
+
|
|
3657
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleSearchTextChanged", function (searchText) {
|
|
3658
|
+
_this.setState({
|
|
3659
|
+
searchText: searchText
|
|
3660
|
+
});
|
|
3661
|
+
});
|
|
3662
|
+
|
|
3663
|
+
multi_select_defineProperty(multi_select_assertThisInitialized(_this), "handleClick", function (e) {
|
|
3664
|
+
_this.handleOpenChanged(!_this.state.open);
|
|
3665
|
+
});
|
|
3666
|
+
|
|
3667
|
+
_this.state = {
|
|
3668
|
+
open: false,
|
|
3669
|
+
searchText: "",
|
|
3670
|
+
lastSelectedValues: [],
|
|
3671
|
+
// merge custom labels with the default ones
|
|
3672
|
+
labels: multi_select_objectSpread(multi_select_objectSpread({}, defaultLabels), props.labels),
|
|
3673
|
+
openerElement: null
|
|
3674
|
+
}; // merge custom labels with the default ones
|
|
3675
|
+
|
|
3676
|
+
_this.labels = multi_select_objectSpread(multi_select_objectSpread({}, defaultLabels), props.labels);
|
|
3677
|
+
return _this;
|
|
3678
|
+
}
|
|
3679
|
+
/**
|
|
3680
|
+
* Used to sync the `opened` state when this component acts as a controlled
|
|
3681
|
+
* component
|
|
3682
|
+
*/
|
|
3683
|
+
|
|
3684
|
+
|
|
3685
|
+
multi_select_createClass(MultiSelect, [{
|
|
3686
|
+
key: "componentDidUpdate",
|
|
3687
|
+
value: function componentDidUpdate(prevProps) {
|
|
3688
|
+
if (this.props.labels !== prevProps.labels) {
|
|
3689
|
+
// eslint-disable-next-line react/no-did-update-set-state
|
|
3690
|
+
this.setState({
|
|
3691
|
+
labels: multi_select_objectSpread(multi_select_objectSpread({}, this.state.labels), this.props.labels)
|
|
3692
|
+
});
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
}, {
|
|
3696
|
+
key: "getMenuText",
|
|
3697
|
+
value: function getMenuText(children) {
|
|
3698
|
+
var _this$props3 = this.props,
|
|
3699
|
+
implicitAllEnabled = _this$props3.implicitAllEnabled,
|
|
3700
|
+
selectedValues = _this$props3.selectedValues;
|
|
3701
|
+
var _this$state$labels = this.state.labels,
|
|
3702
|
+
noneSelected = _this$state$labels.noneSelected,
|
|
3703
|
+
someSelected = _this$state$labels.someSelected,
|
|
3704
|
+
allSelected = _this$state$labels.allSelected; // When implicit all enabled, use `labels.allSelected` when no selection
|
|
3705
|
+
// otherwise, use the `labels.noneSelected` value
|
|
3706
|
+
|
|
3707
|
+
var noSelectionText = implicitAllEnabled ? allSelected : noneSelected;
|
|
3708
|
+
|
|
3709
|
+
switch (selectedValues.length) {
|
|
3710
|
+
case 0:
|
|
3711
|
+
return noSelectionText;
|
|
3712
|
+
|
|
3713
|
+
case 1:
|
|
3714
|
+
// If there is one item selected, we display its label. If for
|
|
3715
|
+
// some reason we can't find the selected item, we use the
|
|
3716
|
+
// display text for the case where nothing is selected.
|
|
3717
|
+
var selectedItem = children.find(function (option) {
|
|
3718
|
+
return option.props.value === selectedValues[0];
|
|
3719
|
+
});
|
|
3720
|
+
return selectedItem ? selectedItem.props.label : noSelectionText;
|
|
3721
|
+
|
|
3722
|
+
case children.length:
|
|
3723
|
+
return allSelected;
|
|
3724
|
+
|
|
3725
|
+
default:
|
|
3726
|
+
return someSelected(selectedValues.length);
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
}, {
|
|
3730
|
+
key: "getSearchField",
|
|
3731
|
+
value: function getSearchField() {
|
|
3732
|
+
if (!this.props.isFilterable) {
|
|
3733
|
+
return [];
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3736
|
+
var _this$state$labels2 = this.state.labels,
|
|
3737
|
+
clearSearch = _this$state$labels2.clearSearch,
|
|
3738
|
+
filter = _this$state$labels2.filter;
|
|
3739
|
+
return [{
|
|
3740
|
+
component: /*#__PURE__*/external_react_["createElement"](search_text_input_SearchTextInput, {
|
|
3741
|
+
key: "search-text-input",
|
|
3742
|
+
onChange: this.handleSearchTextChanged,
|
|
3743
|
+
searchText: this.state.searchText,
|
|
3744
|
+
labels: {
|
|
3745
|
+
clearSearch: clearSearch,
|
|
3746
|
+
filter: filter
|
|
3747
|
+
}
|
|
3748
|
+
}),
|
|
3749
|
+
focusable: true,
|
|
3750
|
+
populatedProps: {}
|
|
3751
|
+
}];
|
|
3752
|
+
}
|
|
3753
|
+
}, {
|
|
3754
|
+
key: "getShortcuts",
|
|
3755
|
+
value: function getShortcuts(numOptions) {
|
|
3756
|
+
var _this$props4 = this.props,
|
|
3757
|
+
selectedValues = _this$props4.selectedValues,
|
|
3758
|
+
shortcuts = _this$props4.shortcuts;
|
|
3759
|
+
var _this$state$labels3 = this.state.labels,
|
|
3760
|
+
selectAllLabel = _this$state$labels3.selectAllLabel,
|
|
3761
|
+
selectNoneLabel = _this$state$labels3.selectNoneLabel; // When there's search text input to filter, shortcuts should be hidden
|
|
3762
|
+
|
|
3763
|
+
if (shortcuts && !this.state.searchText) {
|
|
3764
|
+
var selectAllDisabled = numOptions === selectedValues.length;
|
|
3765
|
+
var selectAll = {
|
|
3766
|
+
component: /*#__PURE__*/external_react_["createElement"](action_item_ActionItem, {
|
|
3767
|
+
disabled: selectAllDisabled,
|
|
3768
|
+
label: selectAllLabel(numOptions),
|
|
3769
|
+
indent: true,
|
|
3770
|
+
onClick: this.handleSelectAll
|
|
3771
|
+
}),
|
|
3772
|
+
focusable: !selectAllDisabled,
|
|
3773
|
+
populatedProps: {}
|
|
3774
|
+
};
|
|
3775
|
+
var selectNoneDisabled = selectedValues.length === 0;
|
|
3776
|
+
var selectNone = {
|
|
3777
|
+
component: /*#__PURE__*/external_react_["createElement"](action_item_ActionItem, {
|
|
3778
|
+
disabled: selectNoneDisabled,
|
|
3779
|
+
label: selectNoneLabel,
|
|
3780
|
+
indent: true,
|
|
3781
|
+
onClick: this.handleSelectNone
|
|
3782
|
+
}),
|
|
3783
|
+
focusable: !selectNoneDisabled,
|
|
3784
|
+
populatedProps: {}
|
|
3785
|
+
};
|
|
3786
|
+
var separator = {
|
|
3787
|
+
component: /*#__PURE__*/external_react_["createElement"](separator_item_SeparatorItem, {
|
|
3788
|
+
key: "shortcuts-separator"
|
|
3789
|
+
}),
|
|
3790
|
+
focusable: false,
|
|
3791
|
+
populatedProps: {}
|
|
3792
|
+
};
|
|
3793
|
+
return [selectAll, selectNone, separator];
|
|
3794
|
+
} else {
|
|
3795
|
+
return [];
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
}, {
|
|
3799
|
+
key: "getMenuItems",
|
|
3800
|
+
value: function getMenuItems(children) {
|
|
3801
|
+
var isFilterable = this.props.isFilterable; // If it's not filterable, no need to do any extra besides mapping the
|
|
3802
|
+
// option items to dropdown items.
|
|
3803
|
+
|
|
3804
|
+
if (!isFilterable) {
|
|
3805
|
+
return children.map(this.mapOptionItemToDropdownItem);
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3808
|
+
var _this$state = this.state,
|
|
3809
|
+
searchText = _this$state.searchText,
|
|
3810
|
+
lastSelectedValues = _this$state.lastSelectedValues;
|
|
3811
|
+
var lowercasedSearchText = searchText.toLowerCase(); // Filter the children with the searchText if any.
|
|
3812
|
+
|
|
3813
|
+
var filteredChildren = children.filter(function (_ref) {
|
|
3814
|
+
var props = _ref.props;
|
|
3815
|
+
return !searchText || props.label.toLowerCase().indexOf(lowercasedSearchText) > -1;
|
|
3816
|
+
});
|
|
3817
|
+
var lastSelectedChildren = [];
|
|
3818
|
+
var restOfTheChildren = [];
|
|
3819
|
+
|
|
3820
|
+
var _iterator = _createForOfIteratorHelper(filteredChildren),
|
|
3821
|
+
_step;
|
|
3822
|
+
|
|
3823
|
+
try {
|
|
3824
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
3825
|
+
var child = _step.value;
|
|
3826
|
+
|
|
3827
|
+
if (lastSelectedValues.includes(child.props.value)) {
|
|
3828
|
+
lastSelectedChildren.push(child);
|
|
3829
|
+
} else {
|
|
3830
|
+
restOfTheChildren.push(child);
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
} catch (err) {
|
|
3834
|
+
_iterator.e(err);
|
|
3835
|
+
} finally {
|
|
3836
|
+
_iterator.f();
|
|
3837
|
+
}
|
|
3838
|
+
|
|
3839
|
+
var lastSelectedItems = lastSelectedChildren.map(this.mapOptionItemToDropdownItem); // We want to add SeparatorItem in between last selected items and the
|
|
3840
|
+
// rest of the items only when both of them exists.
|
|
3841
|
+
|
|
3842
|
+
if (lastSelectedChildren.length && restOfTheChildren.length) {
|
|
3843
|
+
lastSelectedItems.push({
|
|
3844
|
+
component: /*#__PURE__*/external_react_["createElement"](separator_item_SeparatorItem, {
|
|
3845
|
+
key: "selected-separator"
|
|
3846
|
+
}),
|
|
3847
|
+
focusable: false,
|
|
3848
|
+
populatedProps: {}
|
|
3849
|
+
});
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3852
|
+
return [].concat(multi_select_toConsumableArray(lastSelectedItems), multi_select_toConsumableArray(restOfTheChildren.map(this.mapOptionItemToDropdownItem)));
|
|
3853
|
+
}
|
|
3854
|
+
}, {
|
|
3855
|
+
key: "renderOpener",
|
|
3856
|
+
value: function renderOpener(allChildren) {
|
|
3857
|
+
var _this$props5 = this.props,
|
|
3858
|
+
disabled = _this$props5.disabled,
|
|
3859
|
+
id = _this$props5.id,
|
|
3860
|
+
light = _this$props5.light,
|
|
3861
|
+
opener = _this$props5.opener,
|
|
3862
|
+
testId = _this$props5.testId,
|
|
3863
|
+
alignment = _this$props5.alignment,
|
|
3864
|
+
dropdownStyle = _this$props5.dropdownStyle,
|
|
3865
|
+
implicitAllEnabled = _this$props5.implicitAllEnabled,
|
|
3866
|
+
isFilterable = _this$props5.isFilterable,
|
|
3867
|
+
labels = _this$props5.labels,
|
|
3868
|
+
onChange = _this$props5.onChange,
|
|
3869
|
+
onToggle = _this$props5.onToggle,
|
|
3870
|
+
opened = _this$props5.opened,
|
|
3871
|
+
selectedValues = _this$props5.selectedValues,
|
|
3872
|
+
shortcuts = _this$props5.shortcuts,
|
|
3873
|
+
style = _this$props5.style,
|
|
3874
|
+
className = _this$props5.className,
|
|
3875
|
+
sharedProps = multi_select_objectWithoutProperties(_this$props5, ["disabled", "id", "light", "opener", "testId", "alignment", "dropdownStyle", "implicitAllEnabled", "isFilterable", "labels", "onChange", "onToggle", "opened", "selectedValues", "shortcuts", "style", "className"]);
|
|
3876
|
+
|
|
3877
|
+
var noneSelected = this.state.labels.noneSelected;
|
|
3878
|
+
var menuText = this.getMenuText(allChildren);
|
|
3879
|
+
var numOptions = allChildren.length;
|
|
3880
|
+
var dropdownOpener = opener ? /*#__PURE__*/external_react_["createElement"](dropdown_opener, {
|
|
3881
|
+
onClick: this.handleClick,
|
|
3882
|
+
disabled: numOptions === 0 || disabled,
|
|
3883
|
+
ref: this.handleOpenerRef,
|
|
3884
|
+
text: menuText
|
|
3885
|
+
}, opener) : /*#__PURE__*/external_react_["createElement"](select_opener_SelectOpener, multi_select_extends({}, sharedProps, {
|
|
3886
|
+
disabled: numOptions === 0 || disabled,
|
|
3887
|
+
id: id,
|
|
3888
|
+
isPlaceholder: menuText === noneSelected,
|
|
3889
|
+
light: light,
|
|
3890
|
+
onOpenChanged: this.handleOpenChanged,
|
|
3891
|
+
open: this.state.open,
|
|
3892
|
+
ref: this.handleOpenerRef,
|
|
3893
|
+
testId: testId
|
|
3894
|
+
}), menuText);
|
|
3895
|
+
return dropdownOpener;
|
|
3896
|
+
}
|
|
3897
|
+
}, {
|
|
3898
|
+
key: "render",
|
|
3899
|
+
value: function render() {
|
|
3900
|
+
var _this$props6 = this.props,
|
|
3901
|
+
alignment = _this$props6.alignment,
|
|
3902
|
+
light = _this$props6.light,
|
|
3903
|
+
style = _this$props6.style,
|
|
3904
|
+
className = _this$props6.className,
|
|
3905
|
+
dropdownStyle = _this$props6.dropdownStyle,
|
|
3906
|
+
children = _this$props6.children,
|
|
3907
|
+
isFilterable = _this$props6.isFilterable;
|
|
3908
|
+
var _this$state2 = this.state,
|
|
3909
|
+
open = _this$state2.open,
|
|
3910
|
+
searchText = _this$state2.searchText;
|
|
3911
|
+
var noResults = this.state.labels.noResults;
|
|
3912
|
+
var allChildren = external_react_["Children"].toArray(children).filter(Boolean);
|
|
3913
|
+
var numOptions = allChildren.length;
|
|
3914
|
+
var filteredItems = this.getMenuItems(allChildren);
|
|
3915
|
+
var opener = this.renderOpener(allChildren);
|
|
3916
|
+
return /*#__PURE__*/external_react_["createElement"](dropdown_core, {
|
|
3917
|
+
role: "listbox",
|
|
3918
|
+
alignment: alignment,
|
|
3919
|
+
dropdownStyle: [isFilterable && filterableDropdownStyle, selectDropdownStyle, dropdownStyle],
|
|
3920
|
+
items: [].concat(multi_select_toConsumableArray(this.getSearchField()), multi_select_toConsumableArray(this.getShortcuts(numOptions)), multi_select_toConsumableArray(filteredItems)),
|
|
3921
|
+
light: light,
|
|
3922
|
+
onOpenChanged: this.handleOpenChanged,
|
|
3923
|
+
open: open,
|
|
3924
|
+
opener: opener,
|
|
3925
|
+
openerElement: this.state.openerElement,
|
|
3926
|
+
style: style,
|
|
3927
|
+
className: className,
|
|
3928
|
+
onSearchTextChanged: isFilterable ? this.handleSearchTextChanged : null,
|
|
3929
|
+
searchText: isFilterable ? searchText : "",
|
|
3930
|
+
labels: {
|
|
3931
|
+
noResults: noResults
|
|
3932
|
+
}
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3935
|
+
}], [{
|
|
3936
|
+
key: "getDerivedStateFromProps",
|
|
3937
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
3938
|
+
return {
|
|
3939
|
+
open: typeof props.opened === "boolean" ? props.opened : state.open
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
}]);
|
|
3943
|
+
|
|
3944
|
+
return MultiSelect;
|
|
3945
|
+
}(external_react_["Component"]);
|
|
3946
|
+
|
|
3947
|
+
multi_select_defineProperty(multi_select_MultiSelect, "defaultProps", {
|
|
3948
|
+
alignment: "left",
|
|
3949
|
+
disabled: false,
|
|
3950
|
+
light: false,
|
|
3951
|
+
shortcuts: false,
|
|
3952
|
+
selectedValues: []
|
|
3953
|
+
});
|
|
3954
|
+
|
|
3955
|
+
|
|
3956
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-dropdown/src/index.js
|
|
3957
|
+
|
|
3958
|
+
|
|
3959
|
+
|
|
3960
|
+
|
|
3961
|
+
|
|
3962
|
+
|
|
3963
|
+
|
|
3964
|
+
|
|
3965
|
+
/***/ })
|
|
3966
|
+
/******/ ]);
|