argous 1.2.137 → 1.2.141
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/dist/components/AutoCompleteFavorites/AutoCompleteFavorites.d.ts +89 -20
- package/dist/components/AutoCompleteFavorites/AutoCompleteFavorites.js +128 -112
- package/dist/components/AutoCompleteFavorites/index.d.ts +2 -1
- package/dist/components/index.d.ts +4 -1
- package/dist/components/index.js +4 -1
- package/lib/components/AutoCompleteFavorites/AutoCompleteFavorites.d.ts +89 -0
- package/lib/components/AutoCompleteFavorites/AutoCompleteFavorites.js +136 -134
- package/lib/components/AutoCompleteFavorites/index.d.ts +2 -0
- package/lib/components/index.d.ts +4 -1
- package/lib/components/index.js +4 -1
- package/package.json +1 -1
|
@@ -1,20 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { TextFieldProps } from '@material-ui/core';
|
|
2
|
+
import { AutocompleteProps, AutocompleteChangeDetails } from '@material-ui/lab';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export interface AutoCompleteFavoritesProps extends Omit<AutocompleteProps<any, false, false, false>, 'getOptionLabel'>{
|
|
6
|
+
/**
|
|
7
|
+
* Valor do campo
|
|
8
|
+
*/
|
|
9
|
+
value?: Array<number|string> | object,
|
|
10
|
+
/**
|
|
11
|
+
* Props repassados ao componente Textfield
|
|
12
|
+
*/
|
|
13
|
+
textFieldProps?: TextFieldProps,
|
|
14
|
+
/**
|
|
15
|
+
* Callback fired when the value changes.
|
|
16
|
+
*
|
|
17
|
+
* @param event — The event source of the callback.
|
|
18
|
+
*
|
|
19
|
+
* @param value — The new value of the component.
|
|
20
|
+
*
|
|
21
|
+
* @param reason — One of "create-option", "select-option", "remove-option", "blur", "clear" ou "only-one-left".
|
|
22
|
+
*/
|
|
23
|
+
onChange?: ((event: React.ChangeEvent<{}>, value: any, reason: 'create-option' | 'select-option' | 'remove-option' | 'blur' | 'clear' | 'only-one-left', details?: AutocompleteChangeDetails<any> | undefined) => void) | undefined,
|
|
24
|
+
/**
|
|
25
|
+
* Formata o valor que aparece na listagem
|
|
26
|
+
*
|
|
27
|
+
* @param option - Opção sendo testada ou selecionada
|
|
28
|
+
*
|
|
29
|
+
* @param lista - Lista com todas as opções
|
|
30
|
+
*/
|
|
31
|
+
getOptionLabel?: ((option: Array<any>, lista: Array<Array<any>>) => string),
|
|
32
|
+
/**
|
|
33
|
+
* Utiliza um pgCode diferente do padrão
|
|
34
|
+
*/
|
|
35
|
+
pgCode?: string,
|
|
36
|
+
/**
|
|
37
|
+
* Objeto de busca personalizado
|
|
38
|
+
*/
|
|
39
|
+
busca?: string,
|
|
40
|
+
/**
|
|
41
|
+
* Objeto de resposta personalizado
|
|
42
|
+
*/
|
|
43
|
+
resposta?: string,
|
|
44
|
+
/**
|
|
45
|
+
* Action personalizada
|
|
46
|
+
*/
|
|
47
|
+
action?: string,
|
|
48
|
+
/**
|
|
49
|
+
* Label do campo
|
|
50
|
+
*/
|
|
51
|
+
label?: string,
|
|
52
|
+
/**
|
|
53
|
+
* Parametros utilizados no metodo de busca
|
|
54
|
+
*/
|
|
55
|
+
searchParams?: object,
|
|
56
|
+
/**
|
|
57
|
+
* Define a cor do loading
|
|
58
|
+
*/
|
|
59
|
+
loadingColor?: string,
|
|
60
|
+
/**
|
|
61
|
+
* Parametro que define se terá paginação
|
|
62
|
+
*/
|
|
63
|
+
favoritePage?: boolean,
|
|
64
|
+
/**
|
|
65
|
+
* Array contendo nome do grupo
|
|
66
|
+
*/
|
|
67
|
+
groupName?: Array<string>,
|
|
68
|
+
/**
|
|
69
|
+
* Array contendo a cor do titulo no grupo
|
|
70
|
+
*/
|
|
71
|
+
groupTitleColor?: Array<string>,
|
|
72
|
+
/**
|
|
73
|
+
* Array contendo o backgroundColor do header no grupo
|
|
74
|
+
*/
|
|
75
|
+
groupHeaderColor?: Array<string>,
|
|
76
|
+
/**
|
|
77
|
+
* Função para filtrar a lista de opções
|
|
78
|
+
*
|
|
79
|
+
* @param valor - Valor setado no componente
|
|
80
|
+
* @param item - Item a ser testado contra o valor
|
|
81
|
+
*
|
|
82
|
+
* @returns {boolean} Retorna true se item de ser removido da lista
|
|
83
|
+
*/
|
|
84
|
+
filterFunction?: (valor: any, item: any) => boolean,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare function AutoCompleteFavorites(props: AutoCompleteFavoritesProps): JSX.Element
|
|
88
|
+
|
|
89
|
+
export default AutoCompleteFavorites;
|
|
@@ -80,6 +80,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
80
80
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
81
81
|
};
|
|
82
82
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
+
exports.CustomTooltip = void 0;
|
|
83
84
|
var api_1 = require("../../utils/api");
|
|
84
85
|
var core_1 = require("@material-ui/core");
|
|
85
86
|
var lab_1 = require("@material-ui/lab");
|
|
@@ -169,111 +170,25 @@ var useStyles = core_1.makeStyles(function (theme) { return ({
|
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
}); });
|
|
172
|
-
|
|
173
|
+
exports.CustomTooltip = core_1.withStyles(function (theme) { return ({
|
|
173
174
|
tooltip: theme.palette.type === 'light' ? {
|
|
174
175
|
fontSize: 15,
|
|
175
176
|
fontWeight: 400,
|
|
176
|
-
color: '
|
|
177
|
+
color: '#FFF',
|
|
177
178
|
backgroundColor: '#333333e3',
|
|
178
179
|
} : {
|
|
179
180
|
fontSize: 15,
|
|
180
181
|
fontWeight: 400,
|
|
181
|
-
color: '
|
|
182
|
+
color: '#000',
|
|
182
183
|
backgroundColor: '#fbfbfbd1',
|
|
183
184
|
},
|
|
184
185
|
arrow: {
|
|
185
186
|
color: theme.palette.type === 'light' ? '#333333e3' : '#fbfbfbd1'
|
|
186
187
|
}
|
|
187
188
|
}); })(core_1.Tooltip);
|
|
188
|
-
var ListboxFavorites = react_1.forwardRef(function (props, ref) {
|
|
189
|
-
var classes = useStyles();
|
|
190
|
-
var children = props.children, favoritePage = props.favoritePage, dados = props.dados, setDados = props.setDados, groupHeaderColor = props.groupHeaderColor, groupTitleColor = props.groupTitleColor;
|
|
191
|
-
var pageNumber = dados.pageNumber, favoritosLength = dados.favoritosLength, direction = dados.direction, slide = dados.slide;
|
|
192
|
-
function retornaInicio() {
|
|
193
|
-
switch (pageNumber) {
|
|
194
|
-
case 1:
|
|
195
|
-
return 0;
|
|
196
|
-
case 2:
|
|
197
|
-
return 7;
|
|
198
|
-
case 3:
|
|
199
|
-
return 14;
|
|
200
|
-
default: return;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function retornaFim() {
|
|
204
|
-
switch (pageNumber) {
|
|
205
|
-
case 1:
|
|
206
|
-
return 7;
|
|
207
|
-
case 2:
|
|
208
|
-
return 14;
|
|
209
|
-
case 3:
|
|
210
|
-
return favoritosLength;
|
|
211
|
-
default: return;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function retornaArray(sectionIndex, section) {
|
|
215
|
-
if (sectionIndex === 0 && favoritePage && favoritosLength > 7)
|
|
216
|
-
return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
217
|
-
return section.props.children[1].props.children;
|
|
218
|
-
}
|
|
219
|
-
function retornaEstrutura(sectionIndex, item) {
|
|
220
|
-
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
221
|
-
return (react_1.default.createElement(core_1.Slide, { in: slide, direction: direction },
|
|
222
|
-
react_1.default.createElement(CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
223
|
-
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
224
|
-
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText })))));
|
|
225
|
-
}
|
|
226
|
-
return (react_1.default.createElement(CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
227
|
-
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
228
|
-
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText }))));
|
|
229
|
-
}
|
|
230
|
-
function buttonClick(evento, value) {
|
|
231
|
-
evento.preventDefault();
|
|
232
|
-
evento.stopPropagation();
|
|
233
|
-
if (value !== pageNumber) {
|
|
234
|
-
verificaSaidaSlide(value);
|
|
235
|
-
setDados(function (v) { return (__assign(__assign({}, v), { slide: false })); });
|
|
236
|
-
setTimeout(function () {
|
|
237
|
-
setDados(function (v) { return (__assign(__assign({}, v), { pageNumber: value, direction: retornaDirection(value) })); });
|
|
238
|
-
setTimeout(function () { return setDados(function (v) { return (__assign(__assign({}, v), { slide: true })); }); }, 100);
|
|
239
|
-
}, 200);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function verificaSaidaSlide(value) {
|
|
243
|
-
var direction = '';
|
|
244
|
-
if ((value === 2 || value === 3) && pageNumber === 1)
|
|
245
|
-
direction = 'right';
|
|
246
|
-
else if (value === 3 && pageNumber === 2)
|
|
247
|
-
direction = 'right';
|
|
248
|
-
else if (value === 1 && pageNumber === 2)
|
|
249
|
-
direction = 'left';
|
|
250
|
-
direction && setDados(function (v) { return (__assign(__assign({}, v), { direction: direction })); });
|
|
251
|
-
}
|
|
252
|
-
function retornaDirection(value) {
|
|
253
|
-
if (value < pageNumber)
|
|
254
|
-
return 'right';
|
|
255
|
-
return 'left';
|
|
256
|
-
}
|
|
257
|
-
return children.map(function (section, sectionIndex) {
|
|
258
|
-
var _a, _b, _c;
|
|
259
|
-
return (react_1.default.createElement("ul", __assign({}, props, { className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }),
|
|
260
|
-
react_1.default.createElement(core_1.ListSubheader, { className: classes.subHeader, style: { backgroundColor: groupHeaderColor === null || groupHeaderColor === void 0 ? void 0 : groupHeaderColor[sectionIndex], color: groupTitleColor === null || groupTitleColor === void 0 ? void 0 : groupTitleColor[sectionIndex] } },
|
|
261
|
-
section.props.children[0].props.children,
|
|
262
|
-
react_1.default.createElement(core_1.Fade, { in: sectionIndex === 0 && favoritePage && favoritosLength > 7 },
|
|
263
|
-
react_1.default.createElement("div", { className: classes.divButton },
|
|
264
|
-
react_1.default.createElement("div", { className: classes.areaButton },
|
|
265
|
-
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 1); }, className: clsx_1.default((_a = {}, _a[classes.buttonActive] = pageNumber === 1, _a), classes.button) }, "1")),
|
|
266
|
-
react_1.default.createElement("div", { className: classes.areaButton },
|
|
267
|
-
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 2); }, className: clsx_1.default((_b = {}, _b[classes.buttonActive] = pageNumber === 2, _b), classes.button) }, "2")),
|
|
268
|
-
favoritosLength > 14 &&
|
|
269
|
-
react_1.default.createElement(react_1.default.Fragment, null,
|
|
270
|
-
react_1.default.createElement("div", { className: classes.areaButton },
|
|
271
|
-
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 3); }, className: clsx_1.default((_c = {}, _c[classes.buttonActive] = pageNumber === 3, _c), classes.button) }, "3")))))),
|
|
272
|
-
retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item); })));
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
189
|
var AutoCompleteFavorites = function (_a) {
|
|
276
190
|
var action = _a.action, busca = _a.busca, resposta = _a.resposta, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, _b = _a.onChange, onChange = _b === void 0 ? function (e) { return e; } : _b, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, searchParams = _a.searchParams, props = __rest(_a, ["action", "busca", "resposta", "label", "value", "pgCode", "favoritePage", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
|
|
191
|
+
var classes = useStyles();
|
|
277
192
|
var _d = react_1.useState({
|
|
278
193
|
lista: [],
|
|
279
194
|
slide: true,
|
|
@@ -283,6 +198,113 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
283
198
|
}), dados = _d[0], setDados = _d[1];
|
|
284
199
|
var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
|
|
285
200
|
var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
|
|
201
|
+
var ListboxFavorites = react_1.forwardRef(function (props, ref) {
|
|
202
|
+
var children = props.children, favoritePage = props.favoritePage, dados = props.dados, setDados = props.setDados, groupHeaderColor = props.groupHeaderColor, groupTitleColor = props.groupTitleColor;
|
|
203
|
+
var pageNumber = dados.pageNumber, favoritosLength = dados.favoritosLength, direction = dados.direction, slide = dados.slide;
|
|
204
|
+
console.log('Listbox', children);
|
|
205
|
+
function retornaInicio() {
|
|
206
|
+
switch (pageNumber) {
|
|
207
|
+
case 1:
|
|
208
|
+
return 0;
|
|
209
|
+
case 2:
|
|
210
|
+
return 7;
|
|
211
|
+
case 3:
|
|
212
|
+
return 14;
|
|
213
|
+
default: return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function retornaFim() {
|
|
217
|
+
switch (pageNumber) {
|
|
218
|
+
case 1:
|
|
219
|
+
return 7;
|
|
220
|
+
case 2:
|
|
221
|
+
return 14;
|
|
222
|
+
case 3:
|
|
223
|
+
return favoritosLength;
|
|
224
|
+
default: return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function retornaArray(sectionIndex, section) {
|
|
228
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7)
|
|
229
|
+
return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
230
|
+
return section.props.children[1].props.children;
|
|
231
|
+
}
|
|
232
|
+
function retornaEstrutura(sectionIndex, item) {
|
|
233
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
234
|
+
return (react_1.default.createElement(core_1.Slide, { in: slide, direction: direction },
|
|
235
|
+
react_1.default.createElement(exports.CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
236
|
+
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
237
|
+
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText })))));
|
|
238
|
+
}
|
|
239
|
+
return (react_1.default.createElement(exports.CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
240
|
+
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
241
|
+
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText }))));
|
|
242
|
+
}
|
|
243
|
+
function buttonClick(evento, value) {
|
|
244
|
+
evento.preventDefault();
|
|
245
|
+
evento.stopPropagation();
|
|
246
|
+
if (value !== pageNumber) {
|
|
247
|
+
verificaSaidaSlide(value);
|
|
248
|
+
setDados(function (v) { return (__assign(__assign({}, v), { slide: false })); });
|
|
249
|
+
setTimeout(function () {
|
|
250
|
+
setDados(function (v) { return (__assign(__assign({}, v), { pageNumber: value, direction: retornaDirection(value) })); });
|
|
251
|
+
setTimeout(function () { return setDados(function (v) { return (__assign(__assign({}, v), { slide: true })); }); }, 100);
|
|
252
|
+
}, 200);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function verificaSaidaSlide(value) {
|
|
256
|
+
var direction = '';
|
|
257
|
+
if ((value === 2 || value === 3) && pageNumber === 1)
|
|
258
|
+
direction = 'right';
|
|
259
|
+
else if (value === 3 && pageNumber === 2)
|
|
260
|
+
direction = 'right';
|
|
261
|
+
else if (value === 1 && pageNumber === 2)
|
|
262
|
+
direction = 'left';
|
|
263
|
+
direction && setDados(function (v) { return (__assign(__assign({}, v), { direction: direction })); });
|
|
264
|
+
}
|
|
265
|
+
function retornaDirection(value) {
|
|
266
|
+
if (value < pageNumber)
|
|
267
|
+
return 'right';
|
|
268
|
+
return 'left';
|
|
269
|
+
}
|
|
270
|
+
return children.map(function (section, sectionIndex) {
|
|
271
|
+
var _a, _b, _c;
|
|
272
|
+
return (react_1.default.createElement("ul", __assign({}, props, { className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }),
|
|
273
|
+
react_1.default.createElement(core_1.ListSubheader, { className: classes.subHeader, style: { backgroundColor: groupHeaderColor === null || groupHeaderColor === void 0 ? void 0 : groupHeaderColor[sectionIndex], color: groupTitleColor === null || groupTitleColor === void 0 ? void 0 : groupTitleColor[sectionIndex] } },
|
|
274
|
+
section.props.children[0].props.children,
|
|
275
|
+
react_1.default.createElement(core_1.Fade, { in: sectionIndex === 0 && favoritePage && favoritosLength > 7 },
|
|
276
|
+
react_1.default.createElement("div", { className: classes.divButton },
|
|
277
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
278
|
+
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 1); }, className: clsx_1.default((_a = {}, _a[classes.buttonActive] = pageNumber === 1, _a), classes.button) }, "1")),
|
|
279
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
280
|
+
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 2); }, className: clsx_1.default((_b = {}, _b[classes.buttonActive] = pageNumber === 2, _b), classes.button) }, "2")),
|
|
281
|
+
favoritosLength > 14 &&
|
|
282
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
283
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
284
|
+
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 3); }, className: clsx_1.default((_c = {}, _c[classes.buttonActive] = pageNumber === 3, _c), classes.button) }, "3")))))),
|
|
285
|
+
retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item); })));
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
function carimbaLista(lista) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
290
|
+
var completo;
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
completo = [];
|
|
293
|
+
lista.map(function (arr, index) {
|
|
294
|
+
index === 0 && favoritePage && setDados(function (v) { return (__assign(__assign({}, v), { favoritosLength: arr.length })); });
|
|
295
|
+
return arr.map(function (itemArr) { return itemArr.length < 3 && itemArr.push(groupName[index]); });
|
|
296
|
+
});
|
|
297
|
+
lista.forEach(function (v) {
|
|
298
|
+
for (var _i = 0, _a = v.values(); _i < _a.length; _i++) {
|
|
299
|
+
var item = _a[_i];
|
|
300
|
+
completo.push(item);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
setDados(function (v) { return (__assign(__assign({}, v), { lista: completo })); });
|
|
304
|
+
return [2 /*return*/];
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
}
|
|
286
308
|
var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
|
|
287
309
|
var res;
|
|
288
310
|
var _a;
|
|
@@ -294,38 +316,32 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
294
316
|
return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
|
|
295
317
|
case 1:
|
|
296
318
|
res = _c.sent();
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
319
|
+
if (res)
|
|
320
|
+
console.log('Resposta busca', res);
|
|
321
|
+
if (!(((_b = res[resposta || 'result']) === null || _b === void 0 ? void 0 : _b.length) > 1)) return [3 /*break*/, 3];
|
|
322
|
+
return [4 /*yield*/, carimbaLista(res[resposta || 'result'])];
|
|
323
|
+
case 2:
|
|
324
|
+
_c.sent();
|
|
325
|
+
return [3 /*break*/, 4];
|
|
326
|
+
case 3:
|
|
327
|
+
if (res[resposta || 'result'])
|
|
328
|
+
setDados({ lista: res[resposta || 'result'] || [] });
|
|
301
329
|
else
|
|
302
330
|
api_1.setError('Erro ao tentar buscar dados.');
|
|
331
|
+
_c.label = 4;
|
|
332
|
+
case 4:
|
|
303
333
|
setLoading(false);
|
|
304
334
|
return [2 /*return*/];
|
|
305
335
|
}
|
|
306
336
|
});
|
|
307
337
|
}); }, [inputValue, searchParams]);
|
|
308
|
-
function carimbaLista(lista) {
|
|
309
|
-
var completo = [];
|
|
310
|
-
lista.map(function (arr, index) {
|
|
311
|
-
index === 0 && favoritePage && setDados(function (v) { return (__assign(__assign({}, v), { favoritosLength: arr.length })); });
|
|
312
|
-
return arr.map(function (itemArr) { return itemArr.length < 3 && itemArr.push(groupName[index]); });
|
|
313
|
-
});
|
|
314
|
-
lista.forEach(function (v) {
|
|
315
|
-
for (var _i = 0, _a = v.values(); _i < _a.length; _i++) {
|
|
316
|
-
var item = _a[_i];
|
|
317
|
-
completo.push(item);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
setDados(function (v) { return (__assign(__assign({}, v), { lista: completo })); });
|
|
321
|
-
}
|
|
322
338
|
react_1.useEffect(function () { return buscar(); }, [inputValue, buscar]);
|
|
339
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
323
340
|
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
341
|
+
console.log('Lista', dados.lista);
|
|
342
|
+
return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value, onChange: onChange }, { 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, 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', 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) || ''); }, getOptionSelected: function (o, v) { return o[0] === v; }, autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
327
343
|
params.InputProps.endAdornment,
|
|
328
344
|
react_1.default.createElement(core_1.Fade, { in: loading },
|
|
329
|
-
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })))) }) }))); }
|
|
345
|
+
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })))) }) }))); }, ListboxComponent: ListboxFavorites, ListboxProps: { dados: dados, setDados: setDados, favoritePage: favoritePage, groupHeaderColor: groupHeaderColor, groupTitleColor: groupTitleColor } })));
|
|
330
346
|
};
|
|
331
347
|
exports.default = AutoCompleteFavorites;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from
|
|
1
|
+
export { default } from './AutoCompleteFavorites';
|
|
2
|
+
export * from './AutoCompleteFavorites';
|
|
@@ -145,4 +145,7 @@ export { default as ThreadLog } from './ThreadLog';
|
|
|
145
145
|
export * from './ThreadLog';
|
|
146
146
|
|
|
147
147
|
export { default as UtilAutoComplete } from './UtilAutoComplete';
|
|
148
|
-
export * from './UtilAutoComplete';
|
|
148
|
+
export * from './UtilAutoComplete';
|
|
149
|
+
|
|
150
|
+
export { default as AutoCompleteFavorites } from './AutoCompleteFavorites';
|
|
151
|
+
export * from './AutoCompleteFavorites';
|
package/dist/components/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.UtilAutoComplete = exports.ThreadLog = exports.TextArea = exports.Tabs = exports.TablePicker = exports.Stepper = exports.SimpleTable = exports.Select = exports.ProgressBar = exports.Programa = exports.Pagination = exports.OutputText = exports.OtpInput = exports.MultipleSelect = exports.MonthPicker = exports.ModalProvider = exports.MenuBar = exports.MaterialButton = exports.ListSelect = exports.InputTags = exports.Input = exports.ImageResizeButton = exports.ImageResize = exports.Highlight = exports.FormVisualizer = exports.FileUploader = exports.FilePreparer = exports.DropArea = exports.Compartilhar = exports.Collapse = exports.CartaoUsuario = exports.Calendar = exports.Cabecalho = exports.Button = exports.BarraFerramentas = exports.BarChart = exports.AutoComplete = exports.ArgousSimpleTable = exports.ArgousProgressBar = exports.ArgousPagination = exports.ArgousInput = exports.ArgousComplexTableToolbar = exports.ArgousComplexTableHead = exports.ArgousComplexTableBody = exports.ArgousComplexTable = exports.ArgousComplexPagination = exports.ArgousAvatar = exports.ArgousAction = exports.Alert = void 0;
|
|
16
|
+
exports.AutoCompleteFavorites = exports.UtilAutoComplete = exports.ThreadLog = exports.TextArea = exports.Tabs = exports.TablePicker = exports.Stepper = exports.SimpleTable = exports.Select = exports.ProgressBar = exports.Programa = exports.Pagination = exports.OutputText = exports.OtpInput = exports.MultipleSelect = exports.MonthPicker = exports.ModalProvider = exports.MenuBar = exports.MaterialButton = exports.ListSelect = exports.InputTags = exports.Input = exports.ImageResizeButton = exports.ImageResize = exports.Highlight = exports.FormVisualizer = exports.FileUploader = exports.FilePreparer = exports.DropArea = exports.Compartilhar = exports.Collapse = exports.CartaoUsuario = exports.Calendar = exports.Cabecalho = exports.Button = exports.BarraFerramentas = exports.BarChart = exports.AutoComplete = exports.ArgousSimpleTable = exports.ArgousProgressBar = exports.ArgousPagination = exports.ArgousInput = exports.ArgousComplexTableToolbar = exports.ArgousComplexTableHead = exports.ArgousComplexTableBody = exports.ArgousComplexTable = exports.ArgousComplexPagination = exports.ArgousAvatar = exports.ArgousAction = exports.Alert = void 0;
|
|
17
17
|
var Alert_1 = require("./Alert");
|
|
18
18
|
Object.defineProperty(exports, "Alert", { enumerable: true, get: function () { return __importDefault(Alert_1).default; } });
|
|
19
19
|
__exportStar(require("./Alert"), exports);
|
|
@@ -160,3 +160,6 @@ __exportStar(require("./ThreadLog"), exports);
|
|
|
160
160
|
var UtilAutoComplete_1 = require("./UtilAutoComplete");
|
|
161
161
|
Object.defineProperty(exports, "UtilAutoComplete", { enumerable: true, get: function () { return __importDefault(UtilAutoComplete_1).default; } });
|
|
162
162
|
__exportStar(require("./UtilAutoComplete"), exports);
|
|
163
|
+
var AutoCompleteFavorites_1 = require("./AutoCompleteFavorites");
|
|
164
|
+
Object.defineProperty(exports, "AutoCompleteFavorites", { enumerable: true, get: function () { return __importDefault(AutoCompleteFavorites_1).default; } });
|
|
165
|
+
__exportStar(require("./AutoCompleteFavorites"), exports);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { TextFieldProps } from '@material-ui/core';
|
|
2
|
+
import { AutocompleteProps, AutocompleteChangeDetails } from '@material-ui/lab';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
export interface AutoCompleteFavoritesProps extends Omit<AutocompleteProps<any, false, false, false>, 'getOptionLabel'>{
|
|
6
|
+
/**
|
|
7
|
+
* Valor do campo
|
|
8
|
+
*/
|
|
9
|
+
value?: Array<number|string> | object,
|
|
10
|
+
/**
|
|
11
|
+
* Props repassados ao componente Textfield
|
|
12
|
+
*/
|
|
13
|
+
textFieldProps?: TextFieldProps,
|
|
14
|
+
/**
|
|
15
|
+
* Callback fired when the value changes.
|
|
16
|
+
*
|
|
17
|
+
* @param event — The event source of the callback.
|
|
18
|
+
*
|
|
19
|
+
* @param value — The new value of the component.
|
|
20
|
+
*
|
|
21
|
+
* @param reason — One of "create-option", "select-option", "remove-option", "blur", "clear" ou "only-one-left".
|
|
22
|
+
*/
|
|
23
|
+
onChange?: ((event: React.ChangeEvent<{}>, value: any, reason: 'create-option' | 'select-option' | 'remove-option' | 'blur' | 'clear' | 'only-one-left', details?: AutocompleteChangeDetails<any> | undefined) => void) | undefined,
|
|
24
|
+
/**
|
|
25
|
+
* Formata o valor que aparece na listagem
|
|
26
|
+
*
|
|
27
|
+
* @param option - Opção sendo testada ou selecionada
|
|
28
|
+
*
|
|
29
|
+
* @param lista - Lista com todas as opções
|
|
30
|
+
*/
|
|
31
|
+
getOptionLabel?: ((option: Array<any>, lista: Array<Array<any>>) => string),
|
|
32
|
+
/**
|
|
33
|
+
* Utiliza um pgCode diferente do padrão
|
|
34
|
+
*/
|
|
35
|
+
pgCode?: string,
|
|
36
|
+
/**
|
|
37
|
+
* Objeto de busca personalizado
|
|
38
|
+
*/
|
|
39
|
+
busca?: string,
|
|
40
|
+
/**
|
|
41
|
+
* Objeto de resposta personalizado
|
|
42
|
+
*/
|
|
43
|
+
resposta?: string,
|
|
44
|
+
/**
|
|
45
|
+
* Action personalizada
|
|
46
|
+
*/
|
|
47
|
+
action?: string,
|
|
48
|
+
/**
|
|
49
|
+
* Label do campo
|
|
50
|
+
*/
|
|
51
|
+
label?: string,
|
|
52
|
+
/**
|
|
53
|
+
* Parametros utilizados no metodo de busca
|
|
54
|
+
*/
|
|
55
|
+
searchParams?: object,
|
|
56
|
+
/**
|
|
57
|
+
* Define a cor do loading
|
|
58
|
+
*/
|
|
59
|
+
loadingColor?: string,
|
|
60
|
+
/**
|
|
61
|
+
* Parametro que define se terá paginação
|
|
62
|
+
*/
|
|
63
|
+
favoritePage?: boolean,
|
|
64
|
+
/**
|
|
65
|
+
* Array contendo nome do grupo
|
|
66
|
+
*/
|
|
67
|
+
groupName?: Array<string>,
|
|
68
|
+
/**
|
|
69
|
+
* Array contendo a cor do titulo no grupo
|
|
70
|
+
*/
|
|
71
|
+
groupTitleColor?: Array<string>,
|
|
72
|
+
/**
|
|
73
|
+
* Array contendo o backgroundColor do header no grupo
|
|
74
|
+
*/
|
|
75
|
+
groupHeaderColor?: Array<string>,
|
|
76
|
+
/**
|
|
77
|
+
* Função para filtrar a lista de opções
|
|
78
|
+
*
|
|
79
|
+
* @param valor - Valor setado no componente
|
|
80
|
+
* @param item - Item a ser testado contra o valor
|
|
81
|
+
*
|
|
82
|
+
* @returns {boolean} Retorna true se item de ser removido da lista
|
|
83
|
+
*/
|
|
84
|
+
filterFunction?: (valor: any, item: any) => boolean,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare function AutoCompleteFavorites(props: AutoCompleteFavoritesProps): JSX.Element
|
|
88
|
+
|
|
89
|
+
export default AutoCompleteFavorites;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serverAction, setError } from '../../utils/api';
|
|
2
|
-
import {
|
|
2
|
+
import { CircularProgress, Fade, ListItem, ListItemText, ListSubheader, makeStyles, Slide, TextField, Tooltip, withStyles } from '@material-ui/core';
|
|
3
3
|
import { Autocomplete } from '@material-ui/lab';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { isObject, isString } from 'lodash';
|
|
@@ -89,16 +89,16 @@ const useStyles = makeStyles((theme) => ({
|
|
|
89
89
|
}
|
|
90
90
|
}));
|
|
91
91
|
|
|
92
|
-
const CustomTooltip = withStyles((theme) => ({
|
|
92
|
+
export const CustomTooltip = withStyles((theme) => ({
|
|
93
93
|
tooltip: theme.palette.type === 'light' ? {
|
|
94
94
|
fontSize: 15,
|
|
95
95
|
fontWeight: 400,
|
|
96
|
-
color: '
|
|
96
|
+
color: '#FFF',
|
|
97
97
|
backgroundColor: '#333333e3',
|
|
98
98
|
} : {
|
|
99
99
|
fontSize: 15,
|
|
100
100
|
fontWeight: 400,
|
|
101
|
-
color: '
|
|
101
|
+
color: '#000',
|
|
102
102
|
backgroundColor: '#fbfbfbd1',
|
|
103
103
|
},
|
|
104
104
|
arrow: {
|
|
@@ -106,116 +106,9 @@ const CustomTooltip = withStyles((theme) => ({
|
|
|
106
106
|
}
|
|
107
107
|
}))(Tooltip);
|
|
108
108
|
|
|
109
|
-
const ListboxFavorites = forwardRef((props, ref) => {
|
|
110
|
-
|
|
111
|
-
const classes = useStyles();
|
|
112
|
-
const { children, favoritePage, dados, setDados, groupHeaderColor, groupTitleColor } = props;
|
|
113
|
-
const { pageNumber, favoritosLength, direction, slide } = dados;
|
|
114
|
-
|
|
115
|
-
function retornaInicio() {
|
|
116
|
-
switch (pageNumber) {
|
|
117
|
-
case 1:
|
|
118
|
-
return 0;
|
|
119
|
-
case 2:
|
|
120
|
-
return 7;
|
|
121
|
-
case 3:
|
|
122
|
-
return 14;
|
|
123
|
-
default: return;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function retornaFim() {
|
|
128
|
-
switch (pageNumber) {
|
|
129
|
-
case 1:
|
|
130
|
-
return 7;
|
|
131
|
-
case 2:
|
|
132
|
-
return 14;
|
|
133
|
-
case 3:
|
|
134
|
-
return favoritosLength;
|
|
135
|
-
default: return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function retornaArray(sectionIndex, section) {
|
|
140
|
-
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
141
|
-
return section.props.children[1].props.children;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function retornaEstrutura(sectionIndex, item) {
|
|
145
|
-
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
146
|
-
return (
|
|
147
|
-
<Slide in={slide} direction={direction}>
|
|
148
|
-
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
149
|
-
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
150
|
-
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
151
|
-
</ListItem>
|
|
152
|
-
</CustomTooltip>
|
|
153
|
-
</Slide>
|
|
154
|
-
);
|
|
155
|
-
} return (
|
|
156
|
-
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
157
|
-
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
158
|
-
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
159
|
-
</ListItem>
|
|
160
|
-
</CustomTooltip>
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function buttonClick(evento, value) {
|
|
165
|
-
evento.preventDefault();
|
|
166
|
-
evento.stopPropagation();
|
|
167
|
-
if (value !== pageNumber) {
|
|
168
|
-
verificaSaidaSlide(value);
|
|
169
|
-
setDados(v => ({ ...v, slide: false }));
|
|
170
|
-
setTimeout(() => {
|
|
171
|
-
setDados(v => ({ ...v, pageNumber: value, direction: retornaDirection(value) }));
|
|
172
|
-
setTimeout(() => setDados(v => ({ ...v, slide: true })), 100);
|
|
173
|
-
}, 200);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function verificaSaidaSlide(value) {
|
|
178
|
-
let direction = '';
|
|
179
|
-
if ((value === 2 || value === 3) && pageNumber === 1) direction = 'right';
|
|
180
|
-
else if (value === 3 && pageNumber === 2) direction = 'right';
|
|
181
|
-
else if (value === 1 && pageNumber === 2) direction = 'left';
|
|
182
|
-
direction && setDados(v => ({ ...v, direction: direction }));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function retornaDirection(value) {
|
|
186
|
-
if (value < pageNumber) return 'right';
|
|
187
|
-
return 'left';
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return children.map((section, sectionIndex) => (
|
|
191
|
-
<ul {...props} className={clsx('MuiAutocomplete-listbox', classes.box)}>
|
|
192
|
-
<ListSubheader className={classes.subHeader} style={{ backgroundColor: groupHeaderColor?.[sectionIndex], color: groupTitleColor?.[sectionIndex] }}>
|
|
193
|
-
{section.props.children[0].props.children}
|
|
194
|
-
<Fade in={sectionIndex === 0 && favoritePage && favoritosLength > 7}>
|
|
195
|
-
<div className={classes.divButton}>
|
|
196
|
-
<div className={classes.areaButton}>
|
|
197
|
-
<div onClick={e => buttonClick(e, 1)} className={clsx({ [classes.buttonActive]: pageNumber === 1 }, classes.button)}>1</div>
|
|
198
|
-
</div>
|
|
199
|
-
<div className={classes.areaButton}>
|
|
200
|
-
<div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
|
|
201
|
-
</div>
|
|
202
|
-
{favoritosLength > 14 &&
|
|
203
|
-
<>
|
|
204
|
-
<div className={classes.areaButton}>
|
|
205
|
-
<div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
|
|
206
|
-
</div>
|
|
207
|
-
</>
|
|
208
|
-
}
|
|
209
|
-
</div>
|
|
210
|
-
</Fade>
|
|
211
|
-
</ListSubheader>
|
|
212
|
-
{retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item))}
|
|
213
|
-
</ul>
|
|
214
|
-
));
|
|
215
|
-
});
|
|
216
|
-
|
|
217
109
|
const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode, favoritePage, groupName, groupHeaderColor, groupTitleColor, loadingColor, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
|
|
218
110
|
|
|
111
|
+
const classes = useStyles();
|
|
219
112
|
const [dados, setDados] = useState({
|
|
220
113
|
lista: [],
|
|
221
114
|
slide: true,
|
|
@@ -226,16 +119,115 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
226
119
|
const [loading, setLoading] = useState(false);
|
|
227
120
|
const [inputValue, setInputValue] = useState('');
|
|
228
121
|
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
122
|
+
const ListboxFavorites = forwardRef((props, ref) => {
|
|
123
|
+
const { children, favoritePage, dados, setDados, groupHeaderColor, groupTitleColor } = props;
|
|
124
|
+
const { pageNumber, favoritosLength, direction, slide } = dados;
|
|
125
|
+
|
|
126
|
+
console.log('Listbox', children);
|
|
127
|
+
|
|
128
|
+
function retornaInicio() {
|
|
129
|
+
switch (pageNumber) {
|
|
130
|
+
case 1:
|
|
131
|
+
return 0;
|
|
132
|
+
case 2:
|
|
133
|
+
return 7;
|
|
134
|
+
case 3:
|
|
135
|
+
return 14;
|
|
136
|
+
default: return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function retornaFim() {
|
|
141
|
+
switch (pageNumber) {
|
|
142
|
+
case 1:
|
|
143
|
+
return 7;
|
|
144
|
+
case 2:
|
|
145
|
+
return 14;
|
|
146
|
+
case 3:
|
|
147
|
+
return favoritosLength;
|
|
148
|
+
default: return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function retornaArray(sectionIndex, section) {
|
|
153
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
154
|
+
return section.props.children[1].props.children;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function retornaEstrutura(sectionIndex, item) {
|
|
158
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
159
|
+
return (
|
|
160
|
+
<Slide in={slide} direction={direction}>
|
|
161
|
+
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
162
|
+
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
163
|
+
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
164
|
+
</ListItem>
|
|
165
|
+
</CustomTooltip>
|
|
166
|
+
</Slide>
|
|
167
|
+
);
|
|
168
|
+
} return (
|
|
169
|
+
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
170
|
+
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
171
|
+
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
172
|
+
</ListItem>
|
|
173
|
+
</CustomTooltip>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function buttonClick(evento, value) {
|
|
178
|
+
evento.preventDefault();
|
|
179
|
+
evento.stopPropagation();
|
|
180
|
+
if (value !== pageNumber) {
|
|
181
|
+
verificaSaidaSlide(value);
|
|
182
|
+
setDados(v => ({ ...v, slide: false }));
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
setDados(v => ({ ...v, pageNumber: value, direction: retornaDirection(value) }));
|
|
185
|
+
setTimeout(() => setDados(v => ({ ...v, slide: true })), 100);
|
|
186
|
+
}, 200);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function verificaSaidaSlide(value) {
|
|
191
|
+
let direction = '';
|
|
192
|
+
if ((value === 2 || value === 3) && pageNumber === 1) direction = 'right';
|
|
193
|
+
else if (value === 3 && pageNumber === 2) direction = 'right';
|
|
194
|
+
else if (value === 1 && pageNumber === 2) direction = 'left';
|
|
195
|
+
direction && setDados(v => ({ ...v, direction: direction }));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function retornaDirection(value) {
|
|
199
|
+
if (value < pageNumber) return 'right';
|
|
200
|
+
return 'left';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return children.map((section, sectionIndex) => (
|
|
204
|
+
<ul {...props} className={clsx('MuiAutocomplete-listbox', classes.box)}>
|
|
205
|
+
<ListSubheader className={classes.subHeader} style={{ backgroundColor: groupHeaderColor?.[sectionIndex], color: groupTitleColor?.[sectionIndex] }}>
|
|
206
|
+
{section.props.children[0].props.children}
|
|
207
|
+
<Fade in={sectionIndex === 0 && favoritePage && favoritosLength > 7}>
|
|
208
|
+
<div className={classes.divButton}>
|
|
209
|
+
<div className={classes.areaButton}>
|
|
210
|
+
<div onClick={e => buttonClick(e, 1)} className={clsx({ [classes.buttonActive]: pageNumber === 1 }, classes.button)}>1</div>
|
|
211
|
+
</div>
|
|
212
|
+
<div className={classes.areaButton}>
|
|
213
|
+
<div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
|
|
214
|
+
</div>
|
|
215
|
+
{favoritosLength > 14 &&
|
|
216
|
+
<React.Fragment>
|
|
217
|
+
<div className={classes.areaButton}>
|
|
218
|
+
<div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
|
|
219
|
+
</div>
|
|
220
|
+
</React.Fragment>
|
|
221
|
+
}
|
|
222
|
+
</div>
|
|
223
|
+
</Fade>
|
|
224
|
+
</ListSubheader>
|
|
225
|
+
{retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item))}
|
|
226
|
+
</ul>
|
|
227
|
+
));
|
|
228
|
+
});
|
|
237
229
|
|
|
238
|
-
function carimbaLista(lista) {
|
|
230
|
+
async function carimbaLista(lista) {
|
|
239
231
|
let completo = [];
|
|
240
232
|
lista.map((arr, index) => {
|
|
241
233
|
index === 0 && favoritePage && setDados(v => ({ ...v, favoritosLength: arr.length }));
|
|
@@ -249,25 +241,37 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
249
241
|
setDados(v => ({ ...v, lista: completo }));
|
|
250
242
|
}
|
|
251
243
|
|
|
244
|
+
const buscar = useCallback(async valor => {
|
|
245
|
+
setLoading(true);
|
|
246
|
+
const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
|
|
247
|
+
if (res) console.log('Resposta busca', res);
|
|
248
|
+
if (res[resposta || 'result']?.length > 1) await carimbaLista(res[resposta || 'result']);
|
|
249
|
+
else if (res[resposta || 'result']) setDados({ lista: res[resposta || 'result'] || [] });
|
|
250
|
+
else setError('Erro ao tentar buscar dados.');
|
|
251
|
+
setLoading(false);
|
|
252
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
253
|
+
}, [inputValue, searchParams]);
|
|
254
|
+
|
|
252
255
|
useEffect(() => buscar(), [inputValue, buscar]);
|
|
256
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
253
257
|
useEffect(() => isString(value) && buscar(value), []);
|
|
254
258
|
|
|
259
|
+
console.log('Lista', dados.lista);
|
|
260
|
+
|
|
255
261
|
return (
|
|
256
262
|
<Autocomplete
|
|
263
|
+
{...props}
|
|
264
|
+
{...{ value, onChange }}
|
|
265
|
+
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
266
|
+
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
267
|
+
noOptionsText={inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado'}
|
|
268
|
+
onInputChange={e => setInputValue(e?.target?.value || '')}
|
|
269
|
+
getOptionSelected={(o, v) => o[0] === v}
|
|
257
270
|
autoComplete
|
|
258
271
|
autoHighlight
|
|
259
272
|
openText='Abrir'
|
|
260
273
|
clearText='Limpar'
|
|
261
274
|
filterSelectedOptions
|
|
262
|
-
onInputChange={e => setInputValue(e?.target?.value || '')}
|
|
263
|
-
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
264
|
-
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
265
|
-
getOptionSelected={(o, v) => o[0] === v}
|
|
266
|
-
renderTags={(value, getTagProps) =>
|
|
267
|
-
value.map((option, index) => (
|
|
268
|
-
<Chip variant='outlined' size='small' label={option} {...getTagProps({ index })} />
|
|
269
|
-
))
|
|
270
|
-
}
|
|
271
275
|
renderInput={params => (
|
|
272
276
|
<TextField
|
|
273
277
|
margin='dense'
|
|
@@ -279,16 +283,14 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
279
283
|
...textFieldProps.InputProps,
|
|
280
284
|
...params.InputProps,
|
|
281
285
|
endAdornment: (
|
|
282
|
-
|
|
286
|
+
<React.Fragment>
|
|
283
287
|
{params.InputProps.endAdornment}
|
|
284
288
|
<Fade in={loading}><CircularProgress disableShrink color={loadingColor || 'inherit'} size={20} /></Fade>
|
|
285
|
-
|
|
289
|
+
</React.Fragment>
|
|
286
290
|
)
|
|
287
291
|
}}
|
|
288
292
|
/>
|
|
289
293
|
)}
|
|
290
|
-
{...props}
|
|
291
|
-
{...{ value, onChange }}
|
|
292
294
|
ListboxComponent={ListboxFavorites}
|
|
293
295
|
ListboxProps={{ dados, setDados, favoritePage, groupHeaderColor, groupTitleColor }}
|
|
294
296
|
/>
|
|
@@ -145,4 +145,7 @@ export { default as ThreadLog } from './ThreadLog';
|
|
|
145
145
|
export * from './ThreadLog';
|
|
146
146
|
|
|
147
147
|
export { default as UtilAutoComplete } from './UtilAutoComplete';
|
|
148
|
-
export * from './UtilAutoComplete';
|
|
148
|
+
export * from './UtilAutoComplete';
|
|
149
|
+
|
|
150
|
+
export { default as AutoCompleteFavorites } from './AutoCompleteFavorites';
|
|
151
|
+
export * from './AutoCompleteFavorites';
|
package/lib/components/index.js
CHANGED
|
@@ -143,4 +143,7 @@ export { default as ThreadLog } from './ThreadLog';
|
|
|
143
143
|
export * from './ThreadLog';
|
|
144
144
|
|
|
145
145
|
export { default as UtilAutoComplete } from './UtilAutoComplete';
|
|
146
|
-
export * from './UtilAutoComplete';
|
|
146
|
+
export * from './UtilAutoComplete';
|
|
147
|
+
|
|
148
|
+
export { default as AutoCompleteFavorites } from './AutoCompleteFavorites';
|
|
149
|
+
export * from './AutoCompleteFavorites';
|