@vector-business-services/cristal-ds-web 0.9.0 → 0.10.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 CHANGED
@@ -18,16 +18,19 @@ var menubar = require('primereact/menubar');
18
18
  var avatar = require('primereact/avatar');
19
19
  var tooltip = require('primereact/tooltip');
20
20
  var tag = require('primereact/tag');
21
+ var message = require('primereact/message');
21
22
  var dialog = require('primereact/dialog');
22
23
  var multiselect = require('primereact/multiselect');
23
24
  var tabmenu = require('primereact/tabmenu');
25
+ var paginator = require('primereact/paginator');
26
+ var dropdown = require('primereact/dropdown');
24
27
  var panel = require('primereact/panel');
25
28
  var radiobutton = require('primereact/radiobutton');
26
29
  var scrollpanel = require('primereact/scrollpanel');
27
30
  var selectbutton = require('primereact/selectbutton');
28
- var dropdown = require('primereact/dropdown');
29
31
  var inputswitch = require('primereact/inputswitch');
30
32
  var tabview = require('primereact/tabview');
33
+ var toast = require('primereact/toast');
31
34
 
32
35
  // src/components/AutoComplete/AutoComplete.tsx
33
36
  var AutoComplete = react.forwardRef(function AutoComplete2({
@@ -881,9 +884,20 @@ var MenuPrincipal = react.forwardRef(
881
884
  }, ref) {
882
885
  const primeRef = react.useRef(null);
883
886
  const context = react.useContext(api.PrimeReactContext);
887
+ const [baseDoAlvo, setBaseDoAlvo] = react.useState();
888
+ const medirAlvo = (event) => {
889
+ const alvo = event.currentTarget;
890
+ if (alvo instanceof Element) setBaseDoAlvo(alvo.getBoundingClientRect().bottom);
891
+ };
884
892
  react.useImperativeHandle(ref, () => ({
885
- toggle: (event) => primeRef.current?.toggle(event),
886
- show: (event) => primeRef.current?.show(event),
893
+ toggle: (event) => {
894
+ medirAlvo(event);
895
+ primeRef.current?.toggle(event);
896
+ },
897
+ show: (event) => {
898
+ medirAlvo(event);
899
+ primeRef.current?.show(event);
900
+ },
887
901
  hide: (event) => primeRef.current?.hide(event),
888
902
  getElement: () => primeRef.current?.getElement() ?? null
889
903
  }));
@@ -941,6 +955,7 @@ var MenuPrincipal = react.forwardRef(
941
955
  ref: primeRef,
942
956
  id,
943
957
  className: classes,
958
+ style: popup && baseDoAlvo !== void 0 ? { "--cr-menu-principal-topo": `${baseDoAlvo}px` } : void 0,
944
959
  model: items,
945
960
  popup,
946
961
  onShow,
@@ -951,6 +966,43 @@ var MenuPrincipal = react.forwardRef(
951
966
  return context ? menu$1 : /* @__PURE__ */ jsxRuntime.jsx(api.PrimeReactProvider, { children: menu$1 });
952
967
  }
953
968
  );
969
+ var SEVERITY = {
970
+ info: "info",
971
+ warning: "warn",
972
+ success: "success",
973
+ danger: "error",
974
+ highlight: "contrast",
975
+ neutral: "secondary"
976
+ };
977
+ var ICON = {
978
+ info: /* @__PURE__ */ jsxRuntime.jsx(react$1.Info, {}),
979
+ warning: /* @__PURE__ */ jsxRuntime.jsx(react$1.Warning, {}),
980
+ success: /* @__PURE__ */ jsxRuntime.jsx(react$1.CheckCircle, {}),
981
+ danger: /* @__PURE__ */ jsxRuntime.jsx(react$1.XCircle, {}),
982
+ highlight: /* @__PURE__ */ jsxRuntime.jsx(react$1.SealWarning, {}),
983
+ neutral: /* @__PURE__ */ jsxRuntime.jsx(react$1.WarningCircle, {})
984
+ };
985
+ var Message = react.forwardRef(function Message2({ type = "info", children, showIcon = true, id, className }, ref) {
986
+ const primeRef = react.useRef(null);
987
+ react.useImperativeHandle(ref, () => primeRef.current?.getElement());
988
+ return /* @__PURE__ */ jsxRuntime.jsx(
989
+ message.Message,
990
+ {
991
+ unstyled: true,
992
+ ref: primeRef,
993
+ id,
994
+ severity: SEVERITY[type],
995
+ text: children,
996
+ icon: showIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-message__icon", "aria-hidden": "true", children: ICON[type] }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}),
997
+ pt: {
998
+ root: {
999
+ className: ["cr-message", `cr-message--${type}`, className].filter(Boolean).join(" ")
1000
+ },
1001
+ text: { className: "cr-message__text" }
1002
+ }
1003
+ }
1004
+ );
1005
+ });
954
1006
  function Modal({
955
1007
  visible,
956
1008
  onHide,
@@ -1319,6 +1371,193 @@ var PageHeader = react.forwardRef(function PageHeader2({
1319
1371
  )
1320
1372
  ] });
1321
1373
  });
1374
+ var Select = react.forwardRef(function Select2({
1375
+ variant = "outline",
1376
+ size = "large",
1377
+ label,
1378
+ "aria-label": ariaLabel,
1379
+ options,
1380
+ optionLabel = "label",
1381
+ optionValue,
1382
+ value,
1383
+ onChange,
1384
+ placeholder = "Selecione uma op\xE7\xE3o",
1385
+ hint,
1386
+ error,
1387
+ required,
1388
+ disabled,
1389
+ id,
1390
+ name,
1391
+ className
1392
+ }, ref) {
1393
+ const autoId = react.useId();
1394
+ const inputId = id ?? autoId;
1395
+ const hintId = `${inputId}-hint`;
1396
+ const listId = `${inputId}-list`;
1397
+ const supportText = error ?? hint;
1398
+ const [open, setOpen] = react.useState(false);
1399
+ const setInputRef = react.useCallback(
1400
+ (input) => {
1401
+ input?.setAttribute("role", "combobox");
1402
+ if (typeof ref === "function") ref(input);
1403
+ else if (ref) ref.current = input;
1404
+ },
1405
+ [ref]
1406
+ );
1407
+ const classes = [
1408
+ "cr-field",
1409
+ `cr-field--${variant}`,
1410
+ `cr-field--${size}`,
1411
+ "cr-select",
1412
+ error && "cr-field--error",
1413
+ disabled && "cr-field--disabled",
1414
+ className
1415
+ ].filter(Boolean).join(" ");
1416
+ const pt = {
1417
+ root: {
1418
+ className: `cr-field__control cr-select__control${open ? " cr-select__control--open" : ""}`,
1419
+ // O Prime aponta para um item mesmo sem destaque (dropdownItem_-1); o foco vai no item.
1420
+ "aria-activedescendant": void 0
1421
+ },
1422
+ // O <select> escondido do Prime só existe para formulários: fora da árvore de acessibilidade.
1423
+ select: { "aria-hidden": true },
1424
+ hiddenSelectedMessage: { className: "cr-select__hidden" },
1425
+ // O Prime usa a mesma chave no texto do campo e no combobox escondido.
1426
+ input: { className: "cr-select__value" },
1427
+ trigger: { className: "cr-field__icon cr-select__trigger", "aria-hidden": true },
1428
+ panel: { className: "cr-select__panel" },
1429
+ wrapper: { className: "cr-select__wrapper" },
1430
+ list: { className: "cr-select__list", id: listId },
1431
+ item: { className: "cr-select__item" },
1432
+ emptyMessage: { className: "cr-select__item cr-select__empty" }
1433
+ };
1434
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes, children: [
1435
+ label && /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "cr-field__label", htmlFor: inputId, children: [
1436
+ label,
1437
+ required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-field__required", "aria-hidden": "true", children: "*" })
1438
+ ] }),
1439
+ /* @__PURE__ */ jsxRuntime.jsx(
1440
+ dropdown.Dropdown,
1441
+ {
1442
+ unstyled: true,
1443
+ inputId,
1444
+ focusInputRef: setInputRef,
1445
+ value,
1446
+ options,
1447
+ optionLabel,
1448
+ optionValue,
1449
+ onChange: (event) => onChange?.(event.value),
1450
+ onShow: () => setOpen(true),
1451
+ onHide: () => setOpen(false),
1452
+ disabled,
1453
+ required,
1454
+ name,
1455
+ invalid: Boolean(error),
1456
+ placeholder,
1457
+ valueTemplate: (option) => option == null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-select__placeholder", children: placeholder }) : String(option[optionLabel] ?? option),
1458
+ scrollHeight: "185px",
1459
+ dropdownIcon: /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretDown, {}),
1460
+ collapseIcon: /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretUp, {}),
1461
+ "aria-label": label ? void 0 : ariaLabel,
1462
+ "aria-expanded": open,
1463
+ "aria-controls": open ? listId : void 0,
1464
+ "aria-describedby": supportText ? hintId : void 0,
1465
+ "aria-invalid": error ? true : void 0,
1466
+ "aria-required": required || void 0,
1467
+ pt
1468
+ }
1469
+ ),
1470
+ supportText && /* @__PURE__ */ jsxRuntime.jsxs("p", { id: hintId, className: `cr-field__hint${error ? " cr-field__hint--error" : ""}`, children: [
1471
+ /* @__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, {}) }),
1472
+ supportText
1473
+ ] })
1474
+ ] });
1475
+ });
1476
+ var seta = (label, icon) => (options) => /* @__PURE__ */ jsxRuntime.jsx(
1477
+ "button",
1478
+ {
1479
+ type: "button",
1480
+ className: "cr-paginator__arrow",
1481
+ "aria-label": label,
1482
+ disabled: options.disabled,
1483
+ onClick: options.onClick,
1484
+ children: icon
1485
+ }
1486
+ );
1487
+ var Paginator = react.forwardRef(function Paginator2({
1488
+ totalRecords,
1489
+ first,
1490
+ rows,
1491
+ rowsPerPageOptions,
1492
+ pageLinkSize = 5,
1493
+ onPageChange,
1494
+ rowsPerPageLabel = "Itens por p\xE1gina",
1495
+ id,
1496
+ className
1497
+ }, ref) {
1498
+ const primeRef = react.useRef(null);
1499
+ react.useImperativeHandle(ref, () => primeRef.current?.getElement());
1500
+ const [interno, setInterno] = react.useState({
1501
+ first: 0,
1502
+ rows: rowsPerPageOptions?.[0] ?? 10
1503
+ });
1504
+ const atual = { first: first ?? interno.first, rows: rows ?? interno.rows };
1505
+ return /* @__PURE__ */ jsxRuntime.jsx(
1506
+ paginator.Paginator,
1507
+ {
1508
+ unstyled: true,
1509
+ ref: primeRef,
1510
+ id,
1511
+ totalRecords,
1512
+ first: atual.first,
1513
+ rows: atual.rows,
1514
+ rowsPerPageOptions,
1515
+ pageLinkSize,
1516
+ onPageChange: (event) => {
1517
+ setInterno({ first: event.first, rows: event.rows });
1518
+ onPageChange?.(event);
1519
+ },
1520
+ template: {
1521
+ layout: "FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown",
1522
+ FirstPageLink: seta("Primeira p\xE1gina", /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretDoubleLeft, { "aria-hidden": "true" })),
1523
+ PrevPageLink: seta("P\xE1gina anterior", /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretLeft, { "aria-hidden": "true" })),
1524
+ NextPageLink: seta("Pr\xF3xima p\xE1gina", /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretRight, { "aria-hidden": "true" })),
1525
+ LastPageLink: seta("\xDAltima p\xE1gina", /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretDoubleRight, { "aria-hidden": "true" })),
1526
+ PageLinks: (options) => {
1527
+ const ativa = options.page === options.currentPage;
1528
+ return /* @__PURE__ */ jsxRuntime.jsx(
1529
+ "button",
1530
+ {
1531
+ type: "button",
1532
+ className: "cr-paginator__page",
1533
+ "aria-label": `P\xE1gina ${options.page + 1}`,
1534
+ "aria-current": ativa ? "page" : void 0,
1535
+ onClick: options.onClick,
1536
+ children: options.page + 1
1537
+ }
1538
+ );
1539
+ },
1540
+ // O Prime chama o template mesmo sem rowsPerPageOptions.
1541
+ RowsPerPageDropdown: (options) => options.options.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
1542
+ Select,
1543
+ {
1544
+ className: "cr-paginator__rows",
1545
+ size: "medium",
1546
+ "aria-label": rowsPerPageLabel,
1547
+ options: options.options,
1548
+ optionValue: "value",
1549
+ value: options.value,
1550
+ onChange: (value) => options.onChange({ value })
1551
+ }
1552
+ )
1553
+ },
1554
+ pt: {
1555
+ root: { className: ["cr-paginator", className].filter(Boolean).join(" ") },
1556
+ pages: { className: "cr-paginator__pages" }
1557
+ }
1558
+ }
1559
+ );
1560
+ });
1322
1561
  var Panel = react.forwardRef(function Panel2({ className, style, children, ...props }, ref) {
1323
1562
  const primeRef = react.useRef(null);
1324
1563
  react.useImperativeHandle(ref, () => primeRef.current?.getElement());
@@ -1483,108 +1722,6 @@ var SegmentControl = react.forwardRef(
1483
1722
  );
1484
1723
  }
1485
1724
  );
