@entur/dropdown 3.0.15 → 3.0.17
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 +16 -0
- package/dist/Dropdown.d.ts +2 -2
- package/dist/beta/DropdownList.d.ts +17 -0
- package/dist/beta/SearchableDropdown.d.ts +42 -0
- package/dist/beta/index.d.ts +1 -0
- package/dist/dropdown.cjs.development.js +250 -24
- 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 +251 -26
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/styles.css +147 -13
- package/package.json +2 -2
package/dist/dropdown.esm.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { mergeRefs, debounce, useRandomId, warnAboutMissingStyles } from '@entur/utils';
|
|
2
2
|
import React, { useState, useRef } from 'react';
|
|
3
|
-
import Downshift, { useSelect } from 'downshift';
|
|
3
|
+
import Downshift, { useSelect, useCombobox } from 'downshift';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { BaseFormControl, VariantProvider, FeedbackText } from '@entur/form';
|
|
6
6
|
import { CheckIcon, DownArrowIcon, CloseSmallIcon, CloseIcon } from '@entur/icons';
|
|
7
7
|
import { VisuallyHidden } from '@entur/a11y';
|
|
8
8
|
import { LoadingDots } from '@entur/loader';
|
|
9
9
|
import { space } from '@entur/tokens';
|
|
10
|
+
import { IconButton } from '@entur/button';
|
|
10
11
|
|
|
11
12
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
12
13
|
try {
|
|
@@ -77,7 +78,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
77
78
|
return target;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
var _excluded$
|
|
81
|
+
var _excluded$a = ["children", "onChange", "onInputValueChange", "highlightFirstItemOnOpen", "className", "style", "searchable"];
|
|
81
82
|
var DownshiftContext = /*#__PURE__*/React.createContext(null);
|
|
82
83
|
var DownshiftProvider = function DownshiftProvider(_ref) {
|
|
83
84
|
var children = _ref.children,
|
|
@@ -95,7 +96,7 @@ var DownshiftProvider = function DownshiftProvider(_ref) {
|
|
|
95
96
|
style = _ref.style,
|
|
96
97
|
_ref$searchable = _ref.searchable,
|
|
97
98
|
searchable = _ref$searchable === void 0 ? false : _ref$searchable,
|
|
98
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
99
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$a);
|
|
99
100
|
|
|
100
101
|
var handleStateChange = function handleStateChange(changes, stateAndHelpers) {
|
|
101
102
|
if (changes.type === Downshift.stateChangeTypes.controlledPropUpdatedSelectedItem) {
|
|
@@ -165,10 +166,10 @@ var useDownshift = function useDownshift() {
|
|
|
165
166
|
return context;
|
|
166
167
|
};
|
|
167
168
|
|
|
168
|
-
var _excluded$
|
|
169
|
-
var DropdownList = function DropdownList(_ref) {
|
|
169
|
+
var _excluded$9 = ["items"];
|
|
170
|
+
var DropdownList$1 = function DropdownList(_ref) {
|
|
170
171
|
var items = _ref.items,
|
|
171
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
172
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$9);
|
|
172
173
|
|
|
173
174
|
var _useDownshift = useDownshift(),
|
|
174
175
|
highlightedIndex = _useDownshift.highlightedIndex,
|
|
@@ -218,18 +219,18 @@ var DropdownToggleButton$1 = function DropdownToggleButton() {
|
|
|
218
219
|
}), React.createElement(DownArrowIcon, null));
|
|
219
220
|
};
|
|
220
221
|
|
|
221
|
-
var _excluded$
|
|
222
|
+
var _excluded$8 = ["className", "children"];
|
|
222
223
|
var DropdownLoadingDots = function DropdownLoadingDots(_ref) {
|
|
223
224
|
var className = _ref.className,
|
|
224
225
|
children = _ref.children,
|
|
225
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
226
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$8);
|
|
226
227
|
|
|
227
228
|
return React.createElement("div", _extends({
|
|
228
229
|
className: classNames('eds-inline-spinner', className)
|
|
229
230
|
}, rest), React.createElement(LoadingDots, null), React.createElement(VisuallyHidden, null, children));
|
|
230
231
|
};
|
|
231
232
|
|
|
232
|
-
var _excluded$
|
|
233
|
+
var _excluded$7 = ["children", "className", "items", "loading", "loadingText", "placeholder", "style", "listStyle", "clearable", "label", "isFilled", "disableLabelAnimation"];
|
|
233
234
|
var BaseDropdown = function BaseDropdown(_ref) {
|
|
234
235
|
var children = _ref.children,
|
|
235
236
|
className = _ref.className,
|
|
@@ -245,7 +246,7 @@ var BaseDropdown = function BaseDropdown(_ref) {
|
|
|
245
246
|
_ref$isFilled = _ref.isFilled,
|
|
246
247
|
isFilled = _ref$isFilled === void 0 ? false : _ref$isFilled,
|
|
247
248
|
disableLabelAnimation = _ref.disableLabelAnimation,
|
|
248
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
249
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
|
|
249
250
|
|
|
250
251
|
var _useDownshift = useDownshift(),
|
|
251
252
|
getLabelProps = _useDownshift.getLabelProps;
|
|
@@ -254,7 +255,7 @@ var BaseDropdown = function BaseDropdown(_ref) {
|
|
|
254
255
|
className: "eds-dropdown-wrapper",
|
|
255
256
|
style: style
|
|
256
257
|
}, React.createElement(BaseFormControl, _extends({
|
|
257
|
-
append: React.createElement(Appendix$
|
|
258
|
+
append: React.createElement(Appendix$2, {
|
|
258
259
|
clearable: clearable,
|
|
259
260
|
loading: loading,
|
|
260
261
|
loadingText: loadingText,
|
|
@@ -265,7 +266,7 @@ var BaseDropdown = function BaseDropdown(_ref) {
|
|
|
265
266
|
isFilled: isFilled,
|
|
266
267
|
labelProps: getLabelProps(),
|
|
267
268
|
disableLabelAnimation: disableLabelAnimation
|
|
268
|
-
}, rest), children), React.createElement(DropdownList, _extends({
|
|
269
|
+
}, rest), children), React.createElement(DropdownList$1, _extends({
|
|
269
270
|
items: items,
|
|
270
271
|
style: _extends({
|
|
271
272
|
position: 'absolute',
|
|
@@ -293,7 +294,7 @@ var ClearButton$1 = function ClearButton(_ref2) {
|
|
|
293
294
|
}));
|
|
294
295
|
};
|
|
295
296
|
|
|
296
|
-
var Appendix$
|
|
297
|
+
var Appendix$2 = function Appendix(_ref3) {
|
|
297
298
|
var clearable = _ref3.clearable,
|
|
298
299
|
loading = _ref3.loading,
|
|
299
300
|
loadingText = _ref3.loadingText,
|
|
@@ -310,7 +311,7 @@ var Appendix$1 = function Appendix(_ref3) {
|
|
|
310
311
|
return clearable ? React.createElement(React.Fragment, null, React.createElement(ClearButton$1, null), " ", React.createElement(DropdownToggleButton$1, null)) : React.createElement(DropdownToggleButton$1, null);
|
|
311
312
|
};
|
|
312
313
|
|
|
313
|
-
var _excluded$
|
|
314
|
+
var _excluded$6 = ["disabled", "placeholder", "selectOnTab", "openOnFocus", "listStyle", "items", "label", "disableLabelAnimation", "loading", "loadingText", "className", "clearable"];
|
|
314
315
|
var RegularDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
315
316
|
var disabled = _ref.disabled,
|
|
316
317
|
_ref$placeholder = _ref.placeholder,
|
|
@@ -327,7 +328,7 @@ var RegularDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
327
328
|
loadingText = _ref.loadingText,
|
|
328
329
|
className = _ref.className,
|
|
329
330
|
clearable = _ref.clearable,
|
|
330
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
331
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
331
332
|
|
|
332
333
|
var _useDownshift = useDownshift(),
|
|
333
334
|
getToggleButtonProps = _useDownshift.getToggleButtonProps,
|
|
@@ -392,7 +393,7 @@ var RegularDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
392
393
|
}), selectedItem ? selectedItem.label : placeholder));
|
|
393
394
|
});
|
|
394
395
|
|
|
395
|
-
var _excluded$
|
|
396
|
+
var _excluded$5 = ["disabled", "className", "items", "loading", "loadingText", "readOnly", "prepend", "selectOnTab", "openOnFocus", "listStyle", "clearable", "itemFilter", "label", "disableLabelAnimation", "placeholder"];
|
|
396
397
|
|
|
397
398
|
function LowerCaseFilterTest(item, input) {
|
|
398
399
|
if (!input) {
|
|
@@ -427,7 +428,7 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
427
428
|
label = _ref.label,
|
|
428
429
|
disableLabelAnimation = _ref.disableLabelAnimation,
|
|
429
430
|
placeholder = _ref.placeholder,
|
|
430
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
431
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
431
432
|
|
|
432
433
|
var _useDownshift = useDownshift(),
|
|
433
434
|
getInputProps = _useDownshift.getInputProps,
|
|
@@ -1373,7 +1374,7 @@ debounceTimeout) {
|
|
|
1373
1374
|
};
|
|
1374
1375
|
};
|
|
1375
1376
|
|
|
1376
|
-
var _excluded$
|
|
1377
|
+
var _excluded$4 = ["highlightFirstItemOnOpen", "debounceTimeout", "disabled", "feedback", "items", "label", "loadingText", "onChange", "placeholder", "prepend", "readOnly", "searchable", "selectOnTab", "openOnFocus", "variant", "value", "clearable", "className", "style", "listStyle", "itemFilter", "disableLabelAnimation"];
|
|
1377
1378
|
var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1378
1379
|
var highlightFirstItemOnOpen = _ref.highlightFirstItemOnOpen,
|
|
1379
1380
|
debounceTimeout = _ref.debounceTimeout,
|
|
@@ -1401,7 +1402,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1401
1402
|
listStyle = _ref.listStyle,
|
|
1402
1403
|
itemFilter = _ref.itemFilter,
|
|
1403
1404
|
disableLabelAnimation = _ref.disableLabelAnimation,
|
|
1404
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
1405
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
1405
1406
|
|
|
1406
1407
|
var _useResolvedItems = useResolvedItems(items, debounceTimeout),
|
|
1407
1408
|
normalizedItems = _useResolvedItems.items,
|
|
@@ -1450,7 +1451,7 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1450
1451
|
}, searchAbleProps))));
|
|
1451
1452
|
});
|
|
1452
1453
|
|
|
1453
|
-
var _excluded$
|
|
1454
|
+
var _excluded$3 = ["className", "disabled", "readOnly", "items", "loadingText", "prepend", "style", "label", "variant", "feedback", "disableLabelAnimation"];
|
|
1454
1455
|
var NativeDropdown = function NativeDropdown(_ref) {
|
|
1455
1456
|
var className = _ref.className,
|
|
1456
1457
|
_ref$disabled = _ref.disabled,
|
|
@@ -1465,7 +1466,7 @@ var NativeDropdown = function NativeDropdown(_ref) {
|
|
|
1465
1466
|
variant = _ref.variant,
|
|
1466
1467
|
feedback = _ref.feedback,
|
|
1467
1468
|
disableLabelAnimation = _ref.disableLabelAnimation,
|
|
1468
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
1469
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
1469
1470
|
|
|
1470
1471
|
var _useResolvedItems = useResolvedItems(items),
|
|
1471
1472
|
normalizedItems = _useResolvedItems.items,
|
|
@@ -1507,7 +1508,7 @@ var NativeDropdown = function NativeDropdown(_ref) {
|
|
|
1507
1508
|
})));
|
|
1508
1509
|
};
|
|
1509
1510
|
|
|
1510
|
-
var _excluded = ["items", "itemsSelectedLabel", "label", "feedback", "variant", "disabled", "readOnly", "onChange", "className", "clearable", "loading", "loadingText", "openOnFocus", "style", "listStyle", "initialSelectedItems", "debounceTimeout"];
|
|
1511
|
+
var _excluded$2 = ["items", "itemsSelectedLabel", "label", "feedback", "variant", "disabled", "readOnly", "onChange", "className", "clearable", "loading", "loadingText", "openOnFocus", "style", "listStyle", "initialSelectedItems", "debounceTimeout"];
|
|
1511
1512
|
var MultiSelectContext = /*#__PURE__*/React.createContext(null);
|
|
1512
1513
|
|
|
1513
1514
|
var useMultiSelectContext = function useMultiSelectContext() {
|
|
@@ -1569,7 +1570,7 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1569
1570
|
_ref$initialSelectedI = _ref.initialSelectedItems,
|
|
1570
1571
|
initialSelectedItems = _ref$initialSelectedI === void 0 ? [] : _ref$initialSelectedI,
|
|
1571
1572
|
debounceTimeout = _ref.debounceTimeout,
|
|
1572
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1573
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
1573
1574
|
|
|
1574
1575
|
var _useResolvedItems = useResolvedItems(input, debounceTimeout),
|
|
1575
1576
|
items = _useResolvedItems.items;
|
|
@@ -1645,7 +1646,7 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
1645
1646
|
isFilled: selectedItems.length > 0 || isOpen,
|
|
1646
1647
|
disabled: disabled,
|
|
1647
1648
|
readOnly: readOnly,
|
|
1648
|
-
append: React.createElement(Appendix, {
|
|
1649
|
+
append: React.createElement(Appendix$1, {
|
|
1649
1650
|
hasSelected: clearable && selectedItems.length > 0,
|
|
1650
1651
|
loading: loading,
|
|
1651
1652
|
loadingText: loadingText,
|
|
@@ -1718,7 +1719,7 @@ var ClearButton = function ClearButton(_ref3) {
|
|
|
1718
1719
|
}));
|
|
1719
1720
|
};
|
|
1720
1721
|
|
|
1721
|
-
var Appendix = function Appendix(_ref4) {
|
|
1722
|
+
var Appendix$1 = function Appendix(_ref4) {
|
|
1722
1723
|
var loading = _ref4.loading,
|
|
1723
1724
|
loadingText = _ref4.loadingText,
|
|
1724
1725
|
readOnly = _ref4.readOnly,
|
|
@@ -1775,7 +1776,231 @@ function SelectedItemsLabel(items) {
|
|
|
1775
1776
|
}).toString() : items.length + " elementer valgt";
|
|
1776
1777
|
}
|
|
1777
1778
|
|
|
1779
|
+
var _excluded$1 = ["selectedItem", "isOpen", "getMenuProps", "getItemProps", "filteredItems", "highlightedIndex", "listStyle"];
|
|
1780
|
+
var DropdownList = function DropdownList(_ref) {
|
|
1781
|
+
var selectedItem = _ref.selectedItem,
|
|
1782
|
+
isOpen = _ref.isOpen,
|
|
1783
|
+
getMenuProps = _ref.getMenuProps,
|
|
1784
|
+
getItemProps = _ref.getItemProps,
|
|
1785
|
+
filteredItems = _ref.filteredItems,
|
|
1786
|
+
highlightedIndex = _ref.highlightedIndex,
|
|
1787
|
+
listStyle = _ref.listStyle,
|
|
1788
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
1789
|
+
|
|
1790
|
+
return React.createElement("ul", _extends({
|
|
1791
|
+
className: classNames('eds-searchable-dropdown__list', {
|
|
1792
|
+
'eds-searchable-dropdown__list--open': isOpen
|
|
1793
|
+
})
|
|
1794
|
+
}, getMenuProps(), {
|
|
1795
|
+
style: _extends({}, rest.style, listStyle)
|
|
1796
|
+
}), isOpen ? filteredItems.map(function (item, index) {
|
|
1797
|
+
return (// eslint-disable-next-line react/jsx-key
|
|
1798
|
+
React.createElement("li", _extends({
|
|
1799
|
+
className: classNames('eds-searchable-dropdown__list__item', {
|
|
1800
|
+
'eds-searchable-dropdown__list__item--highlighted': highlightedIndex === index,
|
|
1801
|
+
'eds-searchable-dropdown__list__item--selected': (selectedItem == null ? void 0 : selectedItem.value) === item.value
|
|
1802
|
+
})
|
|
1803
|
+
}, getItemProps({
|
|
1804
|
+
key: "" + index + item.value,
|
|
1805
|
+
item: item,
|
|
1806
|
+
index: index
|
|
1807
|
+
})), React.createElement("span", null, item.label), item.icons && React.createElement("span", null, item.icons.map(function (Icon, index) {
|
|
1808
|
+
return React.createElement(Icon, {
|
|
1809
|
+
key: index,
|
|
1810
|
+
inline: true,
|
|
1811
|
+
className: "eds-searchable-dropdown__list__item-icon"
|
|
1812
|
+
});
|
|
1813
|
+
})), (selectedItem == null ? void 0 : selectedItem.value) === item.value && React.createElement(CheckIcon, null))
|
|
1814
|
+
);
|
|
1815
|
+
}) : null);
|
|
1816
|
+
};
|
|
1817
|
+
|
|
1818
|
+
var _excluded = ["items", "selectedItem", "onChange", "label", "placeholder", "clearable", "openOnFocus", "readonly", "feedback", "variant", "className", "listStyle"];
|
|
1819
|
+
|
|
1820
|
+
function lowerCaseFilterTest(item, input) {
|
|
1821
|
+
if (!input) {
|
|
1822
|
+
return true;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
var sanitizeEscapeCharacters = input.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
1826
|
+
var inputRegex = new RegExp(sanitizeEscapeCharacters, 'i');
|
|
1827
|
+
return inputRegex.test(item.label);
|
|
1828
|
+
} // TODO Husk å @deprecate searchable-prop-en til Dropdown når denne komponenten skal ha official release
|
|
1829
|
+
// TODO Husk å generelt legge inn støtte for typeof value === string
|
|
1830
|
+
|
|
1831
|
+
|
|
1832
|
+
var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
1833
|
+
var _selectedItem$label;
|
|
1834
|
+
|
|
1835
|
+
var items = _ref.items,
|
|
1836
|
+
value = _ref.selectedItem,
|
|
1837
|
+
onChange = _ref.onChange,
|
|
1838
|
+
label = _ref.label,
|
|
1839
|
+
placeholder = _ref.placeholder,
|
|
1840
|
+
_ref$clearable = _ref.clearable,
|
|
1841
|
+
clearable = _ref$clearable === void 0 ? false : _ref$clearable,
|
|
1842
|
+
_ref$openOnFocus = _ref.openOnFocus,
|
|
1843
|
+
openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
|
|
1844
|
+
_ref$readonly = _ref.readonly,
|
|
1845
|
+
readonly = _ref$readonly === void 0 ? false : _ref$readonly,
|
|
1846
|
+
feedback = _ref.feedback,
|
|
1847
|
+
_ref$variant = _ref.variant,
|
|
1848
|
+
variant = _ref$variant === void 0 ? 'info' : _ref$variant,
|
|
1849
|
+
className = _ref.className,
|
|
1850
|
+
listStyle = _ref.listStyle,
|
|
1851
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1852
|
+
|
|
1853
|
+
var _React$useState = React.useState(items),
|
|
1854
|
+
filteredItems = _React$useState[0],
|
|
1855
|
+
setFilteredItems = _React$useState[1];
|
|
1856
|
+
|
|
1857
|
+
var _useState = useState(false),
|
|
1858
|
+
hideSelectedItem = _useState[0],
|
|
1859
|
+
setHideSelectedItem = _useState[1];
|
|
1860
|
+
|
|
1861
|
+
var inputRef = useRef(null);
|
|
1862
|
+
var stateReducer = React.useCallback(function (_, actionAndChanges) {
|
|
1863
|
+
var type = actionAndChanges.type,
|
|
1864
|
+
changes = actionAndChanges.changes;
|
|
1865
|
+
|
|
1866
|
+
switch (type) {
|
|
1867
|
+
case useCombobox.stateChangeTypes.ItemClick:
|
|
1868
|
+
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1869
|
+
case useCombobox.stateChangeTypes.InputBlur:
|
|
1870
|
+
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
1871
|
+
return _extends({}, changes, changes.selectedItem && {
|
|
1872
|
+
inputValue: ''
|
|
1873
|
+
});
|
|
1874
|
+
|
|
1875
|
+
default:
|
|
1876
|
+
return changes;
|
|
1877
|
+
}
|
|
1878
|
+
}, []);
|
|
1879
|
+
|
|
1880
|
+
var _useCombobox = useCombobox(_extends({
|
|
1881
|
+
onInputValueChange: function onInputValueChange(_ref2) {
|
|
1882
|
+
var inputValue = _ref2.inputValue;
|
|
1883
|
+
setFilteredItems(items.filter(function (item) {
|
|
1884
|
+
return lowerCaseFilterTest(item, inputValue);
|
|
1885
|
+
}));
|
|
1886
|
+
},
|
|
1887
|
+
items: filteredItems,
|
|
1888
|
+
itemToString: function itemToString(item) {
|
|
1889
|
+
if (item) return item.value;
|
|
1890
|
+
return '';
|
|
1891
|
+
},
|
|
1892
|
+
stateReducer: stateReducer,
|
|
1893
|
+
selectedItem: value,
|
|
1894
|
+
onSelectedItemChange: function onSelectedItemChange(_ref3) {
|
|
1895
|
+
var newSelectedItem = _ref3.selectedItem;
|
|
1896
|
+
return onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1897
|
+
}
|
|
1898
|
+
}, rest)),
|
|
1899
|
+
isOpen = _useCombobox.isOpen,
|
|
1900
|
+
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1901
|
+
getLabelProps = _useCombobox.getLabelProps,
|
|
1902
|
+
getMenuProps = _useCombobox.getMenuProps,
|
|
1903
|
+
getInputProps = _useCombobox.getInputProps,
|
|
1904
|
+
getComboboxProps = _useCombobox.getComboboxProps,
|
|
1905
|
+
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1906
|
+
getItemProps = _useCombobox.getItemProps,
|
|
1907
|
+
selectedItem = _useCombobox.selectedItem,
|
|
1908
|
+
openMenu = _useCombobox.openMenu,
|
|
1909
|
+
inputValue = _useCombobox.inputValue;
|
|
1910
|
+
|
|
1911
|
+
return React.createElement("div", {
|
|
1912
|
+
className: "eds-searchable-dropdown__wrapper"
|
|
1913
|
+
}, React.createElement(BaseFormControl, _extends({
|
|
1914
|
+
append: React.createElement(Appendix, {
|
|
1915
|
+
selectedItem: selectedItem,
|
|
1916
|
+
isOpen: isOpen,
|
|
1917
|
+
clearable: clearable,
|
|
1918
|
+
loading: false,
|
|
1919
|
+
loadingText: '',
|
|
1920
|
+
readOnly: readonly,
|
|
1921
|
+
onChange: onChange,
|
|
1922
|
+
getToggleButtonProps: getToggleButtonProps
|
|
1923
|
+
}),
|
|
1924
|
+
className: classNames('eds-searchable-dropdown', className),
|
|
1925
|
+
label: label,
|
|
1926
|
+
isFilled: selectedItem ? true : false,
|
|
1927
|
+
feedback: feedback,
|
|
1928
|
+
variant: variant,
|
|
1929
|
+
readOnly: readonly,
|
|
1930
|
+
labelProps: getLabelProps()
|
|
1931
|
+
}, getComboboxProps(), rest), !hideSelectedItem && selectedItem && !inputValue && React.createElement("span", {
|
|
1932
|
+
className: "eds-searchable-dropdown__selected-item__wrapper"
|
|
1933
|
+
}, React.createElement("span", {
|
|
1934
|
+
className: "eds-searchable-dropdown__selected-item",
|
|
1935
|
+
onClick: function onClick() {
|
|
1936
|
+
var _inputRef$current;
|
|
1937
|
+
|
|
1938
|
+
return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
1939
|
+
}
|
|
1940
|
+
}, selectedItem.label)), React.createElement("input", _extends({
|
|
1941
|
+
placeholder: (_selectedItem$label = selectedItem == null ? void 0 : selectedItem.label) != null ? _selectedItem$label : placeholder,
|
|
1942
|
+
className: "eds-searchable-dropdown__input eds-form-control"
|
|
1943
|
+
}, getInputProps({
|
|
1944
|
+
onFocus: function onFocus() {
|
|
1945
|
+
if (!isOpen && openOnFocus) openMenu();
|
|
1946
|
+
setHideSelectedItem(true);
|
|
1947
|
+
},
|
|
1948
|
+
onBlur: function onBlur() {
|
|
1949
|
+
setHideSelectedItem(false);
|
|
1950
|
+
},
|
|
1951
|
+
ref: inputRef
|
|
1952
|
+
})))), React.createElement(DropdownList, {
|
|
1953
|
+
selectedItem: selectedItem,
|
|
1954
|
+
isOpen: isOpen,
|
|
1955
|
+
filteredItems: filteredItems,
|
|
1956
|
+
highlightedIndex: highlightedIndex,
|
|
1957
|
+
listStyle: listStyle,
|
|
1958
|
+
getMenuProps: getMenuProps,
|
|
1959
|
+
getItemProps: getItemProps
|
|
1960
|
+
}));
|
|
1961
|
+
};
|
|
1962
|
+
|
|
1963
|
+
var Appendix = function Appendix(_ref4) {
|
|
1964
|
+
var clearable = _ref4.clearable,
|
|
1965
|
+
readOnly = _ref4.readOnly,
|
|
1966
|
+
getToggleButtonProps = _ref4.getToggleButtonProps,
|
|
1967
|
+
selectedItem = _ref4.selectedItem,
|
|
1968
|
+
isOpen = _ref4.isOpen,
|
|
1969
|
+
onChange = _ref4.onChange;
|
|
1970
|
+
|
|
1971
|
+
// TODO implement loading / async
|
|
1972
|
+
// if (loading) {
|
|
1973
|
+
// return <DropdownLoadingDots>{loadingText}</DropdownLoadingDots>;
|
|
1974
|
+
// }
|
|
1975
|
+
if (readOnly) {
|
|
1976
|
+
return null;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
return React.createElement("div", {
|
|
1980
|
+
style: {
|
|
1981
|
+
display: 'flex',
|
|
1982
|
+
alignItems: 'center'
|
|
1983
|
+
}
|
|
1984
|
+
}, clearable && selectedItem && React.createElement(React.Fragment, null, React.createElement(IconButton, {
|
|
1985
|
+
className: "eds-searchable-dropdown-appendix__clear-button",
|
|
1986
|
+
type: "button",
|
|
1987
|
+
tabIndex: -1,
|
|
1988
|
+
onClick: function onClick() {
|
|
1989
|
+
return onChange(null);
|
|
1990
|
+
}
|
|
1991
|
+
}, React.createElement(CloseSmallIcon, null)), React.createElement("div", {
|
|
1992
|
+
className: "eds-searchable-dropdown-appendix__divider"
|
|
1993
|
+
})), React.createElement(IconButton, _extends({}, getToggleButtonProps({
|
|
1994
|
+
className: classNames('eds-searchable-dropdown-appendix__toggle-button', {
|
|
1995
|
+
'eds-searchable-dropdown-appendix__toggle-button--open': isOpen
|
|
1996
|
+
})
|
|
1997
|
+
}), {
|
|
1998
|
+
tabIndex: -1,
|
|
1999
|
+
type: "button"
|
|
2000
|
+
}), React.createElement(DownArrowIcon, null)));
|
|
2001
|
+
};
|
|
2002
|
+
|
|
1778
2003
|
warnAboutMissingStyles('dropdown', 'form', 'a11y', 'chip');
|
|
1779
2004
|
|
|
1780
|
-
export { Dropdown, MultiSelect, NativeDropdown };
|
|
2005
|
+
export { Dropdown, MultiSelect, NativeDropdown, SearchableDropdownBeta };
|
|
1781
2006
|
//# sourceMappingURL=dropdown.esm.js.map
|