argous 1.2.136 → 1.2.140
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 -21
- package/dist/components/AutoCompleteFavorites/AutoCompleteFavorites.js +125 -113
- package/dist/components/AutoCompleteFavorites/index.d.ts +2 -0
- package/dist/components/AutoCompleteFavorites/index.js +8 -0
- 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 +132 -135
- package/lib/components/AutoCompleteFavorites/index.d.ts +2 -0
- package/lib/components/AutoCompleteFavorites/index.js +1 -0
- package/lib/components/index.d.ts +4 -1
- package/lib/components/index.js +4 -1
- package/package.json +1 -1
|
@@ -1,21 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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,112 @@ 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
|
+
function retornaInicio() {
|
|
205
|
+
switch (pageNumber) {
|
|
206
|
+
case 1:
|
|
207
|
+
return 0;
|
|
208
|
+
case 2:
|
|
209
|
+
return 7;
|
|
210
|
+
case 3:
|
|
211
|
+
return 14;
|
|
212
|
+
default: return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function retornaFim() {
|
|
216
|
+
switch (pageNumber) {
|
|
217
|
+
case 1:
|
|
218
|
+
return 7;
|
|
219
|
+
case 2:
|
|
220
|
+
return 14;
|
|
221
|
+
case 3:
|
|
222
|
+
return favoritosLength;
|
|
223
|
+
default: return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function retornaArray(sectionIndex, section) {
|
|
227
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7)
|
|
228
|
+
return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
229
|
+
return section.props.children[1].props.children;
|
|
230
|
+
}
|
|
231
|
+
function retornaEstrutura(sectionIndex, item) {
|
|
232
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
233
|
+
return (react_1.default.createElement(core_1.Slide, { in: slide, direction: direction },
|
|
234
|
+
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 } } },
|
|
235
|
+
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
236
|
+
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText })))));
|
|
237
|
+
}
|
|
238
|
+
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 } } },
|
|
239
|
+
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
240
|
+
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText }))));
|
|
241
|
+
}
|
|
242
|
+
function buttonClick(evento, value) {
|
|
243
|
+
evento.preventDefault();
|
|
244
|
+
evento.stopPropagation();
|
|
245
|
+
if (value !== pageNumber) {
|
|
246
|
+
verificaSaidaSlide(value);
|
|
247
|
+
setDados(function (v) { return (__assign(__assign({}, v), { slide: false })); });
|
|
248
|
+
setTimeout(function () {
|
|
249
|
+
setDados(function (v) { return (__assign(__assign({}, v), { pageNumber: value, direction: retornaDirection(value) })); });
|
|
250
|
+
setTimeout(function () { return setDados(function (v) { return (__assign(__assign({}, v), { slide: true })); }); }, 100);
|
|
251
|
+
}, 200);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function verificaSaidaSlide(value) {
|
|
255
|
+
var direction = '';
|
|
256
|
+
if ((value === 2 || value === 3) && pageNumber === 1)
|
|
257
|
+
direction = 'right';
|
|
258
|
+
else if (value === 3 && pageNumber === 2)
|
|
259
|
+
direction = 'right';
|
|
260
|
+
else if (value === 1 && pageNumber === 2)
|
|
261
|
+
direction = 'left';
|
|
262
|
+
direction && setDados(function (v) { return (__assign(__assign({}, v), { direction: direction })); });
|
|
263
|
+
}
|
|
264
|
+
function retornaDirection(value) {
|
|
265
|
+
if (value < pageNumber)
|
|
266
|
+
return 'right';
|
|
267
|
+
return 'left';
|
|
268
|
+
}
|
|
269
|
+
return children.map(function (section, sectionIndex) {
|
|
270
|
+
var _a, _b, _c;
|
|
271
|
+
return (react_1.default.createElement("ul", __assign({}, props, { className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }),
|
|
272
|
+
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] } },
|
|
273
|
+
section.props.children[0].props.children,
|
|
274
|
+
react_1.default.createElement(core_1.Fade, { in: sectionIndex === 0 && favoritePage && favoritosLength > 7 },
|
|
275
|
+
react_1.default.createElement("div", { className: classes.divButton },
|
|
276
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
277
|
+
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")),
|
|
278
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
279
|
+
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")),
|
|
280
|
+
favoritosLength > 14 &&
|
|
281
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
282
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
283
|
+
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")))))),
|
|
284
|
+
retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item); })));
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
function carimbaLista(lista) {
|
|
288
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
289
|
+
var completo;
|
|
290
|
+
return __generator(this, function (_a) {
|
|
291
|
+
completo = [];
|
|
292
|
+
lista.map(function (arr, index) {
|
|
293
|
+
index === 0 && favoritePage && setDados(function (v) { return (__assign(__assign({}, v), { favoritosLength: arr.length })); });
|
|
294
|
+
return arr.map(function (itemArr) { return itemArr.length < 3 && itemArr.push(groupName[index]); });
|
|
295
|
+
});
|
|
296
|
+
lista.forEach(function (v) {
|
|
297
|
+
for (var _i = 0, _a = v.values(); _i < _a.length; _i++) {
|
|
298
|
+
var item = _a[_i];
|
|
299
|
+
completo.push(item);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
setDados(function (v) { return (__assign(__assign({}, v), { lista: completo })); });
|
|
303
|
+
return [2 /*return*/];
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
286
307
|
var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
|
|
287
308
|
var res;
|
|
288
309
|
var _a;
|
|
@@ -294,38 +315,29 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
294
315
|
return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
|
|
295
316
|
case 1:
|
|
296
317
|
res = _c.sent();
|
|
297
|
-
if (((_b = res[resposta || 'result']) === null || _b === void 0 ? void 0 : _b.length) > 1)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
318
|
+
if (!(((_b = res[resposta || 'result']) === null || _b === void 0 ? void 0 : _b.length) > 1)) return [3 /*break*/, 3];
|
|
319
|
+
return [4 /*yield*/, carimbaLista(res[resposta || 'result'])];
|
|
320
|
+
case 2:
|
|
321
|
+
_c.sent();
|
|
322
|
+
return [3 /*break*/, 4];
|
|
323
|
+
case 3:
|
|
324
|
+
if (res[resposta || 'result'])
|
|
325
|
+
setDados({ lista: res[resposta || 'result'] || [] });
|
|
301
326
|
else
|
|
302
327
|
api_1.setError('Erro ao tentar buscar dados.');
|
|
328
|
+
_c.label = 4;
|
|
329
|
+
case 4:
|
|
303
330
|
setLoading(false);
|
|
304
331
|
return [2 /*return*/];
|
|
305
332
|
}
|
|
306
333
|
});
|
|
307
334
|
}); }, [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
335
|
react_1.useEffect(function () { return buscar(); }, [inputValue, buscar]);
|
|
336
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
323
337
|
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
324
|
-
return (react_1.default.createElement(lab_1.Autocomplete, __assign({
|
|
325
|
-
return value.map(function (option, index) { return (react_1.default.createElement(core_1.Chip, __assign({ variant: 'outlined', size: 'small', label: option }, getTagProps({ index: index })))); });
|
|
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,
|
|
338
|
+
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
339
|
params.InputProps.endAdornment,
|
|
328
340
|
react_1.default.createElement(core_1.Fade, { in: loading },
|
|
329
|
-
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })))) }) }))); }
|
|
341
|
+
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
342
|
};
|
|
331
|
-
exports.default =
|
|
343
|
+
exports.default = AutoCompleteFavorites;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var AutoCompleteFavorites_1 = require("./AutoCompleteFavorites");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(AutoCompleteFavorites_1).default; } });
|
|
@@ -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,113 @@ 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
|
+
function retornaInicio() {
|
|
127
|
+
switch (pageNumber) {
|
|
128
|
+
case 1:
|
|
129
|
+
return 0;
|
|
130
|
+
case 2:
|
|
131
|
+
return 7;
|
|
132
|
+
case 3:
|
|
133
|
+
return 14;
|
|
134
|
+
default: return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function retornaFim() {
|
|
139
|
+
switch (pageNumber) {
|
|
140
|
+
case 1:
|
|
141
|
+
return 7;
|
|
142
|
+
case 2:
|
|
143
|
+
return 14;
|
|
144
|
+
case 3:
|
|
145
|
+
return favoritosLength;
|
|
146
|
+
default: return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function retornaArray(sectionIndex, section) {
|
|
151
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
152
|
+
return section.props.children[1].props.children;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function retornaEstrutura(sectionIndex, item) {
|
|
156
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
157
|
+
return (
|
|
158
|
+
<Slide in={slide} direction={direction}>
|
|
159
|
+
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
160
|
+
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
161
|
+
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
162
|
+
</ListItem>
|
|
163
|
+
</CustomTooltip>
|
|
164
|
+
</Slide>
|
|
165
|
+
);
|
|
166
|
+
} return (
|
|
167
|
+
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
168
|
+
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
169
|
+
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
170
|
+
</ListItem>
|
|
171
|
+
</CustomTooltip>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function buttonClick(evento, value) {
|
|
176
|
+
evento.preventDefault();
|
|
177
|
+
evento.stopPropagation();
|
|
178
|
+
if (value !== pageNumber) {
|
|
179
|
+
verificaSaidaSlide(value);
|
|
180
|
+
setDados(v => ({ ...v, slide: false }));
|
|
181
|
+
setTimeout(() => {
|
|
182
|
+
setDados(v => ({ ...v, pageNumber: value, direction: retornaDirection(value) }));
|
|
183
|
+
setTimeout(() => setDados(v => ({ ...v, slide: true })), 100);
|
|
184
|
+
}, 200);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function verificaSaidaSlide(value) {
|
|
189
|
+
let direction = '';
|
|
190
|
+
if ((value === 2 || value === 3) && pageNumber === 1) direction = 'right';
|
|
191
|
+
else if (value === 3 && pageNumber === 2) direction = 'right';
|
|
192
|
+
else if (value === 1 && pageNumber === 2) direction = 'left';
|
|
193
|
+
direction && setDados(v => ({ ...v, direction: direction }));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function retornaDirection(value) {
|
|
197
|
+
if (value < pageNumber) return 'right';
|
|
198
|
+
return 'left';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return children.map((section, sectionIndex) => (
|
|
202
|
+
<ul {...props} className={clsx('MuiAutocomplete-listbox', classes.box)}>
|
|
203
|
+
<ListSubheader className={classes.subHeader} style={{ backgroundColor: groupHeaderColor?.[sectionIndex], color: groupTitleColor?.[sectionIndex] }}>
|
|
204
|
+
{section.props.children[0].props.children}
|
|
205
|
+
<Fade in={sectionIndex === 0 && favoritePage && favoritosLength > 7}>
|
|
206
|
+
<div className={classes.divButton}>
|
|
207
|
+
<div className={classes.areaButton}>
|
|
208
|
+
<div onClick={e => buttonClick(e, 1)} className={clsx({ [classes.buttonActive]: pageNumber === 1 }, classes.button)}>1</div>
|
|
209
|
+
</div>
|
|
210
|
+
<div className={classes.areaButton}>
|
|
211
|
+
<div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
|
|
212
|
+
</div>
|
|
213
|
+
{favoritosLength > 14 &&
|
|
214
|
+
<React.Fragment>
|
|
215
|
+
<div className={classes.areaButton}>
|
|
216
|
+
<div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
|
|
217
|
+
</div>
|
|
218
|
+
</React.Fragment>
|
|
219
|
+
}
|
|
220
|
+
</div>
|
|
221
|
+
</Fade>
|
|
222
|
+
</ListSubheader>
|
|
223
|
+
{retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item))}
|
|
224
|
+
</ul>
|
|
225
|
+
));
|
|
226
|
+
});
|
|
237
227
|
|
|
238
|
-
function carimbaLista(lista) {
|
|
228
|
+
async function carimbaLista(lista) {
|
|
239
229
|
let completo = [];
|
|
240
230
|
lista.map((arr, index) => {
|
|
241
231
|
index === 0 && favoritePage && setDados(v => ({ ...v, favoritosLength: arr.length }));
|
|
@@ -249,25 +239,34 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
249
239
|
setDados(v => ({ ...v, lista: completo }));
|
|
250
240
|
}
|
|
251
241
|
|
|
242
|
+
const buscar = useCallback(async valor => {
|
|
243
|
+
setLoading(true);
|
|
244
|
+
const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
|
|
245
|
+
if (res[resposta || 'result']?.length > 1) await carimbaLista(res[resposta || 'result']);
|
|
246
|
+
else if (res[resposta || 'result']) setDados({ lista: res[resposta || 'result'] || [] });
|
|
247
|
+
else setError('Erro ao tentar buscar dados.');
|
|
248
|
+
setLoading(false);
|
|
249
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
250
|
+
}, [inputValue, searchParams]);
|
|
251
|
+
|
|
252
252
|
useEffect(() => buscar(), [inputValue, buscar]);
|
|
253
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
253
254
|
useEffect(() => isString(value) && buscar(value), []);
|
|
254
255
|
|
|
255
256
|
return (
|
|
256
257
|
<Autocomplete
|
|
258
|
+
{...props}
|
|
259
|
+
{...{ value, onChange }}
|
|
260
|
+
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
261
|
+
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
262
|
+
noOptionsText={inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado'}
|
|
263
|
+
onInputChange={e => setInputValue(e?.target?.value || '')}
|
|
264
|
+
getOptionSelected={(o, v) => o[0] === v}
|
|
257
265
|
autoComplete
|
|
258
266
|
autoHighlight
|
|
259
267
|
openText='Abrir'
|
|
260
268
|
clearText='Limpar'
|
|
261
269
|
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
270
|
renderInput={params => (
|
|
272
271
|
<TextField
|
|
273
272
|
margin='dense'
|
|
@@ -279,20 +278,18 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
279
278
|
...textFieldProps.InputProps,
|
|
280
279
|
...params.InputProps,
|
|
281
280
|
endAdornment: (
|
|
282
|
-
|
|
281
|
+
<React.Fragment>
|
|
283
282
|
{params.InputProps.endAdornment}
|
|
284
283
|
<Fade in={loading}><CircularProgress disableShrink color={loadingColor || 'inherit'} size={20} /></Fade>
|
|
285
|
-
|
|
284
|
+
</React.Fragment>
|
|
286
285
|
)
|
|
287
286
|
}}
|
|
288
287
|
/>
|
|
289
288
|
)}
|
|
290
|
-
{...props}
|
|
291
|
-
{...{ value, onChange }}
|
|
292
289
|
ListboxComponent={ListboxFavorites}
|
|
293
290
|
ListboxProps={{ dados, setDados, favoritePage, groupHeaderColor, groupTitleColor }}
|
|
294
291
|
/>
|
|
295
292
|
);
|
|
296
293
|
};
|
|
297
294
|
|
|
298
|
-
export default
|
|
295
|
+
export default AutoCompleteFavorites;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } 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/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';
|