1486
- var Select = react.forwardRef(function Select2({
1487
- variant = "outline",
1488
- size = "large",
1489
- label,
1490
- "aria-label": ariaLabel,
1491
- options,
1492
- optionLabel = "label",
1493
- optionValue,
1494
- value,
1495
- onChange,
1496
- placeholder = "Selecione uma op\xE7\xE3o",
1497
- hint,
1498
- error,
1499
- required,
1500
- disabled,
1501
- id,
1502
- name,
1503
- className
1504
- }, ref) {
1505
- const autoId = react.useId();
1506
- const inputId = id ?? autoId;
1507
- const hintId = `${inputId}-hint`;
1508
- const listId = `${inputId}-list`;
1509
- const supportText = error ?? hint;
1510
- const [open, setOpen] = react.useState(false);
1511
- const setInputRef = react.useCallback(
1512
- (input) => {
1513
- input?.setAttribute("role", "combobox");
1514
- if (typeof ref === "function") ref(input);
1515
- else if (ref) ref.current = input;
1516
- },
1517
- [ref]
1518
- );
1519
- const classes = [
1520
- "cr-field",
1521
- `cr-field--${variant}`,
1522
- `cr-field--${size}`,
1523
- "cr-select",
1524
- error && "cr-field--error",
1525
- disabled && "cr-field--disabled",
1526
- className
1527
- ].filter(Boolean).join(" ");
1528
- const pt = {
1529
- root: {
1530
- className: `cr-field__control cr-select__control${open ? " cr-select__control--open" : ""}`,
1531
- // O Prime aponta para um item mesmo sem destaque (dropdownItem_-1); o foco vai no item.
1532
- "aria-activedescendant": void 0
1533
- },
1534
- // O <select> escondido do Prime só existe para formulários: fora da árvore de acessibilidade.
1535
- select: { "aria-hidden": true },
1536
- hiddenSelectedMessage: { className: "cr-select__hidden" },
1537
- // O Prime usa a mesma chave no texto do campo e no combobox escondido.
1538
- input: { className: "cr-select__value" },
1539
- trigger: { className: "cr-field__icon cr-select__trigger", "aria-hidden": true },
1540
- panel: { className: "cr-select__panel" },
1541
- wrapper: { className: "cr-select__wrapper" },
1542
- list: { className: "cr-select__list", id: listId },
1543
- item: { className: "cr-select__item" },
1544
- emptyMessage: { className: "cr-select__item cr-select__empty" }
1545
- };
1546
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes, children: [
1547
- label && /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "cr-field__label", htmlFor: inputId, children: [
1548
- label,
1549
- required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-field__required", "aria-hidden": "true", children: "*" })
1550
- ] }),
1551
- /* @__PURE__ */ jsxRuntime.jsx(
1552
- dropdown.Dropdown,
1553
- {
1554
- unstyled: true,
1555
- inputId,
1556
- focusInputRef: setInputRef,
1557
- value,
1558
- options,
1559
- optionLabel,
1560
- optionValue,
1561
- onChange: (event) => onChange?.(event.value),
1562
- onShow: () => setOpen(true),
1563
- onHide: () => setOpen(false),
1564
- disabled,
1565
- required,
1566
- name,
1567
- invalid: Boolean(error),
1568
- placeholder,
1569
- valueTemplate: (option) => option == null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-select__placeholder", children: placeholder }) : String(option[optionLabel] ?? option),
1570
- scrollHeight: "185px",
1571
- dropdownIcon: /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretDown, {}),
1572
- collapseIcon: /* @__PURE__ */ jsxRuntime.jsx(react$1.CaretUp, {}),
1573
- "aria-label": label ? void 0 : ariaLabel,
1574
- "aria-expanded": open,
1575
- "aria-controls": open ? listId : void 0,
1576
- "aria-describedby": supportText ? hintId : void 0,
1577
- "aria-invalid": error ? true : void 0,
1578
- "aria-required": required || void 0,
1579
- pt
1580
- }
1581
- ),
1582
- supportText && /* @__PURE__ */ jsxRuntime.jsxs("p", { id: hintId, className: `cr-field__hint${error ? " cr-field__hint--error" : ""}`, children: [
1583
- /* @__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, {}) }),
1584
- supportText
1585
- ] })
1586
- ] });
1587
- });
1588
1725
  var Switch = react.forwardRef(function Switch2({
1589
1726
  label,
1590
1727
  showLabel = true,
@@ -1715,6 +1852,71 @@ var Tabs = react.forwardRef(function Tabs2({ activeIndex, onTabChange, children,
1715
1852
  }
1716
1853
  );
1717
1854
  });
1855
+ var SEVERITY2 = {
1856
+ warning: "warn",
1857
+ danger: "error",
1858
+ success: "success",
1859
+ info: "info"
1860
+ };
1861
+ var ICON2 = {
1862
+ warning: /* @__PURE__ */ jsxRuntime.jsx(react$1.Warning, {}),
1863
+ danger: /* @__PURE__ */ jsxRuntime.jsx(react$1.XCircle, {}),
1864
+ success: /* @__PURE__ */ jsxRuntime.jsx(react$1.Check, {}),
1865
+ info: /* @__PURE__ */ jsxRuntime.jsx(react$1.Info, {})
1866
+ };
1867
+ var Toast = react.forwardRef(function Toast2({ position = "top-right", closeLabel = "Fechar", id, className }, ref) {
1868
+ const primeRef = react.useRef(null);
1869
+ const converter = ({
1870
+ type,
1871
+ title,
1872
+ message,
1873
+ showIcon = true,
1874
+ life,
1875
+ sticky
1876
+ }) => ({
1877
+ severity: SEVERITY2[type],
1878
+ summary: title,
1879
+ detail: message,
1880
+ // Sem ícone, um fragmento vazio: com undefined o Prime põe o ícone dele.
1881
+ icon: showIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "cr-toast__icon", "aria-hidden": "true", children: ICON2[type] }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}),
1882
+ closeIcon: /* @__PURE__ */ jsxRuntime.jsx(react$1.X, { "aria-hidden": "true" }),
1883
+ life,
1884
+ sticky,
1885
+ className: `cr-toast__message--${type}`
1886
+ });
1887
+ react.useImperativeHandle(ref, () => ({
1888
+ show: (message) => primeRef.current?.show(Array.isArray(message) ? message.map(converter) : converter(message)),
1889
+ clear: () => primeRef.current?.clear()
1890
+ }));
1891
+ return /* @__PURE__ */ jsxRuntime.jsx(
1892
+ toast.Toast,
1893
+ {
1894
+ ...{ unstyled: true },
1895
+ ref: primeRef,
1896
+ id,
1897
+ position,
1898
+ pt: {
1899
+ root: {
1900
+ className: ["cr-toast", className].filter(Boolean).join(" ")
1901
+ },
1902
+ message: { className: "cr-toast__message" },
1903
+ content: { className: "cr-toast__content" },
1904
+ text: { className: "cr-toast__text" },
1905
+ summary: { className: "cr-toast__title" },
1906
+ detail: { className: "cr-toast__detail" },
1907
+ closeButton: { className: "cr-toast__close", "aria-label": closeLabel },
1908
+ // No unstyled o Prime não põe classes na transição: o Cristal dá as dele (Toast.css).
1909
+ transition: {
1910
+ classNames: {
1911
+ enter: "cr-toast__message--enter",
1912
+ enterActive: "cr-toast__message--enter-active",
1913
+ exitActive: "cr-toast__message--exit-active"
1914
+ }
1915
+ }
1916
+ }
1917
+ }
1918
+ );
1919
+ });
1718
1920
 
1719
1921
  exports.AutoComplete = AutoComplete;
1720
1922
  exports.Badge = Badge;
@@ -1729,9 +1931,11 @@ exports.Input = Input;
1729
1931
  exports.Menu = Menu;
1730
1932
  exports.MenuPrincipal = MenuPrincipal;
1731
1933
  exports.Menubar = Menubar;
1934
+ exports.Message = Message;
1732
1935
  exports.Modal = Modal;
1733
1936
  exports.MultiSelect = MultiSelect;
1734
1937
  exports.PageHeader = PageHeader;
1938
+ exports.Paginator = Paginator;
1735
1939
  exports.Panel = Panel;
1736
1940
  exports.Radio = Radio;
1737
1941
  exports.ScrollPanel = ScrollPanel;
@@ -1741,6 +1945,7 @@ exports.Switch = Switch;
1741
1945
  exports.TabPanel = TabPanel;
1742
1946
  exports.Tabs = Tabs;
1743
1947
  exports.Tag = Tag;
1948
+ exports.Toast = Toast;
1744
1949
  exports.Tooltip = Tooltip;
1745
1950
  //# sourceMappingURL=index.cjs.map
1746
1951
  //# sourceMappingURL=index.cjs.map