@entur/dropdown 2.2.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/dropdown.cjs.development.js +91 -18
- package/dist/dropdown.cjs.development.js.map +1 -1
- package/dist/dropdown.cjs.production.min.js +1 -1
- package/dist/dropdown.cjs.production.min.js.map +1 -1
- package/dist/dropdown.esm.js +92 -19
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +79 -72
- package/package.json +6 -6
package/dist/dropdown.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { debounce, useRandomId, warnAboutMissingStyles } from '@entur/utils';
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useState, useRef } from 'react';
|
|
3
3
|
import Downshift, { useSelect } from 'downshift';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { BaseFormControl, VariantProvider, FeedbackText } from '@entur/form';
|
|
@@ -77,6 +77,44 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
77
77
|
return target;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
81
|
+
if (!o) return;
|
|
82
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
83
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
84
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
85
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
86
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function _arrayLikeToArray(arr, len) {
|
|
90
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
91
|
+
|
|
92
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
93
|
+
|
|
94
|
+
return arr2;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
98
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
99
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
100
|
+
|
|
101
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
102
|
+
if (it) o = it;
|
|
103
|
+
var i = 0;
|
|
104
|
+
return function () {
|
|
105
|
+
if (i >= o.length) return {
|
|
106
|
+
done: true
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
done: false,
|
|
110
|
+
value: o[i++]
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
116
|
+
}
|
|
117
|
+
|
|
80
118
|
var _excluded$8 = ["children", "onChange", "onInputValueChange", "highlightFirstItemOnOpen", "className", "style", "searchable"];
|
|
81
119
|
var DownshiftContext = /*#__PURE__*/React.createContext(null);
|
|
82
120
|
var DownshiftProvider = function DownshiftProvider(_ref) {
|
|
@@ -311,7 +349,7 @@ var Appendix$1 = function Appendix(_ref3) {
|
|
|
311
349
|
};
|
|
312
350
|
|
|
313
351
|
var _excluded$4 = ["disabled", "placeholder", "selectOnTab", "openOnFocus", "listStyle", "items", "label", "disableLabelAnimation", "loading", "loadingText", "className", "clearable"];
|
|
314
|
-
var RegularDropdown = function
|
|
352
|
+
var RegularDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
315
353
|
var disabled = _ref.disabled,
|
|
316
354
|
_ref$placeholder = _ref.placeholder,
|
|
317
355
|
placeholder = _ref$placeholder === void 0 ? 'Vennligst velg' : _ref$placeholder,
|
|
@@ -387,8 +425,10 @@ var RegularDropdown = function RegularDropdown(_ref) {
|
|
|
387
425
|
!isOpen && openMenu();
|
|
388
426
|
}
|
|
389
427
|
}
|
|
390
|
-
}, rest))
|
|
391
|
-
|
|
428
|
+
}, rest)), {
|
|
429
|
+
ref: ref
|
|
430
|
+
}), selectedItem ? selectedItem.label : placeholder));
|
|
431
|
+
});
|
|
392
432
|
|
|
393
433
|
var _excluded$3 = ["disabled", "className", "items", "loading", "loadingText", "readOnly", "prepend", "selectOnTab", "openOnFocus", "listStyle", "clearable", "itemFilter", "label", "disableLabelAnimation", "placeholder"];
|
|
394
434
|
|
|
@@ -402,7 +442,7 @@ function LowerCaseFilterTest(item, input) {
|
|
|
402
442
|
return inputRegex.test(item.label);
|
|
403
443
|
}
|
|
404
444
|
|
|
405
|
-
var SearchableDropdown = function
|
|
445
|
+
var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
406
446
|
var _ref$disabled = _ref.disabled,
|
|
407
447
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
408
448
|
className = _ref.className,
|
|
@@ -433,8 +473,14 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
433
473
|
selectHighlightedItem = _useDownshift.selectHighlightedItem,
|
|
434
474
|
isOpen = _useDownshift.isOpen,
|
|
435
475
|
openMenu = _useDownshift.openMenu,
|
|
476
|
+
closeMenu = _useDownshift.closeMenu,
|
|
436
477
|
selectedItem = _useDownshift.selectedItem;
|
|
437
478
|
|
|
479
|
+
var _useState = useState(false),
|
|
480
|
+
hideSelectedItem = _useState[0],
|
|
481
|
+
setHideSelectedItem = _useState[1];
|
|
482
|
+
|
|
483
|
+
var inputRef = useRef(null);
|
|
438
484
|
var filteredItems = React.useMemo(function () {
|
|
439
485
|
return items.filter(function (item) {
|
|
440
486
|
return itemFilter(item, inputValue);
|
|
@@ -453,24 +499,50 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
453
499
|
label: label,
|
|
454
500
|
isFilled: selectedItem ? true : false,
|
|
455
501
|
disableLabelAnimation: disableLabelAnimation
|
|
456
|
-
}, selectedItem && !inputValue && React.createElement("span", {
|
|
457
|
-
className: "eds-dropdown__searchable-selected-
|
|
458
|
-
},
|
|
502
|
+
}, !hideSelectedItem && selectedItem && !inputValue && React.createElement("span", {
|
|
503
|
+
className: "eds-dropdown__searchable-selected-item__wrapper"
|
|
504
|
+
}, React.createElement("span", {
|
|
505
|
+
className: "eds-dropdown__searchable-selected-item",
|
|
506
|
+
onClick: function onClick() {
|
|
507
|
+
var _inputRef$current;
|
|
508
|
+
|
|
509
|
+
return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
510
|
+
}
|
|
511
|
+
}, selectedItem.label)), React.createElement("input", _extends({}, getInputProps(_extends({
|
|
459
512
|
disabled: disabled,
|
|
460
513
|
readOnly: readOnly,
|
|
461
514
|
className: 'eds-form-control eds-dropdown__input',
|
|
462
515
|
onKeyDown: function onKeyDown(e) {
|
|
463
|
-
if (selectOnTab && e.key === 'Tab')
|
|
464
|
-
selectHighlightedItem();
|
|
465
|
-
}
|
|
516
|
+
if (selectOnTab && e.key === 'Tab') selectHighlightedItem();
|
|
466
517
|
},
|
|
467
518
|
onFocus: function onFocus() {
|
|
468
|
-
if (openOnFocus)
|
|
469
|
-
|
|
470
|
-
}
|
|
519
|
+
if (!isOpen && openOnFocus) openMenu();
|
|
520
|
+
setHideSelectedItem(true);
|
|
471
521
|
},
|
|
472
|
-
placeholder: selectedItem ?
|
|
473
|
-
}, rest))
|
|
522
|
+
placeholder: selectedItem ? selectedItem.label : placeholder
|
|
523
|
+
}, rest)), {
|
|
524
|
+
onBlur: function onBlur() {
|
|
525
|
+
setHideSelectedItem(false);
|
|
526
|
+
closeMenu();
|
|
527
|
+
},
|
|
528
|
+
ref: mergeRefs(ref, inputRef)
|
|
529
|
+
})));
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
var mergeRefs = function mergeRefs() {
|
|
533
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
534
|
+
refs[_key] = arguments[_key];
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return function (node) {
|
|
538
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
539
|
+
var ref = _step.value;
|
|
540
|
+
|
|
541
|
+
if (typeof ref === 'function') {
|
|
542
|
+
ref(node);
|
|
543
|
+
} else if (ref) ref.current = node;
|
|
544
|
+
}
|
|
545
|
+
};
|
|
474
546
|
};
|
|
475
547
|
|
|
476
548
|
var DropdownInputGroup = function DropdownInputGroup(_ref) {
|
|
@@ -1356,7 +1428,7 @@ debounceTimeout) {
|
|
|
1356
1428
|
};
|
|
1357
1429
|
|
|
1358
1430
|
var _excluded$2 = ["highlightFirstItemOnOpen", "debounceTimeout", "disabled", "feedback", "items", "label", "loadingText", "onChange", "placeholder", "prepend", "readOnly", "searchable", "selectOnTab", "openOnFocus", "variant", "value", "clearable", "className", "style", "listStyle", "itemFilter", "disableLabelAnimation"];
|
|
1359
|
-
var Dropdown = function
|
|
1431
|
+
var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1360
1432
|
var highlightFirstItemOnOpen = _ref.highlightFirstItemOnOpen,
|
|
1361
1433
|
debounceTimeout = _ref.debounceTimeout,
|
|
1362
1434
|
disabled = _ref.disabled,
|
|
@@ -1427,9 +1499,10 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
1427
1499
|
openOnFocus: openOnFocus,
|
|
1428
1500
|
listStyle: listStyle,
|
|
1429
1501
|
clearable: clearable,
|
|
1430
|
-
disableLabelAnimation: disableLabelAnimation
|
|
1502
|
+
disableLabelAnimation: disableLabelAnimation,
|
|
1503
|
+
ref: ref
|
|
1431
1504
|
}, searchAbleProps))));
|
|
1432
|
-
};
|
|
1505
|
+
});
|
|
1433
1506
|
|
|
1434
1507
|
var _excluded$1 = ["className", "disabled", "readOnly", "items", "loadingText", "prepend", "style", "label", "variant", "feedback", "disableLabelAnimation"];
|
|
1435
1508
|
var NativeDropdown = function NativeDropdown(_ref) {
|