@jobber/components-native 0.40.0 → 0.41.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 (95) hide show
  1. package/dist/src/FormatFile/FormatFile.js +114 -0
  2. package/dist/src/FormatFile/FormatFile.style.js +16 -0
  3. package/dist/src/FormatFile/components/ErrorIcon/ErrorIcon.js +8 -0
  4. package/dist/src/FormatFile/components/ErrorIcon/ErrorIcon.style.js +10 -0
  5. package/dist/src/FormatFile/components/ErrorIcon/index.js +1 -0
  6. package/dist/src/FormatFile/components/FileView/FileView.js +67 -0
  7. package/dist/src/FormatFile/components/FileView/FileView.style.js +64 -0
  8. package/dist/src/FormatFile/components/FileView/index.js +1 -0
  9. package/dist/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.js +22 -0
  10. package/dist/src/FormatFile/components/FormatFileBottomSheet/index.js +1 -0
  11. package/dist/src/FormatFile/components/FormatFileBottomSheet/messages.js +13 -0
  12. package/dist/src/FormatFile/components/MediaView/MediaView.js +56 -0
  13. package/dist/src/FormatFile/components/MediaView/MediaView.style.js +27 -0
  14. package/dist/src/FormatFile/components/MediaView/index.js +1 -0
  15. package/dist/src/FormatFile/components/ProgressBar/ProgressBar.js +29 -0
  16. package/dist/src/FormatFile/components/ProgressBar/ProgressBar.style.js +15 -0
  17. package/dist/src/FormatFile/components/ProgressBar/index.js +1 -0
  18. package/dist/src/FormatFile/components/_mocks/mockFiles.js +78 -0
  19. package/dist/src/FormatFile/constants.js +14 -0
  20. package/dist/src/FormatFile/context/FormatFileContext.js +8 -0
  21. package/dist/src/FormatFile/context/types.js +1 -0
  22. package/dist/src/FormatFile/index.js +1 -0
  23. package/dist/src/FormatFile/messages.js +23 -0
  24. package/dist/src/FormatFile/types.js +8 -0
  25. package/dist/src/FormatFile/utils/computeA11yLabel.js +12 -0
  26. package/dist/src/FormatFile/utils/createUseCreateThumbnail.js +22 -0
  27. package/dist/src/FormatFile/utils/index.js +1 -0
  28. package/dist/src/InputText/InputText.js +8 -1
  29. package/dist/src/index.js +1 -0
  30. package/dist/src/utils/test/wait.js +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/types/src/Form/components/FormMessage/FormMessage.d.ts +1 -0
  33. package/dist/types/src/FormatFile/FormatFile.d.ts +47 -0
  34. package/dist/types/src/FormatFile/FormatFile.style.d.ts +14 -0
  35. package/dist/types/src/FormatFile/components/ErrorIcon/ErrorIcon.d.ts +2 -0
  36. package/dist/types/src/FormatFile/components/ErrorIcon/ErrorIcon.style.d.ts +8 -0
  37. package/dist/types/src/FormatFile/components/ErrorIcon/index.d.ts +1 -0
  38. package/dist/types/src/FormatFile/components/FileView/FileView.d.ts +12 -0
  39. package/dist/types/src/FormatFile/components/FileView/FileView.style.d.ts +62 -0
  40. package/dist/types/src/FormatFile/components/FileView/index.d.ts +1 -0
  41. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.d.ts +11 -0
  42. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/index.d.ts +2 -0
  43. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/messages.d.ts +12 -0
  44. package/dist/types/src/FormatFile/components/MediaView/MediaView.d.ts +12 -0
  45. package/dist/types/src/FormatFile/components/MediaView/MediaView.style.d.ts +25 -0
  46. package/dist/types/src/FormatFile/components/MediaView/index.d.ts +1 -0
  47. package/dist/types/src/FormatFile/components/ProgressBar/ProgressBar.d.ts +19 -0
  48. package/dist/types/src/FormatFile/components/ProgressBar/ProgressBar.style.d.ts +13 -0
  49. package/dist/types/src/FormatFile/components/ProgressBar/index.d.ts +1 -0
  50. package/dist/types/src/FormatFile/components/_mocks/mockFiles.d.ts +18 -0
  51. package/dist/types/src/FormatFile/constants.d.ts +6 -0
  52. package/dist/types/src/FormatFile/context/FormatFileContext.d.ts +10 -0
  53. package/dist/types/src/FormatFile/context/types.d.ts +9 -0
  54. package/dist/types/src/FormatFile/index.d.ts +3 -0
  55. package/dist/types/src/FormatFile/messages.d.ts +22 -0
  56. package/dist/types/src/FormatFile/types.d.ts +105 -0
  57. package/dist/types/src/FormatFile/utils/computeA11yLabel.d.ts +9 -0
  58. package/dist/types/src/FormatFile/utils/createUseCreateThumbnail.d.ts +5 -0
  59. package/dist/types/src/FormatFile/utils/index.d.ts +1 -0
  60. package/dist/types/src/InputCurrency/InputCurrency.d.ts +1 -1
  61. package/dist/types/src/index.d.ts +1 -0
  62. package/package.json +3 -2
  63. package/src/FormatFile/FormatFile.style.ts +17 -0
  64. package/src/FormatFile/FormatFile.test.tsx +333 -0
  65. package/src/FormatFile/FormatFile.tsx +300 -0
  66. package/src/FormatFile/components/ErrorIcon/ErrorIcon.style.ts +11 -0
  67. package/src/FormatFile/components/ErrorIcon/ErrorIcon.tsx +12 -0
  68. package/src/FormatFile/components/ErrorIcon/index.ts +1 -0
  69. package/src/FormatFile/components/FileView/FileView.style.ts +65 -0
  70. package/src/FormatFile/components/FileView/FileView.tsx +134 -0
  71. package/src/FormatFile/components/FileView/index.ts +1 -0
  72. package/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.tsx +108 -0
  73. package/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.tsx +56 -0
  74. package/src/FormatFile/components/FormatFileBottomSheet/index.ts +2 -0
  75. package/src/FormatFile/components/FormatFileBottomSheet/messages.ts +14 -0
  76. package/src/FormatFile/components/MediaView/MediaView.style.ts +28 -0
  77. package/src/FormatFile/components/MediaView/MediaView.tsx +145 -0
  78. package/src/FormatFile/components/MediaView/index.ts +1 -0
  79. package/src/FormatFile/components/ProgressBar/ProgressBar.style.tsx +16 -0
  80. package/src/FormatFile/components/ProgressBar/ProgressBar.tsx +57 -0
  81. package/src/FormatFile/components/ProgressBar/index.ts +1 -0
  82. package/src/FormatFile/components/_mocks/mockFiles.ts +105 -0
  83. package/src/FormatFile/constants.ts +15 -0
  84. package/src/FormatFile/context/FormatFileContext.ts +13 -0
  85. package/src/FormatFile/context/types.ts +12 -0
  86. package/src/FormatFile/index.ts +13 -0
  87. package/src/FormatFile/messages.ts +24 -0
  88. package/src/FormatFile/types.ts +126 -0
  89. package/src/FormatFile/utils/computeA11yLabel.ts +26 -0
  90. package/src/FormatFile/utils/createUseCreateThumbnail.ts +33 -0
  91. package/src/FormatFile/utils/index.ts +1 -0
  92. package/src/InputCurrency/InputCurrency.tsx +1 -1
  93. package/src/InputText/InputText.tsx +8 -1
  94. package/src/index.ts +1 -0
  95. package/src/utils/test/wait.ts +3 -1
