react-asc 18.6.1 → 18.7.0

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, 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,14 @@ 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]);
279
285
  const getCssClass = () => {
280
286
  const cssClasses = [];
281
287
  className && cssClasses.push(className);
@@ -286,18 +292,14 @@ const AutoComplete = (props) => {
286
292
  const hide = () => setIsShow(false);
287
293
  const handleOnClick = (option) => {
288
294
  if (model !== option.value) {
289
- onChange && onChange(option.value);
295
+ onSelect && onSelect(option);
290
296
  }
291
297
  setModel(option.label);
292
298
  hide();
293
299
  };
294
300
  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);
301
+ setModel(e.target.value);
302
+ setSearchText(e.target.value);
301
303
  show();
302
304
  };
303
305
  const handleOnFocus = () => {
@@ -2134,6 +2136,15 @@ const useConstructor = (callBack = () => { }) => {
2134
2136
  setHasBeenCalled(true);
2135
2137
  };
2136
2138
 
2139
+ function useDebounce(callback, timeout, deps) {
2140
+ const timeoutId = React.useRef();
2141
+ React.useEffect(() => {
2142
+ clearTimeout(timeoutId.current);
2143
+ timeoutId.current = setTimeout(callback, timeout);
2144
+ return () => clearTimeout(timeoutId.current);
2145
+ }, deps);
2146
+ }
2147
+
2137
2148
  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
2149
  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
2150
  styleInject(css_248z$4);
@@ -2638,6 +2649,7 @@ exports.loadingIndicatorService = loadingIndicatorService;
2638
2649
  exports.modalService = modalService;
2639
2650
  exports.snackbarService = snackbarService;
2640
2651
  exports.useConstructor = useConstructor;
2652
+ exports.useDebounce = useDebounce;
2641
2653
  exports.useHover = useHover;
2642
2654
  exports.useWindowSize = useWindowSize;
2643
2655
  //# sourceMappingURL=index.js.map