argous 1.2.171 → 1.2.173

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 })),
@@ -73,6 +73,10 @@ export interface UtilAutoCompleteProps extends Omit<AutocompleteProps<any, false
73
73
  * Parametros utilizados no metodo de busca
74
74
  */
75
75
  searchParams?: object,
76
+ /**
77
+ * Disponível para leitura apenas
78
+ */
79
+ readOnly?: boolean,
76
80
  /**
77
81
  * Função para filtrar a lista de opções
78
82
  *
@@ -147,9 +147,10 @@ var retornaType = function (type) {
147
147
  }
148
148
  };
149
149
  var UtilAutoComplete = function (_a) {
150
- var _b = _a.type, type = _b === void 0 ? '' : _b, label = _a.label, value = _a.value, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, excluidos = _a.excluidos, idEmpresa = _a.idEmpresa, cdEstado = _a.cdEstado, cdUnimed = _a.cdUnimed, getOptionLabel = _a.getOptionLabel, _e = _a.pgCode, pgCode = _e === void 0 ? 'BuscasHelper' : _e, action = _a.action, busca = _a.busca, resposta = _a.resposta, searchParams = _a.searchParams, filterFunction = _a.filterFunction, forceUpdate = _a.forceUpdate, props = __rest(_a, ["type", "label", "value", "textFieldProps", "onChange", "excluidos", "idEmpresa", "cdEstado", "cdUnimed", "getOptionLabel", "pgCode", "action", "busca", "resposta", "searchParams", "filterFunction", "forceUpdate"]);
151
- var _f = react_1.useState([]), lista = _f[0], setLista = _f[1];
152
- var _g = react_1.useState(''), inputValue = _g[0], setInputValue = _g[1];
150
+ var _b = _a.type, type = _b === void 0 ? '' : _b, label = _a.label, value = _a.value, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, excluidos = _a.excluidos, idEmpresa = _a.idEmpresa, cdEstado = _a.cdEstado, cdUnimed = _a.cdUnimed, getOptionLabel = _a.getOptionLabel, _e = _a.pgCode, pgCode = _e === void 0 ? 'BuscasHelper' : _e, action = _a.action, busca = _a.busca, resposta = _a.resposta, searchParams = _a.searchParams, filterFunction = _a.filterFunction, forceUpdate = _a.forceUpdate, readOnly = _a.readOnly, props = __rest(_a, ["type", "label", "value", "textFieldProps", "onChange", "excluidos", "idEmpresa", "cdEstado", "cdUnimed", "getOptionLabel", "pgCode", "action", "busca", "resposta", "searchParams", "filterFunction", "forceUpdate", "readOnly"]);
151
+ var _f = react_1.useState(false), open = _f[0], setOpen = _f[1];
152
+ var _g = react_1.useState([]), lista = _g[0], setLista = _g[1];
153
+ var _h = react_1.useState(''), inputValue = _h[0], setInputValue = _h[1];
153
154
  var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
154
155
  var res;
155
156
  var _a;
@@ -167,12 +168,13 @@ var UtilAutoComplete = function (_a) {
167
168
  react_1.useEffect(function () {
168
169
  if (lodash_1.isString(value))
169
170
  buscar(value);
171
+ // eslint-disable-next-line react-hooks/exhaustive-deps
170
172
  }, []);
171
173
  react_1.useEffect(function () {
172
174
  // if (inputValue.length < 2) return;
173
175
  buscar();
174
176
  }, [inputValue, buscar]);
175
- return (react_1.default.createElement(lab_1.Autocomplete, __assign({ options: lodash_1.isObject(value) ? lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : lista, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel ? (function (option) { return getOptionLabel(option, lista); }) : (function (option) { return retornaType(type).getLabel(option, lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', clearText: 'Limpar', openText: 'Abrir', onInputChange: function (e) { var _a; return setInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, filterSelectedOptions: true, autoComplete: true, autoHighlight: true }, { value: value, onChange: onChange }, props, { renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label || retornaType(type).label }, params, textFieldProps, { InputProps: __assign(__assign({}, textFieldProps.InputProps), params.InputProps) }))); } })));
177
+ return (react_1.default.createElement(lab_1.Autocomplete, __assign({ open: open, onOpen: function () { return !readOnly && setOpen(true); }, onClose: function () { return setOpen(false); }, disableClearable: readOnly, options: lodash_1.isObject(value) ? lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : lista, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel ? (function (option) { return getOptionLabel(option, lista); }) : (function (option) { return retornaType(type).getLabel(option, lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', clearText: 'Limpar', openText: 'Abrir', onInputChange: function (e) { var _a; return setInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, filterSelectedOptions: true, autoComplete: true, autoHighlight: true }, { value: value, onChange: onChange }, props, { renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label || retornaType(type).label }, params, textFieldProps, { InputProps: __assign(__assign({}, textFieldProps.InputProps), params.InputProps), inputProps: __assign(__assign(__assign({}, textFieldProps.inputProps), params.inputProps), { readOnly: readOnly }) }))); } })));
176
178
  };
177
179
  // UtilAutoComplete.propTypes = {
178
180
  // type: PropTypes.oneOf(['beneficiarios', 'empresas', 'gruposUnimed', 'estados', 'cidades', 'unimeds', 'prestadores']).isRequired,
@@ -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'
@@ -73,6 +73,10 @@ export interface UtilAutoCompleteProps extends Omit<AutocompleteProps<any, false
73
73
  * Parametros utilizados no metodo de busca
74
74
  */
