argous 1.2.171 → 1.2.172

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.
@@ -81,6 +81,10 @@ export interface AutoCompleteFavoritesProps extends Omit<AutocompleteProps<any,
81
81
  * Array contendo o backgroundColor do header no grupo
82
82
  */
83
83
  groupHeaderColor?: Array<string>,
84
+ /**
85
+ * Prop que ativa a seleção automática da primeira opção da pesquisa
86
+ */
87
+ autoSelectFirstOption?: boolean,
84
88
  /**
85
89
  * Função para filtrar a lista de opções
86
90
  *
@@ -298,7 +298,7 @@ var ListboxFavorites = react_1.forwardRef(function (props, ref) {
298
298
  });
299
299
  var AutoCompleteFavorites = function (_a) {
300
300
  var _b;
301
- var action = _a.action, busca = _a.busca, resposta = _a.resposta, autoSearch = _a.autoSearch, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, _c = _a.group, group = _c === void 0 ? false : _c, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, widthListBox = _a.widthListBox, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, _e = _a.textFieldProps, textFieldProps = _e === void 0 ? {} : _e, searchParams = _a.searchParams, props = __rest(_a, ["action", "busca", "resposta", "autoSearch", "label", "value", "pgCode", "favoritePage", "group", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "widthListBox", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
301
+ var action = _a.action, busca = _a.busca, resposta = _a.resposta, autoSearch = _a.autoSearch, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, _c = _a.group, group = _c === void 0 ? false : _c, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, widthListBox = _a.widthListBox, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, searchParams = _a.searchParams, autoSelectFirstOption = _a.autoSelectFirstOption, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, _e = _a.textFieldProps, textFieldProps = _e === void 0 ? {} : _e, props = __rest(_a, ["action", "busca", "resposta", "autoSearch", "label", "value", "pgCode", "favoritePage", "group", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "widthListBox", "filterFunction", "getOptionLabel", "searchParams", "autoSelectFirstOption", "onChange", "textFieldProps"]);
302
302
  var classes = useStyles({ widthListBox: widthListBox });
303
303
  var _f = react_1.useState({
304
304
  lista: [],
@@ -370,6 +370,8 @@ var AutoCompleteFavorites = function (_a) {
370
370
  // eslint-disable-next-line react-hooks/exhaustive-deps
371
371
  react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
372
372
  react_1.useEffect(function () { var _a; return (value !== ((_a = dados.cursor) === null || _a === void 0 ? void 0 : _a.linha)) && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: '', page: '' } })); }); }, [value, (_b = dados.cursor) === null || _b === void 0 ? void 0 : _b.linha]);
373
+ // eslint-disable-next-line react-hooks/exhaustive-deps
374
+ react_1.useEffect(function () { var _a; return autoSelectFirstOption && !!inputValue.length && onChange(undefined, ((_a = dados === null || dados === void 0 ? void 0 : dados.lista) === null || _a === void 0 ? void 0 : _a[0]) || null); }, [dados.lista]);
373
375
  var keyDown = function (e) {
374
376
  ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
375
377
  (e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
@@ -451,7 +453,7 @@ var AutoCompleteFavorites = function (_a) {
451
453
  lastScrollTop = elListBox.scrollTop;
452
454
  linha && setDados(function (v) { return (__assign(__assign({}, v), { cursor: { index: indexCapture, page: v.pageNumber, linha: linha, elTop: elTop, elTotalHeight: elTotalHeight, lastScrollTop: lastScrollTop } })); });
453
455
  if (linha !== value)
454
- invokeOnChange('', linha);
456
+ onChange(undefined, linha);
455
457
  }
456
458
  var scrollToSelected = react_1.useCallback(function () {
457
459
  var _a, _b, _c, _d;
@@ -467,8 +469,7 @@ var AutoCompleteFavorites = function (_a) {
467
469
  }
468
470
  }, [dados]);
469
471
  react_1.useEffect(function () { var _a; return ((_a = dados.lista) === null || _a === void 0 ? void 0 : _a.length) && setTimeout(function () { return scrollToSelected(); }, 0); }, [dados.lista, scrollToSelected]);
470
- var invokeOnChange = onChange;
471
- return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value }, { onChange: invokeOnChange, autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, onInputChange: function (e) { var _a; return setInput(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { onKeyUp: function (e) { return keyUp(e); }, inputProps: __assign(__assign({}, params.inputProps), { onKeyDown: function (e) { return keyDown(e); } }), InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
472
+ return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value, onChange: onChange }, { autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, onInputChange: function (e) { var _a; return setInput(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { onKeyUp: function (e) { return keyUp(e); }, inputProps: __assign(__assign({}, params.inputProps), { onKeyDown: function (e) { return keyDown(e); } }), InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
472
473
  params.InputProps.endAdornment,
473
474
  react_1.default.createElement(core_1.Fade, { in: loading },
474
475
  react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })),
@@ -81,6 +81,10 @@ export interface AutoCompleteFavoritesProps extends Omit<AutocompleteProps<any,
81
81
  * Array contendo o backgroundColor do header no grupo
82
82
  */
