@dmsi/wedgekit-react 0.0.411 → 0.0.412

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.
Files changed (35) hide show
  1. package/dist/components/CalendarRange.cjs +46 -71
  2. package/dist/components/CalendarRange.js +1 -6
  3. package/dist/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.cjs +4 -29
  4. package/dist/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.js +1 -6
  5. package/dist/components/DataGrid/ColumnSelectorHeaderCell/index.cjs +13 -38
  6. package/dist/components/DataGrid/ColumnSelectorHeaderCell/index.js +1 -6
  7. package/dist/components/DataGrid/PinnedColumns.cjs +29 -54
  8. package/dist/components/DataGrid/PinnedColumns.js +1 -6
  9. package/dist/components/DataGrid/TableBody/LoadingCell.cjs +5 -30
  10. package/dist/components/DataGrid/TableBody/LoadingCell.js +1 -6
  11. package/dist/components/DataGrid/TableBody/TableBodyRow.cjs +11 -36
  12. package/dist/components/DataGrid/TableBody/TableBodyRow.js +1 -6
  13. package/dist/components/DataGrid/TableBody/index.cjs +26 -51
  14. package/dist/components/DataGrid/TableBody/index.js +1 -6
  15. package/dist/components/DataGrid/index.cjs +115 -140
  16. package/dist/components/DataGrid/index.js +1 -6
  17. package/dist/components/DataGrid/utils.cjs +5 -30
  18. package/dist/components/DataGrid/utils.js +1 -6
  19. package/dist/components/DateInput.cjs +65 -90
  20. package/dist/components/DateInput.js +1 -6
  21. package/dist/components/DateRangeInput.cjs +65 -90
  22. package/dist/components/DateRangeInput.js +1 -6
  23. package/dist/components/MobileDataGrid/ColumnSelector/index.cjs +12 -37
  24. package/dist/components/MobileDataGrid/ColumnSelector/index.js +1 -6
  25. package/dist/components/MobileDataGrid/MobileDataGridHeader.cjs +20 -45
  26. package/dist/components/MobileDataGrid/MobileDataGridHeader.js +1 -6
  27. package/dist/components/MobileDataGrid/index.cjs +499 -524
  28. package/dist/components/MobileDataGrid/index.js +1 -6
  29. package/dist/components/PDFViewer/index.js +109 -6
  30. package/dist/components/index.cjs +0 -286
  31. package/dist/components/index.js +1 -9
  32. package/package.json +1 -1
  33. package/src/components/index.ts +0 -1
  34. package/dist/chunk-LLZ3SSZJ.js +0 -114
  35. /package/dist/{chunk-OW3WN3JV.js → chunk-OBY5EH47.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MobileDataGrid
3
- } from "../../chunk-OW3WN3JV.js";
3
+ } from "../../chunk-OBY5EH47.js";
4
4
  import "../../chunk-M7INAUAJ.js";
5
5
  import "../../chunk-6I5LZ2ZC.js";
6
6
  import "../../chunk-44TDIHUP.js";
@@ -8,11 +8,6 @@ import "../../chunk-LZGYABCX.js";
8
8
  import "../../chunk-G5DEC7H3.js";
9
9
  import "../../chunk-3X3Y4TMS.js";
10
10
  import "../../chunk-BQNPOGD5.js";
11
- import "../../chunk-LLZ3SSZJ.js";
12
- import "../../chunk-EJSPFQCY.js";
13
- import "../../chunk-ERW5DEIO.js";
14
- import "../../chunk-2HMCS25C.js";
15
- import "../../chunk-VJVY6NPF.js";
16
11
  import "../../chunk-MBZ55T2D.js";
17
12
  import "../../chunk-2IKT6IHB.js";
18
13
  import "../../chunk-AA6GE3TH.js";
@@ -1,12 +1,17 @@
1
1
  "use client";
2
2
  import {
3
- PDFViewer
4
- } from "../../chunk-LLZ3SSZJ.js";
5
- import "../../chunk-EJSPFQCY.js";
6
- import "../../chunk-ERW5DEIO.js";
7
- import "../../chunk-2HMCS25C.js";
3
+ DownloadIcon
4
+ } from "../../chunk-EJSPFQCY.js";
5
+ import {
6
+ PDFElement
7
+ } from "../../chunk-ERW5DEIO.js";
8
+ import {
9
+ PdfNavigation
10
+ } from "../../chunk-2HMCS25C.js";
8
11
  import "../../chunk-VJVY6NPF.js";
9
- import "../../chunk-D6YCMQPO.js";
12
+ import {
13
+ Modal
14
+ } from "../../chunk-D6YCMQPO.js";
10
15
  import "../../chunk-4RJKB7LC.js";
11
16
  import "../../chunk-XM7IQHBU.js";
12
17
  import "../../chunk-FRHPFACM.js";
@@ -24,6 +29,104 @@ import "../../chunk-NKUETCDA.js";
24
29
  import "../../chunk-WWAPK5PH.js";
25
30
  import "../../chunk-6CTCHYIS.js";
26
31
  import "../../chunk-ORMEWXMH.js";
32
+
33
+ // src/components/PDFViewer/index.tsx
34
+ import { useCallback, useState } from "react";
35
+ import { jsx } from "react/jsx-runtime";
36
+ function PDFViewer(props) {
37
+ const {
38
+ isOpen,
39
+ onClose,
40
+ encodedPdfs,
41
+ customActions,
42
+ testid,
43
+ isMobile,
44
+ title,
45
+ customFooter = false,
46
+ withPagination = true,
47
+ error
48
+ } = props;
49
+ const [currentIndex, setCurrentIndex] = useState(0);
50
+ const [isDownloading, setIsDownloading] = useState(false);
51
+ const handleDownload = useCallback(() => {
52
+ setIsDownloading(true);
53
+ const link = document.createElement("a");
54
+ const currentPdf = encodedPdfs[currentIndex];
55
+ if (!currentPdf) {
56
+ setIsDownloading(false);
57
+ return;
58
+ }
59
+ link.href = `data:application/pdf;base64,${currentPdf.base64}`;
60
+ link.download = currentPdf.fileName.endsWith(".pdf") ? currentPdf.fileName : `${currentPdf.fileName}.pdf`;
61
+ document.body.appendChild(link);
62
+ link.click();
63
+ document.body.removeChild(link);
64
+ setIsDownloading(false);
65
+ }, [currentIndex, encodedPdfs]);
66
+ if (!encodedPdfs.length) return null;
67
+ function handleNextFile() {
68
+ if (currentIndex < encodedPdfs.length - 1) {
69
+ setCurrentIndex((prev) => prev + 1);
70
+ }
71
+ }
72
+ function handlePreviousFile() {
73
+ if (currentIndex > 0) {
74
+ setCurrentIndex((prev) => prev - 1);
75
+ }
76
+ }
77
+ function handleClose() {
78
+ setCurrentIndex(0);
79
+ setIsDownloading(false);
80
+ onClose();
81
+ }
82
+ return /* @__PURE__ */ jsx(
83
+ Modal,
84
+ {
85
+ testid,
86
+ open: isOpen,
87
+ customFooter,
88
+ onClose: handleClose,
89
+ noWrapper: true,
90
+ showButtons: isMobile && customFooter ? !!customActions : !!encodedPdfs.length,
91
+ customActions: !!encodedPdfs.length && !isMobile && withPagination ? /* @__PURE__ */ jsx(
92
+ PdfNavigation,
93
+ {
94
+ testid,
95
+ currentIndex,
96
+ total: encodedPdfs.length,
97
+ onPrev: handlePreviousFile,
98
+ onNext: handleNextFile,
99
+ disablePrev: currentIndex === 0,
100
+ disableNext: currentIndex === encodedPdfs.length - 1,
101
+ extraActions: customActions,
102
+ fileName: encodedPdfs[currentIndex].fileName
103
+ }
104
+ ) : customActions,
105
+ fixedHeightScrolling: true,
106
+ headerIconAlign: "right",
107
+ headerIcon: !isMobile ? /* @__PURE__ */ jsx(
108
+ DownloadIcon,
109
+ {
110
+ testid: testid ? `${testid}-download-icon` : void 0,
111
+ onClick: handleDownload,
112
+ isDownloading
113
+ }
114
+ ) : void 0,
115
+ title: isMobile ? title != null ? title : encodedPdfs[currentIndex].fileName : void 0,
116
+ size: isMobile ? "screen" : "large",
117
+ headerClassname: "bg-brand-400 desktop:bg-background-grouped-primary-normal p-mobile-layout-padding text-brand-text-action-primary-normal",
118
+ children: /* @__PURE__ */ jsx(
119
+ PDFElement,
120
+ {
121
+ testid,
122
+ b64: encodedPdfs[currentIndex].base64,
123
+ isMobile,
124
+ error
125
+ }
126
+ )
127
+ }
128
+ );
129
+ }
27
130
  export {
28
131
  PDFViewer
29
132
  };
