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.
@@ -9,7 +9,9 @@ export interface IAutoCompleteProps {
9
9
  openOnFocus?: boolean;
10
10
  disabled?: boolean;
11
11
  readOnly?: boolean;
12
- onChange?: (val: string) => void;
12
+ debounce?: number;
13
+ onSelect?: (val: ISelectOption) => void;
14
+ onChange?: (val: string | undefined) => void;
13
15
  onKeyDown?: (event: any) => void;
14
16
  }
15
17
  export declare const AutoComplete: (props: IAutoCompleteProps) => JSX.Element;
package/hooks/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './Debounce.hook';
2
1
  export * from './useWindowSize';
3
2
  export * from './useHover';
4
3
  export * from './useConstructor';
4
+ export * from './useDebounce';
@@ -0,0 +1 @@
1
+ export declare function useDebounce(callback: any, timeout: any, deps: any): void;
package/index.es.js CHANGED
@@ -253,8 +253,9 @@ styleInject(css_248z$I);
253
253
  // multiple
254
254
  // custom template render items
255
255
  const AutoComplete = (props) => {
256
- const { id, name, className, options = [], openOnFocus = true, disabled, readOnly, onChange, value } = props;
256
+ const { id, name, className, options = [], openOnFocus = true, disabled, readOnly, debounce = 0, onChange, onSelect, value } = props;
257
257
  const [model, setModel] = useState('');
258
+ const [searchText, setSearchText] = useState('');
258
259
  const [isShow, setIsShow] = useState(false);
259
260
  const [optionsTemp, setOptionsTemp] = useState([]);
260
261
  const selectConainter = useRef(null);
@@ -265,9 +266,14 @@ const AutoComplete = (props) => {
265
266
  }
266
267
  }, [value]);
267
268
  useEffect(() => {
268
- const optionsOrigin = JSON.parse(JSON.stringify(options));
269
- setOptionsTemp(optionsOrigin);
269
+ if (options && options.length > 0) {
270
+ const optionsOrigin = JSON.parse(JSON.stringify(options));
271
+ const regex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi');
272
+ const optionsFiltered = optionsOrigin.filter(o => { var _a; return (_a = o.label) === null || _a === void 0 ? void 0 : _a.match(regex); });
273
+ setOptionsTemp(optionsFiltered);
274
+ }
270
275
  }, [options]);
276
+ useDebounce(() => { onChange && onChange(searchText); }, debounce, [searchText]);
271
277
  const getCssClass = () => {
272
278
  const cssClasses = [];
273
279
  className && cssClasses.push(className);
@@ -278,18 +284,14 @@ const AutoComplete = (props) => {
278
284
  const hide = () => setIsShow(false);
279
285
  const handleOnClick = (option) => {
280
286
  if (model !== option.value) {
281
- onChange && onChange(option.value);
287
+ onSelect && onSelect(option);
282
288
  }
283
289
  setModel(option.label);
284
290
  hide();
285
291
  };
286
292
  const handleOnChange = (e) => {
287
- const optionsOrigin = JSON.parse(JSON.stringify(options));
288
- const searchText = e.target.value;
289
- setModel(searchText);
290
- const regex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi');
291
- const optionsFiltered = optionsOrigin.filter(o => { var _a; return (_a = o.label) === null || _a === void 0 ? void 0 : _a.match(regex); });
292
- setOptionsTemp(optionsFiltered);
293
+ setModel(e.target.value);
294
+ setSearchText(e.target.value);
293
295
  show();
294
296
  };
295
297
  const handleOnFocus = () => {
@@ -2126,6 +2128,15 @@ const useConstructor = (callBack = () => { }) => {
2126
2128
  setHasBeenCalled(true);
2127
2129
  };
2128
2130
 
2131
+ function useDebounce(callback, timeout, deps) {
2132
+ const timeoutId = useRef();
2133
+ useEffect(() => {
2134
+ clearTimeout(timeoutId.current);
2135
+ timeoutId.current = setTimeout(callback, timeout);
2136
+ return () => clearTimeout(timeoutId.current);
2137
+ }, deps);
2138
+ }
2139
+
2129
2140
  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}";
2130
2141
  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"};
2131
2142
  styleInject(css_248z$4);
@@ -2525,5 +2536,5 @@ const TreeView = (props) => {
2525
2536
  })));
