react-asc 18.6.1 → 18.7.3

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/index.js CHANGED
@@ -261,8 +261,9 @@ styleInject(css_248z$I);
261
261
  // multiple
262
262
  // custom template render items
263
263
  const AutoComplete = (props) => {
264
- const { id, name, className, options = [], openOnFocus = true, disabled, readOnly, onChange, value } = props;
264
+ const { id, name, className, options = [], openOnFocus = true, disabled, readOnly, debounce = 0, placeholder, showClearButton, onChange, onSelect, value } = props;
265
265
  const [model, setModel] = React.useState('');
266
+ const [searchText, setSearchText] = React.useState('');
266
267
  const [isShow, setIsShow] = React.useState(false);
267
268
  const [optionsTemp, setOptionsTemp] = React.useState([]);
268
269
  const selectConainter = React.useRef(null);
@@ -273,9 +274,31 @@ const AutoComplete = (props) => {
273
274
  }
274
275
  }, [value]);
275
276
  React.useEffect(() => {
276
- const optionsOrigin = JSON.parse(JSON.stringify(options));
277
- setOptionsTemp(optionsOrigin);
277
+ if (options && options.length > 0) {
278
+ const optionsOrigin = JSON.parse(JSON.stringify(options));
279
+ const regex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi');
280
+ const optionsFiltered = optionsOrigin.filter(o => { var _a; return (_a = o.label) === null || _a === void 0 ? void 0 : _a.match(regex); });
281
+ setOptionsTemp(optionsFiltered);
282
+ }
278
283
  }, [options]);
284
+ useDebounce(() => { onChange && onChange(searchText); }, debounce, [searchText]);
285
+ React.useEffect(() => {
286
+ if (isShow === true) {
287
+ document.body.classList.add('modal-open');
288
+ const main = document.querySelector('.main');
289
+ main === null || main === void 0 ? void 0 : main.classList.add('modal-open');
290
+ }
291
+ else {
292
+ document.body.classList.remove('modal-open');
293
+ const main = document.querySelector('.main');
294
+ main === null || main === void 0 ? void 0 : main.classList.remove('modal-open');
295
+ }
296
+ }, [isShow]);
297
+ React.useEffect(() => {
298
+ return () => {
299
+ document.body.classList.remove('modal-open');
300
+ };
301
+ }, []);
279
302
  const getCssClass = () => {
280
303
  const cssClasses = [];
281
304
  className && cssClasses.push(className);
@@ -286,26 +309,29 @@ const AutoComplete = (props) => {
286
309
  const hide = () => setIsShow(false);
287
310
  const handleOnClick = (option) => {
288
311
  if (model !== option.value) {
289
- onChange && onChange(option.value);
312
+ onSelect && onSelect(option);
290
313
  }
291
314
  setModel(option.label);
292
315
  hide();
293
316
  };
294
317
  const handleOnChange = (e) => {
295
- const optionsOrigin = JSON.parse(JSON.stringify(options));
296
- const searchText = e.target.value;
297
- setModel(searchText);
298
- const regex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi');
299
- const optionsFiltered = optionsOrigin.filter(o => { var _a; return (_a = o.label) === null || _a === void 0 ? void 0 : _a.match(regex); });
300
- setOptionsTemp(optionsFiltered);
318
+ setModel(e.target.value);
319
+ setSearchText(e.target.value);
301
320
  show();
302
321
  };
303
322
  const handleOnFocus = () => {
304
323
  openOnFocus && show();
305
324
  };
325
+ const handleClickReset = () => {
326
+ setModel('');
327
+ setSearchText('');
328
+ };
306
329
  return (React__default['default'].createElement(React__default['default'].Fragment, null,
307
330
  React__default['default'].createElement("div", { ref: selectConainter, className: styles$I.selectContainer },
308
- React__default['default'].createElement("input", { type: "text", className: getCssClass(), id: id, name: name, tabIndex: 0, readOnly: readOnly, disabled: disabled, onChange: handleOnChange, onFocus: handleOnFocus, value: model }),
331
+ React__default['default'].createElement("div", { className: "d-flex" },
332
+ React__default['default'].createElement("input", { type: "text", className: getCssClass(), id: id, name: name, tabIndex: 0, readOnly: readOnly, disabled: disabled, onChange: handleOnChange, onFocus: handleOnFocus, placeholder: placeholder, value: model }),
333
+ showClearButton && (model === null || model === void 0 ? void 0 : model.length) > 0 &&
334
+ React__default['default'].createElement(IconButton, { icon: React__default['default'].createElement(TimesSolidIcon, null), onClick: handleClickReset })),
309
335
  isShow &&
310
336
  React__default['default'].createElement(React__default['default'].Fragment, null,
311
337
  React__default['default'].createElement("div", { className: styles$I.selectMenu },
@@ -2134,6 +2160,15 @@ const useConstructor = (callBack = () => { }) => {
2134
2160
  setHasBeenCalled(true);
2135
2161
  };
2136
2162
 
2163
+ function useDebounce(callback, timeout, deps) {
2164
+ const timeoutId = React.useRef();
2165
+ React.useEffect(() => {
2166
+ clearTimeout(timeoutId.current);
2167
+ timeoutId.current = setTimeout(callback, timeout);
2168
+ return () => clearTimeout(timeoutId.current);
2169
+ }, deps);
2170
+ }
2171
+
2137
2172
  var css_248z$4 = ".Step-module_stepWrapper__1se3l {\n display: flex;\n align-items: center;\n padding-left: 8px;\n padding-right: 8px;\n transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\n}\n.Step-module_stepWrapper__1se3l.Step-module_hasLabel__3cdCU:not(.Step-module_disabled__1R7hh):hover {\n cursor: pointer;\n background-color: rgba(0, 0, 0, 0.04);\n border-radius: var(--borderRadius);\n}\n\n.Step-module_step__2siYu {\n width: 40px;\n height: 40px;\n position: relative;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\n}\n.Step-module_step__2siYu:not(.Step-module_hasLabel__3cdCU):not(.Step-module_disabled__1R7hh):hover {\n border-radius: 100%;\n cursor: pointer;\n background-color: rgba(0, 0, 0, 0.04);\n}\n.Step-module_step__2siYu.Step-module_hasLabel__3cdCU svg {\n width: 18px !important;\n height: 18px !important;\n}\n\n.Step-module_stepIconCircle__3IyDn svg {\n width: 24px;\n height: 24px;\n}\n\n.Step-module_stepValue__2TVrP {\n position: absolute;\n color: var(--secondary-contrast-text);\n}\n.Step-module_stepValue__2TVrP .Step-module_isActive__1QTL4 {\n color: var(--primary-contrast-text);\n}";
2138
2173
  var styles$4 = {"stepWrapper":"Step-module_stepWrapper__1se3l","hasLabel":"Step-module_hasLabel__3cdCU","disabled":"Step-module_disabled__1R7hh","step":"Step-module_step__2siYu","stepIconCircle":"Step-module_stepIconCircle__3IyDn","stepValue":"Step-module_stepValue__2TVrP","isActive":"Step-module_isActive__1QTL4"};
2139
2174
  styleInject(css_248z$4);
@@ -2638,6 +2673,7 @@ exports.loadingIndicatorService = loadingIndicatorService;
2638
2673
  exports.modalService = modalService;
2639
2674
  exports.snackbarService = snackbarService;
2640
2675
  exports.useConstructor = useConstructor;
2676
+ exports.useDebounce = useDebounce;
2641
2677
  exports.useHover = useHover;
2642
2678
  exports.useWindowSize = useWindowSize;
2643
2679
  //# sourceMappingURL=index.js.map