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