@@ -75,7 +75,6 @@ __export(components_exports, {
75
75
  Menu: () => Menu,
76
76
  MenuOption: () => MenuOption,
77
77
  MobileDataGrid: () => MobileDataGrid,
78
- PDFViewer: () => PDFViewer,
79
78
  Paragraph: () => Paragraph,
80
79
  ProductImagePreview: () => ProductImagePreview,
81
80
  Search: () => Search,
@@ -6582,290 +6581,6 @@ function CompactImagesPreview(props) {
6582
6581
  )) })
6583
6582
  ] });
6584
6583
  }
6585
-
6586
- // src/components/PDFViewer/index.tsx
6587
- var import_react35 = require("react");
6588
-
6589
- // src/components/PDFViewer/PDFElement.tsx
6590
- var import_react_pdf2 = require("@mikecousins/react-pdf");
6591
- var import_react34 = require("react");
6592
-
6593
- // src/components/PDFViewer/PDFPage.tsx
6594
- var import_react_pdf = require("@mikecousins/react-pdf");
6595
- var import_react33 = require("react");
6596
- var import_jsx_runtime52 = require("react/jsx-runtime");
6597
- function PdfPage({
6598
- file,
6599
- pageNumber,
6600
- testid,
6601
- isMobile
6602
- }) {
6603
- const canvasRef = (0, import_react33.useRef)(null);
6604
- const { pdfDocument } = (0, import_react_pdf.usePdf)({
6605
- file,
6606
- page: pageNumber,
6607
- canvasRef,
6608
- workerSrc: "/scripts/pdf.worker.min.mjs",
6609
- scale: isMobile ? 1 : 1.3
6610
- });
6611
- if (!pdfDocument) return null;
6612
- return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
6613
- "canvas",
6614
- {
6615
- ref: canvasRef,
6616
- "data-testid": testid,
6617
- style: { width: "100%", height: "auto" }
6618
- }
6619
- );
6620
- }
6621
-
6622
- // src/components/PDFViewer/PDFElement.tsx
6623
- var import_clsx34 = __toESM(require("clsx"), 1);
6624
- var import_jsx_runtime53 = require("react/jsx-runtime");
6625
- function PDFElement({
6626
- b64,
6627
- testid,
6628
- isMobile,
6629
- error
6630
- }) {
6631
- var _a;
6632
- const canvasRef = (0, import_react34.useRef)(null);
6633
- const { pdfDocument } = (0, import_react_pdf2.usePdf)({
6634
- file: `data:application/pdf;base64,${b64}`,
6635
- workerSrc: "/scripts/pdf.worker.min.mjs",
6636
- scale: isMobile ? 1 : 1.3,
6637
- canvasRef
6638
- });
6639
- const pagesArr = new Array((_a = pdfDocument == null ? void 0 : pdfDocument.numPages) != null ? _a : 1).fill(null);
6640
- return /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
6641
- "div",
6642
- {
6643
- className: "flex flex-col space-y-4",
6644
- style: !isMobile ? {
6645
- minHeight: 871,
6646
- minWidth: 654
6647
- } : void 0,
6648
- children: !!pdfDocument && !!b64 && !error ? /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(Stack, { sizing: "layout-group", children: pagesArr.length > 1 ? pagesArr.map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
6649
- "div",
6650
- {
6651
- className: (0, import_clsx34.default)(
6652
- "flex justify-center border-border-primary-normal",
6653
- isMobile ? "border-0" : "border"
6654
- ),
6655
- children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
6656
- PdfPage,
6657
- {
6658
- testid: testid ? `${testid}-pdf_page_${i + 1}` : void 0,
6659
- file: `data:application/pdf;base64,${b64}`,
6660
- pageNumber: i + 1
6661
- }
6662
- )
6663
- },
6664
- `${testid}-pdf-page-${i + 1}`
6665
- )) : /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
6666
- "div",
6667
- {
6668
- className: (0, import_clsx34.default)(
6669
- "flex justify-center border-border-primary-normal",
6670
- isMobile ? "border-0" : "border"
6671
- ),
6672
- children: /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
6673
- "canvas",
6674
- {
6675
- "data-testid": testid ? `${testid}-pdf-content` : void 0,
6676
- ref: canvasRef,
6677
- style: { width: "100%", height: "auto" }
6678
- }
6679
- )
6680
- }
6681
- ) }) : /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
6682
- Stack,
6683
- {
6684
- justify: "center",
6685
- items: "center",
6686
- height: "full",
6687
- flexGrow: 1,
6688
- "data-testid": testid ? `${testid}-pdf-${error ? "error" : "loading"}` : void 0,
6689
- children: error ? error : /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(Spinner, { size: "large" })
6690
- }
6691
- )
6692
- }
6693
- );
6694
- }
6695
-
6696
- // src/components/PDFViewer/DownloadIcon.tsx
6697
- var import_jsx_runtime54 = require("react/jsx-runtime");
6698
- function DownloadIcon({
6699
- onClick,
6700
- isDownloading,
6701
- testid
6702
- }) {
6703
- return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(
6704
- Button,
6705
- {
6706
- testid,
6707
- iconOnly: true,
6708
- variant: "tertiary",
6709
- leftIcon: /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Icon, { name: isDownloading ? "cached" : "download" }),
6710
- onClick
6711
- }
6712
- );
6713
- }
6714
-
6715
- // src/components/PDFViewer/PDFNavigation.tsx
6716
- var import_jsx_runtime55 = require("react/jsx-runtime");
6717
- function PdfNavigation({
6718
- currentIndex,
6719
- total,
6720
- onPrev,
6721
- onNext,
6722
- disablePrev,
6723
- disableNext,
6724
- extraActions,
6725
- testid,
6726
- fileName
6727
- }) {
6728
- return /* @__PURE__ */ (0, import_jsx_runtime55.jsx)("div", { className: "w-full", children: /* @__PURE__ */ (0, import_jsx_runtime55.jsxs)(
6729
- Stack,
6730
- {
6731
- horizontal: true,
6732
- items: "center",
6733
- justify: "between",
6734
- sizing: "layout-group",
6735
- testid: testid ? `${testid}-pdf-navigation` : void 0,
6736
- children: [
6737
- /* @__PURE__ */ (0, import_jsx_runtime55.jsxs)(Stack, { horizontal: true, items: "center", children: [
6738
- /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(
6739
- Button,
6740
- {
6741
- iconOnly: true,
6742
- variant: "tertiary",
6743
- onClick: onPrev,
6744
- leftIcon: /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(Icon, { name: "chevron_backward" }),
6745
- disabled: disablePrev,
6746
- testid: testid ? `${testid}-pdf-file-previous-button` : void 0
6747
- }
6748
- ),
6749
- /* @__PURE__ */ (0, import_jsx_runtime55.jsxs)(Heading3, { className: "text-text-primary-normal whitespace-nowrap", children: [
6750
- currentIndex + 1,
6751
- " / ",
6752
- total
6753
- ] }),
6754
- /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(
6755
- Button,
6756
- {
6757
- iconOnly: true,
6758
- variant: "tertiary",
6759
- onClick: onNext,
6760
- rightIcon: /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(Icon, { name: "chevron_forward" }),
6761
- disabled: disableNext,
6762
- testid: testid ? `${testid}-pdf-file-next-button` : void 0
6763
- }
6764
- ),
6765
- /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(Paragraph, { children: (fileName == null ? void 0 : fileName.endsWith(".pdf")) ? fileName : `${fileName}.pdf` })
6766
- ] }),
6767
- extraActions && /* @__PURE__ */ (0, import_jsx_runtime55.jsx)("div", { className: "flex items-center gap-2", children: extraActions })
6768
- ]
6769
- }
6770
- ) });
6771
- }
6772
-
6773
- // src/components/PDFViewer/index.tsx
6774
- var import_jsx_runtime56 = require("react/jsx-runtime");
6775
- function PDFViewer(props) {
6776
- const {
6777
- isOpen,
6778
- onClose,
6779
- encodedPdfs,
6780
- customActions,
6781
- testid,
6782
- isMobile,
6783
- title,
6784
- customFooter = false,
6785
- withPagination = true,
6786
- error
6787
- } = props;
6788
- const [currentIndex, setCurrentIndex] = (0, import_react35.useState)(0);
6789
- const [isDownloading, setIsDownloading] = (0, import_react35.useState)(false);
6790
- const handleDownload = (0, import_react35.useCallback)(() => {
6791
- setIsDownloading(true);
6792
- const link = document.createElement("a");
6793
- const currentPdf = encodedPdfs[currentIndex];
6794
- if (!currentPdf) {
6795
- setIsDownloading(false);
6796
- return;
6797
- }
6798
- link.href = `data:application/pdf;base64,${currentPdf.base64}`;
6799
- link.download = currentPdf.fileName.endsWith(".pdf") ? currentPdf.fileName : `${currentPdf.fileName}.pdf`;
6800
- document.body.appendChild(link);
6801
- link.click();
6802
- document.body.removeChild(link);
6803
- setIsDownloading(false);
6804
- }, [currentIndex, encodedPdfs]);
6805
- if (!encodedPdfs.length) return null;
6806
- function handleNextFile() {
6807
- if (currentIndex < encodedPdfs.length - 1) {
6808
- setCurrentIndex((prev) => prev + 1);
6809
- }
6810
- }
6811
- function handlePreviousFile() {
6812
- if (currentIndex > 0) {
6813
- setCurrentIndex((prev) => prev - 1);
6814
- }
6815
- }
6816
- function handleClose() {
6817
- setCurrentIndex(0);
6818
- setIsDownloading(false);
6819
- onClose();
6820
- }
6821
- return /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
6822
- Modal,
6823
- {
6824
- testid,
6825
- open: isOpen,
6826
- customFooter,
6827
- onClose: handleClose,
6828
- noWrapper: true,
6829
- showButtons: isMobile && customFooter ? !!customActions : !!encodedPdfs.length,
6830
- customActions: !!encodedPdfs.length && !isMobile && withPagination ? /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
6831
- PdfNavigation,
6832
- {
6833
- testid,
6834
- currentIndex,
6835
- total: encodedPdfs.length,
6836
- onPrev: handlePreviousFile,
6837
- onNext: handleNextFile,
6838
- disablePrev: currentIndex === 0,
6839
- disableNext: currentIndex === encodedPdfs.length - 1,
6840
- extraActions: customActions,
6841
- fileName: encodedPdfs[currentIndex].fileName
6842
- }
6843
- ) : customActions,
6844
- fixedHeightScrolling: true,
6845
- headerIconAlign: "right",
6846
- headerIcon: !isMobile ? /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
6847
- DownloadIcon,
6848
- {
6849
- testid: testid ? `${testid}-download-icon` : void 0,
6850
- onClick: handleDownload,
6851
- isDownloading
6852
- }
6853
- ) : void 0,
6854
- title: isMobile ? title != null ? title : encodedPdfs[currentIndex].fileName : void 0,
6855
- size: isMobile ? "screen" : "large",
6856
- headerClassname: "bg-brand-400 desktop:bg-background-grouped-primary-normal p-mobile-layout-padding text-brand-text-action-primary-normal",
6857
- children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
6858
- PDFElement,
6859
- {
6860
- testid,
6861
- b64: encodedPdfs[currentIndex].base64,
6862
- isMobile,
6863
- error
6864
- }
6865
- )
6866
- }
6867
- );
6868
- }
6869
6584
  // Annotate the CommonJS export names for ESM import in node:
