@synerise/ds-search 0.9.19 → 0.9.20

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 CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.9.20](https://github.com/Synerise/synerise-design/compare/@synerise/ds-search@0.9.19...@synerise/ds-search@0.9.20) (2024-11-28)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-search
9
+
10
+
11
+
12
+
13
+
6
14
  ## [0.9.19](https://github.com/Synerise/synerise-design/compare/@synerise/ds-search@0.9.18...@synerise/ds-search@0.9.19) (2024-11-21)
7
15
 
8
16
  **Note:** Version bump only for package @synerise/ds-search
@@ -2,13 +2,12 @@ import React from 'react';
2
2
  import Icon, { SearchM } from '@synerise/ds-icon';
3
3
  import Button from '@synerise/ds-button';
4
4
  import * as S from '../../Search.styles';
5
-
6
5
  var SearchButton = function SearchButton(_ref) {
7
6
  var inputOpen = _ref.inputOpen,
8
- hidden = _ref.hidden,
9
- onClick = _ref.onClick,
10
- inputFocused = _ref.inputFocused,
11
- clickable = _ref.clickable;
7
+ hidden = _ref.hidden,
8
+ onClick = _ref.onClick,
9
+ inputFocused = _ref.inputFocused,
10
+ clickable = _ref.clickable;
12
11
  return /*#__PURE__*/React.createElement(S.SearchButton, {
13
12
  isOpen: inputOpen,
14
13
  hidden: hidden,
@@ -25,5 +24,4 @@ var SearchButton = function SearchButton(_ref) {
25
24
  component: /*#__PURE__*/React.createElement(SearchM, null)
26
25
  })));
27
26
  };
28
-
29
27
  export default SearchButton;
@@ -2,10 +2,9 @@ import React from 'react';
2
2
  import Tooltip from '@synerise/ds-tooltip/dist/Tooltip';
3
3
  import Icon, { InfoFillS } from '@synerise/ds-icon';
4
4
  import * as S from '../../Search.styles';
5
-
6
5
  var SearchHeader = function SearchHeader(_ref) {
7
6
  var headerText = _ref.headerText,
8
- tooltip = _ref.tooltip;
7
+ tooltip = _ref.tooltip;
9
8
  return /*#__PURE__*/React.createElement(S.MenuHeader, null, headerText, tooltip && /*#__PURE__*/React.createElement(Tooltip, {
10
9
  type: "default",
11
10
  trigger: "hover",
@@ -14,5 +13,4 @@ var SearchHeader = function SearchHeader(_ref) {
14
13
  component: /*#__PURE__*/React.createElement(InfoFillS, null)
15
14
  }))));
16
15
  };
17
-
18
16
  export default SearchHeader;
@@ -1,15 +1,9 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
2
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
4
-
5
3
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
6
-
7
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
-
11
6
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
-
13
7
  import React from 'react';
14
8
  import onClickOutside from 'react-onclickoutside';
15
9
  import Input from 'antd/lib/input';
@@ -18,110 +12,86 @@ import { theme } from '@synerise/ds-core';
18
12
  import Icon, { Close3M } from '@synerise/ds-icon';
19
13
  import * as S from '../../Search.styles';
20
14
  import SearchButton from '../SearchButton/SearchButton';
21
-
22
15
  var SearchInput = /*#__PURE__*/function (_React$Component) {
23
16
  function SearchInput(props) {
24
17
  var _this;
25
-
26
- _this = _React$Component.call(this, props) || this; // eslint-disable-next-line react/state-in-constructor
27
-
18
+ _this = _React$Component.call(this, props) || this;
19
+ // eslint-disable-next-line react/state-in-constructor
28
20
  _defineProperty(_this, "inputRef", React.createRef());
29
-
30
21
  _defineProperty(_this, "componentDidUpdate", function () {
31
22
  var _this$props = _this.props,
32
- moveCursorToEnd = _this$props.moveCursorToEnd,
33
- value = _this$props.value;
23
+ moveCursorToEnd = _this$props.moveCursorToEnd,
24
+ value = _this$props.value;
34
25
  var input = _this.inputRef;
35
-
36
26
  if (moveCursorToEnd && input && input.current) {
37
27
  input.current.input.selectionStart = value.length || 0;
38
28
  input.current.input.selectionEnd = value.length || 0;
39
29
  }
40
30
  });
41
-
42
31
  _defineProperty(_this, "focusInput", function () {
43
32
  _this.inputRef.current && _this.inputRef.current.focus();
44
33
  });
45
-
46
34
  _defineProperty(_this, "toggleOpen", function () {
47
35
  var onToggle = _this.props.onToggle;
48
36
  var isInputOpen = _this.state.isInputOpen;
49
37
  onToggle && onToggle(!isInputOpen);
50
-
51
38
  _this.setState(function (prevState) {
52
39
  return {
53
40
  isInputOpen: !prevState.isInputOpen
54
41
  };
55
42
  });
56
43
  });
57
-
58
44
  _defineProperty(_this, "handleSearchButtonClick", function () {
59
45
  var _this$props2 = _this.props,
60
- alwaysExpanded = _this$props2.alwaysExpanded,
61
- onButtonClick = _this$props2.onButtonClick;
62
-
46
+ alwaysExpanded = _this$props2.alwaysExpanded,
47
+ onButtonClick = _this$props2.onButtonClick;
63
48
  if (!alwaysExpanded) {
64
49
  _this.toggleOpen();
65
-
66
50
  _this.focusInput();
67
-
68
51
  onButtonClick && onButtonClick();
69
52
  }
70
53
  });
71
-
72
54
  _defineProperty(_this, "handleClearValue", function () {
73
55
  var onClear = _this.props.onClear;
74
-
75
56
  _this.setState({
76
57
  inputOffset: 0,
77
58
  isResultChosen: false
78
59
  });
79
-
80
60
  _this.focusInput();
81
-
82
61
  onClear();
83
62
  });
84
-
85
63
  _defineProperty(_this, "handleChangeValue", function (_ref) {
86
64
  var value = _ref.target.value;
87
65
  var onChange = _this.props.onChange;
88
66
  onChange(value);
89
-
90
67
  _this.setState({
91
68
  isResultChosen: false
92
69
  });
93
70
  });
94
-
95
71
  _defineProperty(_this, "handleSearchInputContentClick", function () {
96
72
  var onClick = _this.props.onClick;
97
73
  onClick && onClick();
98
-
99
74
  _this.focusInput();
100
75
  });
101
-
102
76
  _defineProperty(_this, "handleOffsetWithFilter", function (ref) {
103
77
  ref && _this.setState({
104
78
  inputOffset: ref.getBoundingClientRect().width
105
79
  });
106
80
  });
107
-
108
81
  // This handler is used for onClickOutside HOC
109
82
  _defineProperty(_this, "handleClickOutside", function () {
110
83
  var _this$props3 = _this.props,
111
- closeOnClickOutside = _this$props3.closeOnClickOutside,
112
- onToggle = _this$props3.onToggle,
113
- value = _this$props3.value,
114
- filterLabel = _this$props3.filterLabel;
115
-
84
+ closeOnClickOutside = _this$props3.closeOnClickOutside,
85
+ onToggle = _this$props3.onToggle,
86
+ value = _this$props3.value,
87
+ filterLabel = _this$props3.filterLabel;
116
88
  if (closeOnClickOutside && !value && !filterLabel) {
117
89
  _this.setState({
118
90
  isInputOpen: false
119
91
  });
120
-
121
92
  onToggle && onToggle(false);
122
93
  }
123
94
  });
124
-
125
95
  _this.state = {
126
96
  inputOffset: 0,
127
97
  isInputOpen: props.alwaysExpanded || !!props.value || !!props.filterLabel,
@@ -130,52 +100,43 @@ var SearchInput = /*#__PURE__*/function (_React$Component) {
130
100
  };
131
101
  return _this;
132
102
  }
133
-
134
103
  _inheritsLoose(SearchInput, _React$Component);
135
-
136
104
  var _proto = SearchInput.prototype;
137
-
138
105
  _proto.getSnapshotBeforeUpdate = function getSnapshotBeforeUpdate(prevProps) {
139
106
  var _this2 = this;
140
-
141
107
  var _this$props4 = this.props,
142
- focusTrigger = _this$props4.focusTrigger,
143
- toggleTrigger = _this$props4.toggleTrigger;
144
-
108
+ focusTrigger = _this$props4.focusTrigger,
109
+ toggleTrigger = _this$props4.toggleTrigger;
145
110
  if (prevProps.focusTrigger !== focusTrigger) {
146
111
  setTimeout(function () {
147
112
  _this2.focusInput();
148
113
  }, 0);
149
114
  }
150
-
151
115
  if (prevProps.toggleTrigger !== toggleTrigger) {
152
116
  this.toggleOpen();
153
117
  }
154
-
155
118
  return null;
156
119
  };
157
-
158
120
  _proto.render = function render() {
159
121
  var _this3 = this;
160
-
161
122
  var _this$props5 = this.props,
162
- alwaysExpanded = _this$props5.alwaysExpanded,
163
- alwaysHighlight = _this$props5.alwaysHighlight,
164
- clearTooltip = _this$props5.clearTooltip,
165
- filterLabel = _this$props5.filterLabel,
166
- filterLookupKey = _this$props5.filterLookupKey,
167
- onKeyDown = _this$props5.onKeyDown,
168
- placeholder = _this$props5.placeholder,
169
- textLookupKey = _this$props5.textLookupKey,
170
- value = _this$props5.value,
171
- disableInput = _this$props5.disableInput,
172
- _this$props5$inputPro = _this$props5.inputProps,
173
- inputProps = _this$props5$inputPro === void 0 ? {} : _this$props5$inputPro;
123
+ alwaysExpanded = _this$props5.alwaysExpanded,
124
+ alwaysHighlight = _this$props5.alwaysHighlight,
125
+ clearTooltip = _this$props5.clearTooltip,
126
+ filterLabel = _this$props5.filterLabel,
127
+ filterLookupKey = _this$props5.filterLookupKey,
128
+ onKeyDown = _this$props5.onKeyDown,
129
+ placeholder = _this$props5.placeholder,
130
+ textLookupKey = _this$props5.textLookupKey,
131
+ value = _this$props5.value,
132
+ disableInput = _this$props5.disableInput,
133
+ _this$props5$inputPro = _this$props5.inputProps,
134
+ inputProps = _this$props5$inputPro === void 0 ? {} : _this$props5$inputPro;
174
135
  var _this$state = this.state,
175
- isInputOpen = _this$state.isInputOpen,
176
- inputOffset = _this$state.inputOffset,
177
- isResultChosen = _this$state.isResultChosen,
178
- isInputFocused = _this$state.isInputFocused;
136
+ isInputOpen = _this$state.isInputOpen,
137
+ inputOffset = _this$state.inputOffset,
138
+ isResultChosen = _this$state.isResultChosen,
139
+ isInputFocused = _this$state.isInputFocused;
179
140
  return /*#__PURE__*/React.createElement(S.SearchInputWrapper, null, /*#__PURE__*/React.createElement(S.SearchInputContent, {
180
141
  className: isInputOpen || !!value || !!filterLabel ? 'is-open search-input-wrapper' : 'search-input-wrapper',
181
142
  offset: inputOffset,
@@ -227,8 +188,6 @@ var SearchInput = /*#__PURE__*/function (_React$Component) {
227
188
  size: 18
228
189
  })));
229
190
  };
230
-
231
191
  return SearchInput;
232
192
  }(React.Component);
233
-
234
193
  export default onClickOutside(SearchInput);
@@ -1,37 +1,29 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
2
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
-
11
6
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
-
13
7
  import React, { useMemo, useRef, useEffect, cloneElement } from 'react';
14
8
  import Menu from '@synerise/ds-menu';
15
9
  import { FixedSizeList as List } from 'react-window';
16
10
  var listStyle = {
17
11
  overflowX: 'unset',
18
12
  overflowY: 'unset'
19
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ };
20
14
 
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
16
  export function renderSearchList(props, children) {
22
17
  return /*#__PURE__*/React.createElement(SearchItems, props, children);
23
18
  }
24
-
25
19
  var rowRenderer = function rowRenderer(_ref) {
26
20
  var index = _ref.index,
27
- style = _ref.style,
28
- data = _ref.data;
21
+ style = _ref.style,
22
+ data = _ref.data;
29
23
  var item = data && data.items[index];
30
24
  var itemReturnedFromRenderer = data.itemRender(item);
31
25
  var rendererCustomStyles = itemReturnedFromRenderer && itemReturnedFromRenderer.props && itemReturnedFromRenderer.props.style || {};
32
-
33
26
  var mergedStyles = _objectSpread({}, rendererCustomStyles, {}, style);
34
-
35
27
  return cloneElement(itemReturnedFromRenderer, _objectSpread({}, itemReturnedFromRenderer.props, {
36
28
  style: mergedStyles,
37
29
  highlight: data.highlight,
@@ -41,35 +33,30 @@ var rowRenderer = function rowRenderer(_ref) {
41
33
  className: 'ds-search-item'
42
34
  }));
43
35
  };
44
-
45
36
  var SearchItems = function SearchItems(_ref2) {
46
37
  var data = _ref2.data,
47
- height = _ref2.height,
48
- highlight = _ref2.highlight,
49
- itemRender = _ref2.itemRender,
50
- listProps = _ref2.listProps,
51
- onItemClick = _ref2.onItemClick,
52
- rowHeight = _ref2.rowHeight,
53
- visibleRows = _ref2.visibleRows,
54
- width = _ref2.width,
55
- _ref2$renderInMenu = _ref2.renderInMenu,
56
- renderInMenu = _ref2$renderInMenu === void 0 ? true : _ref2$renderInMenu;
38
+ height = _ref2.height,
39
+ highlight = _ref2.highlight,
40
+ itemRender = _ref2.itemRender,
41
+ listProps = _ref2.listProps,
42
+ onItemClick = _ref2.onItemClick,
43
+ rowHeight = _ref2.rowHeight,
44
+ visibleRows = _ref2.visibleRows,
45
+ width = _ref2.width,
46
+ _ref2$renderInMenu = _ref2.renderInMenu,
47
+ renderInMenu = _ref2$renderInMenu === void 0 ? true : _ref2$renderInMenu;
57
48
  var listRef = useRef(null);
58
49
  var listHeight = useMemo(function () {
59
50
  if (data) {
60
51
  var dataHeight = data.length * rowHeight;
61
-
62
52
  if (visibleRows) {
63
53
  return visibleRows < data.length ? visibleRows * rowHeight : dataHeight;
64
54
  }
65
-
66
55
  if (height) {
67
56
  return dataHeight > height ? height : dataHeight;
68
57
  }
69
-
70
58
  return dataHeight;
71
59
  }
72
-
73
60
  return 0;
74
61
  }, [data, height, rowHeight, visibleRows]);
75
62
  useEffect(function () {
@@ -93,5 +80,4 @@ var SearchItems = function SearchItems(_ref2) {
93
80
  }, listProps), rowRenderer);
94
81
  return renderInMenu ? /*#__PURE__*/React.createElement(Menu, null, list) : /*#__PURE__*/React.createElement(React.Fragment, null, list);
95
82
  };
96
-
97
83
  export default SearchItems;
package/dist/Search.js CHANGED
@@ -1,17 +1,10 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
6
-
7
4
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
8
-
9
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
-
11
6
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
12
-
13
7
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
-
15
8
  import React from 'react';
16
9
  import onClickOutside from 'react-onclickoutside';
17
10
  import Scrollbar from '@synerise/ds-scrollbar';
@@ -24,52 +17,44 @@ var MENU_WIDTH_OFFSET = 17;
24
17
  export var INPUT_EXPAND_ANIMATION_DURATION = 100;
25
18
  var SCROLLBAR_HEIGHT_OFFSET = 28;
26
19
  var LIST_HEADER_HEIGHT = 42;
27
-
28
20
  var getParametersScrollTop = function getParametersScrollTop(_ref) {
29
21
  var scrollTop = _ref.scrollTop,
30
- rowHeight = _ref.rowHeight,
31
- recent = _ref.recent;
22
+ rowHeight = _ref.rowHeight,
23
+ recent = _ref.recent;
32
24
  return scrollTop - LIST_HEADER_HEIGHT - (hasSomeElement(recent) ? recent.length * rowHeight : 0);
33
25
  };
34
-
35
26
  var Search = /*#__PURE__*/function (_React$PureComponent) {
36
27
  function Search(props) {
37
28
  var _this;
38
-
39
- _this = _React$PureComponent.call(this, props) || this; // eslint-disable-next-line react/state-in-constructor
40
-
29
+ _this = _React$PureComponent.call(this, props) || this;
30
+ // eslint-disable-next-line react/state-in-constructor
41
31
  _defineProperty(_this, "wrapperRef", React.createRef());
42
-
43
32
  // This handler is used for onClickOutside HOC
44
33
  _defineProperty(_this, "handleClickOutside", function () {
45
34
  var _this$state = _this.state,
46
- isInputOpen = _this$state.isInputOpen,
47
- label = _this$state.label,
48
- toggleInputTrigger = _this$state.toggleInputTrigger;
35
+ isInputOpen = _this$state.isInputOpen,
36
+ label = _this$state.label,
37
+ toggleInputTrigger = _this$state.toggleInputTrigger;
49
38
  var _this$props = _this.props,
50
- value = _this$props.value,
51
- alwaysExpanded = _this$props.alwaysExpanded;
52
-
39
+ value = _this$props.value,
40
+ alwaysExpanded = _this$props.alwaysExpanded;
53
41
  if (isInputOpen && !value && !label && !alwaysExpanded) {
54
42
  _this.setState({
55
43
  toggleInputTrigger: !toggleInputTrigger
56
44
  });
57
45
  }
58
-
59
46
  _this.setState({
60
47
  isListVisible: false,
61
48
  scrollbarScrollTop: 0
62
49
  });
63
50
  });
64
-
65
51
  _defineProperty(_this, "handleClearValue", function () {
66
52
  var _this$props2 = _this.props,
67
- parameters = _this$props2.parameters,
68
- recent = _this$props2.recent,
69
- suggestions = _this$props2.suggestions,
70
- onClear = _this$props2.onClear;
53
+ parameters = _this$props2.parameters,
54
+ recent = _this$props2.recent,
55
+ suggestions = _this$props2.suggestions,
56
+ onClear = _this$props2.onClear;
71
57
  onClear && onClear();
72
-
73
58
  _this.setState({
74
59
  label: null,
75
60
  filteredRecent: recent,
@@ -78,7 +63,6 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
78
63
  isResultChosen: false
79
64
  });
80
65
  });
81
-
82
66
  _this.state = {
83
67
  isInputOpen: !!props.value || !!props.parameterValue || !!props.alwaysExpanded,
84
68
  label: props.parameterValue ? props.parameters.find(function (param) {
@@ -97,52 +81,43 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
97
81
  };
98
82
  return _this;
99
83
  }
100
-
101
84
  _inheritsLoose(Search, _React$PureComponent);
102
-
103
85
  var _proto = Search.prototype;
104
-
105
86
  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
106
87
  var _prevProps$suggestion;
107
-
108
88
  var _this$props3 = this.props,
109
- recent = _this$props3.recent,
110
- suggestions = _this$props3.suggestions,
111
- parameters = _this$props3.parameters,
112
- value = _this$props3.value,
113
- textLookupConfig = _this$props3.textLookupConfig,
114
- hideLabel = _this$props3.hideLabel,
115
- parameterValue = _this$props3.parameterValue;
116
-
89
+ recent = _this$props3.recent,
90
+ suggestions = _this$props3.suggestions,
91
+ parameters = _this$props3.parameters,
92
+ value = _this$props3.value,
93
+ textLookupConfig = _this$props3.textLookupConfig,
94
+ hideLabel = _this$props3.hideLabel,
95
+ parameterValue = _this$props3.parameterValue;
117
96
  if (prevProps.value !== value && !value || prevProps.parameterValue && !parameterValue) {
118
- this.handleChange(value); // eslint-disable-next-line react/no-did-update-set-state
119
-
97
+ this.handleChange(value);
98
+ // eslint-disable-next-line react/no-did-update-set-state
120
99
  this.setState({
121
100
  isResultChosen: false
122
101
  });
123
102
  }
124
-
125
103
  if (prevProps.recent.length !== recent.length) {
126
104
  // eslint-disable-next-line react/no-did-update-set-state
127
105
  this.setState({
128
106
  filteredRecent: getAllElementsFiltered(recent, value, textLookupConfig.recent)
129
107
  });
130
108
  }
131
-
132
109
  if (prevProps.parameters.length !== parameters.length) {
133
110
  // eslint-disable-next-line react/no-did-update-set-state
134
111
  this.setState({
135
112
  filteredParameters: parameterValue ? parameters : getAllElementsFiltered(parameters, value, textLookupConfig.parameters)
136
113
  });
137
114
  }
138
-
139
115
  if (suggestions && ((_prevProps$suggestion = prevProps.suggestions) == null ? void 0 : _prevProps$suggestion.length) !== suggestions.length) {
140
116
  // eslint-disable-next-line react/no-did-update-set-state
141
117
  this.setState({
142
118
  filteredSuggestions: getAllElementsFiltered(suggestions, value, textLookupConfig.suggestions)
143
119
  });
144
120
  }
145
-
146
121
  if (hideLabel && prevProps.hideLabel !== hideLabel) {
147
122
  // eslint-disable-next-line react/no-did-update-set-state
148
123
  this.setState({
@@ -151,14 +126,12 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
151
126
  });
152
127
  }
153
128
  };
154
-
155
129
  _proto.onKeyDown = function onKeyDown(e) {
156
130
  var _this$props4 = this.props,
157
- value = _this$props4.value,
158
- onParameterValueChange = _this$props4.onParameterValueChange,
159
- recent = _this$props4.recent;
131
+ value = _this$props4.value,
132
+ onParameterValueChange = _this$props4.onParameterValueChange,
133
+ recent = _this$props4.recent;
160
134
  var isInputOpen = this.state.isInputOpen;
161
-
162
135
  if (e.key === 'Backspace' && value === '' && isInputOpen) {
163
136
  this.setState({
164
137
  label: null,
@@ -167,43 +140,35 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
167
140
  onParameterValueChange('', null);
168
141
  return;
169
142
  }
170
-
171
143
  if (e.key === 'Enter' && isInputOpen) {
172
144
  this.setState({
173
145
  isResultChosen: !!value
174
146
  });
175
147
  }
176
-
177
148
  this.setState({
178
149
  moveCursorToEnd: false
179
150
  });
180
151
  };
181
-
182
152
  _proto.getSearchWrapperWidth = function getSearchWrapperWidth() {
183
153
  var width = this.props.width;
184
-
185
154
  if (width) {
186
155
  return width - MENU_WIDTH_OFFSET;
187
156
  }
188
-
189
157
  if (this.wrapperRef !== null && this.wrapperRef.current && this.wrapperRef.current.clientWidth > MENU_WIDTH_OFFSET) {
190
158
  return this.wrapperRef.current.clientWidth - MENU_WIDTH_OFFSET;
191
159
  }
192
-
193
160
  return 0;
194
161
  };
195
-
196
162
  _proto.handleChange = function handleChange(currentValue) {
197
163
  var _this$props5 = this.props,
198
- parameterValue = _this$props5.parameterValue,
199
- recent = _this$props5.recent,
200
- suggestions = _this$props5.suggestions,
201
- parameters = _this$props5.parameters,
202
- onValueChange = _this$props5.onValueChange,
203
- textLookupConfig = _this$props5.textLookupConfig;
164
+ parameterValue = _this$props5.parameterValue,
165
+ recent = _this$props5.recent,
166
+ suggestions = _this$props5.suggestions,
167
+ parameters = _this$props5.parameters,
168
+ onValueChange = _this$props5.onValueChange,
169
+ textLookupConfig = _this$props5.textLookupConfig;
204
170
  var isAnythingToShow;
205
171
  onValueChange(currentValue);
206
-
207
172
  if (parameterValue) {
208
173
  var matchingSuggestions = getAllElementsFiltered(suggestions, currentValue, textLookupConfig.suggestions);
209
174
  this.setState({
@@ -219,23 +184,20 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
219
184
  });
220
185
  isAnythingToShow = matchingRecent.length > 0 || matchingParameters.length > 0;
221
186
  }
222
-
223
187
  this.setState({
224
188
  isResultChosen: false,
225
189
  isListVisible: isAnythingToShow
226
190
  });
227
191
  };
228
-
229
192
  _proto.isListItemRendered = function isListItemRendered() {
230
193
  var _this$props6 = this.props,
231
- suggestions = _this$props6.suggestions,
232
- recent = _this$props6.recent,
233
- parameters = _this$props6.parameters,
234
- value = _this$props6.value,
235
- parameterValue = _this$props6.parameterValue,
236
- textLookupConfig = _this$props6.textLookupConfig;
194
+ suggestions = _this$props6.suggestions,
195
+ recent = _this$props6.recent,
196
+ parameters = _this$props6.parameters,
197
+ value = _this$props6.value,
198
+ parameterValue = _this$props6.parameterValue,
199
+ textLookupConfig = _this$props6.textLookupConfig;
237
200
  var isAnythingToShow;
238
-
239
201
  if (parameterValue) {
240
202
  isAnythingToShow = hasSomeElementFiltered(suggestions, value, textLookupConfig.suggestions);
241
203
  } else {
@@ -243,27 +205,24 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
243
205
  var anyFilter = hasSomeElementFiltered(parameters, value, textLookupConfig.parameters);
244
206
  isAnythingToShow = anyFilter || anyRecentItem;
245
207
  }
246
-
247
208
  return isAnythingToShow;
248
209
  };
249
-
250
210
  _proto.selectResult = function selectResult(item, dataKey) {
251
211
  var _this$props7 = this.props,
252
- onValueChange = _this$props7.onValueChange,
253
- textLookupConfig = _this$props7.textLookupConfig;
212
+ onValueChange = _this$props7.onValueChange,
213
+ textLookupConfig = _this$props7.textLookupConfig;
254
214
  this.setState({
255
215
  isResultChosen: true,
256
216
  moveCursorToEnd: true
257
217
  });
258
218
  onValueChange(item[textLookupConfig[dataKey]]);
259
219
  };
260
-
261
220
  _proto.selectFilter = function selectFilter(item) {
262
221
  var _this$props8 = this.props,
263
- onValueChange = _this$props8.onValueChange,
264
- onParameterValueChange = _this$props8.onParameterValueChange,
265
- filterLookupKey = _this$props8.filterLookupKey,
266
- textLookupConfig = _this$props8.textLookupConfig;
222
+ onValueChange = _this$props8.onValueChange,
223
+ onParameterValueChange = _this$props8.onParameterValueChange,
224
+ filterLookupKey = _this$props8.filterLookupKey,
225
+ textLookupConfig = _this$props8.textLookupConfig;
267
226
  var focusInputTrigger = this.state.focusInputTrigger;
268
227
  onValueChange('');
269
228
  this.setState({
@@ -271,10 +230,10 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
271
230
  focusInputTrigger: !focusInputTrigger,
272
231
  moveCursorToEnd: true
273
232
  });
274
-
275
233
  if (filterLookupKey && item[filterLookupKey]) {
276
- onValueChange(item[textLookupConfig.parameters]); // @ts-ignore
234
+ onValueChange(item[textLookupConfig.parameters]);
277
235
 
236
+ // @ts-ignore
278
237
  onParameterValueChange(item[filterLookupKey], item);
279
238
  this.setState({
280
239
  isResultChosen: true
@@ -284,22 +243,20 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
284
243
  onParameterValueChange(item[textLookupConfig.parameters], item);
285
244
  }
286
245
  };
287
-
288
246
  _proto.renderRecentItems = function renderRecentItems() {
289
247
  var _this2 = this;
290
-
291
248
  var _this$props9 = this.props,
292
- recent = _this$props9.recent,
293
- recentDisplayProps = _this$props9.recentDisplayProps,
294
- value = _this$props9.value;
249
+ recent = _this$props9.recent,
250
+ recentDisplayProps = _this$props9.recentDisplayProps,
251
+ value = _this$props9.value;
295
252
  var _this$state2 = this.state,
296
- label = _this$state2.label,
297
- filteredRecent = _this$state2.filteredRecent,
298
- itemsListWidth = _this$state2.itemsListWidth;
253
+ label = _this$state2.label,
254
+ filteredRecent = _this$state2.filteredRecent,
255
+ itemsListWidth = _this$state2.itemsListWidth;
299
256
  var title = recentDisplayProps.title,
300
- tooltip = recentDisplayProps.tooltip,
301
- rowHeight = recentDisplayProps.rowHeight,
302
- itemRender = recentDisplayProps.itemRender;
257
+ tooltip = recentDisplayProps.tooltip,
258
+ rowHeight = recentDisplayProps.rowHeight,
259
+ itemRender = recentDisplayProps.itemRender;
303
260
  return recent && !label && hasSomeElement(filteredRecent) && /*#__PURE__*/React.createElement(React.Fragment, null, !!title && /*#__PURE__*/React.createElement(SearchHeader, {
304
261
  headerText: title,
305
262
  tooltip: tooltip
@@ -314,27 +271,25 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
314
271
  width: itemsListWidth
315
272
  }));
316
273
  };
317
-
318
274
  _proto.renderParameters = function renderParameters() {
319
275
  var _this3 = this;
320
-
321
276
  var _this$props10 = this.props,
322
- parameters = _this$props10.parameters,
323
- parametersDisplayProps = _this$props10.parametersDisplayProps,
324
- value = _this$props10.value,
325
- dropdownMaxHeight = _this$props10.dropdownMaxHeight,
326
- recentDisplayProps = _this$props10.recentDisplayProps;
277
+ parameters = _this$props10.parameters,
278
+ parametersDisplayProps = _this$props10.parametersDisplayProps,
279
+ value = _this$props10.value,
280
+ dropdownMaxHeight = _this$props10.dropdownMaxHeight,
281
+ recentDisplayProps = _this$props10.recentDisplayProps;
327
282
  var _this$state3 = this.state,
328
- label = _this$state3.label,
329
- filteredParameters = _this$state3.filteredParameters,
330
- itemsListWidth = _this$state3.itemsListWidth,
331
- scrollbarScrollTop = _this$state3.scrollbarScrollTop,
332
- filteredRecent = _this$state3.filteredRecent;
283
+ label = _this$state3.label,
284
+ filteredParameters = _this$state3.filteredParameters,
285
+ itemsListWidth = _this$state3.itemsListWidth,
286
+ scrollbarScrollTop = _this$state3.scrollbarScrollTop,
287
+ filteredRecent = _this$state3.filteredRecent;
333
288
  var title = parametersDisplayProps.title,
334
- tooltip = parametersDisplayProps.tooltip,
335
- rowHeight = parametersDisplayProps.rowHeight,
336
- itemRender = parametersDisplayProps.itemRender,
337
- listProps = parametersDisplayProps.listProps;
289
+ tooltip = parametersDisplayProps.tooltip,
290
+ rowHeight = parametersDisplayProps.rowHeight,
291
+ itemRender = parametersDisplayProps.itemRender,
292
+ listProps = parametersDisplayProps.listProps;
338
293
  return parameters && !label && hasSomeElement(filteredParameters) && /*#__PURE__*/React.createElement(React.Fragment, null, !!title && /*#__PURE__*/React.createElement(SearchHeader, {
339
294
  headerText: title,
340
295
  tooltip: tooltip
@@ -357,21 +312,19 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
357
312
  }, listProps || {})
358
313
  }));
359
314
  };
360
-
361
315
  _proto.renderSuggestions = function renderSuggestions() {
362
316
  var _this4 = this;
363
-
364
317
  var _this$props11 = this.props,
365
- suggestions = _this$props11.suggestions,
366
- parameterValue = _this$props11.parameterValue,
367
- suggestionsDisplayProps = _this$props11.suggestionsDisplayProps,
368
- value = _this$props11.value,
369
- dropdownMaxHeight = _this$props11.dropdownMaxHeight;
318
+ suggestions = _this$props11.suggestions,
319
+ parameterValue = _this$props11.parameterValue,
320
+ suggestionsDisplayProps = _this$props11.suggestionsDisplayProps,
321
+ value = _this$props11.value,
322
+ dropdownMaxHeight = _this$props11.dropdownMaxHeight;
370
323
  var _this$state4 = this.state,
371
- isResultChosen = _this$state4.isResultChosen,
372
- itemsListWidth = _this$state4.itemsListWidth,
373
- filteredSuggestions = _this$state4.filteredSuggestions,
374
- scrollbarScrollTop = _this$state4.scrollbarScrollTop;
324
+ isResultChosen = _this$state4.isResultChosen,
325
+ itemsListWidth = _this$state4.itemsListWidth,
326
+ filteredSuggestions = _this$state4.filteredSuggestions,
327
+ scrollbarScrollTop = _this$state4.scrollbarScrollTop;
375
328
  return suggestions && suggestionsDisplayProps && parameterValue && !isResultChosen && filteredSuggestions && hasSomeElement(filteredSuggestions) && /*#__PURE__*/React.createElement(React.Fragment, null, !!suggestionsDisplayProps.title && /*#__PURE__*/React.createElement(SearchHeader, {
376
329
  headerText: suggestionsDisplayProps.title,
377
330
  tooltip: suggestionsDisplayProps.tooltip
@@ -390,25 +343,23 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
390
343
  }, suggestionsDisplayProps.listProps || {})
391
344
  }));
392
345
  };
393
-
394
346
  _proto.renderInputWrapper = function renderInputWrapper() {
395
347
  var _this5 = this;
396
-
397
348
  var _this$props12 = this.props,
398
- placeholder = _this$props12.placeholder,
399
- clearTooltip = _this$props12.clearTooltip,
400
- value = _this$props12.value,
401
- textLookupConfig = _this$props12.textLookupConfig,
402
- filterLookupKey = _this$props12.filterLookupKey,
403
- disableInput = _this$props12.disableInput,
404
- inputProps = _this$props12.inputProps,
405
- alwaysExpanded = _this$props12.alwaysExpanded;
349
+ placeholder = _this$props12.placeholder,
350
+ clearTooltip = _this$props12.clearTooltip,
351
+ value = _this$props12.value,
352
+ textLookupConfig = _this$props12.textLookupConfig,
353
+ filterLookupKey = _this$props12.filterLookupKey,
354
+ disableInput = _this$props12.disableInput,
355
+ inputProps = _this$props12.inputProps,
356
+ alwaysExpanded = _this$props12.alwaysExpanded;
406
357
  var _this$state5 = this.state,
407
- label = _this$state5.label,
408
- isListVisible = _this$state5.isListVisible,
409
- focusInputTrigger = _this$state5.focusInputTrigger,
410
- toggleInputTrigger = _this$state5.toggleInputTrigger,
411
- moveCursorToEnd = _this$state5.moveCursorToEnd;
358
+ label = _this$state5.label,
359
+ isListVisible = _this$state5.isListVisible,
360
+ focusInputTrigger = _this$state5.focusInputTrigger,
361
+ toggleInputTrigger = _this$state5.toggleInputTrigger,
362
+ moveCursorToEnd = _this$state5.moveCursorToEnd;
412
363
  return /*#__PURE__*/React.createElement(SearchInput, {
413
364
  alwaysHighlight: true,
414
365
  clearTooltip: clearTooltip,
@@ -439,7 +390,6 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
439
390
  isListVisible: toggle,
440
391
  isInputOpen: toggle
441
392
  });
442
-
443
393
  setTimeout(function () {
444
394
  _this5.setState({
445
395
  itemsListWidth: _this5.getSearchWrapperWidth()
@@ -456,23 +406,21 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
456
406
  closeOnClickOutside: !alwaysExpanded && !isListVisible
457
407
  });
458
408
  };
459
-
460
409
  _proto.render = function render() {
461
410
  var _this6 = this;
462
-
463
411
  var _this$props13 = this.props,
464
- divider = _this$props13.divider,
465
- dropdownMaxHeight = _this$props13.dropdownMaxHeight,
466
- width = _this$props13.width,
467
- style = _this$props13.style;
412
+ divider = _this$props13.divider,
413
+ dropdownMaxHeight = _this$props13.dropdownMaxHeight,
414
+ width = _this$props13.width,
415
+ style = _this$props13.style;
468
416
  var _this$state6 = this.state,
469
- isInputOpen = _this$state6.isInputOpen,
470
- label = _this$state6.label,
471
- isListVisible = _this$state6.isListVisible,
472
- focusInputTrigger = _this$state6.focusInputTrigger,
473
- isResultChosen = _this$state6.isResultChosen,
474
- filteredParameters = _this$state6.filteredParameters,
475
- filteredRecent = _this$state6.filteredRecent;
417
+ isInputOpen = _this$state6.isInputOpen,
418
+ label = _this$state6.label,
419
+ isListVisible = _this$state6.isListVisible,
420
+ focusInputTrigger = _this$state6.focusInputTrigger,
421
+ isResultChosen = _this$state6.isResultChosen,
422
+ filteredParameters = _this$state6.filteredParameters,
423
+ filteredRecent = _this$state6.filteredRecent;
476
424
  return /*#__PURE__*/React.createElement(S.SearchWrapper, {
477
425
  ref: this.wrapperRef,
478
426
  className: "SearchWrapper",
@@ -500,15 +448,12 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
500
448
  maxHeight: dropdownMaxHeight - SCROLLBAR_HEIGHT_OFFSET,
501
449
  onScroll: function onScroll(_ref2) {
502
450
  var currentTarget = _ref2.currentTarget;
503
-
504
451
  _this6.setState({
505
452
  scrollbarScrollTop: currentTarget.scrollTop
506
453
  });
507
454
  }
508
455
  }, this.renderRecentItems(), !!(filteredParameters != null && filteredParameters.length) && !!(filteredRecent != null && filteredRecent.length) && !label && divider, this.renderParameters(), this.renderSuggestions()))));
509
456
  };
510
-
511
457
  return Search;
512
458
  }(React.PureComponent);
513
-
514
459
  export default onClickOutside(Search);
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
- export var SelectResultDataKeys;
3
2
 
3
+ export var SelectResultDataKeys;
4
4
  (function (SelectResultDataKeys) {
5
5
  SelectResultDataKeys["RECENT"] = "recent";
6
6
  SelectResultDataKeys["SUGGESTIONS"] = "suggestions";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-search",
3
- "version": "0.9.19",
3
+ "version": "0.9.20",
4
4
  "description": "Search UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -34,11 +34,11 @@
34
34
  ],
35
35
  "types": "dist/index.d.ts",
36
36
  "dependencies": {
37
- "@synerise/ds-button": "^0.21.19",
38
- "@synerise/ds-icon": "^0.67.0",
39
- "@synerise/ds-menu": "^0.20.6",
40
- "@synerise/ds-scrollbar": "^0.11.19",
41
- "@synerise/ds-tooltip": "^0.14.49",
37
+ "@synerise/ds-button": "^0.21.20",
38
+ "@synerise/ds-icon": "^0.67.1",
39
+ "@synerise/ds-menu": "^0.20.7",
40
+ "@synerise/ds-scrollbar": "^0.11.20",
41
+ "@synerise/ds-tooltip": "^0.14.50",
42
42
  "@synerise/ds-utils": "^0.31.2",
43
43
  "react-onclickoutside": "^6.9.0",
44
44
  "react-window": "^1.8.5"
@@ -49,5 +49,5 @@
49
49
  "react": ">=16.9.0 <= 17.0.2",
50
50
  "styled-components": "5.0.1"
51
51
  },
52
- "gitHead": "05f083c767e2cec3c2f91c9475aee89852a77d6c"
52
+ "gitHead": "4a56ee7ef816c22341ce704154dc7aa65b7d1dcc"
53
53
  }