intelicoreact 1.0.90 → 1.0.92

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.
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
+
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+
16
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
+
18
+ var _react = _interopRequireWildcard(require("react"));
19
+
20
+ var _classnames = _interopRequireDefault(require("classnames"));
21
+
22
+ var _reactFeather = require("react-feather");
23
+
24
+ var _useDebounce = require("../../../Functions/useDebounce");
25
+
26
+ var _fieldValueFormatters = require("../../../Functions/fieldValueFormatters");
27
+
28
+ var _Spinner = _interopRequireDefault(require("../../Layout/Spinner/Spinner"));
29
+
30
+ require("./DropdownLiveSearch.scss");
31
+
32
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
+
34
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
+
36
+ var RC = 'dropdown-live-search';
37
+
38
+ var DropdownLiveSearch = function DropdownLiveSearch(_ref) {
39
+ var value = _ref.value,
40
+ error = _ref.error,
41
+ disabled = _ref.disabled,
42
+ onChange = _ref.onChange,
43
+ placeholder = _ref.placeholder,
44
+ className = _ref.className,
45
+ isSearchable = _ref.isSearchable,
46
+ scrollReactionObj = _ref.scrollReactionObj,
47
+ testId = _ref.testId,
48
+ doRequest = _ref.doRequest,
49
+ isLoading = _ref.isLoading,
50
+ _ref$options = _ref.options,
51
+ options = _ref$options === void 0 ? [] : _ref$options,
52
+ fieldKey = _ref.fieldKey,
53
+ id = _ref.id,
54
+ _ref$isNotValidateASC = _ref.isNotValidateASCII,
55
+ isNotValidateASCII = _ref$isNotValidateASC === void 0 ? false : _ref$isNotValidateASC,
56
+ _ref$noOptionsText = _ref.noOptionsText,
57
+ noOptionsText = _ref$noOptionsText === void 0 ? 'No options available' : _ref$noOptionsText;
58
+ var dropdownId = fieldKey || id;
59
+
60
+ var _useState = (0, _react.useState)(false),
61
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
62
+ isOpen = _useState2[0],
63
+ setIsOpen = _useState2[1];
64
+
65
+ var _useState3 = (0, _react.useState)(false),
66
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
67
+ isValueDeleted = _useState4[0],
68
+ setIsValueDeleted = _useState4[1];
69
+
70
+ var labelByValue = (0, _react.useMemo)(function () {
71
+ var _options$find;
72
+
73
+ return (options === null || options === void 0 ? void 0 : (_options$find = options.find(function (item) {
74
+ return item.value === value;
75
+ })) === null || _options$find === void 0 ? void 0 : _options$find.label) || '';
76
+ }, [value]);
77
+
78
+ var _useState5 = (0, _react.useState)(labelByValue),
79
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
80
+ searchValue = _useState6[0],
81
+ setSearchValue = _useState6[1];
82
+
83
+ var dropdownLiveSearchRef = (0, _react.useRef)(null);
84
+ var dropdownListBoxRef = (0, _react.useRef)(null);
85
+ var dropdownListRef = (0, _react.useRef)(null);
86
+ var searchInputRef = (0, _react.useRef)(null);
87
+
88
+ var _useState7 = (0, _react.useState)(false),
89
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
90
+ isFocusedByClick = _useState8[0],
91
+ setIsFocusedByClick = _useState8[1];
92
+
93
+ var debouncedSearchTerm = (0, _useDebounce.useDebounce)({
94
+ searchValue: searchValue,
95
+ delay: 600
96
+ });
97
+ if (!options) return null;
98
+
99
+ var handleClickOutside = function handleClickOutside(event) {
100
+ if (!dropdownLiveSearchRef.current.contains(event.target)) setIsOpen(false);
101
+ };
102
+
103
+ var highlightedText = function highlightedText(text, postfix) {
104
+ var _text;
105
+
106
+ var prepare = function prepare(text) {
107
+ return text === null || text === void 0 ? void 0 : text.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
108
+ };
109
+
110
+ text = text.replace(/["&<>]/g, function (a) {
111
+ return {
112
+ '"': '&quot;',
113
+ '&': '&amp;',
114
+ '<': '&lt;',
115
+ '>': '&gt;'
116
+ }[a];
117
+ });
118
+ var main = searchValue ? (_text = text) === null || _text === void 0 ? void 0 : _text.replace(new RegExp(prepare(searchValue), 'i'), function (match) {
119
+ return "<span class=\"bg--yellow\">".concat(match, "</span>");
120
+ }) : text;
121
+ var postfixPart = postfix ? "<span class=\"dropdown__list-item-postfix\">".concat(postfix, "</span>") : '';
122
+ return main + postfixPart;
123
+ };
124
+
125
+ var getMarkupForElement = function getMarkupForElement(item, index, optTestId) {
126
+ var _item$value, _item$value$toString, _item$value2, _item$value2$toString, _cn;
127
+
128
+ var lowerLabel = item.label.toLowerCase();
129
+ var lowerSearchValue = searchValue.toLowerCase();
130
+ return /*#__PURE__*/_react.default.createElement("button", {
131
+ "data-testid": "dropdown-live-search--button--key-".concat(optTestId || (item === null || item === void 0 ? void 0 : (_item$value = item.value) === null || _item$value === void 0 ? void 0 : (_item$value$toString = _item$value.toString()) === null || _item$value$toString === void 0 ? void 0 : _item$value$toString.replace(/\s/, '-')) || (item === null || item === void 0 ? void 0 : item.key) || 'item', "--option"),
132
+ key: (_item$value2 = item.value) === null || _item$value2 === void 0 ? void 0 : (_item$value2$toString = _item$value2.toString()) === null || _item$value2$toString === void 0 ? void 0 : _item$value2$toString.replace(/ /g, '_'),
133
+ onClick: function onClick() {
134
+ onChange(item.value);
135
+ setIsOpen(false);
136
+ setSearchValue(item.label);
137
+ },
138
+ className: (0, _classnames.default)("".concat(RC, "__list-item"), (_cn = {}, (0, _defineProperty2.default)(_cn, "".concat(RC, "__list-item_active"), item.value === value), (0, _defineProperty2.default)(_cn, "".concat(RC, "__list-item_disabled"), item.disabled), _cn), item.className)
139
+ }, /*#__PURE__*/_react.default.createElement("span", {
140
+ className: (0, _classnames.default)("".concat(RC, "__active-icon"), (0, _defineProperty2.default)({}, "".concat(RC, "__active-icon_active"), lowerLabel === lowerSearchValue))
141
+ }, /*#__PURE__*/_react.default.createElement(_reactFeather.Check, null)), /*#__PURE__*/_react.default.createElement("div", {
142
+ className: item.labelClassName || '',
143
+ dangerouslySetInnerHTML: {
144
+ __html: highlightedText(item.label, item.postfix)
145
+ }
146
+ }));
147
+ };
148
+
149
+ var getListMarkUp = function getListMarkUp() {
150
+ return /*#__PURE__*/_react.default.createElement("div", {
151
+ id: "dropdown-live-search-list",
152
+ className: (0, _classnames.default)("".concat(RC, "__container")),
153
+ ref: dropdownListBoxRef
154
+ }, /*#__PURE__*/_react.default.createElement("div", {
155
+ className: (0, _classnames.default)("".concat(RC, "__list"), {
156
+ disabled: isLoading
157
+ }),
158
+ ref: dropdownListRef
159
+ }, options.map(function (option) {
160
+ return getMarkupForElement(option);
161
+ }), !options.length && /*#__PURE__*/_react.default.createElement("div", {
162
+ className: "".concat(RC, "__list-item ").concat(RC, "__list-item--no-options")
163
+ }, noOptionsText)), isLoading && isOpen && /*#__PURE__*/_react.default.createElement(_Spinner.default, {
164
+ size: options.length <= 3 ? 'small' : null
165
+ }));
166
+ };
167
+
168
+ var getListContainer = function getListContainer() {
169
+ return document.getElementById(dropdownId);
170
+ };
171
+
172
+ (0, _react.useEffect)(function () {
173
+ document.addEventListener('click', handleClickOutside, true);
174
+ return function () {
175
+ return document.removeEventListener('click', handleClickOutside, true);
176
+ };
177
+ }, [value]);
178
+
179
+ var searchableInputFocus = function searchableInputFocus(e) {
180
+ if (!isOpen) {
181
+ e.preventDefault();
182
+ e.stopPropagation();
183
+ return;
184
+ }
185
+ };
186
+
187
+ var handle = {
188
+ onInputClick: function onInputClick(e) {
189
+ if (!isOpen) setIsOpen(true);
190
+ e.target.select();
191
+ },
192
+ onInputChange: function onInputChange(e) {
193
+ var inputValue = e.target.value;
194
+ if (!isNotValidateASCII) inputValue = (0, _fieldValueFormatters.formatToOnlyASCIICodeText)(inputValue);
195
+ setSearchValue(inputValue);
196
+ if (searchValue && !e.target.value) setIsValueDeleted(true);else setIsValueDeleted(false);
197
+ }
198
+ };
199
+ (0, _react.useEffect)(function () {
200
+ if (isSearchable && debouncedSearchTerm || isValueDeleted) {
201
+ doRequest(debouncedSearchTerm);
202
+ }
203
+ }, [debouncedSearchTerm, isValueDeleted]);
204
+
205
+ var closeListViaEsc = function closeListViaEsc(e) {
206
+ if ([27].includes(e.keyCode)) setIsOpen(false);
207
+ };
208
+
209
+ (0, _react.useLayoutEffect)(function () {
210
+ window.addEventListener('keyup', closeListViaEsc);
211
+ return function () {
212
+ window.removeEventListener('keyup', closeListViaEsc);
213
+ };
214
+ }, [getListContainer]);
215
+ (0, _react.useLayoutEffect)(function () {
216
+ var list = document.getElementById('dropdown-live-search-list');
217
+
218
+ if (list || isOpen) {
219
+ var _dropdownLiveSearchRe;
220
+
221
+ var dropdownWidth = dropdownLiveSearchRef === null || dropdownLiveSearchRef === void 0 ? void 0 : (_dropdownLiveSearchRe = dropdownLiveSearchRef.current) === null || _dropdownLiveSearchRe === void 0 ? void 0 : _dropdownLiveSearchRe.clientWidth;
222
+ list.style.width = "".concat(dropdownWidth, "px");
223
+ }
224
+ }, [dropdownLiveSearchRef, isOpen]);
225
+ var doScrollCallback = (0, _react.useCallback)(function (e) {
226
+ if (doRequest && typeof doRequest === 'function') {
227
+ if (Math.round(e.target.clientHeight + e.target.scrollTop) == e.target.scrollHeight) {
228
+ doRequest(searchValue);
229
+ }
230
+ }
231
+ }, [options]);
232
+ (0, _react.useEffect)(function () {
233
+ if (!isOpen) setIsFocusedByClick(false);
234
+
235
+ if (scrollReactionObj && (0, _typeof2.default)(scrollReactionObj) === 'object' && isOpen && dropdownListRef && dropdownListRef.current) {
236
+ dropdownListRef.current.addEventListener('scroll', doScrollCallback);
237
+ }
238
+
239
+ return function () {
240
+ if (scrollReactionObj && (0, _typeof2.default)(scrollReactionObj) === 'object') removeEventListener('scroll', doScrollCallback);
241
+ };
242
+ }, [isOpen, dropdownListRef]);
243
+ return /*#__PURE__*/_react.default.createElement("div", {
244
+ className: (0, _classnames.default)(RC, className, disabled),
245
+ ref: dropdownLiveSearchRef
246
+ }, /*#__PURE__*/_react.default.createElement("button", {
247
+ "data-testid": "dropdown-live-search--".concat(testId || '', "--container"),
248
+ className: "".concat(RC, "__trigger input__wrap ").concat(isOpen ? 'input__wrap--focus' : '', " ").concat(!value ? 'placeholder' : '', " ").concat(error ? 'error' : ''),
249
+ onClick: function onClick() {
250
+ return !isSearchable ? setIsOpen(!isOpen) : null;
251
+ },
252
+ onMouseDown: function onMouseDown() {
253
+ return setIsFocusedByClick(true);
254
+ },
255
+ onFocus: function onFocus() {
256
+ return !isFocusedByClick ? setIsOpen(true) : null;
257
+ }
258
+ }, isSearchable ? /*#__PURE__*/_react.default.createElement("input", {
259
+ ref: searchInputRef,
260
+ className: "".concat(RC, "__input"),
261
+ value: searchValue,
262
+ onChange: handle.onInputChange,
263
+ placeholder: placeholder,
264
+ onFocus: searchableInputFocus,
265
+ onClick: handle.onInputClick
266
+ }) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("span", {
267
+ className: "text"
268
+ }, labelByValue || placeholder)), /*#__PURE__*/_react.default.createElement("span", {
269
+ className: (0, _classnames.default)("".concat(RC, "__arrow"), (0, _defineProperty2.default)({}, "".concat(RC, "__arrow_active"), isOpen)),
270
+ onClick: function onClick() {
271
+ return setIsOpen(!isOpen);
272
+ }
273
+ }, isOpen ? /*#__PURE__*/_react.default.createElement(_reactFeather.ChevronUp, null) : /*#__PURE__*/_react.default.createElement(_reactFeather.ChevronDown, null))), isOpen && getListMarkUp());
274
+ };
275
+
276
+ var _default = DropdownLiveSearch;
277
+ exports.default = _default;
@@ -0,0 +1,193 @@
1
+ @import "../../../scss/vars";
2
+
3
+ .dropdown-live-search {
4
+ position: relative;
5
+ display: inline-flex;
6
+ flex-direction: column;
7
+ width: 100%;
8
+ border-radius: 7px;
9
+
10
+ &__trigger {
11
+ position: relative;
12
+ display: block;
13
+ align-items: center;
14
+ box-sizing: border-box;
15
+ width: 100%;
16
+ height: 28px;
17
+ cursor: pointer;
18
+ text-align: left;
19
+ border: 1px solid #E2E5EC;
20
+ border-radius: 3px;
21
+ background: #FFF;
22
+ font-weight: 400;
23
+
24
+ .text {
25
+ overflow: hidden;
26
+ max-width: calc(100% - 5px);
27
+ padding: 0 16px 0 8px;
28
+ white-space: nowrap;
29
+ text-overflow: ellipsis;
30
+ }
31
+
32
+ &.error {
33
+ border-color: $color--secondary;
34
+ }
35
+
36
+ &.placeholder .text {
37
+ opacity: 0.7;
38
+ }
39
+ }
40
+
41
+ &__input {
42
+ width: 100%;
43
+ height: 100%;
44
+ padding: 0 16px 0 8px;
45
+ text-overflow: ellipsis;
46
+ border: none;
47
+ background: none;
48
+ font-weight: 400;
49
+ box-sizing: border-box;
50
+ }
51
+
52
+ &__list {
53
+ position: relative;
54
+ z-index: 6;
55
+ top: 100%;
56
+ overflow-y: auto;
57
+ box-sizing: border-box;
58
+ min-width: 100%;
59
+ max-height: 320px;
60
+ margin-top: 4px;
61
+ padding: 5px 0;
62
+ border: 1px solid #E2E5EC;
63
+ background: #FFF;
64
+ box-shadow: 0 5px 20px rgb(0 0 0 / 15%);
65
+
66
+ &::-webkit-scrollbar {
67
+ width: 4px;
68
+ }
69
+
70
+ &::-webkit-scrollbar-track {
71
+ background: transparent;
72
+ }
73
+
74
+ &::-webkit-scrollbar-thumb {
75
+ border-radius: 4px;
76
+ background: $color--gray--dark;
77
+ }
78
+
79
+ &-top {
80
+ top: auto;
81
+ bottom: calc(100% + 4px);
82
+ box-shadow: 0 -3px 10px rgb(0 0 0 / 15%);
83
+ }
84
+
85
+ &-item {
86
+ position: relative;
87
+ display: flex;
88
+ overflow: hidden;
89
+ align-items: center;
90
+ width: 100%;
91
+ height: 24px;
92
+ padding: 0 20px 0 30px;
93
+ cursor: pointer;
94
+ white-space: nowrap;
95
+ color: $color--dark;
96
+ border: none;
97
+ background: transparent;
98
+ font-size: 13px;
99
+ font-weight: 400;
100
+ line-height: 24px;
101
+
102
+ &--modal {
103
+ position: relative;
104
+ width: 100%;
105
+ text-align: left;
106
+ letter-spacing: 0.2px;
107
+ color: #1F7499;
108
+ font-size: 14px;
109
+ line-height: 20px;
110
+
111
+ &::after {
112
+ position: absolute;
113
+ bottom: -2px;
114
+ width: 300%;
115
+ height: 1px;
116
+ content: "";
117
+ transform: translateX(-50%);
118
+ background-color: #E8E9EC;
119
+ }
120
+ }
121
+
122
+ &--no-options {
123
+ box-sizing: border-box;
124
+ }
125
+
126
+ &:hover,
127
+ &_active {
128
+ background: $color--gray--gentle;
129
+ }
130
+
131
+ &_disabled {
132
+ pointer-events: none;
133
+ opacity: 0.3;
134
+ }
135
+
136
+ &-postfix {
137
+ margin-left: 5px;
138
+ }
139
+ }
140
+
141
+ &--with-label {
142
+ top: 45px;
143
+ }
144
+ }
145
+
146
+ &__arrow {
147
+ position: absolute;
148
+ top: 50%;
149
+ right: 4px;
150
+ display: flex;
151
+ align-items: center;
152
+ width: 16px;
153
+ height: 16px;
154
+ transform: translate(0, -50%);
155
+
156
+ & svg {
157
+ width: 16px;
158
+ height: 16px;
159
+ }
160
+ }
161
+
162
+ &__active-icon {
163
+ position: absolute;
164
+ top: 0;
165
+ bottom: 0;
166
+ left: 9px;
167
+ display: none;
168
+ align-items: center;
169
+ margin: auto;
170
+
171
+ &_active {
172
+ display: flex;
173
+
174
+ & svg {
175
+ width: 16px;
176
+ height: 16px;
177
+ }
178
+ }
179
+ }
180
+
181
+ &__container {
182
+ position: fixed;
183
+ z-index: 99999;
184
+ display: block;
185
+ box-sizing: border-box;
186
+ top: 43px;
187
+ }
188
+
189
+ &.disabled {
190
+ pointer-events: none;
191
+ opacity: 0.5;
192
+ }
193
+ }
@@ -293,7 +293,8 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
293
293
  var uniProps = _objectSpread(_objectSpread({
294
294
  name: inputName,
295
295
  className: (0, _classnames.default)('input', className, {
296
- 'input--with-icon': icon
296
+ 'input--with-icon': icon,
297
+ 'input--with-delete': withDelete
297
298
  }),
298
299
  placeholder: placeholder,
299
300
  value: formatedValue,
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.useDebounce = void 0;
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ var useDebounce = function useDebounce(_ref) {
21
+ var searchValue = _ref.searchValue,
22
+ delay = _ref.delay;
23
+
24
+ var _useState = (0, _react.useState)(searchValue),
25
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
26
+ debouncedValue = _useState2[0],
27
+ setDebouncedValue = _useState2[1];
28
+
29
+ (0, _react.useEffect)(function () {
30
+ var handler = setTimeout(function () {
31
+ setDebouncedValue(searchValue);
32
+ }, delay);
33
+ return function () {
34
+ clearTimeout(handler);
35
+ };
36
+ }, [searchValue, delay]);
37
+ return debouncedValue;
38
+ };
39
+
40
+ exports.useDebounce = useDebounce;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.0.90",
3
+ "version": "1.0.92",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [