@geotab/zenith 3.18.0 → 3.19.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.
Files changed (89) hide show
  1. package/README.md +9 -0
  2. package/dist/chart/accessibleChart/accessibleChartTable.d.ts +1 -1
  3. package/dist/chart/accessibleChart/accessibleChartTable.js +29 -6
  4. package/dist/chart/accessibleChart/interfaces.d.ts +8 -2
  5. package/dist/chart/barChart.d.ts +3 -1
  6. package/dist/chart/barChart.js +5 -3
  7. package/dist/chart/lineChart.d.ts +3 -1
  8. package/dist/chart/lineChart.js +5 -3
  9. package/dist/chart/pieChart.d.ts +3 -1
  10. package/dist/chart/pieChart.js +5 -3
  11. package/dist/chart/utils/isEmptyDataPoint.d.ts +1 -0
  12. package/dist/chart/utils/isEmptyDataPoint.js +5 -0
  13. package/dist/dataGrid/columns/mainColumn/mainColumnWrapper.d.ts +2 -0
  14. package/dist/dataGrid/columns/mainColumn/mainColumnWrapper.js +2 -2
  15. package/dist/fileUpload/components/filePreview.d.ts +15 -0
  16. package/dist/fileUpload/components/filePreview.js +272 -0
  17. package/dist/fileUpload/components/previewableFile.d.ts +16 -0
  18. package/dist/fileUpload/components/previewableFile.js +48 -0
  19. package/dist/fileUpload/components/resolveFileActions.d.ts +10 -0
  20. package/dist/fileUpload/components/resolveFileActions.js +11 -0
  21. package/dist/fileUpload/components/uploadedFilesSection.d.ts +9 -1
  22. package/dist/fileUpload/components/uploadedFilesSection.js +91 -16
  23. package/dist/fileUpload/components/useFilePreview.d.ts +12 -0
  24. package/dist/fileUpload/components/useFilePreview.js +85 -0
  25. package/dist/fileUpload/fileUpload.d.ts +1 -1
  26. package/dist/fileUpload/fileUpload.js +63 -2
  27. package/dist/fileUpload/fileUploadType.d.ts +35 -0
  28. package/dist/filtersBar/components/filtersBarSearch/filtersBarSearch.d.ts +1 -1
  29. package/dist/formSection/components/formSectionCard.js +1 -1
  30. package/dist/icons/iconEngine.d.ts +3 -0
  31. package/dist/icons/iconEngine.js +12 -0
  32. package/dist/index.css +74 -2
  33. package/dist/index.d.ts +3 -1
  34. package/dist/index.js +12 -10
  35. package/dist/inputAdornments/inputAdornments.d.ts +3 -1
  36. package/dist/inputAdornments/inputAdornments.js +2 -2
  37. package/dist/lineChartMini/lineChartMini.d.ts +3 -1
  38. package/dist/lineChartMini/lineChartMini.js +5 -3
  39. package/dist/modal/modal.d.ts +2 -0
  40. package/dist/primaryIcon/primaryIcon.d.ts +3 -1
  41. package/dist/primaryIcon/primaryIcon.js +3 -3
  42. package/dist/searchInputRaw/searchInputRaw.js +4 -2
  43. package/dist/searchInputRaw/types.d.ts +2 -0
  44. package/dist/textInputRaw/textInputRaw.js +1 -1
  45. package/dist/textInputRaw/types.d.ts +2 -0
  46. package/esm/chart/accessibleChart/accessibleChartTable.d.ts +1 -1
  47. package/esm/chart/accessibleChart/accessibleChartTable.js +29 -6
  48. package/esm/chart/accessibleChart/interfaces.d.ts +8 -2
  49. package/esm/chart/barChart.d.ts +3 -1
  50. package/esm/chart/barChart.js +5 -3
  51. package/esm/chart/lineChart.d.ts +3 -1
  52. package/esm/chart/lineChart.js +5 -3
  53. package/esm/chart/pieChart.d.ts +3 -1
  54. package/esm/chart/pieChart.js +5 -3
  55. package/esm/chart/utils/isEmptyDataPoint.d.ts +1 -0
  56. package/esm/chart/utils/isEmptyDataPoint.js +1 -0
  57. package/esm/dataGrid/columns/mainColumn/mainColumnWrapper.d.ts +2 -0
  58. package/esm/dataGrid/columns/mainColumn/mainColumnWrapper.js +2 -2
  59. package/esm/fileUpload/components/filePreview.d.ts +15 -0
  60. package/esm/fileUpload/components/filePreview.js +263 -0
  61. package/esm/fileUpload/components/previewableFile.d.ts +16 -0
  62. package/esm/fileUpload/components/previewableFile.js +43 -0
  63. package/esm/fileUpload/components/resolveFileActions.d.ts +10 -0
  64. package/esm/fileUpload/components/resolveFileActions.js +7 -0
  65. package/esm/fileUpload/components/uploadedFilesSection.d.ts +9 -1
  66. package/esm/fileUpload/components/uploadedFilesSection.js +91 -16
  67. package/esm/fileUpload/components/useFilePreview.d.ts +12 -0
  68. package/esm/fileUpload/components/useFilePreview.js +81 -0
  69. package/esm/fileUpload/fileUpload.d.ts +1 -1
  70. package/esm/fileUpload/fileUpload.js +63 -2
  71. package/esm/fileUpload/fileUploadType.d.ts +35 -0
  72. package/esm/filtersBar/components/filtersBarSearch/filtersBarSearch.d.ts +1 -1
  73. package/esm/formSection/components/formSectionCard.js +1 -1
  74. package/esm/icons/iconEngine.d.ts +3 -0
  75. package/esm/icons/iconEngine.js +8 -0
  76. package/esm/index.d.ts +3 -1
  77. package/esm/index.js +1 -0
  78. package/esm/inputAdornments/inputAdornments.d.ts +3 -1
  79. package/esm/inputAdornments/inputAdornments.js +2 -2
  80. package/esm/lineChartMini/lineChartMini.d.ts +3 -1
  81. package/esm/lineChartMini/lineChartMini.js +5 -3
  82. package/esm/modal/modal.d.ts +2 -0
  83. package/esm/primaryIcon/primaryIcon.d.ts +3 -1
  84. package/esm/primaryIcon/primaryIcon.js +3 -3
  85. package/esm/searchInputRaw/searchInputRaw.js +4 -2
  86. package/esm/searchInputRaw/types.d.ts +2 -0
  87. package/esm/textInputRaw/textInputRaw.js +1 -1
  88. package/esm/textInputRaw/types.d.ts +2 -0
  89. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveFileActions = void 0;