75
75
  searchParams?: object,
76
+ /**
77
+ * Disponível para leitura apenas
78
+ */
79
+ readOnly?: boolean,
76
80
  /**
77
81
  * Função para filtrar a lista de opções
78
82
  *
@@ -69,17 +69,20 @@ const retornaType = type => {
69
69
  }
70
70
  };
71
71
 
72
- const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChange = e => e, excluidos, idEmpresa, cdEstado, cdUnimed, getOptionLabel, pgCode = 'BuscasHelper', action, busca, resposta, searchParams, filterFunction, forceUpdate, ...props }) => {
72
+ const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChange = e => e, excluidos, idEmpresa, cdEstado, cdUnimed, getOptionLabel, pgCode = 'BuscasHelper', action, busca, resposta, searchParams, filterFunction, forceUpdate, readOnly, ...props }) => {
73
+ const [open, setOpen] = useState(false);
73
74
  const [lista, setLista] = useState([]);
74
75
  const [inputValue, setInputValue] = useState('');
75
76
 
76
77
  const buscar = useCallback(async valor => {
77
78
  const res = await serverAction(action || retornaType(type).action, { [busca || retornaType(type)?.busca || 'value']: valor || inputValue, excluidos, idEmpresa, cdEstado, cdUnimed, ...searchParams }, true, pgCode);
78
79
  setLista(res[resposta || retornaType(type)?.res || 'result'] || []);
80
+ // eslint-disable-next-line react-hooks/exhaustive-deps
79
81
  }, [inputValue, type, searchParams]);
80
82
 
81
83
  useEffect(() => {
82
84
  if (isString(value)) buscar(value);
85
+ // eslint-disable-next-line react-hooks/exhaustive-deps
83
86
  }, []);
84
87
 
85
88
  useEffect(() => {
@@ -89,6 +92,10 @@ const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChan
89
92
 
90
93
  return (
91
94
  <Autocomplete
95
+ open={open}
96
+ onOpen={() => !readOnly && setOpen(true)}
97
+ onClose={() => setOpen(false)}
98
+ disableClearable={readOnly}
92
99
  options={isObject(value) ? lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : lista}
93
100
  getOptionSelected={(o, v) => o[0] === v}
94
101
  getOptionLabel={getOptionLabel ? (option => getOptionLabel(option, lista)) : (option => retornaType(type).getLabel(option, lista)) }
@@ -109,6 +116,7 @@ const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChan
109
116
  {...params}
110
117
  {...textFieldProps}
111
118
  InputProps={{ ...textFieldProps.InputProps, ...params.InputProps }}
119
+ inputProps={{ ...textFieldProps.inputProps, ...params.inputProps, readOnly }}
112
120
  />
113
121
  )}
114
122
  />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argous",
3
- "version": "1.2.171",
3
+ "version": "1.2.173",
4
4
  "description": "Argous.",
5
5
  "main": "lib/index.js",
6
6
  "author": "Carlos Schneider",