@@ -0,0 +1,114 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { createRef, useCallback, useState } from "react";
11
+ import { TouchableOpacity, View } from "react-native";
12
+ import { useIntl } from "react-intl";
13
+ import { messages } from "./messages";
14
+ import { styles } from "./FormatFile.style";
15
+ import { MediaView } from "./components/MediaView";
16
+ import { FormatFileBottomSheet, } from "./components/FormatFileBottomSheet";
17
+ import { FileView } from "./components/FileView";
18
+ import { acceptedExtensions, videoExtensions } from "./constants";
19
+ import { StatusCode, } from "./types";
20
+ import { AtlantisFormatFileContext } from "./context/FormatFileContext";
21
+ import { createUseCreateThumbnail } from "./utils/createUseCreateThumbnail";
22
+ function FormatFileContent({ accessibilityLabel, file, showOverlay, styleInGrid, onUploadComplete, isMedia, }) {
23
+ return (React.createElement(View, { style: [
24
+ styles.thumbnailContainer,
25
+ styleInGrid && styles.thumbnailContainerGrid,
26
+ ] }, isMedia ? (React.createElement(MediaView, { accessibilityLabel: accessibilityLabel, file: file, showOverlay: showOverlay, showError: file.error, styleInGrid: styleInGrid, onUploadComplete: onUploadComplete })) : (React.createElement(FileView, { accessibilityLabel: accessibilityLabel, file: file, showOverlay: showOverlay, showError: file.error, styleInGrid: styleInGrid, onUploadComplete: onUploadComplete }))));
27
+ }
28
+ const FormatFileInternalMemoized = React.memo(FormatFileInternal);
29
+ function isMediaFile(fileType) {
30
+ return fileType.includes("image") || fileType.includes("video");
31
+ }
32
+ function isVideo(fileName) {
33
+ const extension = fileName.substring(fileName.lastIndexOf(".") + 1);
34
+ return videoExtensions.some(({ type }) => type === extension.toLowerCase());
35
+ }
36
+ function getContentType(fileName = "", fileType = "unknown") {
37
+ if (isVideo(fileName)) {
38
+ return "video";
39
+ }
40
+ return fileType;
41
+ }
42
+ function isAcceptedExtension(file) {
43
+ return acceptedExtensions.some(extension =>
44
+ // type property may return undefined on M1 Systems running iOS Simulator
45
+ (file.type || "").includes(extension.name));
46
+ }
47
+ function parseFile(file, showFileTypeIndicator) {
48
+ let formattedFile;
49
+ if ("progress" in file) {
50
+ formattedFile = {
51
+ source: file.sourcePath,
52
+ name: file.name,
53
+ size: file.size,
54
+ external: false,
55
+ progress: file.progress,
56
+ status: file.status,
57
+ error: file.status === StatusCode.Failed,
58
+ type: file.type || file.key,
59
+ isMedia: false,
60
+ showPreview: false,
61
+ showFileTypeIndicator: showFileTypeIndicator,
62
+ };
63
+ }
64
+ else {
65
+ formattedFile = {
66
+ source: file.url,
67
+ thumbnailUrl: file.thumbnailUrl,
68
+ name: file.fileName,
69
+ size: file.fileSize,
70
+ external: true,
71
+ progress: 1,
72
+ status: StatusCode.Completed,
73
+ error: false,
74
+ type: getContentType(file.fileName, file.contentType),
75
+ isMedia: false,
76
+ showPreview: false,
77
+ showFileTypeIndicator: showFileTypeIndicator,
78
+ };
79
+ }
80
+ formattedFile.isMedia = isMediaFile(formattedFile.type || "");
81
+ formattedFile.showPreview =
82
+ formattedFile.isMedia || isAcceptedExtension(formattedFile);
83
+ return formattedFile;
84
+ }
85
+ export function FormatFile({ file, accessibilityLabel, accessibilityHint, onTap, onRemove, bottomSheetOptionsSuffix, styleInGrid = false, testID, showFileTypeIndicator = true, createThumbnail, onPreviewPress, }) {
86
+ const onTapModified = onTap ? () => onTap(file) : () => undefined;
87
+ const formattedFile = parseFile(file, showFileTypeIndicator);
88
+ return (React.createElement(FormatFileInternalMemoized, { file: formattedFile, accessibilityLabel: accessibilityLabel, accessibilityHint: accessibilityHint, onTap: onTapModified, onRemove: onRemove, bottomSheetOptionsSuffix: bottomSheetOptionsSuffix, styleInGrid: styleInGrid, testID: testID, createThumbnail: createThumbnail, onPreviewPress: onPreviewPress }));
89
+ }
90
+ function FormatFileInternal({ file, accessibilityLabel, accessibilityHint, onTap, onRemove, bottomSheetOptionsSuffix, styleInGrid = false, onPreviewPress, testID, createThumbnail: createThumbnailProp, }) {
91
+ const [showOverlay, setShowOverlay] = useState(file.status !== StatusCode.Completed);
92
+ const { formatMessage } = useIntl();
93
+ const bottomSheetRef = createRef();
94
+ const handlePreviewPress = useCallback(() => {
95
+ onPreviewPress === null || onPreviewPress === void 0 ? void 0 : onPreviewPress(file);
96
+ }, [file, onPreviewPress]);
97
+ const createThumbnail = createThumbnailProp
98
+ ? createThumbnailProp
99
+ : () => __awaiter(this, void 0, void 0, function* () { return ({ error: false, thumbnail: "" }); });
100
+ const { useCreateThumbnail } = createUseCreateThumbnail(createThumbnail);
101
+ return (React.createElement(AtlantisFormatFileContext.Provider, { value: { useCreateThumbnail } },
102
+ React.createElement(View, null,
103
+ React.createElement(TouchableOpacity, { accessibilityRole: "imagebutton", accessibilityHint: accessibilityHint !== null && accessibilityHint !== void 0 ? accessibilityHint : formatMessage(messages.defaultAccessibilityHint), onPress: handleOnPress, testID: testID },
104
+ React.createElement(FormatFileContent, { accessibilityLabel: accessibilityLabel, file: file, onUploadComplete: () => setShowOverlay(false), isMedia: !!file.isMedia, styleInGrid: styleInGrid, showOverlay: showOverlay })),
105
+ React.createElement(FormatFileBottomSheet, { bottomSheetRef: bottomSheetRef, onRemovePress: onRemove, bottomSheetOptionsSuffix: bottomSheetOptionsSuffix, onPreviewPress: file.showPreview ? handlePreviewPress : undefined }))));
106
+ function handleOnPress() {
107
+ var _a;
108
+ if (showOverlay || !onRemove) {
109
+ onTap();
110
+ return;
111
+ }
112
+ (_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.open();
113
+ }
114
+ }
@@ -0,0 +1,16 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ thumbnailContainer: {
5
+ backgroundColor: tokens["color-surface--background"],
6
+ borderWidth: tokens["border-base"],
7
+ borderColor: tokens["color-border"],
8
+ borderRadius: tokens["radius-base"],
9
+ marginBottom: tokens["space-small"],
10
+ },
11
+ thumbnailContainerGrid: {
12
+ width: tokens["space-extravagant"],
13
+ height: tokens["space-extravagant"],
14
+ marginRight: tokens["space-small"],
15
+ },
16
+ });
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { styles } from "./ErrorIcon.style";
4
+ import { Icon } from "../../../Icon";
5
+ export function ErrorIcon() {
6
+ return (React.createElement(View, { testID: "format-file-error-icon", style: styles.circle },
7
+ React.createElement(Icon, { name: "alert", color: "critical" })));
8
+ }
@@ -0,0 +1,10 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../../../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ circle: {
5
+ width: tokens["space-large"],
6
+ height: tokens["space-large"],
7
+ borderRadius: tokens["radius-circle"],
8
+ backgroundColor: tokens["color-surface"],
9
+ },
10
+ });
@@ -0,0 +1 @@
1
+ export { ErrorIcon } from "./ErrorIcon";
@@ -0,0 +1,67 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { useIntl } from "react-intl";
4
+ import { styles } from "./FileView.style";
5
+ import { Icon } from "../../../Icon";
6
+ import { Text } from "../../../Text";
7
+ import { StatusCode } from "../../types";
8
+ import { computeA11yLabel } from "../../utils";
9
+ import { ProgressBar } from "../ProgressBar";
10
+ import { ErrorIcon } from "../ErrorIcon";
11
+ export function FileView({ accessibilityLabel, styleInGrid, file, showOverlay, showError, onUploadComplete, }) {
12
+ const { formatMessage } = useIntl();
13
+ const a11yLabel = computeA11yLabel({
14
+ accessibilityLabel,
15
+ showOverlay,
16
+ showError,
17
+ formatMessage,
18
+ });
19
+ const freezeProgressBar = file.status !== StatusCode.Completed && file.progress >= 0.9;
20
+ return (React.createElement(View, { style: [
21
+ styles.fileBackground,
22
+ styleInGrid ? styles.fileBackgroundGrid : styles.fileBackgroundFlat,
23
+ ], accessible: true, accessibilityLabel: a11yLabel },
24
+ React.createElement(View, { style: [
25
+ styles.fileBackground,
26
+ styleInGrid ? styles.fileIconGrid : styles.fileIconFlat,
27
+ ], testID: "test-file" }, (styleInGrid || !showError) && file.showFileTypeIndicator && (React.createElement(Icon, { size: "large", name: mapFileTypeToIconName({
28
+ fileName: file.name,
29
+ fileType: file.type,
30
+ }) }))),
31
+ React.createElement(View, { style: [
32
+ showError && styleInGrid ? styles.fileNameError : styles.fileName,
33
+ styleInGrid ? styles.fileNameGrid : styles.fileNameFlat,
34
+ ] },
35
+ React.createElement(Text, { level: "textSupporting", variation: "subdued", maxLines: "single" }, file.name)),
36
+ !showError && showOverlay && (React.createElement(View, { style: [styles.fileBackground, styles.overlay, styles.fileOverlay], testID: "format-file-progress-bar-container" },
37
+ React.createElement(ProgressBar, { status: file.status, progress: freezeProgressBar ? 0.9 : file.progress, onComplete: onUploadComplete }))),
38
+ showError && (React.createElement(View, { style: [
39
+ styles.fileBackground,
40
+ styles.overlayError,
41
+ styles.fileOverlay,
42
+ ], testID: "format-file-error-container" },
43
+ React.createElement(View, { style: !styleInGrid ? styles.iconCenter : undefined },
44
+ React.createElement(ErrorIcon, null))))));
45
+ }
46
+ function mapFileTypeToIconName({ fileName, fileType, }) {
47
+ if (!fileName && !fileType) {
48
+ return "alert";
49
+ }
50
+ if ((fileType === null || fileType === void 0 ? void 0 : fileType.includes("pdf")) || (fileName === null || fileName === void 0 ? void 0 : fileName.match(/~*.pdf$/))) {
51
+ return "pdf";
52
+ }
53
+ else if ((fileType === null || fileType === void 0 ? void 0 : fileType.includes("ms-word")) ||
54
+ (fileName === null || fileName === void 0 ? void 0 : fileName.match(/~*.doc$|docx$/))) {
55
+ return "word";
56
+ }
57
+ else if ((fileType === null || fileType === void 0 ? void 0 : fileType.includes("ms-excel")) ||
58
+ (fileName === null || fileName === void 0 ? void 0 : fileName.match(/~*.xls$|xlsx$/))) {
59
+ return "excel";
60
+ }
61
+ else if ((fileType === null || fileType === void 0 ? void 0 : fileType.includes("video")) || (fileName === null || fileName === void 0 ? void 0 : fileName.match(/~*.mp4$|mp4$/))) {
62
+ return "video";
63
+ }
64
+ else {
65
+ return "file";
66
+ }
67
+ }
@@ -0,0 +1,64 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../../../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ overlay: {
5
+ backgroundColor: tokens["color-overlay--dimmed"],
6
+ },
7
+ overlayError: {
8
+ backgroundColor: tokens["color-overlay--dimmed"],
9
+ borderColor: tokens["color-critical"],
10
+ borderWidth: tokens["border-base"],
11
+ },
12
+ iconCenter: {
13
+ marginBottom: tokens["space-large"],
14
+ },
15
+ fileBackground: {
16
+ width: "100%",
17
+ display: "flex",
18
+ alignItems: "center",
19
+ },
20
+ fileBackgroundGrid: {
21
+ height: "100%",
22
+ },
23
+ fileBackgroundFlat: {
24
+ justifyContent: "center",
25
+ height: tokens["space-extravagant"],
26
+ },
27
+ fileIconGrid: {
28
+ top: tokens["space-small"],
29
+ },
30
+ fileIconFlat: {
31
+ top: tokens["space-smaller"],
32
+ },
33
+ fileNameError: {
34
+ alignItems: "center",
35
+ borderTopColor: tokens["color-border"],
36
+ borderTopWidth: tokens["space-minuscule"],
37
+ width: "100%",
38
+ marginTop: tokens["space-base"],
39
+ },
40
+ fileName: {
41
+ alignItems: "center",
42
+ borderTopColor: tokens["color-border"],
43
+ borderTopWidth: tokens["space-minuscule"],
44
+ width: "100%",
45
+ },
46
+ fileNameGrid: {
47
+ position: "absolute",
48
+ right: 0,
49
+ bottom: 0,
50
+ left: 0,
51
+ },
52
+ fileNameFlat: {
53
+ top: tokens["space-small"],
54
+ },
55
+ fileOverlay: {
56
+ position: "absolute",
57
+ justifyContent: "center",
58
+ right: 0,
59
+ bottom: 0,
60
+ left: 0,
61
+ height: "100%",
62
+ paddingHorizontal: tokens["space-small"],
63
+ },
64
+ });
@@ -0,0 +1 @@
1
+ export { FileView } from "./FileView";
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Portal } from "react-native-portalize";
3
+ import { useIntl } from "react-intl";
4
+ import { messages } from "./messages";
5
+ import { BottomSheet } from "../../../BottomSheet/BottomSheet";
6
+ import { BottomSheetOption } from "../../../BottomSheet/components/BottomSheetOption";
7
+ export const FormatFileBottomSheet = ({ bottomSheetRef, onPreviewPress, onRemovePress, bottomSheetOptionsSuffix, }) => {
8
+ const { formatMessage } = useIntl();
9
+ const handlePress = (onPressAction) => {
10
+ var _a;
11
+ onPressAction();
12
+ (_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.close();
13
+ };
14
+ return (React.createElement(Portal, null,
15
+ React.createElement(BottomSheet, { ref: bottomSheetRef },
16
+ onPreviewPress ? (React.createElement(BottomSheetOption, { icon: "eye", text: formatMessage(messages.lightBoxPreviewButton, {
17
+ bottomSheetOptionsSuffix,
18
+ }), onPress: () => handlePress(onPreviewPress) })) : undefined,
19
+ onRemovePress ? (React.createElement(BottomSheetOption, { icon: "trash", destructive: true, text: formatMessage(messages.removeButton, {
20
+ bottomSheetOptionsSuffix,
21
+ }), onPress: () => handlePress(onRemovePress) })) : undefined)));
22
+ };
@@ -0,0 +1 @@
1
+ export { FormatFileBottomSheet } from "./FormatFileBottomSheet";
@@ -0,0 +1,13 @@
1
+ import { defineMessages } from "react-intl";
2
+ export const messages = defineMessages({
3
+ lightBoxPreviewButton: {
4
+ id: "lightBoxPreviewButton",
5
+ defaultMessage: "Preview {bottomSheetOptionsSuffix}",
6
+ description: "Label for button when preview the file",
7
+ },
8
+ removeButton: {
9
+ id: "removeButton",
10
+ defaultMessage: "Remove {bottomSheetOptionsSuffix}",
11
+ description: "Label for button when remove the file",
12
+ },
13
+ });
@@ -0,0 +1,56 @@
1
+ import React, { useState } from "react";
2
+ import { ImageBackground, View } from "react-native";
3
+ import { useIntl } from "react-intl";
4
+ import { styles } from "./MediaView.style";
5
+ import { StatusCode } from "../../types";
6
+ import { computeA11yLabel } from "../../utils";
7
+ import { ActivityIndicator } from "../../../ActivityIndicator";
8
+ import { Icon } from "../../../Icon";
9
+ import { ProgressBar } from "../ProgressBar";
10
+ import { ErrorIcon } from "../ErrorIcon";
11
+ import { useAtlantisFormatFileContext } from "../../context/FormatFileContext";
12
+ export function MediaView({ accessibilityLabel, showOverlay, showError, file, styleInGrid, onUploadComplete, }) {
13
+ const { formatMessage } = useIntl();
14
+ const { useCreateThumbnail } = useAtlantisFormatFileContext();
15
+ const { thumbnail, error } = useCreateThumbnail(file);
16
+ const [isLoading, setIsLoading] = useState(false);
17
+ const a11yLabel = computeA11yLabel({
18
+ accessibilityLabel,
19
+ showOverlay,
20
+ showError,
21
+ formatMessage,
22
+ });
23
+ const hasError = showError || error;
24
+ const uri = thumbnail || file.thumbnailUrl || file.source;
25
+ return (React.createElement(View, { accessible: true, accessibilityLabel: a11yLabel },
26
+ React.createElement(ImageBackground, { style: [
27
+ styles.imageBackground,
28
+ styleInGrid ? styles.imageBackgroundGrid : styles.imageBackgroundFlat,
29
+ ], resizeMode: styleInGrid ? "cover" : "contain", source: { uri }, testID: "test-image", onLoadStart: () => setIsLoading(true), onLoadEnd: () => setIsLoading(false) },
30
+ React.createElement(Overlay, { isLoading: isLoading, showOverlay: showOverlay, hasError: hasError, file: file, onUploadComplete: onUploadComplete }))));
31
+ }
32
+ function Overlay({ isLoading, showOverlay, hasError, file, onUploadComplete, }) {
33
+ if (isLoading)
34
+ return React.createElement(ActivityIndicator, null);
35
+ if (hasError)
36
+ return React.createElement(ErrorOverlay, null);
37
+ if (showOverlay) {
38
+ return (React.createElement(ProgressOverlay, { status: file.status, progress: file.progress, onUploadComplete: onUploadComplete }));
39
+ }
40
+ if (isVideo(file.type) && file.showFileTypeIndicator) {
41
+ return React.createElement(Icon, { name: "video", color: "white" });
42
+ }
43
+ return React.createElement(React.Fragment, null);
44
+ }
45
+ function ProgressOverlay({ status, progress, onUploadComplete, }) {
46
+ const freezeProgressBar = status !== StatusCode.Completed && progress >= 0.9;
47
+ return (React.createElement(View, { style: [styles.imageBackground, styles.overlay], testID: "format-file-progress-bar-container" },
48
+ React.createElement(ProgressBar, { status: status, progress: freezeProgressBar ? 0.9 : progress, onComplete: onUploadComplete })));
49
+ }
50
+ function ErrorOverlay() {
51
+ return (React.createElement(View, { style: [styles.imageBackground, styles.overlayError], testID: "format-file-error-container" },
52
+ React.createElement(ErrorIcon, null)));
53
+ }
54
+ function isVideo(fileType = "") {
55
+ return fileType.includes("video");
56
+ }
@@ -0,0 +1,27 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../../../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ imageBackground: {
5
+ width: "100%",
6
+ justifyContent: "center",
7
+ alignItems: "center",
8
+ },
9
+ imageBackgroundFlat: {
10
+ aspectRatio: 375 / 150,
11
+ },
12
+ imageBackgroundGrid: {
13
+ height: "100%",
14
+ },
15
+ overlay: {
16
+ height: "100%",
17
+ backgroundColor: tokens["color-overlay--dimmed"],
18
+ paddingHorizontal: tokens["space-small"],
19
+ },
20
+ overlayError: {
21
+ height: "100%",
22
+ backgroundColor: tokens["color-overlay--dimmed"],
23
+ paddingHorizontal: tokens["space-small"],
24
+ borderColor: tokens["color-critical"],
25
+ borderWidth: tokens["border-base"],
26
+ },
27
+ });
@@ -0,0 +1 @@
1
+ export { MediaView } from "./MediaView";
@@ -0,0 +1,29 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { Animated, View } from "react-native";
3
+ import { styles } from "./ProgressBar.style";
4
+ import { StatusCode } from "../../types";
5
+ export const ProgressBar = ({ progress, status, onComplete, }) => {
6
+ const barWidth = useRef(new Animated.Value(0)).current;
7
+ const progressPercentage = barWidth.interpolate({
8
+ inputRange: [0, 1],
9
+ outputRange: ["0%", `100%`],
10
+ });
11
+ useEffect(() => {
12
+ Animated.timing(barWidth, {
13
+ toValue: progress,
14
+ duration: 500,
15
+ useNativeDriver: false,
16
+ }).start(({ finished }) => {
17
+ if (status === StatusCode.Completed && finished && onComplete) {
18
+ onComplete();
19
+ }
20
+ });
21
+ }, [progress, barWidth, onComplete, status]);
22
+ return (React.createElement(View, { testID: "format-file-progress-bar", style: styles.container },
23
+ React.createElement(Animated.View, { testID: "format-file-inner-progress-bar", style: [
24
+ styles.progress,
25
+ {
26
+ width: progressPercentage,
27
+ },
28
+ ] })));
29
+ };
@@ -0,0 +1,15 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../../../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ width: "100%",
6
+ height: 8,
7
+ borderRadius: tokens["radius-circle"],
8
+ overflow: "hidden",
9
+ backgroundColor: tokens["color-surface--background"],
10
+ },
11
+ progress: {
12
+ height: "100%",
13
+ backgroundColor: tokens["color-green"],
14
+ },
15
+ });
@@ -0,0 +1 @@
1
+ export { ProgressBar } from "./ProgressBar";
@@ -0,0 +1,78 @@
1
+ import { v4 } from "react-native-uuid";
2
+ import { StatusCode } from "../../types";
3
+ export const FILE_UPLOAD_MOCK_FILE = ({ progress, status = StatusCode.InProgress, }) => ({
4
+ batchContext: {
5
+ batchCount: 1,
6
+ batchId: "FILES",
7
+ },
8
+ uuid: v4(),
9
+ key: "path/test.txt",
10
+ name: "test.txt",
11
+ size: 1,
12
+ type: "application/txt",
13
+ progress: progress,
14
+ status: status,
15
+ sourcePath: "path/test.txt",
16
+ uploadUrl: "uploadUrl",
17
+ cancel: jest.fn(),
18
+ });
19
+ export const FILE_UPLOAD_MOCK_IMAGE = ({ progress, size, status = StatusCode.InProgress, }) => ({
20
+ batchContext: {
21
+ batchCount: 1,
22
+ batchId: "IMAGES",
23
+ },
24
+ uuid: v4(),
25
+ key: "path/test.png",
26
+ name: "test.png",
27
+ size: size || 1,
28
+ type: "image/png",
29
+ progress: progress,
30
+ status: status,
31
+ sourcePath: "path/test.png",
32
+ uploadUrl: "uploadUrl",
33
+ cancel: jest.fn(),
34
+ });
35
+ export const FILE_UPLOAD_MOCK_PDF = ({ progress, status = StatusCode.InProgress, }) => ({
36
+ batchContext: {
37
+ batchCount: 1,
38
+ batchId: "FILES",
39
+ },
40
+ uuid: v4(),
41
+ key: "path/test.pdf",
42
+ name: "test.pdf",
43
+ size: 1,
44
+ type: "file/pdf",
45
+ progress: progress,
46
+ status: status,
47
+ sourcePath: "path/test.pdf",
48
+ uploadUrl: "uploadUrl",
49
+ cancel: jest.fn(),
50
+ });
51
+ export const FILE_MOCK_PDF = {
52
+ fileName: "some_file.pdf",
53
+ fileSize: 1,
54
+ contentType: "pdf",
55
+ url: "https://path/to/file.pdf",
56
+ thumbnailUrl: "https://path/to/fileThumbnail.pdf",
57
+ };
58
+ export const FILE_MOCK_VIDEO = {
59
+ fileName: "some_file.mp4",
60
+ fileSize: 1,
61
+ contentType: "video",
62
+ url: undefined,
63
+ thumbnailUrl: "path/to/fileThumbnail.mp4",
64
+ };
65
+ export const FILE_MOCK_FILE = {
66
+ fileName: "some_file.txt",
67
+ fileSize: 1,
68
+ contentType: "file",
69
+ url: "https://path/to/file",
70
+ thumbnailUrl: "https://path/to/fileThumbnail",
71
+ };
72
+ export const FILE_MOCK_IMAGE = {
73
+ fileName: "some_image.jpg",
74
+ fileSize: 1,
75
+ contentType: "image/jpg",
76
+ url: "https://path/to/image",
77
+ thumbnailUrl: "https://path/to/imageThumbnail",
78
+ };
@@ -0,0 +1,14 @@
1
+ export const acceptedExtensions = [
2
+ { name: "video" },
3
+ { name: "pdf" },
4
+ { name: "mov" },
5
+ { name: "mp4" },
6
+ { name: "docx" },
7
+ { name: "xlsx" },
8
+ ];
9
+ export const videoExtensions = [
10
+ { type: "mov" },
11
+ { type: "mp4" },
12
+ { type: "3gpp" },
13
+ { type: "hevc" },
14
+ ];
@@ -0,0 +1,8 @@
1
+ import { createContext, useContext } from "react";
2
+ export const formatFileContextDefaultValues = {
3
+ useCreateThumbnail: () => ({ thumbnail: undefined, error: false }),
4
+ };
5
+ export const AtlantisFormatFileContext = createContext(formatFileContextDefaultValues);
6
+ export function useAtlantisFormatFileContext() {
7
+ return useContext(AtlantisFormatFileContext);
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { FormatFile } from "./FormatFile";
@@ -0,0 +1,23 @@
1
+ import { defineMessages } from "react-intl";
2
+ export const messages = defineMessages({
3
+ defaultAccessibilityLabel: {
4
+ id: "defaultAccessibilityLabel",
5
+ defaultMessage: "Attachment Preview",
6
+ description: "The default accessibility label",
7
+ },
8
+ defaultAccessibilityHint: {
9
+ id: "defaultAccessibilityHint",
10
+ defaultMessage: "Select for more options",
11
+ description: "The default accessibility hint",
12
+ },
13
+ errorAccessibilityLabel: {
14
+ id: "errorAccessibilityLabel",
15
+ defaultMessage: "Failed upload",
16
+ description: "The accessibility label for error states",
17
+ },
18
+ inProgressAccessibilityLabel: {
19
+ id: "inProgress",
20
+ defaultMessage: "Upload in progress",
21
+ description: "The accessibility label for in-progress states",
22
+ },
23
+ });
@@ -0,0 +1,8 @@
1
+ export var StatusCode;
2
+ (function (StatusCode) {
3
+ StatusCode[StatusCode["Pending"] = 0] = "Pending";
4
+ StatusCode[StatusCode["Started"] = 1] = "Started";
5
+ StatusCode[StatusCode["InProgress"] = 2] = "InProgress";
6
+ StatusCode[StatusCode["Completed"] = 3] = "Completed";
7
+ StatusCode[StatusCode["Failed"] = 4] = "Failed";
8
+ })(StatusCode || (StatusCode = {}));
@@ -0,0 +1,12 @@
1
+ import { messages } from "../messages";
2
+ export function computeA11yLabel({ accessibilityLabel, showOverlay, showError, formatMessage, }) {
3
+ if (!showError && showOverlay) {
4
+ return formatMessage(messages.inProgressAccessibilityLabel);
5
+ }
6
+ else if (showError) {
7
+ return formatMessage(messages.errorAccessibilityLabel);
8
+ }
9
+ else {
10
+ return (accessibilityLabel || formatMessage(messages.defaultAccessibilityLabel));
11
+ }
12
+ }
@@ -0,0 +1,22 @@
1
+ import { useIsMounted } from "@jobber/hooks/useIsMounted";
2
+ import { useCallback, useEffect, useState } from "react";
3
+ export function createUseCreateThumbnail(createThumbnail) {
4
+ const useCreateThumbnail = useCallback((file) => {
5
+ const [thumbnail, setThumbnail] = useState(undefined);
6
+ const [error, setError] = useState(false);
7
+ const { current } = useIsMounted();
8
+ useEffect(() => {
9
+ createThumbnail(file)
10
+ .then(({ thumbnail: newThumbnail, error: newError }) => {
11
+ setThumbnail(newThumbnail);
12
+ setError(newError);
13
+ })
14
+ .catch(() => {
15
+ setError(true);
16
+ setThumbnail(undefined);
17
+ });
18
+ }, [current, file]);
19
+ return { thumbnail, error };
20
+ }, [createThumbnail]);
21
+ return { useCreateThumbnail };
22
+ }
@@ -0,0 +1 @@
1
+ export { computeA11yLabel } from "./computeA11yLabel";