@megafon/ui-core 2.4.0 → 3.0.0-beta.10
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 +154 -7
- package/dist/es/colors/ColorItem/ColorItem.css +1 -8
- package/dist/es/colors/ColorItem/ColorItem.js +1 -1
- package/dist/es/colors/Colors.css +3 -11
- package/dist/es/colors/Colors.d.ts +2 -2
- package/dist/es/colors/Colors.js +64 -4
- package/dist/es/colors/colorsData.js +78 -71
- package/dist/es/components/Accordion/Accordion.css +7 -27
- package/dist/es/components/Accordion/Accordion.d.ts +12 -7
- package/dist/es/components/Accordion/Accordion.js +25 -20
- package/dist/es/components/Banner/Banner.css +2 -37
- package/dist/es/components/Banner/Banner.d.ts +10 -2
- package/dist/es/components/Banner/Banner.js +35 -26
- package/dist/es/components/Banner/BannerDot.css +4 -11
- package/dist/es/components/Banner/BannerDot.d.ts +3 -0
- package/dist/es/components/Banner/BannerDot.js +8 -3
- package/dist/es/components/Button/Button.css +83 -74
- package/dist/es/components/Button/Button.d.ts +8 -2
- package/dist/es/components/Button/Button.js +16 -8
- package/dist/es/components/Calendar/Calendar.css +0 -7
- package/dist/es/components/Calendar/Calendar.js +2 -3
- package/dist/es/components/Calendar/components/Day/Day.css +10 -17
- package/dist/es/components/Calendar/components/Day/Day.js +1 -1
- package/dist/es/components/Calendar/components/Month/Month.css +3 -10
- package/dist/es/components/Calendar/components/Month/Month.js +21 -5
- package/dist/es/components/Carousel/Carousel.css +4 -11
- package/dist/es/components/Carousel/Carousel.d.ts +9 -2
- package/dist/es/components/Carousel/Carousel.js +28 -25
- package/dist/es/components/Checkbox/Checkbox.css +18 -25
- package/dist/es/components/Checkbox/Checkbox.d.ts +11 -27
- package/dist/es/components/Checkbox/Checkbox.js +77 -90
- package/dist/es/components/Collapse/Collapse.d.ts +15 -3
- package/dist/es/components/Collapse/Collapse.js +11 -4
- package/dist/es/components/ContentArea/ContentArea.css +18 -28
- package/dist/es/components/ContentArea/ContentArea.d.ts +2 -7
- package/dist/es/components/ContentArea/ContentArea.js +5 -39
- package/dist/es/components/Counter/Counter.css +14 -11
- package/dist/es/components/Counter/Counter.js +3 -3
- package/dist/es/components/Grid/GridColumn.css +0 -7
- package/dist/es/components/Header/Header.css +8 -12
- package/dist/es/components/Header/Header.d.ts +7 -21
- package/dist/es/components/Header/Header.js +31 -67
- package/dist/es/components/InputLabel/InputLabel.css +0 -7
- package/dist/es/components/InputLabel/InputLabel.d.ts +3 -0
- package/dist/es/components/InputLabel/InputLabel.js +9 -4
- package/dist/es/components/Link/Link.d.ts +3 -3
- package/dist/es/components/Link/Link.js +32 -21
- package/dist/es/components/List/List.css +9 -13
- package/dist/es/components/List/List.d.ts +1 -1
- package/dist/es/components/List/List.js +2 -2
- package/dist/es/components/List/ListItem.css +0 -7
- package/dist/es/components/Logo/Logo.css +0 -7
- package/dist/es/components/Logo/Logo.js +4 -8
- package/dist/es/components/NavArrow/NavArrow.css +5 -12
- package/dist/es/components/Notification/Notification.css +41 -24
- package/dist/es/components/Notification/Notification.d.ts +8 -0
- package/dist/es/components/Notification/Notification.js +21 -4
- package/dist/es/components/Pagination/Pagination.css +0 -7
- package/dist/es/components/Pagination/Pagination.d.ts +9 -2
- package/dist/es/components/Pagination/Pagination.js +20 -3
- package/dist/es/components/Pagination/components/PaginationButton/PaginationButton.css +9 -9
- package/dist/es/components/Pagination/components/PaginationButton/PaginationButton.d.ts +6 -3
- package/dist/es/components/Pagination/components/PaginationButton/PaginationButton.js +12 -7
- package/dist/es/components/Pagination/components/PaginationButtons/PaginationButtons.d.ts +5 -2
- package/dist/es/components/Pagination/components/PaginationButtons/PaginationButtons.js +10 -2
- package/dist/es/components/Pagination/components/PaginationNavigation/PaginationNavigation.d.ts +5 -2
- package/dist/es/components/Pagination/components/PaginationNavigation/PaginationNavigation.js +6 -1
- package/dist/es/components/Pagination/helpers.d.ts +1 -1
- package/dist/es/components/Paragraph/Paragraph.css +10 -31
- package/dist/es/components/Paragraph/Paragraph.d.ts +9 -13
- package/dist/es/components/Paragraph/Paragraph.js +14 -40
- package/dist/es/components/Preloader/Preloader.css +5 -12
- package/dist/es/components/Preloader/Preloader.d.ts +4 -0
- package/dist/es/components/Preloader/Preloader.js +10 -5
- package/dist/es/components/RadioButton/RadioButton.css +7 -14
- package/dist/es/components/RadioButton/RadioButton.d.ts +8 -28
- package/dist/es/components/RadioButton/RadioButton.js +50 -85
- package/dist/es/components/Search/Search.css +20 -25
- package/dist/es/components/Search/Search.js +3 -4
- package/dist/es/components/Select/Select.css +34 -37
- package/dist/es/components/Select/Select.d.ts +43 -50
- package/dist/es/components/Select/Select.js +382 -461
- package/dist/es/components/Select/reducer/selectReducer.d.ts +34 -0
- package/dist/es/components/Select/reducer/selectReducer.js +123 -0
- package/dist/es/components/Switcher/Switcher.css +18 -28
- package/dist/es/components/Switcher/Switcher.js +1 -1
- package/dist/es/components/Tabs/Tab.d.ts +5 -2
- package/dist/es/components/Tabs/Tab.js +4 -2
- package/dist/es/components/Tabs/Tabs.css +30 -37
- package/dist/es/components/Tabs/Tabs.d.ts +8 -0
- package/dist/es/components/Tabs/Tabs.js +38 -31
- package/dist/es/components/TextField/TextField.css +27 -33
- package/dist/es/components/TextField/TextField.d.ts +9 -3
- package/dist/es/components/TextField/TextField.js +32 -24
- package/dist/es/components/TextLink/TextLink.css +10 -14
- package/dist/es/components/TextLink/TextLink.d.ts +1 -1
- package/dist/es/components/TextLink/TextLink.js +7 -2
- package/dist/es/components/Tile/Tile.css +2 -8
- package/dist/es/components/Tile/Tile.d.ts +5 -2
- package/dist/es/components/Tile/Tile.js +2 -2
- package/dist/es/components/Tooltip/Tooltip.css +1 -8
- package/dist/es/components/Tooltip/Tooltip.d.ts +8 -2
- package/dist/es/components/Tooltip/Tooltip.js +28 -27
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/lib/colors/ColorItem/ColorItem.css +1 -8
- package/dist/lib/colors/ColorItem/ColorItem.js +1 -1
- package/dist/lib/colors/Colors.css +3 -11
- package/dist/lib/colors/Colors.d.ts +2 -2
- package/dist/lib/colors/Colors.js +63 -4
- package/dist/lib/colors/colorsData.js +78 -71
- package/dist/lib/components/Accordion/Accordion.css +7 -27
- package/dist/lib/components/Accordion/Accordion.d.ts +12 -7
- package/dist/lib/components/Accordion/Accordion.js +24 -19
- package/dist/lib/components/Banner/Banner.css +2 -37
- package/dist/lib/components/Banner/Banner.d.ts +10 -2
- package/dist/lib/components/Banner/Banner.js +35 -25
- package/dist/lib/components/Banner/BannerDot.css +4 -11
- package/dist/lib/components/Banner/BannerDot.d.ts +3 -0
- package/dist/lib/components/Banner/BannerDot.js +10 -2
- package/dist/lib/components/Button/Button.css +83 -74
- package/dist/lib/components/Button/Button.d.ts +8 -2
- package/dist/lib/components/Button/Button.js +16 -8
- package/dist/lib/components/Calendar/Calendar.css +0 -7
- package/dist/lib/components/Calendar/Calendar.js +3 -3
- package/dist/lib/components/Calendar/components/Day/Day.css +10 -17
- package/dist/lib/components/Calendar/components/Day/Day.js +1 -1
- package/dist/lib/components/Calendar/components/Month/Month.css +3 -10
- package/dist/lib/components/Calendar/components/Month/Month.js +20 -4
- package/dist/lib/components/Carousel/Carousel.css +4 -11
- package/dist/lib/components/Carousel/Carousel.d.ts +9 -2
- package/dist/lib/components/Carousel/Carousel.js +26 -23
- package/dist/lib/components/Checkbox/Checkbox.css +18 -25
- package/dist/lib/components/Checkbox/Checkbox.d.ts +11 -27
- package/dist/lib/components/Checkbox/Checkbox.js +82 -125
- package/dist/lib/components/Collapse/Collapse.d.ts +15 -3
- package/dist/lib/components/Collapse/Collapse.js +13 -4
- package/dist/lib/components/ContentArea/ContentArea.css +18 -28
- package/dist/lib/components/ContentArea/ContentArea.d.ts +2 -7
- package/dist/lib/components/ContentArea/ContentArea.js +5 -42
- package/dist/lib/components/Counter/Counter.css +14 -11
- package/dist/lib/components/Counter/Counter.js +3 -3
- package/dist/lib/components/Grid/GridColumn.css +0 -7
- package/dist/lib/components/Header/Header.css +8 -12
- package/dist/lib/components/Header/Header.d.ts +7 -21
- package/dist/lib/components/Header/Header.js +31 -98
- package/dist/lib/components/InputLabel/InputLabel.css +0 -7
- package/dist/lib/components/InputLabel/InputLabel.d.ts +3 -0
- package/dist/lib/components/InputLabel/InputLabel.js +11 -3
- package/dist/lib/components/Link/Link.d.ts +3 -3
- package/dist/lib/components/Link/Link.js +44 -26
- package/dist/lib/components/List/List.css +9 -13
- package/dist/lib/components/List/List.d.ts +1 -1
- package/dist/lib/components/List/List.js +2 -2
- package/dist/lib/components/List/ListItem.css +0 -7
- package/dist/lib/components/Logo/Logo.css +0 -7
- package/dist/lib/components/Logo/Logo.js +4 -8
- package/dist/lib/components/NavArrow/NavArrow.css +5 -12
- package/dist/lib/components/Notification/Notification.css +41 -24
- package/dist/lib/components/Notification/Notification.d.ts +8 -0
- package/dist/lib/components/Notification/Notification.js +20 -3
- package/dist/lib/components/Pagination/Pagination.css +0 -7
- package/dist/lib/components/Pagination/Pagination.d.ts +9 -2
- package/dist/lib/components/Pagination/Pagination.js +20 -2
- package/dist/lib/components/Pagination/components/PaginationButton/PaginationButton.css +9 -9
- package/dist/lib/components/Pagination/components/PaginationButton/PaginationButton.d.ts +6 -3
- package/dist/lib/components/Pagination/components/PaginationButton/PaginationButton.js +12 -6
- package/dist/lib/components/Pagination/components/PaginationButtons/PaginationButtons.d.ts +5 -2
- package/dist/lib/components/Pagination/components/PaginationButtons/PaginationButtons.js +9 -1
- package/dist/lib/components/Pagination/components/PaginationNavigation/PaginationNavigation.d.ts +5 -2
- package/dist/lib/components/Pagination/components/PaginationNavigation/PaginationNavigation.js +6 -1
- package/dist/lib/components/Pagination/helpers.d.ts +1 -1
- package/dist/lib/components/Paragraph/Paragraph.css +10 -31
- package/dist/lib/components/Paragraph/Paragraph.d.ts +9 -13
- package/dist/lib/components/Paragraph/Paragraph.js +15 -41
- package/dist/lib/components/Preloader/Preloader.css +5 -12
- package/dist/lib/components/Preloader/Preloader.d.ts +4 -0
- package/dist/lib/components/Preloader/Preloader.js +10 -4
- package/dist/lib/components/RadioButton/RadioButton.css +7 -14
- package/dist/lib/components/RadioButton/RadioButton.d.ts +8 -28
- package/dist/lib/components/RadioButton/RadioButton.js +51 -117
- package/dist/lib/components/Search/Search.css +20 -25
- package/dist/lib/components/Search/Search.js +3 -4
- package/dist/lib/components/Select/Select.css +34 -37
- package/dist/lib/components/Select/Select.d.ts +43 -50
- package/dist/lib/components/Select/Select.js +375 -483
- package/dist/lib/components/Select/reducer/selectReducer.d.ts +34 -0
- package/dist/lib/components/Select/reducer/selectReducer.js +136 -0
- package/dist/lib/components/Switcher/Switcher.css +18 -28
- package/dist/lib/components/Switcher/Switcher.js +1 -1
- package/dist/lib/components/Tabs/Tab.d.ts +5 -2
- package/dist/lib/components/Tabs/Tab.js +4 -2
- package/dist/lib/components/Tabs/Tabs.css +30 -37
- package/dist/lib/components/Tabs/Tabs.d.ts +8 -0
- package/dist/lib/components/Tabs/Tabs.js +38 -31
- package/dist/lib/components/TextField/TextField.css +27 -33
- package/dist/lib/components/TextField/TextField.d.ts +9 -3
- package/dist/lib/components/TextField/TextField.js +30 -23
- package/dist/lib/components/TextLink/TextLink.css +10 -14
- package/dist/lib/components/TextLink/TextLink.d.ts +1 -1
- package/dist/lib/components/TextLink/TextLink.js +7 -2
- package/dist/lib/components/Tile/Tile.css +2 -8
- package/dist/lib/components/Tile/Tile.d.ts +5 -2
- package/dist/lib/components/Tile/Tile.js +2 -2
- package/dist/lib/components/Tooltip/Tooltip.css +1 -8
- package/dist/lib/components/Tooltip/Tooltip.d.ts +8 -2
- package/dist/lib/components/Tooltip/Tooltip.js +27 -26
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +8 -0
- package/package.json +5 -4
- package/styles/base.less +2 -73
- package/styles/colors.css +60 -0
- package/styles/colorsDark.css +62 -0
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
import "core-js/modules/es.array.concat";
|
|
2
|
-
import "core-js/modules/es.array.every";
|
|
3
2
|
import "core-js/modules/es.array.filter";
|
|
4
3
|
import "core-js/modules/es.array.find";
|
|
5
4
|
import "core-js/modules/es.array.find-index";
|
|
6
5
|
import "core-js/modules/es.array.map";
|
|
7
|
-
import "core-js/modules/es.date.to-string";
|
|
8
|
-
import "core-js/modules/es.object.to-string";
|
|
9
6
|
import "core-js/modules/es.object.values";
|
|
10
|
-
import "core-js/modules/es.reflect.construct";
|
|
11
7
|
import "core-js/modules/es.regexp.constructor";
|
|
12
8
|
import "core-js/modules/es.regexp.exec";
|
|
13
9
|
import "core-js/modules/es.regexp.to-string";
|
|
14
10
|
import "core-js/modules/es.string.replace";
|
|
15
11
|
import "core-js/modules/es.string.split";
|
|
12
|
+
import "core-js/modules/es.string.trim";
|
|
16
13
|
import _extends from "@babel/runtime/helpers/extends";
|
|
17
|
-
import
|
|
18
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
19
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
20
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
21
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
22
|
-
|
|
23
|
-
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
24
|
-
|
|
25
|
-
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; } }
|
|
26
|
-
|
|
14
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
27
15
|
import * as React from 'react';
|
|
16
|
+
import { Fragment, useEffect, useReducer, useCallback } from 'react';
|
|
28
17
|
import { cnCreate, detectTouch, filterDataAttrs } from '@megafon/ui-helpers';
|
|
29
18
|
import debounce from 'lodash.debounce';
|
|
30
19
|
import * as PropTypes from 'prop-types';
|
|
31
20
|
import InputLabel from "../InputLabel/InputLabel";
|
|
32
21
|
import "./Select.css";
|
|
22
|
+
import selectReducer, { initialState, SelectActions } from "./reducer/selectReducer";
|
|
23
|
+
var UPDATE_ITEMS_LIST = SelectActions.UPDATE_ITEMS_LIST,
|
|
24
|
+
UPDATE_VALUE_FROM_PROPS = SelectActions.UPDATE_VALUE_FROM_PROPS,
|
|
25
|
+
COMBOBOX_VALUE_DEBOUNCE = SelectActions.COMBOBOX_VALUE_DEBOUNCE,
|
|
26
|
+
COMBOBOX_INPUT_CHANGE = SelectActions.COMBOBOX_INPUT_CHANGE,
|
|
27
|
+
TOGGLE_DROPDOWN = SelectActions.TOGGLE_DROPDOWN,
|
|
28
|
+
UPDATE_SELECT_VALUE = SelectActions.UPDATE_SELECT_VALUE,
|
|
29
|
+
SET_HOVERED_ITEM_INDEX = SelectActions.SET_HOVERED_ITEM_INDEX;
|
|
33
30
|
export var Verification = {
|
|
34
31
|
VALID: 'valid',
|
|
35
32
|
ERROR: 'error'
|
|
@@ -37,492 +34,413 @@ export var Verification = {
|
|
|
37
34
|
export var SelectTypes = {
|
|
38
35
|
CLASSIC: 'classic',
|
|
39
36
|
COMBOBOX: 'combobox'
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
}; // List of cases to check on component change:
|
|
38
|
+
// - Should correctly choose value and trigger callbacks with correct arguments on click or touch.
|
|
39
|
+
// - Should correctly choose value and trigger callbacks with correct arguments on choose via filtration in combobox.
|
|
40
|
+
// - Should highlight chosen item with bold only in cases without view
|
|
41
|
+
// - Should scroll to chosen element (to make it visible), highlight it with bold and set hovered on dropdown open.
|
|
42
|
+
// - Should scroll (to make hovered element visible) and highlight next/previous element on arrow up and arrow down presses when dropdown is opened.
|
|
43
|
+
// - Should correctly set value on enter press while some element hovered.
|
|
44
|
+
// - If select dropdown is closed and select focused, dropdown should toggle open on Enter press.
|
|
45
|
+
// - Opened dropdown could be closed only via value choose, click outside of select and on TAB press.
|
|
46
|
+
// - Should add event listener for outside of dropdown click on list open and remove it on list close.
|
|
47
|
+
// - onClose callback shouldn't fire multiple times on outside click if dropdown was opened multiple times.
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
var cn = cnCreate('mfui-select');
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
var Select = function Select(_ref) {
|
|
52
|
+
var _ref$type = _ref.type,
|
|
53
|
+
type = _ref$type === void 0 ? 'classic' : _ref$type,
|
|
54
|
+
_ref$disabled = _ref.disabled,
|
|
55
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
56
|
+
verification = _ref.verification,
|
|
57
|
+
noticeText = _ref.noticeText,
|
|
58
|
+
label = _ref.label,
|
|
59
|
+
labelId = _ref.labelId,
|
|
60
|
+
_ref$required = _ref.required,
|
|
61
|
+
required = _ref$required === void 0 ? false : _ref$required,
|
|
62
|
+
_ref$className = _ref.className,
|
|
63
|
+
className = _ref$className === void 0 ? '' : _ref$className,
|
|
64
|
+
_ref$classes = _ref.classes,
|
|
65
|
+
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
66
|
+
dataAttrs = _ref.dataAttrs,
|
|
67
|
+
_ref$notFoundText = _ref.notFoundText,
|
|
68
|
+
notFoundText = _ref$notFoundText === void 0 ? 'Ничего не нашлось' : _ref$notFoundText,
|
|
69
|
+
items = _ref.items,
|
|
70
|
+
placeholder = _ref.placeholder,
|
|
71
|
+
currentValue = _ref.currentValue,
|
|
72
|
+
onClosed = _ref.onClosed,
|
|
73
|
+
onOpened = _ref.onOpened,
|
|
74
|
+
onSelect = _ref.onSelect;
|
|
75
|
+
|
|
76
|
+
var _useReducer = useReducer(selectReducer, initialState),
|
|
77
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
78
|
+
selectState = _useReducer2[0],
|
|
79
|
+
changeSelectState = _useReducer2[1];
|
|
80
|
+
|
|
81
|
+
var itemWrapperNode = React.useRef(null);
|
|
82
|
+
var itemsNodeList = React.useRef([]);
|
|
83
|
+
var selectNode = React.useRef(null);
|
|
84
|
+
var itemsList = selectState.itemsList,
|
|
85
|
+
filterValue = selectState.comparableInputValue,
|
|
86
|
+
isOpened = selectState.isOpened,
|
|
87
|
+
hoveredItemIndex = selectState.hoveredItemIndex,
|
|
88
|
+
inputValue = selectState.inputValue;
|
|
89
|
+
var isTouch = detectTouch();
|
|
90
|
+
var currentIndex = itemsList.findIndex(function (elem) {
|
|
91
|
+
return elem.value === currentValue;
|
|
92
|
+
}); // Used in various handlers instead useEffect with isOpened dependency because on initial component render isOpened is false
|
|
93
|
+
// so it triggers onClosed callback call
|
|
94
|
+
|
|
95
|
+
var handleClosed = function handleClosed() {
|
|
96
|
+
onClosed === null || onClosed === void 0 ? void 0 : onClosed(); // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
97
|
+
|
|
98
|
+
document.removeEventListener('click', handleClickOutside);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var handleClickOutside = useCallback(function (e) {
|
|
102
|
+
var _a;
|
|
103
|
+
|
|
104
|
+
if (e.target instanceof Node && ((_a = selectNode.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)) || !isOpened) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
50
107
|
|
|
51
|
-
|
|
108
|
+
handleClosed();
|
|
109
|
+
changeSelectState({
|
|
110
|
+
type: TOGGLE_DROPDOWN,
|
|
111
|
+
isOpened: false
|
|
112
|
+
});
|
|
113
|
+
}, [isOpened]);
|
|
52
114
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var query = filterValue.replace(/[^A-Z-a-zА-ЯЁа-яё0-9]/g, function (w) {
|
|
58
|
-
return "\\".concat(w);
|
|
59
|
-
});
|
|
60
|
-
var filteredItems = items.filter(function (_ref) {
|
|
61
|
-
var title = _ref.title;
|
|
115
|
+
var scrollList = function scrollList(itemIndex) {
|
|
116
|
+
if (!itemsNodeList.current.length) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
62
119
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
120
|
+
var wrapper = itemWrapperNode.current;
|
|
121
|
+
var item = itemsNodeList.current[itemIndex];
|
|
66
122
|
|
|
67
|
-
|
|
68
|
-
|
|
123
|
+
if (!item || !wrapper) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
69
126
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
activeIndex: 0
|
|
75
|
-
});
|
|
76
|
-
}, 250);
|
|
127
|
+
var wrapperScroll = wrapper === null || wrapper === void 0 ? void 0 : wrapper.scrollTop;
|
|
128
|
+
var wrapperHeight = wrapper === null || wrapper === void 0 ? void 0 : wrapper.offsetHeight;
|
|
129
|
+
var itemOffset = item.offsetTop;
|
|
130
|
+
var itemHeight = item.offsetHeight;
|
|
77
131
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
132
|
+
if (itemOffset + itemHeight > wrapperScroll + wrapperHeight) {
|
|
133
|
+
wrapper.scrollTop = itemOffset + itemHeight - wrapperHeight;
|
|
134
|
+
}
|
|
82
135
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
136
|
+
if (itemOffset < wrapperScroll) {
|
|
137
|
+
wrapper.scrollTop = itemOffset;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
useEffect(function () {
|
|
142
|
+
if (!isOpened) {
|
|
143
|
+
// Changes hovered item on dropdown close to currently chosen to hover it on dropdown open
|
|
144
|
+
changeSelectState({
|
|
145
|
+
type: SET_HOVERED_ITEM_INDEX,
|
|
146
|
+
hoveredItemIndex: currentIndex === -1 ? 0 : currentIndex
|
|
87
147
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_this.handleOpened = function () {
|
|
91
|
-
var onOpened = _this.props.onOpened;
|
|
92
|
-
onOpened === null || onOpened === void 0 ? void 0 : onOpened();
|
|
93
|
-
};
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
94
150
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
151
|
+
onOpened === null || onOpened === void 0 ? void 0 : onOpened();
|
|
152
|
+
scrollList(currentIndex);
|
|
153
|
+
document.addEventListener('click', handleClickOutside);
|
|
154
|
+
return function () {
|
|
155
|
+
document.removeEventListener('click', handleClickOutside);
|
|
98
156
|
};
|
|
157
|
+
}, [isOpened, currentIndex]);
|
|
158
|
+
useEffect(function () {
|
|
159
|
+
changeSelectState({
|
|
160
|
+
type: UPDATE_ITEMS_LIST,
|
|
161
|
+
items: items
|
|
162
|
+
});
|
|
163
|
+
}, [items]);
|
|
164
|
+
useEffect(function () {
|
|
165
|
+
if (currentIndex === -1) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
99
168
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
169
|
+
changeSelectState({
|
|
170
|
+
type: UPDATE_VALUE_FROM_PROPS,
|
|
171
|
+
hoveredItemIndex: currentIndex,
|
|
172
|
+
inputValue: itemsList[currentIndex].title,
|
|
173
|
+
comparableInputValue: itemsList[currentIndex].title
|
|
174
|
+
});
|
|
175
|
+
}, [currentIndex, itemsList]);
|
|
176
|
+
var debouncedComboboxChange = debounce(function (debounceFilterValue) {
|
|
177
|
+
var query = debounceFilterValue.replace(/[^A-Z-a-zА-ЯЁа-яё0-9]/g, function (w) {
|
|
178
|
+
return "\\".concat(w);
|
|
179
|
+
});
|
|
180
|
+
var debounceItemsList = items.filter(function (_ref2) {
|
|
181
|
+
var title = _ref2.title;
|
|
182
|
+
|
|
183
|
+
if (debounceFilterValue.length <= title.length) {
|
|
184
|
+
return RegExp(query, 'ig').test(title);
|
|
105
185
|
}
|
|
106
186
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
187
|
+
return false;
|
|
188
|
+
});
|
|
189
|
+
changeSelectState({
|
|
190
|
+
type: COMBOBOX_VALUE_DEBOUNCE,
|
|
191
|
+
items: debounceItemsList,
|
|
192
|
+
comparableInputValue: debounceFilterValue
|
|
193
|
+
});
|
|
194
|
+
}, 250);
|
|
195
|
+
|
|
196
|
+
var handleSelectClick = function handleSelectClick() {
|
|
197
|
+
var isCurrentlyOpened = isOpened;
|
|
198
|
+
changeSelectState({
|
|
199
|
+
type: TOGGLE_DROPDOWN,
|
|
200
|
+
isOpened: !isCurrentlyOpened
|
|
201
|
+
});
|
|
202
|
+
isCurrentlyOpened && handleClosed();
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
var handleSelectItem = function handleSelectItem(e) {
|
|
206
|
+
var currentItem = itemsList[hoveredItemIndex].value;
|
|
207
|
+
var item = itemsList.find(function (elem) {
|
|
208
|
+
return elem.value === currentItem;
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (!item) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
115
214
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
215
|
+
var title = item.title;
|
|
216
|
+
changeSelectState({
|
|
217
|
+
type: UPDATE_SELECT_VALUE,
|
|
218
|
+
inputValue: title,
|
|
219
|
+
comparableInputValue: title,
|
|
220
|
+
items: items
|
|
221
|
+
});
|
|
222
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(e, item);
|
|
223
|
+
handleClosed();
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
var handleHoverItem = function handleHoverItem(index) {
|
|
227
|
+
return function (e) {
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
changeSelectState({
|
|
230
|
+
type: SET_HOVERED_ITEM_INDEX,
|
|
231
|
+
hoveredItemIndex: index
|
|
127
232
|
});
|
|
128
233
|
};
|
|
234
|
+
};
|
|
129
235
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
filteredItems = _this$state.filteredItems;
|
|
137
|
-
var currentItem = filteredItems[activeIndex].value;
|
|
138
|
-
var item = filteredItems.find(function (elem) {
|
|
139
|
-
return elem.value === currentItem;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
if (!item) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
236
|
+
var handleComboboxFocus = function handleComboboxFocus(e) {
|
|
237
|
+
e.stopPropagation();
|
|
238
|
+
changeSelectState({
|
|
239
|
+
type: TOGGLE_DROPDOWN,
|
|
240
|
+
isOpened: !isOpened
|
|
241
|
+
});
|
|
145
242
|
|
|
146
|
-
|
|
243
|
+
if (!isOpened && itemsList) {
|
|
244
|
+
e.target.select();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
var handleChangeCombobox = function handleChangeCombobox(e) {
|
|
249
|
+
var comboboxValue = e.target.value;
|
|
250
|
+
onSelect && onSelect(null);
|
|
251
|
+
changeSelectState({
|
|
252
|
+
type: COMBOBOX_INPUT_CHANGE,
|
|
253
|
+
inputValue: comboboxValue
|
|
254
|
+
});
|
|
255
|
+
debouncedComboboxChange(comboboxValue);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
259
|
+
if (itemsList.length === 0 || disabled) {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
147
262
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
263
|
+
if (e.key === 'ArrowDown' && isOpened && hoveredItemIndex < itemsList.length - 1) {
|
|
264
|
+
var nextIndex = hoveredItemIndex + 1;
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
changeSelectState({
|
|
267
|
+
type: SET_HOVERED_ITEM_INDEX,
|
|
268
|
+
hoveredItemIndex: nextIndex
|
|
154
269
|
});
|
|
270
|
+
scrollList(nextIndex);
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
155
273
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
_this.handleClosed();
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
_this.handleHoverItem = function (index) {
|
|
162
|
-
return function (e) {
|
|
163
|
-
e.preventDefault();
|
|
164
|
-
|
|
165
|
-
_this.setState({
|
|
166
|
-
activeIndex: index
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
_this.handleComboboxFocus = function (e) {
|
|
172
|
-
var _this$state2 = _this.state,
|
|
173
|
-
isOpened = _this$state2.isOpened,
|
|
174
|
-
filteredItems = _this$state2.filteredItems;
|
|
175
|
-
e.stopPropagation();
|
|
274
|
+
if (e.key === 'ArrowUp' && isOpened && hoveredItemIndex > 0) {
|
|
275
|
+
var _nextIndex = hoveredItemIndex - 1;
|
|
176
276
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
changeSelectState({
|
|
279
|
+
type: SET_HOVERED_ITEM_INDEX,
|
|
280
|
+
hoveredItemIndex: _nextIndex
|
|
181
281
|
});
|
|
282
|
+
scrollList(_nextIndex);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
182
285
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
_this.handleChangeCombobox = function (e) {
|
|
191
|
-
var onSelect = _this.props.onSelect;
|
|
192
|
-
var isChoosenItem = _this.state.isChoosenItem;
|
|
193
|
-
var filterValue = e.target.value;
|
|
194
|
-
|
|
195
|
-
if (isChoosenItem) {
|
|
196
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(null);
|
|
197
|
-
}
|
|
286
|
+
if (e.key === 'Enter' && isOpened) {
|
|
287
|
+
handleSelectItem(e);
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
198
290
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
291
|
+
if (e.key === 'Enter' && !isOpened) {
|
|
292
|
+
changeSelectState({
|
|
293
|
+
type: TOGGLE_DROPDOWN,
|
|
294
|
+
isOpened: true
|
|
202
295
|
});
|
|
296
|
+
onOpened === null || onOpened === void 0 ? void 0 : onOpened();
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
203
299
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
filteredItems = _this$state3.filteredItems;
|
|
212
|
-
var disabled = _this.props.disabled;
|
|
213
|
-
|
|
214
|
-
if (filteredItems.length === 0 || disabled) {
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (e.key === 'ArrowDown' && isOpened && activeIndex < filteredItems.length - 1) {
|
|
219
|
-
_this.setState({
|
|
220
|
-
activeIndex: activeIndex + 1
|
|
221
|
-
}, function () {
|
|
222
|
-
_this.scrollList(_this.state.activeIndex);
|
|
223
|
-
});
|
|
300
|
+
if (e.key === 'Tab') {
|
|
301
|
+
changeSelectState({
|
|
302
|
+
type: TOGGLE_DROPDOWN,
|
|
303
|
+
isOpened: false
|
|
304
|
+
});
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
224
307
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
308
|
+
return true;
|
|
309
|
+
};
|
|
228
310
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
_this.scrollList(_this.state.activeIndex);
|
|
311
|
+
var highlightString = function highlightString(title, isItemActive, view) {
|
|
312
|
+
if (type === SelectTypes.CLASSIC) {
|
|
313
|
+
if (typeof view === 'function' && !React.isValidElement(view)) {
|
|
314
|
+
return view({
|
|
315
|
+
filterValue: inputValue,
|
|
316
|
+
isItemActive: isItemActive
|
|
236
317
|
});
|
|
237
|
-
|
|
238
|
-
e.preventDefault();
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (e.key === 'Enter' && isOpened) {
|
|
243
|
-
_this.handleSelectItem(e);
|
|
244
|
-
|
|
245
|
-
return false;
|
|
246
318
|
}
|
|
247
319
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
isOpened: true
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
_this.handleOpened();
|
|
254
|
-
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
320
|
+
return view || title;
|
|
321
|
+
}
|
|
257
322
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
323
|
+
if (type === SelectTypes.COMBOBOX && view) {
|
|
324
|
+
if (typeof view === 'function' && !React.isValidElement(view)) {
|
|
325
|
+
return view({
|
|
326
|
+
filterValue: inputValue,
|
|
327
|
+
isItemActive: isItemActive
|
|
261
328
|
});
|
|
262
|
-
|
|
263
|
-
return false;
|
|
264
329
|
}
|
|
265
330
|
|
|
266
|
-
return
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
_this.highlightString = function (title, view) {
|
|
270
|
-
var type = _this.props.type;
|
|
271
|
-
var _this$state4 = _this.state,
|
|
272
|
-
comparableInputValue = _this$state4.comparableInputValue,
|
|
273
|
-
inputValue = _this$state4.inputValue;
|
|
274
|
-
|
|
275
|
-
if (type === SelectTypes.CLASSIC) {
|
|
276
|
-
if (typeof view === 'function' && !React.isValidElement(view)) {
|
|
277
|
-
return view({
|
|
278
|
-
filterValue: inputValue
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return view || title;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (type === SelectTypes.COMBOBOX && view) {
|
|
286
|
-
if (typeof view === 'function' && !React.isValidElement(view)) {
|
|
287
|
-
return view({
|
|
288
|
-
filterValue: inputValue
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return view;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
var stringFragments = title.split(RegExp("(".concat(comparableInputValue, ")"), 'ig'));
|
|
296
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, stringFragments.map(function (fragment, i) {
|
|
297
|
-
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
298
|
-
key: i
|
|
299
|
-
}, fragment.toLowerCase() === comparableInputValue.toLowerCase() && fragment !== '' ? /*#__PURE__*/React.createElement("span", {
|
|
300
|
-
className: cn('highlighted-fragment')
|
|
301
|
-
}, fragment) : fragment);
|
|
302
|
-
}));
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
_this.getItemWrapper = function (node) {
|
|
306
|
-
_this.itemWrapperNode = node;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
_this.getSelectNode = function (node) {
|
|
310
|
-
_this.selectNode = node;
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
_this.getNodeList = function (node) {
|
|
314
|
-
_this.itemsNodeList.push(node);
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
_this.state = {
|
|
318
|
-
isOpened: false,
|
|
319
|
-
activeIndex: 0,
|
|
320
|
-
filteredItems: props.items,
|
|
321
|
-
comparableInputValue: '',
|
|
322
|
-
inputValue: '',
|
|
323
|
-
isChoosenItem: false
|
|
324
|
-
};
|
|
325
|
-
_this.itemsNodeList = [];
|
|
326
|
-
return _this;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
_createClass(Select, [{
|
|
330
|
-
key: "componentDidMount",
|
|
331
|
-
value: function componentDidMount() {
|
|
332
|
-
var currentValue = this.props.currentValue;
|
|
333
|
-
var filteredItems = this.state.filteredItems;
|
|
334
|
-
var currentIndex = filteredItems.findIndex(function (elem) {
|
|
335
|
-
return elem.value === currentValue;
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
if (currentIndex !== -1) {
|
|
339
|
-
this.setState({
|
|
340
|
-
activeIndex: currentIndex,
|
|
341
|
-
inputValue: filteredItems[currentIndex].title,
|
|
342
|
-
comparableInputValue: filteredItems[currentIndex].title
|
|
343
|
-
});
|
|
344
|
-
}
|
|
331
|
+
return view;
|
|
345
332
|
}
|
|
346
|
-
}, {
|
|
347
|
-
key: "componentDidUpdate",
|
|
348
|
-
value: function componentDidUpdate(_ref2) {
|
|
349
|
-
var prevItems = _ref2.items;
|
|
350
|
-
var items = this.props.items;
|
|
351
|
-
var isOpened = this.state.isOpened;
|
|
352
|
-
|
|
353
|
-
if (!this.isEqualItems(items, prevItems)) {
|
|
354
|
-
// eslint-disable-next-line react/no-did-update-set-state
|
|
355
|
-
this.setState({
|
|
356
|
-
filteredItems: items
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
333
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
334
|
+
var stringFragments = title.split(RegExp("(".concat(filterValue, ")"), 'ig'));
|
|
335
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, stringFragments.map(function (fragment, i) {
|
|
336
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
337
|
+
key: i
|
|
338
|
+
}, fragment.toLowerCase() === filterValue.toLowerCase() && fragment !== '' ? /*#__PURE__*/React.createElement("span", {
|
|
339
|
+
className: cn('highlighted-fragment')
|
|
340
|
+
}, fragment) : fragment);
|
|
341
|
+
}));
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
var getNodeList = useCallback(function (node) {
|
|
345
|
+
if (filterValue.trim()) {
|
|
346
|
+
itemsNodeList.current = [];
|
|
347
|
+
return;
|
|
366
348
|
}
|
|
367
|
-
}, {
|
|
368
|
-
key: "componentWillUnmount",
|
|
369
|
-
value: function componentWillUnmount() {
|
|
370
|
-
document.removeEventListener('click', this.handleClickOutside);
|
|
371
|
-
}
|
|
372
|
-
}, {
|
|
373
|
-
key: "scrollList",
|
|
374
|
-
value: function scrollList(activeIndex) {
|
|
375
|
-
if (!this.itemsNodeList) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
349
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
var wrapperHeight = wrapper.offsetHeight;
|
|
382
|
-
var item = this.itemsNodeList[activeIndex];
|
|
350
|
+
!filterValue && node && itemsNodeList.current.push(node);
|
|
351
|
+
}, [filterValue]);
|
|
383
352
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
var itemHeight = item.offsetHeight;
|
|
353
|
+
var renderTitle = function renderTitle() {
|
|
354
|
+
var item = items.find(function (elem) {
|
|
355
|
+
return elem.value === currentValue;
|
|
356
|
+
});
|
|
357
|
+
var inputTitle = placeholder;
|
|
390
358
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (itemOffset < wrapperScroll) {
|
|
396
|
-
wrapper.scrollTop = itemOffset;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}, {
|
|
400
|
-
key: "renderTitle",
|
|
401
|
-
value: function renderTitle() {
|
|
402
|
-
var _this$props2 = this.props,
|
|
403
|
-
placeholder = _this$props2.placeholder,
|
|
404
|
-
items = _this$props2.items,
|
|
405
|
-
currentValue = _this$props2.currentValue,
|
|
406
|
-
classes = _this$props2.classes;
|
|
407
|
-
var item = items.find(function (elem) {
|
|
408
|
-
return elem.value === currentValue;
|
|
409
|
-
});
|
|
410
|
-
var inputTitle = placeholder;
|
|
411
|
-
|
|
412
|
-
if (item && item.title) {
|
|
413
|
-
inputTitle = item.selectedView ? item.selectedView : item.title;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
417
|
-
className: cn('title', {
|
|
418
|
-
placeholder: !!placeholder && !currentValue
|
|
419
|
-
}, [classes === null || classes === void 0 ? void 0 : classes.title]),
|
|
420
|
-
role: "button",
|
|
421
|
-
tabIndex: 0,
|
|
422
|
-
onClick: this.handleOpenDropdown
|
|
423
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
424
|
-
className: cn('title-inner', [classes === null || classes === void 0 ? void 0 : classes.titleInner])
|
|
425
|
-
}, inputTitle));
|
|
359
|
+
if (item && item.title) {
|
|
360
|
+
inputTitle = item.selectedView ? item.selectedView : item.title;
|
|
426
361
|
}
|
|
427
|
-
}, {
|
|
428
|
-
key: "renderCombobox",
|
|
429
|
-
value: function renderCombobox() {
|
|
430
|
-
var placeholder = this.props.placeholder;
|
|
431
|
-
var inputValue = this.state.inputValue;
|
|
432
|
-
return /*#__PURE__*/React.createElement("input", {
|
|
433
|
-
className: cn('combobox'),
|
|
434
|
-
onFocus: this.handleComboboxFocus,
|
|
435
|
-
onChange: this.handleChangeCombobox,
|
|
436
|
-
type: "text",
|
|
437
|
-
value: inputValue,
|
|
438
|
-
placeholder: placeholder
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
}, {
|
|
442
|
-
key: "renderChildren",
|
|
443
|
-
value: function renderChildren() {
|
|
444
|
-
var _this2 = this;
|
|
445
|
-
|
|
446
|
-
var _this$props3 = this.props,
|
|
447
|
-
type = _this$props3.type,
|
|
448
|
-
items = _this$props3.items,
|
|
449
|
-
notFoundText = _this$props3.notFoundText,
|
|
450
|
-
_this$props3$classes = _this$props3.classes,
|
|
451
|
-
classes = _this$props3$classes === void 0 ? {} : _this$props3$classes;
|
|
452
|
-
var _this$state5 = this.state,
|
|
453
|
-
filteredItems = _this$state5.filteredItems,
|
|
454
|
-
activeIndex = _this$state5.activeIndex;
|
|
455
|
-
var currentItems = type === SelectTypes.COMBOBOX ? filteredItems : items;
|
|
456
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
457
|
-
className: cn('list', [classes.list])
|
|
458
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
459
|
-
className: cn('list-inner'),
|
|
460
|
-
ref: this.getItemWrapper
|
|
461
|
-
}, currentItems.map(function (_ref3, i) {
|
|
462
|
-
var title = _ref3.title,
|
|
463
|
-
value = _ref3.value,
|
|
464
|
-
view = _ref3.view;
|
|
465
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
466
|
-
className: cn('list-item', {
|
|
467
|
-
active: activeIndex === i
|
|
468
|
-
}, [classes.listItem]),
|
|
469
|
-
key: "".concat(i, "_").concat(value),
|
|
470
|
-
onClick: _this2.handleSelectItem,
|
|
471
|
-
onMouseEnter: _this2.handleHoverItem(i),
|
|
472
|
-
ref: _this2.getNodeList
|
|
473
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
474
|
-
className: cn('item-title', [classes.listItemTitle])
|
|
475
|
-
}, _this2.highlightString(title, view)));
|
|
476
|
-
}), type === SelectTypes.COMBOBOX && !currentItems.length && /*#__PURE__*/React.createElement("div", {
|
|
477
|
-
className: cn('not-found')
|
|
478
|
-
}, notFoundText)));
|
|
479
|
-
}
|
|
480
|
-
}, {
|
|
481
|
-
key: "render",
|
|
482
|
-
value: function render() {
|
|
483
|
-
var _this$props4 = this.props,
|
|
484
|
-
type = _this$props4.type,
|
|
485
|
-
disabled = _this$props4.disabled,
|
|
486
|
-
verification = _this$props4.verification,
|
|
487
|
-
noticeText = _this$props4.noticeText,
|
|
488
|
-
label = _this$props4.label,
|
|
489
|
-
labelId = _this$props4.labelId,
|
|
490
|
-
required = _this$props4.required,
|
|
491
|
-
_this$props4$classNam = _this$props4.className,
|
|
492
|
-
className = _this$props4$classNam === void 0 ? '' : _this$props4$classNam,
|
|
493
|
-
_this$props4$classes = _this$props4.classes,
|
|
494
|
-
classes = _this$props4$classes === void 0 ? {} : _this$props4$classes,
|
|
495
|
-
dataAttrs = _this$props4.dataAttrs;
|
|
496
|
-
var isOpened = this.state.isOpened;
|
|
497
|
-
return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs), {
|
|
498
|
-
className: cn({
|
|
499
|
-
open: isOpened,
|
|
500
|
-
disabled: disabled,
|
|
501
|
-
'no-touch': !this.isTouch,
|
|
502
|
-
valid: verification === Verification.VALID,
|
|
503
|
-
error: verification === Verification.ERROR
|
|
504
|
-
}, [className, classes.root]),
|
|
505
|
-
ref: this.getSelectNode
|
|
506
|
-
}), /*#__PURE__*/React.createElement("div", {
|
|
507
|
-
className: cn('inner')
|
|
508
|
-
}, label && /*#__PURE__*/React.createElement(InputLabel, {
|
|
509
|
-
htmlFor: labelId
|
|
510
|
-
}, label, required && /*#__PURE__*/React.createElement("span", {
|
|
511
|
-
className: cn('require-mark')
|
|
512
|
-
}, "*")), /*#__PURE__*/React.createElement("div", {
|
|
513
|
-
className: cn('control', classes.control),
|
|
514
|
-
onKeyDown: this.handleKeyDown
|
|
515
|
-
}, type === SelectTypes.COMBOBOX && this.renderCombobox(), type === SelectTypes.CLASSIC && this.renderTitle()), this.renderChildren()), noticeText && /*#__PURE__*/React.createElement("div", {
|
|
516
|
-
className: cn('text', {
|
|
517
|
-
error: verification === Verification.ERROR,
|
|
518
|
-
success: verification === Verification.VALID
|
|
519
|
-
})
|
|
520
|
-
}, noticeText));
|
|
521
|
-
}
|
|
522
|
-
}]);
|
|
523
362
|
|
|
524
|
-
|
|
525
|
-
|
|
363
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.title), {
|
|
364
|
+
className: cn('title', {
|
|
365
|
+
placeholder: !!placeholder && !currentValue
|
|
366
|
+
}, [classes === null || classes === void 0 ? void 0 : classes.title]),
|
|
367
|
+
role: "button",
|
|
368
|
+
tabIndex: 0,
|
|
369
|
+
onClick: handleSelectClick
|
|
370
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
371
|
+
className: cn('title-inner', [classes === null || classes === void 0 ? void 0 : classes.titleInner])
|
|
372
|
+
}, inputTitle));
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
var renderCombobox = function renderCombobox() {
|
|
376
|
+
return /*#__PURE__*/React.createElement("input", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.input), {
|
|
377
|
+
className: cn('combobox'),
|
|
378
|
+
onFocus: handleComboboxFocus,
|
|
379
|
+
onChange: handleChangeCombobox,
|
|
380
|
+
type: "text",
|
|
381
|
+
value: inputValue,
|
|
382
|
+
placeholder: placeholder
|
|
383
|
+
}));
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
var renderChildren = function renderChildren() {
|
|
387
|
+
var currentItems = type === SelectTypes.COMBOBOX ? itemsList : items;
|
|
388
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
389
|
+
className: cn('list', [classes.list])
|
|
390
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
391
|
+
className: cn('list-inner'),
|
|
392
|
+
ref: itemWrapperNode
|
|
393
|
+
}, currentItems.map(function (_ref3, i) {
|
|
394
|
+
var title = _ref3.title,
|
|
395
|
+
value = _ref3.value,
|
|
396
|
+
view = _ref3.view;
|
|
397
|
+
var isItemActive = currentValue === value;
|
|
398
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.listItem, i + 1), {
|
|
399
|
+
className: cn('list-item', {
|
|
400
|
+
hovered: hoveredItemIndex === i
|
|
401
|
+
}, [classes.listItem]),
|
|
402
|
+
key: "".concat(i, "_").concat(value),
|
|
403
|
+
onClick: handleSelectItem,
|
|
404
|
+
onMouseEnter: handleHoverItem(i),
|
|
405
|
+
ref: getNodeList
|
|
406
|
+
}), /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.listItemTitle, i + 1), {
|
|
407
|
+
className: cn('item-title', {
|
|
408
|
+
active: isItemActive && !view
|
|
409
|
+
}, [classes.listItemTitle])
|
|
410
|
+
}), highlightString(title, isItemActive, view)));
|
|
411
|
+
}), type === SelectTypes.COMBOBOX && !currentItems.length && /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.notFound), {
|
|
412
|
+
className: cn('not-found')
|
|
413
|
+
}), notFoundText)));
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
|
417
|
+
className: cn({
|
|
418
|
+
open: isOpened,
|
|
419
|
+
disabled: disabled,
|
|
420
|
+
'no-touch': !isTouch,
|
|
421
|
+
valid: verification === Verification.VALID,
|
|
422
|
+
error: verification === Verification.ERROR
|
|
423
|
+
}, [className, classes.root]),
|
|
424
|
+
ref: selectNode
|
|
425
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
426
|
+
className: cn('inner')
|
|
427
|
+
}, label && /*#__PURE__*/React.createElement(InputLabel, {
|
|
428
|
+
dataAttrs: {
|
|
429
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.label
|
|
430
|
+
},
|
|
431
|
+
htmlFor: labelId
|
|
432
|
+
}, label, required && /*#__PURE__*/React.createElement("span", {
|
|
433
|
+
className: cn('require-mark')
|
|
434
|
+
}, "*")), /*#__PURE__*/React.createElement("div", {
|
|
435
|
+
className: cn('control', classes.control),
|
|
436
|
+
onKeyDown: handleKeyDown
|
|
437
|
+
}, type === SelectTypes.COMBOBOX && renderCombobox(), type === SelectTypes.CLASSIC && renderTitle()), renderChildren()), noticeText && /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.noticeText), {
|
|
438
|
+
className: cn('text', {
|
|
439
|
+
error: verification === Verification.ERROR,
|
|
440
|
+
success: verification === Verification.VALID
|
|
441
|
+
})
|
|
442
|
+
}), noticeText));
|
|
443
|
+
};
|
|
526
444
|
|
|
527
445
|
Select.propTypes = {
|
|
528
446
|
type: PropTypes.oneOf(Object.values(SelectTypes)),
|
|
@@ -545,6 +463,16 @@ Select.propTypes = {
|
|
|
545
463
|
listItem: PropTypes.string,
|
|
546
464
|
listItemTitle: PropTypes.string
|
|
547
465
|
}),
|
|
466
|
+
dataAttrs: PropTypes.shape({
|
|
467
|
+
root: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
468
|
+
label: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
469
|
+
title: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
470
|
+
input: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
471
|
+
noticeText: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
472
|
+
listItem: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
473
|
+
listItemTitle: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
474
|
+
notFound: PropTypes.objectOf(PropTypes.string.isRequired)
|
|
475
|
+
}),
|
|
548
476
|
items: PropTypes.arrayOf(PropTypes.exact({
|
|
549
477
|
view: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func]),
|
|
550
478
|
selectedView: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func]),
|
|
@@ -552,14 +480,7 @@ Select.propTypes = {
|
|
|
552
480
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
|
|
553
481
|
})).isRequired,
|
|
554
482
|
onSelect: PropTypes.func,
|
|
555
|
-
dataAttrs: PropTypes.objectOf(PropTypes.string.isRequired),
|
|
556
483
|
onOpened: PropTypes.func,
|
|
557
484
|
onClosed: PropTypes.func
|
|
558
485
|
};
|
|
559
|
-
Select.defaultProps = {
|
|
560
|
-
disabled: false,
|
|
561
|
-
required: false,
|
|
562
|
-
type: 'classic',
|
|
563
|
-
notFoundText: 'Ничего не нашлось'
|
|
564
|
-
};
|
|
565
486
|
export default Select;
|