4
+ /** An action button is only shown when it is switched on and the consumer provided something for it to do. */
5
+ /** Which action buttons are shown, and the base for their `data-analytics-id` (defaults to the component id). */
6
+ const resolveFileActions = ({ id, dataAnalyticsId, showViewButton, showDownloadButton, onView, getPreviewBlob, onDownload }) => ({
7
+ analyticsBase: dataAnalyticsId !== null && dataAnalyticsId !== void 0 ? dataAnalyticsId : id,
8
+ canView: !!showViewButton && !!(onView || getPreviewBlob),
9
+ canDownload: !!showDownloadButton && !!onDownload
10
+ });
11
+ exports.resolveFileActions = resolveFileActions;
@@ -8,6 +8,14 @@ interface IUploadedFilesSectionProps {
8
8
  handleRemoveFile: (fileId: string, index: number) => void;
9
9
  translate: (key: string) => string;
10
10
  removeButtonRefs: RefObject<Map<number, HTMLButtonElement>>;
11
+ /** Base for `data-analytics-id` on the action buttons */
12
+ analyticsBase?: string;
13
+ viewButtonRefs?: RefObject<Map<string, HTMLButtonElement>>;
14
+ showRemoveButton?: boolean;
15
+ showViewButton?: boolean;
16
+ showDownloadButton?: boolean;
17
+ handleViewFile?: (file: IUploadedFile) => void;
18
+ handleDownloadFile?: (file: IUploadedFile) => void;
11
19
  }
12
- export declare const UploadedFilesSection: ({ id, uploadedFiles, disabled, isUploading, handleRemoveFile, translate, removeButtonRefs }: IUploadedFilesSectionProps) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const UploadedFilesSection: ({ id, uploadedFiles, disabled, isUploading, handleRemoveFile, translate, removeButtonRefs, analyticsBase, viewButtonRefs, showRemoveButton, showViewButton, showDownloadButton, handleViewFile, handleDownloadFile }: IUploadedFilesSectionProps) => import("react/jsx-runtime").JSX.Element;
13
21
  export {};
@@ -14,10 +14,13 @@ const iconExcel_1 = require("../../icons/iconExcel");
14
14
  const iconPDF_1 = require("../../icons/iconPDF");
15
15
  const iconDocument_1 = require("../../icons/iconDocument");
16
16
  const iconClose_1 = require("../../icons/iconClose");
17
+ const iconEye_1 = require("../../icons/iconEye");
18
+ const iconDownload_1 = require("../../icons/iconDownload");
17
19
  const banner_1 = require("../../banner/banner");
18
20
  const textIconButton_1 = require("../../textIconButton/textIconButton");
19
21
  const buttonType_1 = require("../../button/buttonType");
20
22
  const svgIconSize_1 = require("../../svgIcon/svgIconSize");
23
+ const previewableFile_1 = require("./previewableFile");
21
24
  injectString("cs", "Uploaded", "Uploaded");
22
25
  injectString("da-DK", "Uploaded", "Uploadet");
23
26
  injectString("de", "Uploaded", "Uploaded");
