@entur/dropdown 4.0.0-beta.0 → 4.0.0-beta.2
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 +13 -0
- package/dist/beta/SearchableDropdown.d.ts +26 -3
- package/dist/dropdown.cjs.development.js +43 -35
- 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 +44 -36
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +142 -84
- package/package.json +2 -2
package/dist/dropdown.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mergeRefs, debounce, useRandomId, warnAboutMissingStyles } from '@entur/utils';
|
|
2
|
-
import React, { useState, useRef
|
|
2
|
+
import React, { useState, useRef } from 'react';
|
|
3
3
|
import Downshift, { useSelect, useCombobox } from 'downshift';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { BaseFormControl, VariantProvider, FeedbackText } from '@entur/form';
|
|
@@ -1775,7 +1775,7 @@ function SelectedItemsLabel(items) {
|
|
|
1775
1775
|
}).toString() : items.length + " elementer valgt";
|
|
1776
1776
|
}
|
|
1777
1777
|
|
|
1778
|
-
var _excluded = ["items", "
|
|
1778
|
+
var _excluded = ["items", "selectedItem", "onChange", "label", "placeholder", "clearable", "openOnFocus", "readonly", "feedback", "variant", "className", "listStyle"];
|
|
1779
1779
|
|
|
1780
1780
|
function lowerCaseFilterTest(item, input) {
|
|
1781
1781
|
if (!input) {
|
|
@@ -1785,22 +1785,28 @@ function lowerCaseFilterTest(item, input) {
|
|
|
1785
1785
|
var sanitizeEscapeCharacters = input.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
1786
1786
|
var inputRegex = new RegExp(sanitizeEscapeCharacters, 'i');
|
|
1787
1787
|
return inputRegex.test(item.label);
|
|
1788
|
-
}
|
|
1788
|
+
} // TODO Husk å @deprecate searchable-prop-en til Dropdown når denne komponenten skal ha official release
|
|
1789
|
+
|
|
1789
1790
|
|
|
1790
1791
|
var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
1791
1792
|
var _selectedItem$label;
|
|
1792
1793
|
|
|
1793
1794
|
var items = _ref.items,
|
|
1794
|
-
value = _ref.
|
|
1795
|
+
value = _ref.selectedItem,
|
|
1795
1796
|
onChange = _ref.onChange,
|
|
1796
|
-
|
|
1797
|
-
label = _ref$label === void 0 ? '!MANGLER LABEL!' : _ref$label,
|
|
1797
|
+
label = _ref.label,
|
|
1798
1798
|
placeholder = _ref.placeholder,
|
|
1799
1799
|
_ref$clearable = _ref.clearable,
|
|
1800
1800
|
clearable = _ref$clearable === void 0 ? false : _ref$clearable,
|
|
1801
1801
|
_ref$openOnFocus = _ref.openOnFocus,
|
|
1802
1802
|
openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
|
|
1803
|
+
_ref$readonly = _ref.readonly,
|
|
1804
|
+
readonly = _ref$readonly === void 0 ? false : _ref$readonly,
|
|
1805
|
+
feedback = _ref.feedback,
|
|
1806
|
+
_ref$variant = _ref.variant,
|
|
1807
|
+
variant = _ref$variant === void 0 ? 'info' : _ref$variant,
|
|
1803
1808
|
className = _ref.className,
|
|
1809
|
+
listStyle = _ref.listStyle,
|
|
1804
1810
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1805
1811
|
|
|
1806
1812
|
var _React$useState = React.useState(items),
|
|
@@ -1839,13 +1845,14 @@ var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
|
1839
1845
|
},
|
|
1840
1846
|
items: filteredItems,
|
|
1841
1847
|
itemToString: function itemToString(item) {
|
|
1842
|
-
|
|
1848
|
+
if (item) return item.value;
|
|
1849
|
+
return '';
|
|
1843
1850
|
},
|
|
1844
1851
|
stateReducer: stateReducer,
|
|
1845
1852
|
selectedItem: value,
|
|
1846
1853
|
onSelectedItemChange: function onSelectedItemChange(_ref3) {
|
|
1847
1854
|
var newSelectedItem = _ref3.selectedItem;
|
|
1848
|
-
return onChange(newSelectedItem);
|
|
1855
|
+
return onChange(newSelectedItem != null ? newSelectedItem : null);
|
|
1849
1856
|
}
|
|
1850
1857
|
}, rest)),
|
|
1851
1858
|
isOpen = _useCombobox.isOpen,
|
|
@@ -1858,26 +1865,28 @@ var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
|
1858
1865
|
getItemProps = _useCombobox.getItemProps,
|
|
1859
1866
|
selectedItem = _useCombobox.selectedItem,
|
|
1860
1867
|
openMenu = _useCombobox.openMenu,
|
|
1861
|
-
inputValue = _useCombobox.inputValue
|
|
1862
|
-
setInputValue = _useCombobox.setInputValue;
|
|
1868
|
+
inputValue = _useCombobox.inputValue; // TODO Husk å generelt legge inn støtte for typeof value === string
|
|
1863
1869
|
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1870
|
+
|
|
1871
|
+
return React.createElement("div", {
|
|
1872
|
+
className: "eds-searchable-dropdown__wrapper"
|
|
1873
|
+
}, React.createElement(BaseFormControl, _extends({
|
|
1868
1874
|
append: React.createElement(Appendix, {
|
|
1869
1875
|
selectedItem: selectedItem,
|
|
1870
1876
|
isOpen: isOpen,
|
|
1871
1877
|
clearable: clearable,
|
|
1872
1878
|
loading: false,
|
|
1873
1879
|
loadingText: '',
|
|
1874
|
-
readOnly:
|
|
1880
|
+
readOnly: readonly,
|
|
1875
1881
|
onChange: onChange,
|
|
1876
1882
|
getToggleButtonProps: getToggleButtonProps
|
|
1877
1883
|
}),
|
|
1878
1884
|
className: classNames('eds-searchable-dropdown', className),
|
|
1879
1885
|
label: label,
|
|
1880
1886
|
isFilled: selectedItem ? true : false,
|
|
1887
|
+
feedback: feedback,
|
|
1888
|
+
variant: variant,
|
|
1889
|
+
readOnly: readonly,
|
|
1881
1890
|
labelProps: getLabelProps()
|
|
1882
1891
|
}, getComboboxProps(), rest), !hideSelectedItem && selectedItem && !inputValue && React.createElement("span", {
|
|
1883
1892
|
className: "eds-searchable-dropdown__selected-item__wrapper"
|
|
@@ -1895,22 +1904,23 @@ var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
|
1895
1904
|
onFocus: function onFocus() {
|
|
1896
1905
|
if (!isOpen && openOnFocus) openMenu();
|
|
1897
1906
|
setHideSelectedItem(true);
|
|
1898
|
-
}
|
|
1899
|
-
}), {
|
|
1907
|
+
},
|
|
1900
1908
|
onBlur: function onBlur() {
|
|
1901
1909
|
setHideSelectedItem(false);
|
|
1902
1910
|
},
|
|
1903
1911
|
ref: inputRef
|
|
1904
|
-
}))), React.createElement("ul", _extends({
|
|
1905
|
-
className: classNames('eds-
|
|
1906
|
-
'eds-
|
|
1912
|
+
})))), React.createElement("ul", _extends({
|
|
1913
|
+
className: classNames('eds-searchable-dropdown__list', {
|
|
1914
|
+
'eds-searchable-dropdown__list--open': isOpen
|
|
1907
1915
|
})
|
|
1908
|
-
}, getMenuProps(),
|
|
1916
|
+
}, getMenuProps(), {
|
|
1917
|
+
style: _extends({}, rest.style, listStyle)
|
|
1918
|
+
}), isOpen ? filteredItems.map(function (item, index) {
|
|
1909
1919
|
return (// eslint-disable-next-line react/jsx-key
|
|
1910
1920
|
React.createElement("li", _extends({
|
|
1911
|
-
className: classNames('eds-
|
|
1912
|
-
'eds-
|
|
1913
|
-
'eds-
|
|
1921
|
+
className: classNames('eds-searchable-dropdown__list__item', {
|
|
1922
|
+
'eds-searchable-dropdown__list__item--highlighted': highlightedIndex === index,
|
|
1923
|
+
'eds-searchable-dropdown__list__item--selected': (selectedItem == null ? void 0 : selectedItem.value) === item.value
|
|
1914
1924
|
})
|
|
1915
1925
|
}, getItemProps({
|
|
1916
1926
|
key: "" + index + item.value,
|
|
@@ -1920,27 +1930,25 @@ var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
|
1920
1930
|
return React.createElement(Icon, {
|
|
1921
1931
|
key: index,
|
|
1922
1932
|
inline: true,
|
|
1923
|
-
className: "eds-
|
|
1933
|
+
className: "eds-searchable-dropdown__list__item-icon"
|
|
1924
1934
|
});
|
|
1925
|
-
})), selectedItem === item && React.createElement(CheckIcon, null))
|
|
1935
|
+
})), (selectedItem == null ? void 0 : selectedItem.value) === item.value && React.createElement(CheckIcon, null))
|
|
1926
1936
|
);
|
|
1927
1937
|
}) : null));
|
|
1928
1938
|
};
|
|
1929
1939
|
|
|
1930
1940
|
var Appendix = function Appendix(_ref4) {
|
|
1931
1941
|
var clearable = _ref4.clearable,
|
|
1932
|
-
loading = _ref4.loading,
|
|
1933
|
-
loadingText = _ref4.loadingText,
|
|
1934
1942
|
readOnly = _ref4.readOnly,
|
|
1935
1943
|
getToggleButtonProps = _ref4.getToggleButtonProps,
|
|
1936
1944
|
selectedItem = _ref4.selectedItem,
|
|
1937
1945
|
isOpen = _ref4.isOpen,
|
|
1938
1946
|
onChange = _ref4.onChange;
|
|
1939
1947
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
}
|
|
1943
|
-
|
|
1948
|
+
// TODO implement loading / async
|
|
1949
|
+
// if (loading) {
|
|
1950
|
+
// return <DropdownLoadingDots>{loadingText}</DropdownLoadingDots>;
|
|
1951
|
+
// }
|
|
1944
1952
|
if (readOnly) {
|
|
1945
1953
|
return null;
|
|
1946
1954
|
}
|
|
@@ -1951,17 +1959,17 @@ var Appendix = function Appendix(_ref4) {
|
|
|
1951
1959
|
alignItems: 'center'
|
|
1952
1960
|
}
|
|
1953
1961
|
}, clearable && selectedItem && React.createElement(React.Fragment, null, React.createElement("button", {
|
|
1954
|
-
className: "eds-
|
|
1962
|
+
className: "eds-searchable-dropdown-appendix__clear-button",
|
|
1955
1963
|
type: "button",
|
|
1956
1964
|
tabIndex: -1,
|
|
1957
1965
|
onClick: function onClick() {
|
|
1958
1966
|
return onChange(null);
|
|
1959
1967
|
}
|
|
1960
1968
|
}, React.createElement(CloseSmallIcon, null)), React.createElement("div", {
|
|
1961
|
-
className: "eds-
|
|
1969
|
+
className: "eds-searchable-dropdown-appendix__divider"
|
|
1962
1970
|
})), React.createElement("button", _extends({}, getToggleButtonProps({
|
|
1963
|
-
className: classNames('eds-
|
|
1964
|
-
'eds-
|
|
1971
|
+
className: classNames('eds-searchable-dropdown-appendix__toggle-button', {
|
|
1972
|
+
'eds-searchable-dropdown-appendix__toggle-button--open': isOpen
|
|
1965
1973
|
})
|
|
1966
1974
|
}), {
|
|
1967
1975
|
tabIndex: "-1",
|