83
83
  groupHeaderColor?: Array<string>,
84
+ /**
85
+ * Prop que ativa a seleção automática da primeira opção da pesquisa
86
+ */
87
+ autoSelectFirstOption?: boolean,
84
88
  /**
85
89
  * Função para filtrar a lista de opções
86
90
  *
@@ -232,7 +232,29 @@ const ListboxFavorites = forwardRef((props, ref) => {
232
232
  </ul>;
233
233
  });
234
234
 
235
- const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, value, pgCode, favoritePage, group = false, groupName, groupHeaderColor, groupTitleColor, loadingColor, widthListBox, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
235
+ const AutoCompleteFavorites = ({
236
+ action,
237
+ busca,
238
+ resposta,
239
+ autoSearch,
240
+ label,
241
+ value,
242
+ pgCode,
243
+ favoritePage,
244
+ group = false,
245
+ groupName,
246
+ groupHeaderColor,
247
+ groupTitleColor,
248
+ loadingColor,
249
+ widthListBox,
250
+ filterFunction,
251
+ getOptionLabel,
252
+ searchParams,
253
+ autoSelectFirstOption,
254
+ onChange = e => e,
255
+ textFieldProps = {},
256
+ ...props
257
+ }) => {
236
258
 
237
259
  const classes = useStyles({ widthListBox });
238
260
  const [dados, setDados] = useState({
@@ -288,6 +310,9 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
288
310
 
289
311
  useEffect(() => (value !== dados.cursor?.linha) && setDados(v => ({ ...v, cursor: { index: '', page: '' } })), [value, dados.cursor?.linha]);
290
312
 
313
+ // eslint-disable-next-line react-hooks/exhaustive-deps
314
+ useEffect(() => autoSelectFirstOption && !!inputValue.length && onChange(undefined, dados?.lista?.[0] || null), [dados.lista]);
315
+
291
316
  const keyDown = e => {
292
317
  ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar();
293
318
  (e.key === 'ArrowDown' || e.key === 'ArrowUp') && selectListboxItem(e.key);
@@ -362,7 +387,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
362
387
  if (elListBox) lastScrollTop = elListBox.scrollTop;
363
388
 
364
389
  linha && setDados(v => ({ ...v, cursor: { index: indexCapture, page: v.pageNumber, linha: linha, elTop: elTop, elTotalHeight: elTotalHeight, lastScrollTop: lastScrollTop } }));
365
- if (linha !== value) invokeOnChange('', linha);
390
+ if (linha !== value) onChange(undefined, linha);
366
391
  }
367
392
 
368
393
  const scrollToSelected = useCallback(() => {
@@ -378,13 +403,10 @@ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, val
378
403
  }, [dados]);
379
404
  useEffect(() => dados.lista?.length && setTimeout(() => scrollToSelected(), 0), [dados.lista, scrollToSelected]);
380
405
 
381
- const invokeOnChange = onChange;
382
-
383
406
  return (
384
407
  <Autocomplete
385
408
  {...props}
386
- {...{ value }}
387
- onChange={invokeOnChange}
409
+ {...{ value, onChange }}
388
410
  autoComplete
389
411
  autoHighlight
390
412
  openText='Abrir'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argous",
3
- "version": "1.2.171",
3
+ "version": "1.2.172",
4
4
  "description": "Argous.",
5
5
  "main": "lib/index.js",
6
6
  "author": "Carlos Schneider",