@vector-business-services/cristal-ds-web 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +362 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +123 -87
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +46 -28
- package/dist/index.d.ts +46 -28
- package/dist/index.js +362 -185
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -16,9 +16,9 @@ var checkbox = require('primereact/checkbox');
|
|
|
16
16
|
var chip = require('primereact/chip');
|
|
17
17
|
var contextmenu = require('primereact/contextmenu');
|
|
18
18
|
var menu = require('primereact/menu');
|
|
19
|
-
var overlaypanel = require('primereact/overlaypanel');
|
|
20
19
|
var inputtext = require('primereact/inputtext');
|
|
21
20
|
var radiobutton = require('primereact/radiobutton');
|
|
21
|
+
var overlaypanel = require('primereact/overlaypanel');
|
|
22
22
|
var divider = require('primereact/divider');
|
|
23
23
|
var sidebar = require('primereact/sidebar');
|
|
24
24
|
var menubar = require('primereact/menubar');
|
|
@@ -140,6 +140,7 @@ var AutoComplete = react.forwardRef(function AutoComplete2({
|
|
|
140
140
|
error,
|
|
141
141
|
dropdown = false,
|
|
142
142
|
dropdownAriaLabel = "Mostrar op\xE7\xF5es",
|
|
143
|
+
openOnClick = true,
|
|
143
144
|
inputId,
|
|
144
145
|
required,
|
|
145
146
|
disabled,
|
|
@@ -151,6 +152,8 @@ var AutoComplete = react.forwardRef(function AutoComplete2({
|
|
|
151
152
|
const id = inputId ?? autoId;
|
|
152
153
|
const hintId = `${id}-hint`;
|
|
153
154
|
const supportText = error ?? hint;
|
|
155
|
+
const prime = react.useRef(null);
|
|
156
|
+
const aberta = () => Boolean(prime.current?.getOverlay());
|
|
154
157
|
const classes2 = [
|
|
155
158
|
"cr-field",
|
|
156
159
|
"cr-autocomplete",
|
|
@@ -169,6 +172,7 @@ var AutoComplete = react.forwardRef(function AutoComplete2({
|
|
|
169
172
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
170
173
|
autocomplete.AutoComplete,
|
|
171
174
|
{
|
|
175
|
+
ref: prime,
|
|
172
176
|
unstyled: true,
|
|
173
177
|
inputRef: ref,
|
|
174
178
|
inputId: id,
|
|
@@ -184,12 +188,31 @@ var AutoComplete = react.forwardRef(function AutoComplete2({
|
|
|
184
188
|
root: {
|
|
185
189
|
className: "cr-field__control cr-autocomplete__input",
|
|
186
190
|
"aria-describedby": juntarIds(supportText && hintId, props["aria-describedby"]),
|
|
187
|
-
"aria-invalid": error ? true : void 0
|
|
191
|
+
"aria-invalid": error ? true : void 0,
|
|
192
|
+
// O clique no campo abre a lista (o Prime só abre ao digitar ou pela seta).
|
|
193
|
+
...openOnClick && {
|
|
194
|
+
onClick: (event) => {
|
|
195
|
+
if (!aberta() && !disabled) {
|
|
196
|
+
prime.current?.search(event, event.currentTarget.value, "dropdown");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
188
200
|
}
|
|
189
201
|
},
|
|
190
202
|
// A seta: o botão de dropdown do Prime, por cima do fim do <input> (que segue sendo a caixa,
|
|
191
203
|
// para a lista continuar alinhada ao campo).
|
|
192
|
-
dropdownButton: {
|
|
204
|
+
dropdownButton: {
|
|
205
|
+
root: {
|
|
206
|
+
className: "cr-autocomplete__dropdown",
|
|
207
|
+
// Com a lista aberta, a seta fecha (como no p-autoComplete do PrimeNG 19); a do
|
|
208
|
+
// PrimeReact só abre. Na captura, antes do clique do Prime, que buscaria de novo.
|
|
209
|
+
onClickCapture: (event) => {
|
|
210
|
+
if (!aberta()) return;
|
|
211
|
+
event.stopPropagation();
|
|
212
|
+
prime.current?.hide();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
193
216
|
// O Prime mostra um spinner próprio enquanto busca; o Figma não define esse estado.
|
|
194
217
|
loadingIcon: { className: "cr-autocomplete__loader" },
|
|
195
218
|
panel: { className: "cr-lista cr-autocomplete__panel" },
|
|
@@ -1112,116 +1135,6 @@ var ContextMenu = react.forwardRef(function ContextMenu2({
|
|
|
1112
1135
|
}
|
|
1113
1136
|
);
|
|
1114
1137
|
});
|
|
1115
|
-
function DatePickerBase({
|
|
1116
|
-
variant = "outline",
|
|
1117
|
-
size = "large",
|
|
1118
|
-
label,
|
|
1119
|
-
hint,
|
|
1120
|
-
error,
|
|
1121
|
-
offDays,
|
|
1122
|
-
locale = LOCALE,
|
|
1123
|
-
placeholder = "dd/mm/aaaa",
|
|
1124
|
-
inputId,
|
|
1125
|
-
required,
|
|
1126
|
-
disabled,
|
|
1127
|
-
className,
|
|
1128
|
-
style,
|
|
1129
|
-
onShow,
|
|
1130
|
-
onHide,
|
|
1131
|
-
...props
|
|
1132
|
-
}, ref) {
|
|
1133
|
-
const autoId = react.useId();
|
|
1134
|
-
const id = inputId ?? autoId;
|
|
1135
|
-
const hintId = `${id}-hint`;
|
|
1136
|
-
const supportText = error ?? hint;
|
|
1137
|
-
const pelaSeta = react.useRef(false);
|
|
1138
|
-
const peloTeclado = react.useRef(false);
|
|
1139
|
-
const calendario = react.useRef(null);
|
|
1140
|
-
react.useImperativeHandle(ref, () => calendario.current, []);
|
|
1141
|
-
const classes2 = [
|
|
1142
|
-
"cr-field",
|
|
1143
|
-
"cr-datepicker",
|
|
1144
|
-
`cr-field--${variant}`,
|
|
1145
|
-
`cr-field--${size}`,
|
|
1146
|
-
error && "cr-field--error",
|
|
1147
|
-
disabled && "cr-field--disabled",
|
|
1148
|
-
className
|
|
1149
|
-
].filter(Boolean).join(" ");
|
|
1150
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes2, style, children: [
|
|
1151
|
-
label && /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "cr-field__label", htmlFor: id, children: [
|
|
1152
|
-
label,
|
|
1153
|
-
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-field__required", "aria-hidden": "true", children: "*" })
|
|
1154
|
-
] }),
|
|
1155
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1156
|
-
calendar.Calendar,
|
|
1157
|
-
{
|
|
1158
|
-
...setas,
|
|
1159
|
-
locale,
|
|
1160
|
-
placeholder,
|
|
1161
|
-
...props,
|
|
1162
|
-
ref: calendario,
|
|
1163
|
-
unstyled: true,
|
|
1164
|
-
inputId: id,
|
|
1165
|
-
required,
|
|
1166
|
-
disabled,
|
|
1167
|
-
showIcon: true,
|
|
1168
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(react$1.CalendarDot, { "aria-hidden": "true" }),
|
|
1169
|
-
onShow: () => {
|
|
1170
|
-
if (!pelaSeta.current) document.getElementById(id)?.focus();
|
|
1171
|
-
pelaSeta.current = false;
|
|
1172
|
-
onShow?.();
|
|
1173
|
-
},
|
|
1174
|
-
onHide: () => {
|
|
1175
|
-
const atual = calendario.current;
|
|
1176
|
-
const ativo = document.activeElement;
|
|
1177
|
-
const semFoco = ativo === document.body || atual?.getOverlay()?.contains(ativo);
|
|
1178
|
-
if (peloTeclado.current && semFoco && atual) {
|
|
1179
|
-
atual.focus();
|
|
1180
|
-
atual.hide();
|
|
1181
|
-
}
|
|
1182
|
-
peloTeclado.current = false;
|
|
1183
|
-
pelaSeta.current = false;
|
|
1184
|
-
onHide?.();
|
|
1185
|
-
},
|
|
1186
|
-
pt: {
|
|
1187
|
-
root: { className: "cr-datepicker__root" },
|
|
1188
|
-
input: {
|
|
1189
|
-
root: {
|
|
1190
|
-
className: "cr-field__control cr-datepicker__input",
|
|
1191
|
-
"aria-describedby": supportText ? hintId : void 0,
|
|
1192
|
-
"aria-invalid": error ? true : void 0,
|
|
1193
|
-
onKeyDown: (event) => {
|
|
1194
|
-
if (event.code === "ArrowDown" && !calendario.current?.getOverlay()) {
|
|
1195
|
-
pelaSeta.current = true;
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
},
|
|
1200
|
-
dropdownButton: { root: { className: "cr-datepicker__button" } },
|
|
1201
|
-
panel: {
|
|
1202
|
-
className: "cr-calendar cr-datepicker__panel",
|
|
1203
|
-
onKeyDown: (event) => {
|
|
1204
|
-
if (["Enter", "NumpadEnter", "Space"].includes(event.code))
|
|
1205
|
-
peloTeclado.current = true;
|
|
1206
|
-
}
|
|
1207
|
-
},
|
|
1208
|
-
// Animação de entrada e saída (a do Prime) e o lado do painel, medido logo depois de o
|
|
1209
|
-
// Prime posicionar.
|
|
1210
|
-
transition: transicaoDoPopup(() => {
|
|
1211
|
-
const campo = document.getElementById(id);
|
|
1212
|
-
seguirLado(painelDoCampo(campo, ".cr-datepicker__panel"), campo);
|
|
1213
|
-
}),
|
|
1214
|
-
...ptDoPainel(offDays)
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
),
|
|
1218
|
-
supportText && /* @__PURE__ */ jsxRuntime.jsxs("p", { id: hintId, className: `cr-field__hint${error ? " cr-field__hint--error" : ""}`, children: [
|
|
1219
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-field__hint-icon", "aria-hidden": "true", children: error ? /* @__PURE__ */ jsxRuntime.jsx(react$1.WarningCircle, {}) : /* @__PURE__ */ jsxRuntime.jsx(react$1.Info, {}) }),
|
|
1220
|
-
supportText
|
|
1221
|
-
] })
|
|
1222
|
-
] });
|
|
1223
|
-
}
|
|
1224
|
-
var DatePicker = react.forwardRef(DatePickerBase);
|
|
1225
1138
|
var Input = react.forwardRef(function Input2({
|
|
1226
1139
|
variant = "outline",
|
|
1227
1140
|
size = "large",
|
|
@@ -1334,7 +1247,7 @@ var Radio = react.forwardRef(function Radio2({
|
|
|
1334
1247
|
] });
|
|
1335
1248
|
});
|
|
1336
1249
|
|
|
1337
|
-
// src/components/
|
|
1250
|
+
// src/components/Calendar/periodos.ts
|
|
1338
1251
|
var dia = (ano, mes, numero) => new Date(ano, mes, numero);
|
|
1339
1252
|
var semHora = (data) => dia(data.getFullYear(), data.getMonth(), data.getDate());
|
|
1340
1253
|
var menos = (data, dias) => dia(data.getFullYear(), data.getMonth(), data.getDate() - dias);
|
|
@@ -1392,6 +1305,310 @@ function lerData(texto) {
|
|
|
1392
1305
|
const data = dia(a, m - 1, d);
|
|
1393
1306
|
return data.getMonth() === m - 1 && data.getDate() === d ? data : null;
|
|
1394
1307
|
}
|
|
1308
|
+
function ListaDePeriodos({
|
|
1309
|
+
periods,
|
|
1310
|
+
periodo,
|
|
1311
|
+
onEscolher
|
|
1312
|
+
}) {
|
|
1313
|
+
const grupo = react.useId();
|
|
1314
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1315
|
+
"div",
|
|
1316
|
+
{
|
|
1317
|
+
className: "cr-data-picker__periods cr-rolagem-fina",
|
|
1318
|
+
role: "radiogroup",
|
|
1319
|
+
"aria-label": "Per\xEDodos",
|
|
1320
|
+
children: periods.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1321
|
+
Radio,
|
|
1322
|
+
{
|
|
1323
|
+
className: "cr-data-picker__period",
|
|
1324
|
+
name: grupo,
|
|
1325
|
+
label: item.label,
|
|
1326
|
+
value: item.label,
|
|
1327
|
+
checked: periodo === item,
|
|
1328
|
+
onChange: () => onEscolher(item)
|
|
1329
|
+
},
|
|
1330
|
+
item.label
|
|
1331
|
+
))
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
var mesmoRascunho = (a, b) => (a[0] === b[0] || mesmoDia2(a[0], b[0])) && (a[1] === b[1] || mesmoDia2(a[1], b[1]));
|
|
1336
|
+
function CamposDoPeriodo({
|
|
1337
|
+
value,
|
|
1338
|
+
onChange
|
|
1339
|
+
}) {
|
|
1340
|
+
const [textos, setTextos] = react.useState([
|
|
1341
|
+
dataCurta(value[0]),
|
|
1342
|
+
dataCurta(value[1])
|
|
1343
|
+
]);
|
|
1344
|
+
const [base, setBase] = react.useState(value);
|
|
1345
|
+
if (!mesmoRascunho(base, value)) {
|
|
1346
|
+
setBase(value);
|
|
1347
|
+
setTextos([dataCurta(value[0]), dataCurta(value[1])]);
|
|
1348
|
+
}
|
|
1349
|
+
const digitar = (indice, texto) => {
|
|
1350
|
+
const novosTextos = [...textos];
|
|
1351
|
+
novosTextos[indice] = texto;
|
|
1352
|
+
setTextos(novosTextos);
|
|
1353
|
+
const data = lerData(texto);
|
|
1354
|
+
if (!data) return;
|
|
1355
|
+
const novo = [...value];
|
|
1356
|
+
novo[indice] = data;
|
|
1357
|
+
if (novo[0] && novo[1] && novo[0] > novo[1]) novo[indice === 0 ? 1 : 0] = null;
|
|
1358
|
+
setBase(novo);
|
|
1359
|
+
onChange(novo);
|
|
1360
|
+
};
|
|
1361
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cr-data-picker__inputs", children: [
|
|
1362
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1363
|
+
Input,
|
|
1364
|
+
{
|
|
1365
|
+
size: "medium",
|
|
1366
|
+
"aria-label": "Data inicial",
|
|
1367
|
+
placeholder: "dd / mm / aaaa",
|
|
1368
|
+
value: textos[0],
|
|
1369
|
+
onChange: (event) => digitar(0, event.target.value)
|
|
1370
|
+
}
|
|
1371
|
+
),
|
|
1372
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-data-picker__dash", "aria-hidden": "true", children: "-" }),
|
|
1373
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1374
|
+
Input,
|
|
1375
|
+
{
|
|
1376
|
+
size: "medium",
|
|
1377
|
+
"aria-label": "Data final",
|
|
1378
|
+
placeholder: "dd / mm / aaaa",
|
|
1379
|
+
value: textos[1],
|
|
1380
|
+
onChange: (event) => digitar(1, event.target.value)
|
|
1381
|
+
}
|
|
1382
|
+
)
|
|
1383
|
+
] });
|
|
1384
|
+
}
|
|
1385
|
+
function RodapeDoPeriodo({
|
|
1386
|
+
podeSelecionar,
|
|
1387
|
+
onFechar,
|
|
1388
|
+
onSelecionar
|
|
1389
|
+
}) {
|
|
1390
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cr-data-picker__footer", children: [
|
|
1391
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "tertiary", size: "medium", onClick: onFechar, children: "Fechar" }),
|
|
1392
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { size: "medium", disabled: !podeSelecionar, onClick: onSelecionar, children: "Selecionar" })
|
|
1393
|
+
] });
|
|
1394
|
+
}
|
|
1395
|
+
function DatePickerBase({
|
|
1396
|
+
variant = "outline",
|
|
1397
|
+
size = "large",
|
|
1398
|
+
label,
|
|
1399
|
+
hint,
|
|
1400
|
+
error,
|
|
1401
|
+
offDays,
|
|
1402
|
+
locale = LOCALE,
|
|
1403
|
+
placeholder = "dd/mm/aaaa",
|
|
1404
|
+
inputId,
|
|
1405
|
+
required,
|
|
1406
|
+
disabled,
|
|
1407
|
+
className,
|
|
1408
|
+
style,
|
|
1409
|
+
onShow,
|
|
1410
|
+
onHide,
|
|
1411
|
+
periods = [],
|
|
1412
|
+
footer = false,
|
|
1413
|
+
today,
|
|
1414
|
+
value,
|
|
1415
|
+
onChange,
|
|
1416
|
+
footerTemplate,
|
|
1417
|
+
...props
|
|
1418
|
+
}, ref) {
|
|
1419
|
+
const autoId = react.useId();
|
|
1420
|
+
const id = inputId ?? autoId;
|
|
1421
|
+
const hintId = `${id}-hint`;
|
|
1422
|
+
const supportText = error ?? hint;
|
|
1423
|
+
const pelaSeta = react.useRef(false);
|
|
1424
|
+
const peloTeclado = react.useRef(false);
|
|
1425
|
+
const calendario = react.useRef(null);
|
|
1426
|
+
react.useImperativeHandle(ref, () => calendario.current, []);
|
|
1427
|
+
const comPeriodos = props.selectionMode === "range" && periods.length > 0;
|
|
1428
|
+
const dataPicker = footer || comPeriodos;
|
|
1429
|
+
const [aberto, setAberto] = react.useState(false);
|
|
1430
|
+
const [rascunho, setRascunho] = react.useState(null);
|
|
1431
|
+
const [periodo, setPeriodo] = react.useState(null);
|
|
1432
|
+
const devolverFoco = react.useRef(false);
|
|
1433
|
+
const ignorarAbertura = react.useRef(false);
|
|
1434
|
+
const valorNaTela = footer && aberto ? rascunho : value;
|
|
1435
|
+
const emitir = (novo) => onChange?.({
|
|
1436
|
+
value: novo,
|
|
1437
|
+
stopPropagation: () => {
|
|
1438
|
+
},
|
|
1439
|
+
preventDefault: () => {
|
|
1440
|
+
},
|
|
1441
|
+
target: { name: props.name, id, value: novo }
|
|
1442
|
+
});
|
|
1443
|
+
const fechar = (pelosBotoes) => {
|
|
1444
|
+
devolverFoco.current = pelosBotoes;
|
|
1445
|
+
setAberto(false);
|
|
1446
|
+
};
|
|
1447
|
+
const mudar = (novo, novoPeriodo) => {
|
|
1448
|
+
setPeriodo(novoPeriodo);
|
|
1449
|
+
if (footer) setRascunho(novo);
|
|
1450
|
+
else emitir(novo);
|
|
1451
|
+
};
|
|
1452
|
+
const classes2 = [
|
|
1453
|
+
"cr-field",
|
|
1454
|
+
"cr-datepicker",
|
|
1455
|
+
`cr-field--${variant}`,
|
|
1456
|
+
`cr-field--${size}`,
|
|
1457
|
+
error && "cr-field--error",
|
|
1458
|
+
disabled && "cr-field--disabled",
|
|
1459
|
+
className
|
|
1460
|
+
].filter(Boolean).join(" ");
|
|
1461
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes2, style, children: [
|
|
1462
|
+
label && /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "cr-field__label", htmlFor: id, children: [
|
|
1463
|
+
label,
|
|
1464
|
+
required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-field__required", "aria-hidden": "true", children: "*" })
|
|
1465
|
+
] }),
|
|
1466
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1467
|
+
calendar.Calendar,
|
|
1468
|
+
{
|
|
1469
|
+
...setas,
|
|
1470
|
+
locale,
|
|
1471
|
+
placeholder,
|
|
1472
|
+
...props,
|
|
1473
|
+
value: valorNaTela,
|
|
1474
|
+
onChange: footer ? (event) => mudar(event.value, null) : comPeriodos ? (event) => {
|
|
1475
|
+
setPeriodo(null);
|
|
1476
|
+
onChange?.(event);
|
|
1477
|
+
} : onChange,
|
|
1478
|
+
...dataPicker && {
|
|
1479
|
+
visible: aberto,
|
|
1480
|
+
onVisibleChange: (event) => {
|
|
1481
|
+
if (!event.callback) {
|
|
1482
|
+
if (ignorarAbertura.current || aberto) return;
|
|
1483
|
+
const hoje = today ?? /* @__PURE__ */ new Date();
|
|
1484
|
+
setRascunho(value);
|
|
1485
|
+
setPeriodo(periodoDe(periods, value ?? null, hoje) ?? null);
|
|
1486
|
+
setAberto(true);
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
if (footer && event.type === "dateselect") return;
|
|
1490
|
+
fechar(false);
|
|
1491
|
+
event.callback?.();
|
|
1492
|
+
},
|
|
1493
|
+
footerTemplate: () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1494
|
+
comPeriodos && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1495
|
+
ListaDePeriodos,
|
|
1496
|
+
{
|
|
1497
|
+
periods,
|
|
1498
|
+
periodo,
|
|
1499
|
+
onEscolher: (item) => {
|
|
1500
|
+
mudar(item.range(today ?? /* @__PURE__ */ new Date()), item);
|
|
1501
|
+
if (!footer) fechar(true);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
),
|
|
1505
|
+
props.selectionMode === "range" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1506
|
+
CamposDoPeriodo,
|
|
1507
|
+
{
|
|
1508
|
+
value: valorNaTela ?? [null, null],
|
|
1509
|
+
onChange: (novo) => mudar(novo, null)
|
|
1510
|
+
}
|
|
1511
|
+
),
|
|
1512
|
+
footer && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1513
|
+
RodapeDoPeriodo,
|
|
1514
|
+
{
|
|
1515
|
+
podeSelecionar: props.selectionMode === "range" ? Boolean(rascunho?.[0] && rascunho[1]) : rascunho != null,
|
|
1516
|
+
onFechar: () => fechar(true),
|
|
1517
|
+
onSelecionar: () => {
|
|
1518
|
+
emitir(rascunho);
|
|
1519
|
+
fechar(true);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
)
|
|
1523
|
+
] })
|
|
1524
|
+
},
|
|
1525
|
+
...!dataPicker && { footerTemplate },
|
|
1526
|
+
ref: calendario,
|
|
1527
|
+
unstyled: true,
|
|
1528
|
+
inputId: id,
|
|
1529
|
+
required,
|
|
1530
|
+
disabled,
|
|
1531
|
+
showIcon: true,
|
|
1532
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(react$1.CalendarDot, { "aria-hidden": "true" }),
|
|
1533
|
+
onShow: () => {
|
|
1534
|
+
if (!pelaSeta.current) document.getElementById(id)?.focus();
|
|
1535
|
+
pelaSeta.current = false;
|
|
1536
|
+
onShow?.();
|
|
1537
|
+
},
|
|
1538
|
+
onHide: () => {
|
|
1539
|
+
const atual = calendario.current;
|
|
1540
|
+
const ativo = document.activeElement;
|
|
1541
|
+
const semFoco = ativo === document.body || atual?.getOverlay()?.contains(ativo);
|
|
1542
|
+
if ((peloTeclado.current || devolverFoco.current) && semFoco && atual) {
|
|
1543
|
+
if (dataPicker) {
|
|
1544
|
+
ignorarAbertura.current = true;
|
|
1545
|
+
atual.focus();
|
|
1546
|
+
ignorarAbertura.current = false;
|
|
1547
|
+
} else {
|
|
1548
|
+
atual.focus();
|
|
1549
|
+
atual.hide();
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
peloTeclado.current = false;
|
|
1553
|
+
pelaSeta.current = false;
|
|
1554
|
+
devolverFoco.current = false;
|
|
1555
|
+
onHide?.();
|
|
1556
|
+
},
|
|
1557
|
+
pt: {
|
|
1558
|
+
root: { className: "cr-datepicker__root" },
|
|
1559
|
+
input: {
|
|
1560
|
+
root: {
|
|
1561
|
+
className: "cr-field__control cr-datepicker__input",
|
|
1562
|
+
"aria-describedby": supportText ? hintId : void 0,
|
|
1563
|
+
"aria-invalid": error ? true : void 0,
|
|
1564
|
+
onKeyDown: (event) => {
|
|
1565
|
+
if (event.code === "ArrowDown" && !calendario.current?.getOverlay()) {
|
|
1566
|
+
pelaSeta.current = true;
|
|
1567
|
+
}
|
|
1568
|
+
const painel = calendario.current?.getOverlay();
|
|
1569
|
+
if (dataPicker && event.code === "ArrowDown" && painel) {
|
|
1570
|
+
const dia2 = painel.querySelector(".cr-calendar__date--selected") ?? painel.querySelector(
|
|
1571
|
+
".cr-calendar__date:not(.cr-calendar__date--disabled)"
|
|
1572
|
+
);
|
|
1573
|
+
if (dia2) {
|
|
1574
|
+
event.preventDefault();
|
|
1575
|
+
dia2.tabIndex = 0;
|
|
1576
|
+
dia2.focus();
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
},
|
|
1582
|
+
dropdownButton: { root: { className: "cr-datepicker__button" } },
|
|
1583
|
+
panel: {
|
|
1584
|
+
className: `cr-calendar cr-datepicker__panel${dataPicker ? " cr-datepicker__panel--data-picker" : ""}`,
|
|
1585
|
+
onKeyDown: (event) => {
|
|
1586
|
+
if (["Enter", "NumpadEnter", "Space"].includes(event.code))
|
|
1587
|
+
peloTeclado.current = true;
|
|
1588
|
+
if (dataPicker && event.code === "Escape" && aberto) fechar(true);
|
|
1589
|
+
}
|
|
1590
|
+
},
|
|
1591
|
+
// Animação de entrada e saída (a do Prime) e o lado do painel, medido logo depois de o
|
|
1592
|
+
// Prime posicionar.
|
|
1593
|
+
transition: transicaoDoPopup(() => {
|
|
1594
|
+
const campo = document.getElementById(id);
|
|
1595
|
+
seguirLado(painelDoCampo(campo, ".cr-datepicker__panel"), campo);
|
|
1596
|
+
}),
|
|
1597
|
+
...ptDoPainel(offDays),
|
|
1598
|
+
// As partes do Data Picker entram no rodapé do Prime, que some no layout: cada uma ocupa o
|
|
1599
|
+
// seu lugar na grade do painel (DatePicker.css). O Prime aplica o pt do footer, mas não o
|
|
1600
|
+
// declara no tipo.
|
|
1601
|
+
...{ footer: { className: "cr-datepicker__extras" } }
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
),
|
|
1605
|
+
supportText && /* @__PURE__ */ jsxRuntime.jsxs("p", { id: hintId, className: `cr-field__hint${error ? " cr-field__hint--error" : ""}`, children: [
|
|
1606
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-field__hint-icon", "aria-hidden": "true", children: error ? /* @__PURE__ */ jsxRuntime.jsx(react$1.WarningCircle, {}) : /* @__PURE__ */ jsxRuntime.jsx(react$1.Info, {}) }),
|
|
1607
|
+
supportText
|
|
1608
|
+
] })
|
|
1609
|
+
] });
|
|
1610
|
+
}
|
|
1611
|
+
var DatePicker = react.forwardRef(DatePickerBase);
|
|
1395
1612
|
function mesDaTela(range, meses, hoje) {
|
|
1396
1613
|
const base = (meses > 1 ? range[1] : range[0]) ?? range[0] ?? hoje;
|
|
1397
1614
|
return new Date(base.getFullYear(), base.getMonth() - (meses > 1 ? 1 : 0), 1);
|
|
@@ -1409,76 +1626,40 @@ function PainelDePeriodo({
|
|
|
1409
1626
|
onSelect,
|
|
1410
1627
|
onClose
|
|
1411
1628
|
}) {
|
|
1412
|
-
const grupo = react.useId();
|
|
1413
1629
|
const [rascunho, setRascunho] = react.useState(value ?? [null, null]);
|
|
1414
1630
|
const [periodo, setPeriodo] = react.useState(() => periodoDe(periods, value, today) ?? null);
|
|
1415
|
-
const [textos, setTextos] = react.useState([
|
|
1416
|
-
dataCurta(value?.[0]),
|
|
1417
|
-
dataCurta(value?.[1])
|
|
1418
|
-
]);
|
|
1419
1631
|
const [mes, setMes] = react.useState(() => mesDaTela(rascunho, numberOfMonths, today));
|
|
1420
|
-
const mudar = (novo, novoPeriodo
|
|
1632
|
+
const mudar = (novo, novoPeriodo) => {
|
|
1421
1633
|
setRascunho(novo);
|
|
1422
1634
|
setPeriodo(novoPeriodo);
|
|
1423
|
-
if (mudarTextos) setTextos([dataCurta(novo[0]), dataCurta(novo[1])]);
|
|
1424
1635
|
if (!footer && novo[0] && novo[1]) onSelect([novo[0], novo[1]], novoPeriodo);
|
|
1425
1636
|
};
|
|
1426
|
-
const escolherPeriodo = (item) => {
|
|
1427
|
-
const range = item.range(today);
|
|
1428
|
-
setMes(mesDaTela(range, numberOfMonths, today));
|
|
1429
|
-
mudar(range, item);
|
|
1430
|
-
};
|
|
1431
|
-
const digitar = (indice, texto) => {
|
|
1432
|
-
const novosTextos = [...textos];
|
|
1433
|
-
novosTextos[indice] = texto;
|
|
1434
|
-
setTextos(novosTextos);
|
|
1435
|
-
const data = lerData(texto);
|
|
1436
|
-
if (!data) return;
|
|
1437
|
-
const novo = [...rascunho];
|
|
1438
|
-
novo[indice] = data;
|
|
1439
|
-
if (novo[0] && novo[1] && novo[0] > novo[1]) novo[indice === 0 ? 1 : 0] = null;
|
|
1440
|
-
setMes(mesDaTela(novo, numberOfMonths, today));
|
|
1441
|
-
mudar(novo, null, false);
|
|
1442
|
-
};
|
|
1443
1637
|
const [inicio, fim] = rascunho;
|
|
1444
1638
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cr-date-range", children: [
|
|
1445
1639
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cr-date-range__body", children: [
|
|
1446
|
-
periods.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1447
|
-
|
|
1640
|
+
periods.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1641
|
+
ListaDePeriodos,
|
|
1448
1642
|
{
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
)
|
|
1643
|
+
periods,
|
|
1644
|
+
periodo,
|
|
1645
|
+
onEscolher: (item) => {
|
|
1646
|
+
const range = item.range(today);
|
|
1647
|
+
setMes(mesDaTela(range, numberOfMonths, today));
|
|
1648
|
+
mudar(range, item);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
),
|
|
1458
1652
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cr-date-range__calendars", children: [
|
|
1459
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
value: textos[0],
|
|
1467
|
-
onChange: (event) => digitar(0, event.target.value)
|
|
1468
|
-
}
|
|
1469
|
-
),
|
|
1470
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-date-range__dash", "aria-hidden": "true", children: "-" }),
|
|
1471
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1472
|
-
Input,
|
|
1473
|
-
{
|
|
1474
|
-
size: "medium",
|
|
1475
|
-
"aria-label": "Data final",
|
|
1476
|
-
placeholder: "dd / mm / aaaa",
|
|
1477
|
-
value: textos[1],
|
|
1478
|
-
onChange: (event) => digitar(1, event.target.value)
|
|
1653
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1654
|
+
CamposDoPeriodo,
|
|
1655
|
+
{
|
|
1656
|
+
value: rascunho,
|
|
1657
|
+
onChange: (novo) => {
|
|
1658
|
+
setMes(mesDaTela(novo, numberOfMonths, today));
|
|
1659
|
+
mudar(novo, null);
|
|
1479
1660
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1661
|
+
}
|
|
1662
|
+
),
|
|
1482
1663
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1483
1664
|
Calendar,
|
|
1484
1665
|
{
|
|
@@ -1488,8 +1669,8 @@ function PainelDePeriodo({
|
|
|
1488
1669
|
viewDate: mes,
|
|
1489
1670
|
onViewDateChange: (event) => setMes(event.value),
|
|
1490
1671
|
onChange: (event) => {
|
|
1491
|
-
const [
|
|
1492
|
-
mudar([
|
|
1672
|
+
const [novoInicio = null, novoFim = null] = event.value ?? [];
|
|
1673
|
+
mudar([novoInicio, novoFim], null);
|
|
1493
1674
|
},
|
|
1494
1675
|
minDate,
|
|
1495
1676
|
maxDate,
|
|
@@ -1499,18 +1680,14 @@ function PainelDePeriodo({
|
|
|
1499
1680
|
)
|
|
1500
1681
|
] })
|
|
1501
1682
|
] }),
|
|
1502
|
-
footer && /* @__PURE__ */ jsxRuntime.
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
children: "Selecionar"
|
|
1511
|
-
}
|
|
1512
|
-
)
|
|
1513
|
-
] })
|
|
1683
|
+
footer && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1684
|
+
RodapeDoPeriodo,
|
|
1685
|
+
{
|
|
1686
|
+
podeSelecionar: Boolean(inicio && fim),
|
|
1687
|
+
onFechar: onClose,
|
|
1688
|
+
onSelecionar: () => inicio && fim && onSelect([inicio, fim], periodo)
|
|
1689
|
+
}
|
|
1690
|
+
)
|
|
1514
1691
|
] });
|
|
1515
1692
|
}
|
|
1516
1693
|
var DateRangeButton = react.forwardRef(
|