@zohodesk/dot 1.0.0-beta.217 → 1.0.0-beta.218

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 (29) hide show
  1. package/README.md +4 -0
  2. package/assets/Appearance/dark/mode/dotDarkMode.module.css +10 -0
  3. package/assets/Appearance/dark/themes/blue/blueDarkDotTheme.module.css +6 -0
  4. package/assets/Appearance/dark/themes/green/greenDarkDotTheme.module.css +6 -0
  5. package/assets/Appearance/dark/themes/orange/orangeDarkDotTheme.module.css +6 -0
  6. package/assets/Appearance/dark/themes/red/redDarkDotTheme.module.css +6 -0
  7. package/assets/Appearance/dark/themes/yellow/yellowDarkDotTheme.module.css +6 -0
  8. package/assets/Appearance/default/mode/dotDefaultMode.module.css +10 -0
  9. package/assets/Appearance/default/themes/blue/blueDefaultDotTheme.module.css +6 -0
  10. package/assets/Appearance/default/themes/green/greenDefaultDotTheme.module.css +6 -0
  11. package/assets/Appearance/default/themes/orange/orangeDefaultDotTheme.module.css +6 -0
  12. package/assets/Appearance/default/themes/red/redDefaultDotTheme.module.css +6 -0
  13. package/assets/Appearance/default/themes/yellow/yellowDefaultDotTheme.module.css +6 -0
  14. package/es/AttachmentViewer/Attachment.js +17 -0
  15. package/es/AttachmentViewer/AttachmentImage.js +85 -0
  16. package/es/AttachmentViewer/AttachmentViewer.js +530 -0
  17. package/es/AttachmentViewer/AttachmentViewer.module.css +346 -0
  18. package/es/AttachmentViewer/utils.js +107 -0
  19. package/es/common/dot_animation.module.css +27 -0
  20. package/es/common/dot_common.module.css +4 -0
  21. package/images/audio_thumbnail.png +0 -0
  22. package/lib/AttachmentViewer/Attachment.js +28 -0
  23. package/lib/AttachmentViewer/AttachmentImage.js +129 -0
  24. package/lib/AttachmentViewer/AttachmentViewer.js +613 -0
  25. package/lib/AttachmentViewer/AttachmentViewer.module.css +346 -0
  26. package/lib/AttachmentViewer/utils.js +134 -0
  27. package/lib/common/dot_animation.module.css +27 -0
  28. package/lib/common/dot_common.module.css +4 -0
  29. package/package.json +15 -13