6870
6585
  0 && (module.exports = {
6871
6586
  Accordion,
@@ -6884,7 +6599,6 @@ function PDFViewer(props) {
6884
6599
  Menu,
6885
6600
  MenuOption,
6886
6601
  MobileDataGrid,
6887
- PDFViewer,
6888
6602
  Paragraph,
6889
6603
  ProductImagePreview,
6890
6604
  Search,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DataGrid,
3
3
  MobileDataGrid
4
- } from "../chunk-OW3WN3JV.js";
4
+ } from "../chunk-OBY5EH47.js";
5
5
  import "../chunk-M7INAUAJ.js";
6
6
  import "../chunk-6I5LZ2ZC.js";
7
7
  import "../chunk-44TDIHUP.js";
@@ -11,13 +11,6 @@ import {
11
11
  import "../chunk-G5DEC7H3.js";
12
12
  import "../chunk-3X3Y4TMS.js";
13
13
  import "../chunk-BQNPOGD5.js";
14
- import {
15
- PDFViewer
16
- } from "../chunk-LLZ3SSZJ.js";
17
- import "../chunk-EJSPFQCY.js";
18
- import "../chunk-ERW5DEIO.js";
19
- import "../chunk-2HMCS25C.js";
20
- import "../chunk-VJVY6NPF.js";
21
14
  import "../chunk-MBZ55T2D.js";
22
15
  import "../chunk-2IKT6IHB.js";
23
16
  import "../chunk-AA6GE3TH.js";
@@ -114,7 +107,6 @@ export {
114
107
  Menu,
115
108
  MenuOption,
116
109
  MobileDataGrid,
117
- PDFViewer,
118
110
  Paragraph,
119
111
  ProductImagePreview,
120
112
  Search,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dmsi/wedgekit-react",
3
3
  "private": false,
4
- "version": "0.0.411",
4
+ "version": "0.0.412",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsup",
@@ -23,4 +23,3 @@ export { Card } from "./Card";
23
23
  export { MobileDataGrid } from "./MobileDataGrid";
24
24
  export { ProductImagePreview } from "./ProductImagePreview";
25
25
  export { CompactImagesPreview } from "./CompactImagesPreview";
26
- export { PDFViewer } from "./PDFViewer";
@@ -1,114 +0,0 @@
1
- import {
2
- DownloadIcon
3
- } from "./chunk-EJSPFQCY.js";
4
- import {
5
- PDFElement
6
- } from "./chunk-ERW5DEIO.js";
7
- import {
8
- PdfNavigation
9
- } from "./chunk-2HMCS25C.js";
10
- import {
11
- Modal
12
- } from "./chunk-D6YCMQPO.js";
13
-
14
- // src/components/PDFViewer/index.tsx
15
- import { useCallback, useState } from "react";
16
- import { jsx } from "react/jsx-runtime";
17
- function PDFViewer(props) {
18
- const {
19
- isOpen,
20
- onClose,
21
- encodedPdfs,
22
- customActions,
23
- testid,
24
- isMobile,
25
- title,
26
- customFooter = false,
27
- withPagination = true,
28
- error
29
- } = props;
30
- const [currentIndex, setCurrentIndex] = useState(0);
31
- const [isDownloading, setIsDownloading] = useState(false);
32
- const handleDownload = useCallback(() => {
33
- setIsDownloading(true);
34
- const link = document.createElement("a");
35
- const currentPdf = encodedPdfs[currentIndex];
36
- if (!currentPdf) {
37
- setIsDownloading(false);
38
- return;
39
- }
40
- link.href = `data:application/pdf;base64,${currentPdf.base64}`;
41
- link.download = currentPdf.fileName.endsWith(".pdf") ? currentPdf.fileName : `${currentPdf.fileName}.pdf`;
42
- document.body.appendChild(link);
43
- link.click();
44
- document.body.removeChild(link);
45
- setIsDownloading(false);
46
- }, [currentIndex, encodedPdfs]);
47
- if (!encodedPdfs.length) return null;
48
- function handleNextFile() {
49
- if (currentIndex < encodedPdfs.length - 1) {
50
- setCurrentIndex((prev) => prev + 1);
51
- }
52
- }
53
- function handlePreviousFile() {
54
- if (currentIndex > 0) {
55
- setCurrentIndex((prev) => prev - 1);
56
- }
57
- }
58
- function handleClose() {
59
- setCurrentIndex(0);
60
- setIsDownloading(false);
61
- onClose();
62
- }
63
- return /* @__PURE__ */ jsx(
64
- Modal,
65
- {
66
- testid,
67
- open: isOpen,
68
- customFooter,
69
- onClose: handleClose,
70
- noWrapper: true,
71
- showButtons: isMobile && customFooter ? !!customActions : !!encodedPdfs.length,
72
- customActions: !!encodedPdfs.length && !isMobile && withPagination ? /* @__PURE__ */ jsx(
73
- PdfNavigation,
74
- {
75
- testid,
76
- currentIndex,
77
- total: encodedPdfs.length,
78
- onPrev: handlePreviousFile,
79
- onNext: handleNextFile,
80
- disablePrev: currentIndex === 0,
81
- disableNext: currentIndex === encodedPdfs.length - 1,
82
- extraActions: customActions,
83
- fileName: encodedPdfs[currentIndex].fileName
84
- }
85
- ) : customActions,
86
- fixedHeightScrolling: true,
87
- headerIconAlign: "right",
88
- headerIcon: !isMobile ? /* @__PURE__ */ jsx(
89
- DownloadIcon,
90
- {
91
- testid: testid ? `${testid}-download-icon` : void 0,
92
- onClick: handleDownload,
93
- isDownloading
94
- }
95
- ) : void 0,
96
- title: isMobile ? title != null ? title : encodedPdfs[currentIndex].fileName : void 0,
97
- size: isMobile ? "screen" : "large",
98
- headerClassname: "bg-brand-400 desktop:bg-background-grouped-primary-normal p-mobile-layout-padding text-brand-text-action-primary-normal",
99
- children: /* @__PURE__ */ jsx(
100
- PDFElement,
101
- {
102
- testid,
103
- b64: encodedPdfs[currentIndex].base64,
104
- isMobile,
105
- error
106
- }
107
- )
108
- }
109
- );
110
- }
111
-
112
- export {
113
- PDFViewer
114
- };
File without changes