@@ -51,6 +54,40 @@ injectString("ka-GE", "Uploaded", "\u10D0\u10E2\u10D5\u10D8\u10E0\u10D7\u10E3\u1
51
54
  injectString("el-GR", "Uploaded", "\u0391\u03BD\u03B5\u03B2\u03AC\u03C3\u03C4\u03B7\u03BA\u03B5");
52
55
  injectString("et-EE", "Uploaded", "\xDCles laaditud");
53
56
  injectString("bg-BG", "Uploaded", "\u041A\u0430\u0447\u0435\u043D\u043E");
57
+ injectString("en", "View", "View");
58
+ injectString("cs", "Download", "St\xE1hnout");
59
+ injectString("da-DK", "Download", "Download");
60
+ injectString("de", "Download", "Herunterladen");
61
+ injectString("en", "Download", "Download");
62
+ injectString("es", "Download", "Descargar");
63
+ injectString("fi-FI", "Download", "Lataa");
64
+ injectString("fr", "Download", "T\xE9l\xE9charger");
65
+ injectString("fr-FR", "Download", "T\xE9l\xE9charger");
66
+ injectString("hu-HU", "Download", "Let\xF6lt\xE9s");
67
+ injectString("id", "Download", "Unduh");
68
+ injectString("it", "Download", "Scaricare");
69
+ injectString("ja", "Download", "\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9");
70
+ injectString("ko-KR", "Download", "\uB2E4\uC6B4\uB85C\uB4DC");
71
+ injectString("ms", "Download", "Muat Turun");
72
+ injectString("nb-NO", "Download", "Last ned");
73
+ injectString("nl", "Download", "Downloaden");
74
+ injectString("pl", "Download", "Pobierz");
75
+ injectString("pt-BR", "Download", "Download");
76
+ injectString("pt-PT", "Download", "Download");
77
+ injectString("sk-SK", "Download", "Stiahni");
78
+ injectString("sv", "Download", "Ladda ned");
79
+ injectString("th", "Download", "\u0E14\u0E32\u0E27\u0E19\u0E4C\u0E42\u0E2B\u0E25\u0E14");
80
+ injectString("tr", "Download", "\u0130ndir");
81
+ injectString("zh-Hans", "Download", "\u4E0B\u8F7D");
82
+ injectString("zh-TW", "Download", "\u4E0B\u8F09");
83
+ injectString("ro-RO", "Download", "Desc\u0103rca\u021Bi");
84
+ injectString("ar-001", "Download", "\u062A\u0646\u0632\u064A\u0644");
85
+ injectString("lt-LT", "Download", "Atsisi\u0173sti");
86
+ injectString("lv-LV", "Download", "Lejupiel\u0101d\u0113t");
87
+ injectString("ka-GE", "Download", "\u10E9\u10D0\u10DB\u10DD\u10E2\u10D5\u10D8\u10E0\u10D7\u10D5\u10D0");
88
+ injectString("el-GR", "Download", "\u039B\u03AE\u03C8\u03B7");
89
+ injectString("et-EE", "Download", "Laadi alla");
90
+ injectString("bg-BG", "Download", "\u0418\u0437\u0442\u0435\u0433\u043B\u044F\u043D\u0435");
54
91
  injectString("cs", "Remove", "Odebrat");
55
92
  injectString("da-DK", "Remove", "Fjern");
56
93
  injectString("de", "Remove", "Entfernen");
@@ -113,7 +150,14 @@ const UploadedFilesSection = ({
113
150
  isUploading,
114
151
  handleRemoveFile,
115
152
  translate,
116
- removeButtonRefs
153
+ removeButtonRefs,
154
+ analyticsBase = id,
155
+ viewButtonRefs,
156
+ showRemoveButton = true,
157
+ showViewButton = false,
158
+ showDownloadButton = false,
159
+ handleViewFile,
160
+ handleDownloadFile
117
161
  }) => (0, jsx_runtime_1.jsxs)("div", {
118
162
  className: "zen-file-upload__uploaded",
119
163
  children: [(0, jsx_runtime_1.jsx)("span", {
@@ -127,6 +171,8 @@ const UploadedFilesSection = ({
127
171
  const FileIcon = getFileIcon(file);
128
172
  const hasError = file.hasError || !!file.errorMessage;
129
173
  const fileItemClasses = (0, classNames_1.classNames)(["zen-file-upload__file-item", hasError ? "zen-file-upload__file-item--error" : ""]);
174
+ const canView = showViewButton && !!handleViewFile && !hasError && (0, previewableFile_1.getPreviewKind)(file) !== null;
175
+ const canDownload = showDownloadButton && !!handleDownloadFile && !hasError;
130
176
  const fileNameClasses = (0, classNames_1.classNames)(["zen-file-upload__file-name", hasError ? "zen-file-upload__file-name--error" : ""]);
131
177
  return (0, jsx_runtime_1.jsxs)("li", {
132
178
  className: "zen-file-upload__file-list-item",
@@ -147,21 +193,50 @@ const UploadedFilesSection = ({
147
193
  className: fileNameClasses,
148
194
  children: file.name
149
195
  })]
150
- }), (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, {
151
- ref: el => {
152
- if (el) {
153
- removeButtonRefs.current.set(index, el);
154
- } else {
155
- removeButtonRefs.current.delete(index);
156
- }
157
- },
158
- icon: iconClose_1.IconClose,
159
- iconSize: svgIconSize_1.SvgIconSize.Bigger,
160
- type: buttonType_1.ButtonType.TertiaryBlack,
161
- className: "zen-file-upload__remove-button",
162
- onClick: () => handleRemoveFile(file.id, index),
163
- ariaLabel: `${translate("Remove")} ${file.name}`,
164
- disabled: disabled || isUploading
196
+ }), (canView || canDownload || showRemoveButton) && (0, jsx_runtime_1.jsxs)("div", {
197
+ className: "zen-file-upload__file-actions",
198
+ children: [canView && (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, {
199
+ ref: el => {
200
+ if (el) {
201
+ viewButtonRefs === null || viewButtonRefs === void 0 ? void 0 : viewButtonRefs.current.set(file.id, el);
202
+ } else {
203
+ viewButtonRefs === null || viewButtonRefs === void 0 ? void 0 : viewButtonRefs.current.delete(file.id);
204
+ }
205
+ },
206
+ icon: iconEye_1.IconEye,
207
+ iconSize: svgIconSize_1.SvgIconSize.Bigger,
208
+ type: buttonType_1.ButtonType.TertiaryBlack,
209
+ className: "zen-file-upload__view-button",
210
+ dataAnalyticsId: `${analyticsBase}-view`,
211
+ onClick: () => handleViewFile(file),
212
+ ariaLabel: `${translate("View")} ${file.name}`,
213
+ disabled: disabled || isUploading
214
+ }), canDownload && (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, {
215
+ icon: iconDownload_1.IconDownload,
216
+ iconSize: svgIconSize_1.SvgIconSize.Bigger,
217
+ type: buttonType_1.ButtonType.TertiaryBlack,
218
+ className: "zen-file-upload__download-button",
219
+ dataAnalyticsId: `${analyticsBase}-download`,
220
+ onClick: () => handleDownloadFile(file),
221
+ ariaLabel: `${translate("Download")} ${file.name}`,
222
+ disabled: disabled || isUploading
223
+ }), showRemoveButton && (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, {
224
+ ref: el => {
225
+ if (el) {
226
+ removeButtonRefs.current.set(index, el);
227
+ } else {
228
+ removeButtonRefs.current.delete(index);
229
+ }
230
+ },
231
+ icon: iconClose_1.IconClose,
232
+ iconSize: svgIconSize_1.SvgIconSize.Bigger,
233
+ type: buttonType_1.ButtonType.TertiaryBlack,
234
+ className: "zen-file-upload__remove-button",
235
+ dataAnalyticsId: `${analyticsBase}-remove`,
236
+ onClick: () => handleRemoveFile(file.id, index),
237
+ ariaLabel: `${translate("Remove")} ${file.name}`,
238
+ disabled: disabled || isUploading
239
+ })]
165
240
  })]
166
241
  })]
167
242
  }, file.id);
@@ -0,0 +1,12 @@
1
+ import { RefObject } from "react";
2
+ import { IFileUpload, IUploadedFile } from "../fileUploadType";
3
+ import { IPreviewState } from "./previewableFile";
4
+ interface IUseFilePreviewProps extends Pick<IFileUpload, "onView" | "getPreviewBlob" | "previewMode"> {
5
+ viewButtonRefs: RefObject<Map<string, HTMLButtonElement>>;
6
+ }
7
+ export declare const useFilePreview: ({ onView, getPreviewBlob, previewMode, viewButtonRefs }: IUseFilePreviewProps) => {
8
+ preview: IPreviewState | null;
9
+ handleViewFile: (file: IUploadedFile) => Promise<void>;
10
+ handleClosePreview: () => void;
11
+ };
12
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFilePreview = void 0;
4
+ const react_1 = require("react");
5
+ const zen_1 = require("../../utils/zen");
6
+ const previewableFile_1 = require("./previewableFile");
7
+ const useFilePreview = ({ onView, getPreviewBlob, previewMode = "modal", viewButtonRefs }) => {
8
+ const [previewFile, setPreviewFile] = (0, react_1.useState)(null);
9
+ const [previewUrl, setPreviewUrl] = (0, react_1.useState)(undefined);
10
+ // Incremented on every open and every close, so a slow getPreviewBlob() from an earlier request can never
11
+ // overwrite or close a newer preview, even when the same file is closed and reopened.
12
+ const requestTokenRef = (0, react_1.useRef)(0);
13
+ const openFileIdRef = (0, react_1.useRef)(null);
14
+ // The object URL Zenith created for the open preview. It is the only URL the preview and Open in new tab use.
15
+ const objectUrlRef = (0, react_1.useRef)(null);
16
+ const revokeObjectUrl = (0, react_1.useCallback)(() => {
17
+ if (objectUrlRef.current) {
18
+ URL.revokeObjectURL(objectUrlRef.current);
19
+ objectUrlRef.current = null;
20
+ }
21
+ }, []);
22
+ // On unmount: invalidate any pending getPreviewBlob() request first, so it cannot resolve later, pass the token check,
23
+ // create an object URL nothing would ever revoke, or set state on a component that is gone. Then revoke the current URL.
24
+ (0, react_1.useEffect)(() => () => {
25
+ requestTokenRef.current += 1;
26
+ openFileIdRef.current = null;
27
+ revokeObjectUrl();
28
+ }, [revokeObjectUrl]);
29
+ // Single close path: invalidates in-flight requests and returns focus to the View button that opened the preview.
30
+ // Inline mode unmounts that button, so focus must be restored on every close, including failed requests.
31
+ const closePreview = (0, react_1.useCallback)(() => {
32
+ var _a;
33
+ const closedId = openFileIdRef.current;
34
+ requestTokenRef.current += 1;
35
+ openFileIdRef.current = null;
36
+ revokeObjectUrl();
37
+ setPreviewFile(null);
38
+ setPreviewUrl(undefined);
39
+ if (closedId) {
40
+ (_a = zen_1.zen.requestAnimationFrame) === null || _a === void 0 ? void 0 : _a.call(zen_1.zen, () => { var _a; return (_a = viewButtonRefs.current.get(closedId)) === null || _a === void 0 ? void 0 : _a.focus(); });
41
+ }
42
+ }, [viewButtonRefs, revokeObjectUrl]);
43
+ const handleViewFile = (0, react_1.useCallback)(async (file) => {
44
+ if (onView) {
45
+ onView(file);
46
+ return;
47
+ }
48
+ const kind = (0, previewableFile_1.getPreviewKind)(file);
49
+ if (!getPreviewBlob || !kind) {
50
+ return;
51
+ }
52
+ requestTokenRef.current += 1;
53
+ const token = requestTokenRef.current;
54
+ openFileIdRef.current = file.id;
55
+ // A newer request supersedes the previous preview, so its object URL is released straight away
56
+ revokeObjectUrl();
57
+ setPreviewUrl(undefined);
58
+ setPreviewFile(file);
59
+ try {
60
+ const data = await getPreviewBlob(file);
61
+ if (requestTokenRef.current !== token) {
62
+ return;
63
+ }
64
+ if (data) {
65
+ // Always re-label the bytes from the file kind, never trust the type the consumer's Blob carries
66
+ const blob = new Blob([data], { type: (0, previewableFile_1.getPreviewMimeType)(file, kind) });
67
+ objectUrlRef.current = URL.createObjectURL(blob);
68
+ setPreviewUrl(objectUrlRef.current);
69
+ }
70
+ else {
71
+ // Nothing to preview: close instead of showing the loading state forever
72
+ closePreview();
73
+ }
74
+ }
75
+ catch (_a) {
76
+ if (requestTokenRef.current === token) {
77
+ closePreview();
78
+ }
79
+ }
80
+ }, [onView, getPreviewBlob, closePreview, revokeObjectUrl]);
81
+ const kind = previewFile ? (0, previewableFile_1.getPreviewKind)(previewFile) : null;
82
+ const preview = previewFile && kind ? { file: previewFile, fileName: previewFile.name, kind, url: previewUrl, mode: previewMode } : null;
83
+ return { preview, handleViewFile, handleClosePreview: closePreview };
84
+ };
85
+ exports.useFilePreview = useFilePreview;
@@ -1,6 +1,6 @@
1
1
  import { IFileUpload } from "./fileUploadType";
2
2
  import "./fileUpload.less";
3
3
  export declare const FileUpload: {
4
- ({ id, className, size, supportedFormatsText, accept, allowMultiple, value, isUploading, disabled, showTemplateSection, showUploadedSection, templateDownload, onChange }: IFileUpload): import("react/jsx-runtime").JSX.Element;
4
+ ({ id, className, size, supportedFormatsText, accept, allowMultiple, value, isUploading, disabled, showTemplateSection, showUploadedSection, templateDownload, dataAnalyticsId, showRemoveButton, showViewButton, showDownloadButton, onView, onDownload, getPreviewBlob, previewMode, onChange }: IFileUpload): import("react/jsx-runtime").JSX.Element;
5
5
  displayName: string;
6
6
  };
@@ -14,6 +14,9 @@ const useDriveClassName_1 = require("../utils/theme/useDriveClassName");
14
14
  const useLanguage_1 = require("../utils/localization/useLanguage");
15
15
  const useMobile_1 = require("../commonHelpers/hooks/useMobile");
16
16
  const waiting_1 = require("../waiting/waiting");
17
+ const filePreview_1 = require("./components/filePreview");
18
+ const resolveFileActions_1 = require("./components/resolveFileActions");
19
+ const useFilePreview_1 = require("./components/useFilePreview");
17
20
  const dropZoneContent_1 = require("./components/dropZoneContent");
18
21
  const templateDownloadSection_1 = require("./components/templateDownloadSection");
19
22
  const uploadedFilesSection_1 = require("./components/uploadedFilesSection");
@@ -234,6 +237,14 @@ const FileUpload = ({
234
237
  showTemplateSection = true,
235
238
  showUploadedSection = true,
236
239
  templateDownload,
240
+ dataAnalyticsId,
241
+ showRemoveButton,
242
+ showViewButton,
243
+ showDownloadButton,
244
+ onView,
245
+ onDownload,
246
+ getPreviewBlob,
247
+ previewMode,
237
248
  onChange
238
249
  }) => {
239
250
  const {
@@ -245,6 +256,7 @@ const FileUpload = ({
245
256
  const fileInputRef = (0, react_1.useRef)(null);
246
257
  const browseButtonRef = (0, react_1.useRef)(null);
247
258
  const removeButtonRefs = (0, react_1.useRef)(new Map());
259
+ const viewButtonRefs = (0, react_1.useRef)(new Map());
248
260
  const pendingFocusIndexRef = (0, react_1.useRef)(null);
249
261
  const driveClasses = (0, useDriveClassName_1.useDriveClassName)("zen-file-upload");
250
262
  const classes = (0, react_1.useMemo)(() => (0, classNames_1.classNames)(["zen-file-upload", `zen-file-upload--${size}`, isMobile ? "zen-file-upload--mobile" : "", driveClasses || "", disabled ? "zen-file-upload--disabled" : "", className !== null && className !== void 0 ? className : ""]), [size, isMobile, driveClasses, disabled, className]);
@@ -354,10 +366,52 @@ const FileUpload = ({
354
366
  }
355
367
  }
356
368
  }, [templateDownload]);
369
+ const {
370
+ preview,
371
+ handleViewFile,
372
+ handleClosePreview
373
+ } = (0, useFilePreview_1.useFilePreview)({
374
+ onView,
375
+ getPreviewBlob,
376
+ previewMode,
377
+ viewButtonRefs
378
+ });
379
+ const fileActions = (0, resolveFileActions_1.resolveFileActions)({
380
+ id,
381
+ dataAnalyticsId,
382
+ showViewButton,
383
+ showDownloadButton,
384
+ onView,
385
+ getPreviewBlob,
386
+ onDownload
387
+ });
388
+ const handleDownloadFile = (0, react_1.useCallback)(file => {
389
+ void (onDownload === null || onDownload === void 0 ? void 0 : onDownload(file));
390
+ }, [onDownload]);
357
391
  // Generate accessible description
358
392
  const dropZoneDescriptionId = `${id}-description`;
359
393
  const acceptedFormats = supportedFormatsText || accept || "";
360
394
  const uploadMethodDescription = isMobile ? translate("Tap to add files") : `${translate("Drag & drop files or")} ${translate("Browse")}`;
395
+ const previewElement = (0, jsx_runtime_1.jsx)(filePreview_1.FilePreview, {
396
+ analyticsBase: fileActions.analyticsBase,
397
+ preview: preview,
398
+ onClose: handleClosePreview,
399
+ onDownload: fileActions.canDownload ? handleDownloadFile : undefined,
400
+ disabled: isInteractionDisabled,
401
+ translate: translate
402
+ });
403
+ if ((preview === null || preview === void 0 ? void 0 : preview.mode) === "inline") {
404
+ // Inline preview takes the place of the upload UI so no second modal is stacked
405
+ return (0, jsx_runtime_1.jsxs)("div", {
406
+ id: id,
407
+ className: classes,
408
+ children: [previewElement, (0, jsx_runtime_1.jsx)(waiting_1.Waiting, {
409
+ isLoading: isUploading,
410
+ delay: 0,
411
+ hideOverlay: false
412
+ })]
413
+ });
414
+ }
361
415
  return (0, jsx_runtime_1.jsxs)("div", {
362
416
  id: id,
363
417
  className: classes,
@@ -410,8 +464,15 @@ const FileUpload = ({
410
464
  isUploading: isUploading,
411
465
  handleRemoveFile: handleRemoveFile,
412
466
  translate: translate,
413
- removeButtonRefs: removeButtonRefs
414
- }), (0, jsx_runtime_1.jsx)(waiting_1.Waiting, {
467
+ removeButtonRefs: removeButtonRefs,
468
+ analyticsBase: fileActions.analyticsBase,
469
+ viewButtonRefs: viewButtonRefs,
470
+ showRemoveButton: showRemoveButton,
471
+ showViewButton: fileActions.canView,
472
+ showDownloadButton: fileActions.canDownload,
473
+ handleViewFile: handleViewFile,
474
+ handleDownloadFile: handleDownloadFile
475
+ }), previewElement, (0, jsx_runtime_1.jsx)(waiting_1.Waiting, {
415
476
  isLoading: isUploading,
416
477
  delay: 0,
417
478
  hideOverlay: false
@@ -17,6 +17,9 @@ export interface IFileUploadMeta {
17
17
  addedFiles?: FileList;
18
18
  removedFileId?: string;
19
19
  }
20
+ /** Bytes for the built-in preview. A Blob is also accepted, so a browser `File` can be returned as is. */
21
+ export type TPreviewData = Blob | ArrayBuffer | Uint8Array;
22
+ export type TFilePreviewMode = "modal" | "inline";
20
23
  export interface IFileUpload extends IZenComponentProps {
21
24
  id: string;
22
25
  size?: "large" | "condensed";
@@ -29,5 +32,37 @@ export interface IFileUpload extends IZenComponentProps {
29
32
  showTemplateSection?: boolean;
30
33
  showUploadedSection?: boolean;
31
34
  templateDownload?: ITemplateDownload;
35
+ /**
36
+ * Base for the `data-analytics-id` of the file action buttons (default: the component `id`).
37
+ * Buttons get `{base}-view`, `{base}-download`, `{base}-remove`, `{base}-preview-open-in-new-tab`,
38
+ * `{base}-preview-download` and `{base}-preview-back`. File names are never included.
39
+ */
40
+ dataAnalyticsId?: string;
41
+ /** Show a Remove (X) button on each uploaded file (default: true). */
42
+ showRemoveButton?: boolean;
43
+ /** Show a View button on each uploaded image or PDF file (default: false). Hidden for other file types, for files with errors, and when neither `onView` nor `getPreviewBlob` is provided. */
44
+ showViewButton?: boolean;
45
+ /** Show a Download button on each uploaded file (default: false). Hidden for files with errors and when `onDownload` is not provided. */
46
+ showDownloadButton?: boolean;
47
+ /**
48
+ * Called when View is clicked. When provided, the built-in preview is not opened,
49
+ * so the consumer can show its own previewer.
50
+ */
51
+ onView?: (file: IUploadedFile) => void;
52
+ /** Called when Download is clicked. The consumer owns the fetch (blob URL, authenticated request, etc.). */
53
+ onDownload?: (file: IUploadedFile) => void | Promise<void>;
54
+ /**
55
+ * Returns the bytes for the built-in preview (sync or async). The consumer owns fetching, including any authentication.
56
+ * Zenith creates its own object URL from them, labelled with the type derived from the file kind
57
+ * (`application/pdf`, or the matching image type) and not with the type the Blob carries, so HTML can never be
58
+ * rendered as a page. The same URL feeds the preview and Open in new tab, and Zenith revokes it when the preview
59
+ * closes, when the component unmounts and when a newer request replaces it. If nothing is returned, the preview closes.
60
+ */
61
+ getPreviewBlob?: (file: IUploadedFile) => TPreviewData | undefined | Promise<TPreviewData | undefined>;
62
+ /**
63
+ * How the built-in preview is presented (default: "modal").
64
+ * Use "inline" when the file upload is already inside a Modal, to avoid stacking modals.
65
+ */
66
+ previewMode?: TFilePreviewMode;
32
67
  onChange?: (files: IUploadedFile[], meta?: IFileUploadMeta) => void;
33
68
  }
@@ -3,7 +3,7 @@ import { ISearchInputRaw } from "../../../searchInputRaw/searchInputRaw";
3
3
  export interface IFiltersBarSearchState {
4
4
  value: string;
5
5
  }
6
- interface IFiltersBarSearchProps extends Pick<ISearchInputRaw, "withDefaultCloseIcon" | "disabled" | "placeholder" | "ariaLabel" | "closeButtonTitle" | "onKeyDown" | "maxLength"> {
6
+ interface IFiltersBarSearchProps extends Pick<ISearchInputRaw, "withDefaultCloseIcon" | "disabled" | "placeholder" | "ariaLabel" | "closeButtonTitle" | "onKeyDown" | "maxLength" | "dataAnalyticsId"> {
7
7
  }
8
8
  export interface IFiltersBarSearch extends IFiltersBarItem<IFiltersBarSearchState, IFiltersBarSearchProps> {
9
9
  className?: string;
@@ -49,6 +49,6 @@ const FormSectionCard = (_a) => {
49
49
  const { error } = (0, useError_1.useError)({ isError, isLoading, retry, type: "card" });
50
50
  const contentClasses = (0, classNames_1.classNames)(["zen-form-section-card-content", loadingContent ? "zen-form-section-card-content--loading" : ""]);
51
51
  // TODO: tests for header
52
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [header && (0, jsx_runtime_1.jsx)(formLayoutTitle_1.FormLayoutTitle, { className: className, value: header || "" }), (0, jsx_runtime_1.jsxs)(card_1.Card, Object.assign({ size: "L", autoHeight: true, title: title, className: className, cardContentClasses: contentClasses }, cardProps, { children: [actions.length > 0 && (0, jsx_runtime_1.jsx)(card_1.Card.Actions, { children: cardButtons }), loadingContent || error || ((0, jsx_runtime_1.jsxs)(formSectionInner_1.FormSectionInner, { mode: mode, labelAlign: labelAlign, children: [content, additional.length > 0 && ((0, jsx_runtime_1.jsx)(formSectionInner_1.FormSectionInner.Additional, Object.assign({}, additional[0].props, { children: additional[0].props.children })))] }))] }))] }));
52
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [header && (0, jsx_runtime_1.jsx)(formLayoutTitle_1.FormLayoutTitle, { className: className, value: header || "" }), (0, jsx_runtime_1.jsxs)(card_1.Card, Object.assign({ size: "L", autoHeight: true, title: title, className: (0, classNames_1.classNames)(["zen-form-section-card", className || ""]), cardContentClasses: contentClasses }, cardProps, { children: [actions.length > 0 && (0, jsx_runtime_1.jsx)(card_1.Card.Actions, { children: cardButtons }), loadingContent || error || ((0, jsx_runtime_1.jsxs)(formSectionInner_1.FormSectionInner, { mode: mode, labelAlign: labelAlign, children: [content, additional.length > 0 && ((0, jsx_runtime_1.jsx)(formSectionInner_1.FormSectionInner.Additional, Object.assign({}, additional[0].props, { children: additional[0].props.children })))] }))] }))] }));
53
53
  };
54
54
  exports.FormSectionCard = FormSectionCard;
@@ -0,0 +1,3 @@
1
+ import "./icon.less";
2
+ import { IIcon } from "./icon";
3
+ export declare const IconEngine: ({ className, size, title, description, focusable }: IIcon) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IconEngine = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const classNames_1 = require("../commonHelpers/classNames/classNames");
7
+ const IconEngine = ({ className, size, title, description, focusable = false }) => {
8
+ const uniqueId = (0, react_1.useId)();
9
+ const classes = (0, react_1.useMemo)(() => (0, classNames_1.classNames)(["zen-icon", size ? `zen-icon--${size}` : "", className !== null && className !== void 0 ? className : ""]), [size, className]);
10
+ return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", focusable: focusable ? "true" : undefined, tabIndex: focusable ? 0 : undefined, role: focusable || title || description ? undefined : "presentation", className: classes, "aria-labelledby": title && focusable ? uniqueId : undefined, "data-name": "IconEngine", children: [title ? (0, jsx_runtime_1.jsx)("title", { id: uniqueId, children: title }) : null, description ? (0, jsx_runtime_1.jsx)("desc", { children: description }) : null, (0, jsx_runtime_1.jsx)("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M15.2588 4.00244C15.811 4.00248 16.2588 4.45018 16.2588 5.00244C16.2588 5.5547 15.811 6.0024 15.2588 6.00244H12.4355V7.59424H13.1533C13.801 7.59424 14.4091 7.90804 14.7842 8.43604L16.0186 10.1743L16.6641 10.1763C16.903 9.34121 17.6704 8.72902 18.582 8.72705L19.9922 8.72412C21.0981 8.72208 21.9959 9.61822 21.9961 10.7241V16.4019C21.9961 17.5048 21.1029 18.3996 20 18.4019L18.5898 18.4048C17.6861 18.4064 16.9212 17.8082 16.6719 16.9858L16.5449 16.9849L16.5225 18.0415C16.4986 19.1285 15.6107 19.9974 14.5234 19.9976H10.2607C9.62116 19.9974 9.01984 19.6915 8.64355 19.1743L7.76562 17.9663H6.35254C5.64354 17.966 5.0685 17.3912 5.06836 16.6821V14.9722H4.00391V17.8062C4.00391 18.3584 3.55619 18.8062 3.00391 18.8062C2.45182 18.8059 2.00391 18.3583 2.00391 17.8062V10.1489C2.00397 9.59684 2.45186 9.14916 3.00391 9.14893C3.55615 9.14893 4.00384 9.5967 4.00391 10.1489V12.9722H5.06836V11.814C5.06836 10.7095 5.96396 9.81416 7.06836 9.81396H7.29297L8.71387 8.24951C9.09285 7.83229 9.63069 7.59434 10.1943 7.59424H10.4355V6.00244H7.60156C7.04935 6.00236 6.60157 5.55467 6.60156 5.00244C6.60156 4.4502 7.04934 4.00252 7.60156 4.00244H15.2588ZM8.17871 11.814H7.06836V15.9663H8.7832L10.2607 17.9976H14.5234L14.5889 14.979L15.5703 14.9829L17.5889 14.9888L18.5859 14.9927V16.4048L18.9982 16.4039C19.5496 16.4028 19.9961 15.9554 19.9961 15.4039V11.7262C19.9961 11.1731 19.5471 10.7251 18.994 10.7262L18.5859 10.7271V12.1831L14.9844 12.1714L13.1533 9.59424H10.1943L8.17871 11.814Z" })] }));
11
+ };
12
+ exports.IconEngine = IconEngine;
package/dist/index.css CHANGED
@@ -14655,7 +14655,7 @@ html:lang(ar) .zen-tab-item {
14655
14655
  visibility: hidden;
14656
14656
  }
14657
14657
  .zen-tab-item:hover,
14658
- .zen-tab-item:focus {
14658
+ .zen-tab-item:focus-visible {
14659
14659
  color: var(--text-hyperlink);
14660
14660
  fill: var(--action-primary--default);
14661
14661
  }
@@ -15617,8 +15617,77 @@ html:lang(ar) .zen-file-upload__file-name {
15617
15617
  .zen-file-upload__file-name--error {
15618
15618
  color: var(--text-error-message);
15619
15619
  }
15620
- .zen-file-upload__remove-button {
15620
+ .zen-file-upload__file-actions {
15621
+ display: flex;
15622
+ align-items: center;
15621
15623
  flex-shrink: 0;
15624
+ gap: 0.25rem;
15625
+ }
15626
+ .zen-file-upload__remove-button,
15627
+ .zen-file-upload__view-button,
15628
+ .zen-file-upload__download-button {
15629
+ flex-shrink: 0;
15630
+ }
15631
+ .zen-file-upload__preview-inline {
15632
+ display: flex;
15633
+ flex-direction: column;
15634
+ gap: 0.625rem;
15635
+ }
15636
+ .zen-file-upload__preview-header {
15637
+ display: flex;
15638
+ align-items: center;
15639
+ gap: 0.625rem;
15640
+ }
15641
+ .zen-file-upload__preview-title {
15642
+ flex: 1;
15643
+ min-width: 0;
15644
+ font-family: Roboto, "Segoe UI", Segoe, "Helvetica Neue", Helvetica, sans-serif;
15645
+ font-size: 0.75rem;
15646
+ font-style: normal;
15647
+ font-weight: 700;
15648
+ letter-spacing: 0.02rem;
15649
+ line-height: 1rem;
15650
+ text-transform: none;
15651
+ text-decoration: none;
15652
+ color: var(--text-primary);
15653
+ overflow: hidden;
15654
+ text-overflow: ellipsis;
15655
+ white-space: nowrap;
15656
+ }
15657
+ html:lang(ar) .zen-file-upload__preview-title {
15658
+ font-family: "Noto Sans Arabic", Roboto, "Segoe UI", Segoe, "Helvetica Neue", Helvetica, sans-serif;
15659
+ }
15660
+ .zen-file-upload__preview-body {
15661
+ position: relative;
15662
+ display: flex;
15663
+ justify-content: center;
15664
+ min-width: 0;
15665
+ min-height: 7.5rem;
15666
+ }
15667
+ .zen-file-upload__preview-image {
15668
+ display: block;
15669
+ max-width: 100%;
15670
+ max-height: calc(90vh - 12rem);
15671
+ max-height: calc(90dvh - 12rem);
15672
+ object-fit: contain;
15673
+ }
15674
+ .zen-file-upload__preview-pdf {
15675
+ display: block;
15676
+ width: 100%;
15677
+ min-width: 0;
15678
+ height: calc(90vh - 12rem);
15679
+ height: calc(90dvh - 12rem);
15680
+ border: 0;
15681
+ }
15682
+ @media (max-width: 640px) {
15683
+ .zen-file-upload__preview-image {
15684
+ max-height: calc(90vh - 16.25rem);
15685
+ max-height: calc(90dvh - 16.25rem);
15686
+ }
15687
+ .zen-file-upload__preview-pdf {
15688
+ height: calc(90vh - 16.25rem);
15689
+ height: calc(90dvh - 16.25rem);
15690
+ }
15622
15691
  }
15623
15692
  @media (max-width: 640px) {
15624
15693
  .zen-file-upload--mobile .zen-file-upload__drop-zone-text {
@@ -19419,6 +19488,9 @@ html:lang(ar) .zen-form-section-default-title {
19419
19488
  .zen-form-section-error-banner {
19420
19489
  height: fit-content;
19421
19490
  }
19491
+ .zen-card-container.zen-form-section-card:not(.zen-card-container--absolute) {
19492
+ min-width: 0;
19493
+ }
19422
19494
  .zen-form-layout-title {
19423
19495
  font-family: Roboto, "Segoe UI", Segoe, "Helvetica Neue", Helvetica, sans-serif;
19424
19496
  font-size: 1rem;
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ export { type ICardsRow, CardsRow } from "./cards/cardsRow";
38
38
  export { AccessibleChart } from "./chart/accessibleChart/accessibleChart";
39
39
  export { collectAllPoints, simplifyData, AccessibleChartNarrative } from "./chart/accessibleChart/accessibleChartNarrative";
40
40
  export { AccessibleChartTable } from "./chart/accessibleChart/accessibleChartTable";
41
+ export { type AccessibleChartDataset, type AccessibleTableCellRenderer, type IChartAccessibilityOptions } from "./chart/accessibleChart/interfaces";
41
42
  export { Chart } from "./chart/chart";
42
43
  export { getFormattedLabel } from "./chart/utils/getFormattedLabel";
43
44
  export { removeTrendDataFromDatasets } from "./chart/utils/removeTrendDataFromDatasets";
@@ -78,7 +79,7 @@ export { FeedbackProvider } from "./feedbackProvider/feedbackProvider";
78
79
  export { TemplateDownloadSection } from "./fileUpload/components/templateDownloadSection";
79
80
  export { UploadedFilesSection } from "./fileUpload/components/uploadedFilesSection";
80
81
  export { FileUpload } from "./fileUpload/fileUpload";
81
- export { type IUploadedFile, type ITemplateDownload, type IFileUploadMeta, type IFileUpload } from "./fileUpload/fileUploadType";
82
+ export { type IUploadedFile, type ITemplateDownload, type IFileUploadMeta, type TPreviewData, type TFilePreviewMode, type IFileUpload } from "./fileUpload/fileUploadType";
82
83
  export { type TFilterButton, type IFilterButton, FilterButton } from "./filterButton/filterButton";
83
84
  export { type IFiltersChip, FiltersChip } from "./filters/components/filtersChip";
84
85
  export { type IFiltersDateInputProps, type TFiltersDateInputState, type IFiltersDateInput, FiltersDateInputDisplayName, FiltersDateInput } from "./filters/components/filtersDateInput";
@@ -387,6 +388,7 @@ export { IconEditSmall } from "./icons/iconEditSmall";
387
388
  export { IconEmail } from "./icons/iconEmail";
388
389
  export { IconEmail2 } from "./icons/iconEmail2";
389
390
  export { IconEmailNotification } from "./icons/iconEmailNotification";
391
+ export { IconEngine } from "./icons/iconEngine";
390
392
  export { IconEsc } from "./icons/iconEsc";
391
393
  export { IconEthereum } from "./icons/iconEthereum";
392
394
  export { IconEuro } from "./icons/iconEuro";