@@ -0,0 +1,530 @@
1
+ import React, { Component } from "react";
2
+ import PropTypes from "prop-types";
3
+ import { Container, Box } from "@zohodesk/components/lib/Layout";
4
+ import Icon from "@zohodesk/icons/lib/Icon";
5
+ import Avatar from "@zohodesk/components/lib/Avatar/Avatar";
6
+ import { ResponsiveReceiver } from "@zohodesk/components/lib/Responsive/CustomResponsive";
7
+ import { getUniqueId } from "@zohodesk/components/lib/Provider/IdProvider";
8
+ import AttachmentImage from "./AttachmentImage";
9
+ import Link from "../Link/Link";
10
+ import IconButton from "../IconButton/IconButton";
11
+ import FreezeLayer from "../FreezeLayer/FreezeLayer";
12
+ import { isAudioFile, getExtensionFromFileName } from "./Attachment";
13
+ import style from "./AttachmentViewer.module.css";
14
+ export default class AttachmentViewer extends Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.state = {
18
+ isPViewListOpen: !!(this.props.previewObj && this.props.previewObj.previewData),
19
+ selectedIndex: this.props.previewObj.selectedIndex,
20
+ isZoomed: false,
21
+ data: this.props.previewObj ? this.props.previewObj.previewData : [],
22
+ dataList: this.getUpdateDataList({
23
+ index: this.props.previewObj.selectedIndex,
24
+ data: this.props.previewObj ? this.props.previewObj.previewData : [],
25
+ dataList: []
26
+ })
27
+ };
28
+ this.togglePViewList = this.togglePViewList.bind(this);
29
+ this.changeSelectedIndex = this.changeSelectedIndex.bind(this);
30
+ this.closeAttachmentViewer = this.closeAttachmentViewer.bind(this);
31
+ this.responsiveFunc = this.responsiveFunc.bind(this);
32
+ this.zoomIn = this.zoomIn.bind(this);
33
+ this.zoomOut = this.zoomOut.bind(this);
34
+ this.imgPreviewView = this.imgPreviewView.bind(this);
35
+ this.getNextId = getUniqueId(this);
36
+ this.getUpdateDataList = this.getUpdateDataList.bind(this);
37
+ this.zoomMaintain = this.zoomMaintain.bind(this);
38
+ }
39
+
40
+ togglePViewList() {
41
+ this.setState(prevState => ({
42
+ isPViewListOpen: !prevState.isPViewListOpen
43
+ }), () => {
44
+ this.focusSelectedImg(this.state.selectedIndex);
45
+ });
46
+ }
47
+
48
+ zoomOut(ele) {
49
+ this.setState({
50
+ isZoomed: false
51
+ });
52
+ const img = document.getElementById(`img${ele}`);
53
+
54
+ if (img) {
55
+ img.classList.remove(style.zoomedImg);
56
+ img.classList.add(style.normalImg);
57
+ }
58
+ }
59
+
60
+ zoomIn(event, ele) {
61
+ let moveToPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
62
+ this.setState({
63
+ isZoomed: true
64
+ });
65
+ const img = document.getElementById(`img${ele}`);
66
+ const ratio = 95;
67
+ let imgContainer, imgUnits, imgSize, imgRatio, imgContainerUnits, imgContainerPosition;
68
+
69
+ if (moveToPosition) {
70
+ imgContainer = document.getElementById(`imgBox${ele}`);
71
+ imgUnits = img.getBoundingClientRect();
72
+ imgSize = {
73
+ height: img.naturalHeight,
74
+ width: img.naturalWidth
75
+ };
76
+ imgRatio = {
77
+ height: Math.floor(imgSize.height / imgUnits.height / 100 * ratio),
78
+ width: Math.floor(imgSize.width / imgUnits.width / 100 * ratio)
79
+ };
80
+ imgContainerUnits = imgContainer.getBoundingClientRect();
81
+ imgContainerPosition = imgContainer ? {
82
+ top: imgContainerUnits.top,
83
+ left: imgContainerUnits.left
84
+ } : {
85
+ top: 0,
86
+ left: 0
87
+ };
88
+ }
89
+
90
+ if (img) {
91
+ img.classList.remove(style.normalImg);
92
+ img.classList.add(style.zoomedImg);
93
+ }
94
+
95
+ if (moveToPosition) {
96
+ imgContainer.scrollLeft = (event.pageX - imgContainerPosition.left - imgUnits.left) * imgRatio.width;
97
+ imgContainer.scrollTop = (event.pageY - imgContainerPosition.top - imgUnits.top) * imgRatio.height;
98
+ }
99
+ }
100
+
101
+ zoomMaintain(selectedIndex) {
102
+ let {
103
+ isZoomed
104
+ } = this.state;
105
+ isZoomed ? this.zoomIn({}, selectedIndex) : this.zoomOut(selectedIndex);
106
+ }
107
+
108
+ getUpdateDataList(_ref) {
109
+ let {
110
+ index,
111
+ data,
112
+ dataList
113
+ } = _ref;
114
+ data = data || this.state.data;
115
+ dataList = dataList || this.state.dataList;
116
+ const finalDataList = [...dataList];
117
+
118
+ if (index >= finalDataList.length) {
119
+ for (let i = dataList.length; i <= index; i++) {
120
+ finalDataList.push(data.slice(i)[0]);
121
+ }
122
+ } else if (index + 1 === finalDataList.length && index + 1 < data.length) {
123
+ finalDataList.push(data.slice(index + 1)[0]);
124
+ }
125
+
126
+ return finalDataList;
127
+ }
128
+
129
+ updateDataList(index) {
130
+ this.setState({
131
+ dataList: this.getUpdateDataList({
132
+ index
133
+ })
134
+ });
135
+ }
136
+
137
+ changeSelectedIndex(index) {
138
+ const {
139
+ data,
140
+ selectedIndex
141
+ } = this.state;
142
+ const {
143
+ maintainZoom
144
+ } = this.props;
145
+ maintainZoom ? this.zoomMaintain(index) : this.zoomOut(selectedIndex);
146
+
147
+ if (index <= data.length - 1) {
148
+ this.updateDataList(index);
149
+ }
150
+
151
+ this.setState({
152
+ selectedIndex: index
153
+ }, () => {
154
+ this.focusSelectedImg(index);
155
+ });
156
+ }
157
+
158
+ focusSelectedImg(index) {
159
+ const ele = this[`img_${index}`];
160
+
161
+ if (ele) {
162
+ const cont = this.imgListCont;
163
+ cont.scrollLeft = ele.offsetLeft;
164
+ }
165
+ }
166
+
167
+ closeAttachmentViewer() {
168
+ this.setState({
169
+ isPViewListOpen: false,
170
+ isZoomed: false
171
+ });
172
+ this.props.hideAttachmentViewer();
173
+ }
174
+
175
+ responsiveFunc(_ref2) {
176
+ let {
177
+ mediaQueryOR
178
+ } = _ref2;
179
+ return {
180
+ uptoTablet: mediaQueryOR([{
181
+ maxWidth: 768
182
+ }])
183
+ };
184
+ }
185
+
186
+ imgPreviewView() {
187
+ var _this = this;
188
+
189
+ const {
190
+ dataList,
191
+ selectedIndex,
192
+ isZoomed
193
+ } = this.state;
194
+ const {
195
+ maintainZoom
196
+ } = this.props;
197
+
198
+ const getImgStyle = i => {
199
+ let position;
200
+
201
+ if (selectedIndex < i) {
202
+ position = (i - selectedIndex) * 100;
203
+ return {
204
+ transform: `translateX(${parseInt(position)}%)`,
205
+ opacity: "0"
206
+ };
207
+ }
208
+
209
+ if (i === selectedIndex) {
210
+ return {
211
+ transform: "translateX(0%)",
212
+ opacity: "1"
213
+ };
214
+ }
215
+
216
+ position = (selectedIndex - i) * 100 * -1;
217
+ return {
218
+ transform: `translateX(${parseInt(position)}%)`,
219
+ opacity: "0"
220
+ };
221
+ };
222
+
223
+ return dataList.length && dataList.map(function () {
224
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
225
+ let i = arguments.length > 1 ? arguments[1] : undefined;
226
+ const selectedImgUrl = data.viewUrl;
227
+ return /*#__PURE__*/React.createElement(Container, {
228
+ className: style.imgBox,
229
+ id: `imgBox${i}`,
230
+ key: i,
231
+ alignBox: "row",
232
+ align: "both",
233
+ style: getImgStyle(i)
234
+ }, /*#__PURE__*/React.createElement(Box, {
235
+ className: style.imgRef,
236
+ id: `imgPreviewRef${i}`
237
+ }, isAudioFile(data.name) ? selectedIndex == i ? /*#__PURE__*/React.createElement("video", {
238
+ autoPlay: true,
239
+ controls: true,
240
+ className: style.zoomIn
241
+ }, /*#__PURE__*/React.createElement("source", {
242
+ src: data.viewUrl,
243
+ type: `audio/${getExtensionFromFileName(data.name)}`
244
+ })) : null : /*#__PURE__*/React.createElement(AttachmentImage, {
245
+ className: `${style.img} ${selectedIndex == i && maintainZoom ? isZoomed ? style.zoomedImg : style.normalImg : ""}`,
246
+ src: selectedImgUrl,
247
+ onClick: isZoomed ? _this.zoomOut.bind(_this, i) : e => {
248
+ _this.zoomIn(e, i, true);
249
+ },
250
+ alt: "Preview",
251
+ dataId: "attachViewed",
252
+ id: `img${i}`,
253
+ isImage: true,
254
+ isCover: false
255
+ })));
256
+ });
257
+ }
258
+
259
+ render() {
260
+ const {
261
+ isPViewListOpen,
262
+ selectedIndex,
263
+ data,
264
+ isZoomed
265
+ } = this.state;
266
+ const {
267
+ responsiveId,
268
+ needDownload,
269
+ i18nKeys
270
+ } = this.props;
271
+ const totalLen = data.length;
272
+ const selectedAttachment = data[selectedIndex] || {};
273
+ const selectedImgUrl = selectedAttachment.viewUrl;
274
+ const downloadUrl = selectedAttachment.downloadUrl;
275
+ let authorHref;
276
+ let authorName;
277
+ const {
278
+ author
279
+ } = data[selectedIndex] ? data[selectedIndex] : null;
280
+
281
+ if (author) {
282
+ authorHref = author.href;
283
+ authorName = author.name;
284
+ }
285
+
286
+ const ariaId = this.getNextId();
287
+ return /*#__PURE__*/React.createElement(FreezeLayer, {
288
+ isActive: true
289
+ }, /*#__PURE__*/React.createElement(ResponsiveReceiver, {
290
+ responsiveId: responsiveId,
291
+ query: this.responsiveFunc
292
+ }, _ref3 => {
293
+ let {
294
+ uptoTablet
295
+ } = _ref3;
296
+ return /*#__PURE__*/React.createElement(Container, {
297
+ scroll: "none",
298
+ "data-scroll-palette": "dark"
299
+ }, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Container, {
300
+ alignBox: "row",
301
+ className: style.header,
302
+ align: "between",
303
+ tabindex: "0"
304
+ }, /*#__PURE__*/React.createElement(Box, {
305
+ shrink: true,
306
+ className: style.title,
307
+ "data-title": selectedAttachment.name,
308
+ dataId: "attachName",
309
+ id: ariaId
310
+ }, selectedAttachment.name), /*#__PURE__*/React.createElement(Box, {
311
+ flexible: true,
312
+ className: style.count,
313
+ dataId: "attachCountContainer"
314
+ }, selectedIndex + 1, "/", totalLen), /*#__PURE__*/React.createElement(Box, {
315
+ className: uptoTablet ? style.mbleMenuBar : style.menuBar
316
+ }, /*#__PURE__*/React.createElement(Container, {
317
+ isInline: true,
318
+ alignBox: uptoTablet ? "column-reverse" : "row",
319
+ align: uptoTablet ? "bottom" : "center",
320
+ wrap: "wrap",
321
+ isCover: false
322
+ }, isZoomed ? /*#__PURE__*/React.createElement("div", {
323
+ className: uptoTablet ? style.mobileMenu : style.menu,
324
+ onClick: this.zoomOut.bind(this, selectedIndex),
325
+ "data-id": "zoomOut",
326
+ "data-title": i18nKeys.zoomOutText
327
+ }, /*#__PURE__*/React.createElement(IconButton, {
328
+ iconName: "ZD-GN-zoomOut",
329
+ className: style.menuIcon,
330
+ iconSize: "16",
331
+ hoverType: "border",
332
+ a11y: {
333
+ ariaLabel: i18nKeys.zoomOutText
334
+ }
335
+ })) : /*#__PURE__*/React.createElement("div", {
336
+ className: uptoTablet ? style.mobileMenu : style.menu,
337
+ onClick: e => this.zoomIn(e, selectedIndex),
338
+ "data-id": "zoomIn",
339
+ "data-title": i18nKeys.zoomInText
340
+ }, /*#__PURE__*/React.createElement(IconButton, {
341
+ iconName: "ZD-GN-zoomIn",
342
+ className: style.menuIcon,
343
+ iconSize: "16",
344
+ hoverType: "border",
345
+ a11y: {
346
+ ariaLabel: i18nKeys.zoomInText
347
+ }
348
+ })), /*#__PURE__*/React.createElement("div", {
349
+ className: uptoTablet ? style.mobileMenu : style.menu
350
+ }, /*#__PURE__*/React.createElement(Link, {
351
+ href: selectedImgUrl,
352
+ target: "_blank",
353
+ dataId: "newTabAttach",
354
+ title: i18nKeys.newTabText
355
+ }, /*#__PURE__*/React.createElement(IconButton, {
356
+ iconName: "ZD-GN-newLink",
357
+ className: style.menuIcon,
358
+ iconSize: "16",
359
+ hoverType: "border",
360
+ needButtonTag: false,
361
+ a11y: {
362
+ ariaLabel: i18nKeys.newTabText
363
+ }
364
+ }))), needDownload ? /*#__PURE__*/React.createElement("div", {
365
+ className: uptoTablet ? style.mobileMenu : style.menu
366
+ }, /*#__PURE__*/React.createElement(Link, {
367
+ href: downloadUrl,
368
+ target: "_parent",
369
+ hasReload: true,
370
+ download: true,
371
+ title: i18nKeys.downloadText
372
+ }, /*#__PURE__*/React.createElement(IconButton, {
373
+ iconName: "ZD-GN-download",
374
+ className: style.menuIcon,
375
+ iconSize: "16",
376
+ hoverType: "border",
377
+ needButtonTag: false,
378
+ a11y: {
379
+ ariaLabel: i18nKeys.downloadText
380
+ }
381
+ }))) : null, /*#__PURE__*/React.createElement("div", {
382
+ className: uptoTablet ? style.mobileMenu : style.menu,
383
+ onClick: this.closeAttachmentViewer,
384
+ "data-id": "closeAttach",
385
+ "data-title": i18nKeys.closeText
386
+ }, /*#__PURE__*/React.createElement(IconButton, {
387
+ iconName: "ZD-cross",
388
+ iconSize: "15",
389
+ hoverType: "border",
390
+ className: style.menuIcon,
391
+ a11y: {
392
+ ariaLabel: i18nKeys.closeText
393
+ },
394
+ title: i18nKeys.closeText
395
+ })))))), /*#__PURE__*/React.createElement(Box, {
396
+ flexible: true,
397
+ role: "toolbar",
398
+ tabindex: "0"
399
+ }, /*#__PURE__*/React.createElement(Container, {
400
+ alignBox: "row"
401
+ }, /*#__PURE__*/React.createElement(Box, {
402
+ className: `${style.arrowBox} ${uptoTablet ? style.mbleArrowBox : style.nrmlArrowBox} ${selectedIndex === 0 ? style.hidden : ""}`,
403
+ onClick: this.changeSelectedIndex.bind(this, selectedIndex - 1),
404
+ "data-title": i18nKeys.previousText,
405
+ "data-title-position": "left"
406
+ }, /*#__PURE__*/React.createElement("button", {
407
+ className: style.btn,
408
+ "aria-label": i18nKeys.previousText
409
+ }, /*#__PURE__*/React.createElement(Icon, {
410
+ name: "ZD-arrowLeft3",
411
+ iconClass: style.arrow,
412
+ dataId: "leftAttachNav",
413
+ isBold: true
414
+ }))), /*#__PURE__*/React.createElement(Box, {
415
+ className: style.previewBox,
416
+ role: "option",
417
+ tabindex: "0",
418
+ "aria-describedby": ariaId,
419
+ isShrink: false,
420
+ eleRef: this.setImgBoxRef,
421
+ scroll: "both",
422
+ flexible: true
423
+ }, this.imgPreviewView()), /*#__PURE__*/React.createElement(Box, {
424
+ className: `${style.arrowBox} ${uptoTablet ? style.mbleArrowBox : style.nrmlArrowBox} ${totalLen === selectedIndex + 1 ? style.hidden : ""}`,
425
+ onClick: this.changeSelectedIndex.bind(this, selectedIndex + 1),
426
+ "data-title": i18nKeys.nextText,
427
+ "data-title-position": "right"
428
+ }, /*#__PURE__*/React.createElement("button", {
429
+ className: style.btn,
430
+ "aria-label": i18nKeys.nextText
431
+ }, /*#__PURE__*/React.createElement(Icon, {
432
+ name: "ZD-arrowRight3",
433
+ iconClass: style.arrow,
434
+ dataId: "rightAttachNav",
435
+ isBold: true
436
+ }))))), /*#__PURE__*/React.createElement(Box, {
437
+ className: `${style.footer} ${isPViewListOpen && totalLen !== 1 ? style.footerHeight : style.footerHide} `
438
+ }, /*#__PURE__*/React.createElement(Container, {
439
+ align: "vertical",
440
+ alignBox: "row",
441
+ className: style.footerHeight
442
+ }, author && /*#__PURE__*/React.createElement(Box, {
443
+ className: style.author
444
+ }, /*#__PURE__*/React.createElement(Container, {
445
+ alignBox: "row",
446
+ align: "both"
447
+ }, /*#__PURE__*/React.createElement(Avatar, {
448
+ name: authorName,
449
+ size: "xmedium",
450
+ src: authorHref,
451
+ palette: "info"
452
+ }), /*#__PURE__*/React.createElement(Box, {
453
+ flexible: true,
454
+ className: style.authorName,
455
+ "data-title": authorName
456
+ }, authorName))), /*#__PURE__*/React.createElement(Box, {
457
+ flexible: true
458
+ }, /*#__PURE__*/React.createElement(Container, {
459
+ align: "vertical",
460
+ alignBox: "row",
461
+ scroll: "horizontal",
462
+ eleRef: el => this.imgListCont = el,
463
+ className: style.listContainer
464
+ }, data.map((item, index) => {
465
+ const {
466
+ name,
467
+ viewUrl
468
+ } = item;
469
+ const isAudio = isAudioFile(name);
470
+ return /*#__PURE__*/React.createElement(Box, {
471
+ className: `${style.imgItem} ${index === selectedIndex ? style.selected : ""} ${isAudio ? style.isAudio : ""}`,
472
+ key: index,
473
+ onClick: this.changeSelectedIndex.bind(this, index),
474
+ eleRef: el => this[`img_${index}`] = el,
475
+ dataId: "attachPreviewList",
476
+ "data-title": name
477
+ }, /*#__PURE__*/React.createElement(AttachmentImage, {
478
+ src: viewUrl,
479
+ size: "small",
480
+ alt: name,
481
+ className: style.image,
482
+ isImage: !isAudio
483
+ }));
484
+ }))))), totalLen !== 1 && /*#__PURE__*/React.createElement(IconButton, {
485
+ dataId: "attachToggle",
486
+ onClick: this.togglePViewList,
487
+ iconName: "ZD-GN-hideTab",
488
+ iconSize: "14",
489
+ hoverType: "border",
490
+ iconClass: `${style.thumpIcon} ${isPViewListOpen ? style.thumpIconActive : ""}`,
491
+ className: style.button,
492
+ a11y: {
493
+ ariaLabel: i18nKeys.hideText
494
+ },
495
+ title: isPViewListOpen ? i18nKeys.hideText : i18nKeys.showText
496
+ }));
497
+ }));
498
+ }
499
+
500
+ }
501
+ AttachmentViewer.propTypes = {
502
+ hideAttachmentViewer: PropTypes.func,
503
+ i18nKeys: PropTypes.shape({
504
+ nextText: PropTypes.string,
505
+ previousText: PropTypes.string,
506
+ zoomOutText: PropTypes.string,
507
+ zoomInText: PropTypes.string,
508
+ newTabText: PropTypes.string,
509
+ downloadText: PropTypes.string,
510
+ closeText: PropTypes.string,
511
+ hideText: PropTypes.string,
512
+ showText: PropTypes.string
513
+ }),
514
+ needDownload: PropTypes.string,
515
+ previewObj: PropTypes.object,
516
+ responsiveId: PropTypes.string,
517
+ maintainZoom: PropTypes.bool
518
+ };
519
+ AttachmentViewer.defaultProps = {
520
+ responsiveId: "Helmet",
521
+ needDownload: true,
522
+ i18nKeys: {},
523
+ maintainZoom: false
524
+ };
525
+
526
+ if (false) {
527
+ AttachmentViewer.docs = {
528
+ componentGroup: "Molecule"
529
+ };
530
+ }