2526
2537
  };
2527
2538
 
2528
- export { Alert, AppBar, AppBarTitle, AutoComplete, Backdrop, Badge, Breadcrumb, BreadcrumbItem, Button, ButtonGroup, COLOR, Card, CardBody, CardFooter, CardImage, CardSubtitle, CardText, CardTitle, CaretDownSolidIcon, CheckSolidIcon, CheckSquareRegularIcon, Checkbox, ChevronDownSolidIcon, ChevronLeftSolidIcon, ChevronRightSolidIcon, ChevronUpSolidIcon, Chip, CircleSolidIcon, Column, ConditionalWrapper, DATEMODE, DateSelect, DaySelect, Drawer, EmailValidator, ExpansionPanel, ExpansionPanelContent, ExpansionPanelHeader, FileInput, FloatingActionButton, Form, FormControl, FormError, FormGroup, FormHint, FormInput, FormLabel, GlobalModal, HomeSolidIcon, HourSelect, Icon, IconButton, IsEmptyValidator, IsEqualValidator, Link, List, ListItem, ListItemAction, ListItemAvatar, ListItemIcon, ListItemText, LoadingIndicator, LoadingIndicatorContainer, MODALBUTTONTYPE, MODALTYPE, Menu, MenuBody, MenuDivider, MenuItem, MenuToggle, MilliSecondSelect, MinuteSelect, Modal, ModalBody, ModalFooter, ModalHeader, MonthSelect, NumberSelect, POSITION, PlusSolidIcon, Row, SIZE, STATUS, SecondSelect, Select, Sidebar, Snackbar, SpeedDial, SpeedDialAction, SpeedDialIcon, SpinnerSolidIcon, SquareRegularIcon, Step, Stepper, StepperActions, TIMEMODE, Tab, TabPanel, Table, Tabs, Textarea, TimeSelect, TimesCircleSolidIcon, TimesSolidIcon, Tooltip, TreeView, Typography, VARIANT, YearSelect, loadingIndicatorService, modalService, snackbarService, useConstructor, useHover, useWindowSize };
2539
+ export { Alert, AppBar, AppBarTitle, AutoComplete, Backdrop, Badge, Breadcrumb, BreadcrumbItem, Button, ButtonGroup, COLOR, Card, CardBody, CardFooter, CardImage, CardSubtitle, CardText, CardTitle, CaretDownSolidIcon, CheckSolidIcon, CheckSquareRegularIcon, Checkbox, ChevronDownSolidIcon, ChevronLeftSolidIcon, ChevronRightSolidIcon, ChevronUpSolidIcon, Chip, CircleSolidIcon, Column, ConditionalWrapper, DATEMODE, DateSelect, DaySelect, Drawer, EmailValidator, ExpansionPanel, ExpansionPanelContent, ExpansionPanelHeader, FileInput, FloatingActionButton, Form, FormControl, FormError, FormGroup, FormHint, FormInput, FormLabel, GlobalModal, HomeSolidIcon, HourSelect, Icon, IconButton, IsEmptyValidator, IsEqualValidator, Link, List, ListItem, ListItemAction, ListItemAvatar, ListItemIcon, ListItemText, LoadingIndicator, LoadingIndicatorContainer, MODALBUTTONTYPE, MODALTYPE, Menu, MenuBody, MenuDivider, MenuItem, MenuToggle, MilliSecondSelect, MinuteSelect, Modal, ModalBody, ModalFooter, ModalHeader, MonthSelect, NumberSelect, POSITION, PlusSolidIcon, Row, SIZE, STATUS, SecondSelect, Select, Sidebar, Snackbar, SpeedDial, SpeedDialAction, SpeedDialIcon, SpinnerSolidIcon, SquareRegularIcon, Step, Stepper, StepperActions, TIMEMODE, Tab, TabPanel, Table, Tabs, Textarea, TimeSelect, TimesCircleSolidIcon, TimesSolidIcon, Tooltip, TreeView, Typography, VARIANT, YearSelect, loadingIndicatorService, modalService, snackbarService, useConstructor, useDebounce, useHover, useWindowSize };
2529
2540
  //# sourceMappingURL=index.es.js.map