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