@jobber/components-native 0.36.0 → 0.37.1-unblock-fo.10

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 (131) hide show
  1. package/dist/src/ContentOverlay/ContentOverlay.js +144 -0
  2. package/dist/src/ContentOverlay/ContentOverlay.style.js +56 -0
  3. package/dist/src/ContentOverlay/hooks/useKeyboardVisibility.js +21 -0
  4. package/dist/src/ContentOverlay/hooks/useViewLayoutHeight.js +10 -0
  5. package/dist/src/ContentOverlay/index.js +1 -0
  6. package/dist/src/ContentOverlay/messages.js +8 -0
  7. package/dist/src/ContentOverlay/types.js +1 -0
  8. package/dist/src/Disclosure/Disclosure.js +50 -0
  9. package/dist/src/Disclosure/Disclosure.style.js +21 -0
  10. package/dist/src/Disclosure/constants.js +1 -0
  11. package/dist/src/Disclosure/index.js +1 -0
  12. package/dist/src/FormatFile/FormatFile.js +114 -0
  13. package/dist/src/FormatFile/FormatFile.style.js +16 -0
  14. package/dist/src/FormatFile/components/ErrorIcon/ErrorIcon.js +8 -0
  15. package/dist/src/FormatFile/components/ErrorIcon/ErrorIcon.style.js +10 -0
  16. package/dist/src/FormatFile/components/ErrorIcon/index.js +1 -0
  17. package/dist/src/FormatFile/components/FileView/FileView.js +67 -0
  18. package/dist/src/FormatFile/components/FileView/FileView.style.js +64 -0
  19. package/dist/src/FormatFile/components/FileView/index.js +1 -0
  20. package/dist/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.js +22 -0
  21. package/dist/src/FormatFile/components/FormatFileBottomSheet/index.js +1 -0
  22. package/dist/src/FormatFile/components/FormatFileBottomSheet/messages.js +13 -0
  23. package/dist/src/FormatFile/components/MediaView/MediaView.js +56 -0
  24. package/dist/src/FormatFile/components/MediaView/MediaView.style.js +27 -0
  25. package/dist/src/FormatFile/components/MediaView/index.js +1 -0
  26. package/dist/src/FormatFile/components/ProgressBar/ProgressBar.js +29 -0
  27. package/dist/src/FormatFile/components/ProgressBar/ProgressBar.style.js +15 -0
  28. package/dist/src/FormatFile/components/ProgressBar/index.js +1 -0
  29. package/dist/src/FormatFile/components/_mocks/mockFiles.js +78 -0
  30. package/dist/src/FormatFile/constants.js +14 -0
  31. package/dist/src/FormatFile/context/FormatFileContext.js +8 -0
  32. package/dist/src/FormatFile/context/types.js +1 -0
  33. package/dist/src/FormatFile/index.js +1 -0
  34. package/dist/src/FormatFile/messages.js +23 -0
  35. package/dist/src/FormatFile/types.js +8 -0
  36. package/dist/src/FormatFile/utils/computeA11yLabel.js +12 -0
  37. package/dist/src/FormatFile/utils/createUseCreateThumbnail.js +22 -0
  38. package/dist/src/FormatFile/utils/index.js +1 -0
  39. package/dist/src/index.js +3 -0
  40. package/dist/src/utils/test/wait.js +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/dist/types/src/ContentOverlay/ContentOverlay.d.ts +6 -0
  43. package/dist/types/src/ContentOverlay/ContentOverlay.style.d.ts +60 -0
  44. package/dist/types/src/ContentOverlay/hooks/useKeyboardVisibility.d.ts +6 -0
  45. package/dist/types/src/ContentOverlay/hooks/useViewLayoutHeight.d.ts +6 -0
  46. package/dist/types/src/ContentOverlay/index.d.ts +2 -0
  47. package/dist/types/src/ContentOverlay/messages.d.ts +7 -0
  48. package/dist/types/src/ContentOverlay/types.d.ts +87 -0
  49. package/dist/types/src/Disclosure/Disclosure.d.ts +35 -0
  50. package/dist/types/src/Disclosure/Disclosure.style.d.ts +19 -0
  51. package/dist/types/src/Disclosure/constants.d.ts +1 -0
  52. package/dist/types/src/Disclosure/index.d.ts +1 -0
  53. package/dist/types/src/FormatFile/FormatFile.d.ts +48 -0
  54. package/dist/types/src/FormatFile/FormatFile.style.d.ts +14 -0
  55. package/dist/types/src/FormatFile/components/ErrorIcon/ErrorIcon.d.ts +2 -0
  56. package/dist/types/src/FormatFile/components/ErrorIcon/ErrorIcon.style.d.ts +8 -0
  57. package/dist/types/src/FormatFile/components/ErrorIcon/index.d.ts +1 -0
  58. package/dist/types/src/FormatFile/components/FileView/FileView.d.ts +12 -0
  59. package/dist/types/src/FormatFile/components/FileView/FileView.style.d.ts +62 -0
  60. package/dist/types/src/FormatFile/components/FileView/index.d.ts +1 -0
  61. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.d.ts +11 -0
  62. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/index.d.ts +2 -0
  63. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/messages.d.ts +12 -0
  64. package/dist/types/src/FormatFile/components/MediaView/MediaView.d.ts +12 -0
  65. package/dist/types/src/FormatFile/components/MediaView/MediaView.style.d.ts +25 -0
  66. package/dist/types/src/FormatFile/components/MediaView/index.d.ts +1 -0
  67. package/dist/types/src/FormatFile/components/ProgressBar/ProgressBar.d.ts +19 -0
  68. package/dist/types/src/FormatFile/components/ProgressBar/ProgressBar.style.d.ts +13 -0
  69. package/dist/types/src/FormatFile/components/ProgressBar/index.d.ts +1 -0
  70. package/dist/types/src/FormatFile/components/_mocks/mockFiles.d.ts +18 -0
  71. package/dist/types/src/FormatFile/constants.d.ts +6 -0
  72. package/dist/types/src/FormatFile/context/FormatFileContext.d.ts +10 -0
  73. package/dist/types/src/FormatFile/context/types.d.ts +9 -0
  74. package/dist/types/src/FormatFile/index.d.ts +3 -0
  75. package/dist/types/src/FormatFile/messages.d.ts +22 -0
  76. package/dist/types/src/FormatFile/types.d.ts +105 -0
  77. package/dist/types/src/FormatFile/utils/computeA11yLabel.d.ts +9 -0
  78. package/dist/types/src/FormatFile/utils/createUseCreateThumbnail.d.ts +5 -0
  79. package/dist/types/src/FormatFile/utils/index.d.ts +1 -0
  80. package/dist/types/src/InputCurrency/InputCurrency.d.ts +1 -1
  81. package/dist/types/src/index.d.ts +3 -0
  82. package/package.json +3 -2
  83. package/src/ContentOverlay/ContentOverlay.style.ts +70 -0
  84. package/src/ContentOverlay/ContentOverlay.test.tsx +371 -0
  85. package/src/ContentOverlay/ContentOverlay.tsx +295 -0
  86. package/src/ContentOverlay/hooks/useKeyboardVisibility.test.ts +42 -0
  87. package/src/ContentOverlay/hooks/useKeyboardVisibility.ts +36 -0
  88. package/src/ContentOverlay/hooks/useViewLayoutHeight.test.ts +56 -0
  89. package/src/ContentOverlay/hooks/useViewLayoutHeight.ts +18 -0
  90. package/src/ContentOverlay/index.ts +2 -0
  91. package/src/ContentOverlay/messages.ts +9 -0
  92. package/src/ContentOverlay/types.ts +96 -0
  93. package/src/Disclosure/Disclosure.style.ts +22 -0
  94. package/src/Disclosure/Disclosure.test.tsx +71 -0
  95. package/src/Disclosure/Disclosure.tsx +162 -0
  96. package/src/Disclosure/__snapshots__/Disclosure.test.tsx.snap +488 -0
  97. package/src/Disclosure/constants.ts +1 -0
  98. package/src/Disclosure/index.ts +1 -0
  99. package/src/FormatFile/FormatFile.stories.mdx +101 -0
  100. package/src/FormatFile/FormatFile.style.ts +17 -0
  101. package/src/FormatFile/FormatFile.test.tsx +333 -0
  102. package/src/FormatFile/FormatFile.tsx +300 -0
  103. package/src/FormatFile/components/ErrorIcon/ErrorIcon.style.ts +11 -0
  104. package/src/FormatFile/components/ErrorIcon/ErrorIcon.tsx +12 -0
  105. package/src/FormatFile/components/ErrorIcon/index.ts +1 -0
  106. package/src/FormatFile/components/FileView/FileView.style.ts +65 -0
  107. package/src/FormatFile/components/FileView/FileView.tsx +134 -0
  108. package/src/FormatFile/components/FileView/index.ts +1 -0
  109. package/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.tsx +108 -0
  110. package/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.tsx +56 -0
  111. package/src/FormatFile/components/FormatFileBottomSheet/index.ts +2 -0
  112. package/src/FormatFile/components/FormatFileBottomSheet/messages.ts +14 -0
  113. package/src/FormatFile/components/MediaView/MediaView.style.ts +28 -0
  114. package/src/FormatFile/components/MediaView/MediaView.tsx +145 -0
  115. package/src/FormatFile/components/MediaView/index.ts +1 -0
  116. package/src/FormatFile/components/ProgressBar/ProgressBar.style.tsx +16 -0
  117. package/src/FormatFile/components/ProgressBar/ProgressBar.tsx +57 -0
  118. package/src/FormatFile/components/ProgressBar/index.ts +1 -0
  119. package/src/FormatFile/components/_mocks/mockFiles.ts +105 -0
  120. package/src/FormatFile/constants.ts +15 -0
  121. package/src/FormatFile/context/FormatFileContext.ts +13 -0
  122. package/src/FormatFile/context/types.ts +12 -0
  123. package/src/FormatFile/index.ts +13 -0
  124. package/src/FormatFile/messages.ts +24 -0
  125. package/src/FormatFile/types.ts +126 -0
  126. package/src/FormatFile/utils/computeA11yLabel.ts +26 -0
  127. package/src/FormatFile/utils/createUseCreateThumbnail.ts +33 -0
  128. package/src/FormatFile/utils/index.ts +1 -0
  129. package/src/InputCurrency/InputCurrency.tsx +1 -1
  130. package/src/index.ts +3 -0
  131. package/src/utils/test/wait.ts +3 -1
@@ -0,0 +1,144 @@
1
+ import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, useState, } from "react";
2
+ import { Modalize } from "react-native-modalize";
3
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
4
+ import { AccessibilityInfo, Platform, View, findNodeHandle, useWindowDimensions, } from "react-native";
5
+ import { Portal } from "react-native-portalize";
6
+ import { useIntl } from "react-intl";
7
+ import { useKeyboardVisibility } from "./hooks/useKeyboardVisibility";
8
+ import { styles } from "./ContentOverlay.style";
9
+ import { messages } from "./messages";
10
+ import { useViewLayoutHeight } from "./hooks/useViewLayoutHeight";
11
+ import { useIsScreenReaderEnabled } from "../hooks";
12
+ import { IconButton } from "../IconButton";
13
+ import { tokens } from "../utils/design";
14
+ import { Heading } from "../Heading";
15
+ export const ContentOverlay = forwardRef(ContentOverlayPortal);
16
+ const ContentOverlayModal = forwardRef(ContentOverlayInternal);
17
+ // eslint-disable-next-line max-statements
18
+ function ContentOverlayInternal({ children, title, accessibilityLabel, fullScreen = false, showDismiss = false, isDraggable = true, adjustToContentHeight = false, keyboardShouldPersistTaps = false, keyboardAvoidingBehavior, scrollEnabled = false, modalBackgroundColor = "surface", onClose, onOpen, onBeforeExit, loading = false, avoidKeyboardLikeIOS, }, ref) {
19
+ isDraggable = onBeforeExit ? false : isDraggable;
20
+ const isCloseableOnOverlayTap = onBeforeExit ? false : true;
21
+ const { formatMessage } = useIntl();
22
+ const { width: windowWidth, height: windowHeight } = useWindowDimensions();
23
+ const insets = useSafeAreaInsets();
24
+ const [position, setPosition] = useState("initial");
25
+ const isScreenReaderEnabled = useIsScreenReaderEnabled();
26
+ const isFullScreenOrTopPosition = fullScreen || (!adjustToContentHeight && position === "top");
27
+ const shouldShowDismiss = showDismiss || isScreenReaderEnabled || isFullScreenOrTopPosition;
28
+ const [showHeaderShadow, setShowHeaderShadow] = useState(false);
29
+ const overlayHeader = useRef();
30
+ const internalRef = useRef();
31
+ const [modalizeMethods, setModalizeMethods] = useState();
32
+ const callbackInternalRef = useCallback((instance) => {
33
+ if (instance && !internalRef.current) {
34
+ internalRef.current = instance;
35
+ setModalizeMethods(instance);
36
+ }
37
+ }, []);
38
+ const refMethods = useMemo(() => {
39
+ if (!(modalizeMethods === null || modalizeMethods === void 0 ? void 0 : modalizeMethods.open) || !(modalizeMethods === null || modalizeMethods === void 0 ? void 0 : modalizeMethods.close)) {
40
+ return {};
41
+ }
42
+ return {
43
+ open: modalizeMethods === null || modalizeMethods === void 0 ? void 0 : modalizeMethods.open,
44
+ close: modalizeMethods === null || modalizeMethods === void 0 ? void 0 : modalizeMethods.close,
45
+ };
46
+ }, [modalizeMethods]);
47
+ const { keyboardHeight } = useKeyboardVisibility();
48
+ useImperativeHandle(ref, () => refMethods, [refMethods]);
49
+ const { handleLayout: handleChildrenLayout, height: childrenHeight, heightKnown: childrenHeightKnown, } = useViewLayoutHeight();
50
+ const { handleLayout: handleHeaderLayout, height: headerHeight, heightKnown: headerHeightKnown, } = useViewLayoutHeight();
51
+ const snapPoint = useMemo(() => {
52
+ if (fullScreen || !isDraggable || adjustToContentHeight) {
53
+ return undefined;
54
+ }
55
+ const overlayHeight = headerHeight + childrenHeight;
56
+ if (overlayHeight >= windowHeight) {
57
+ return undefined;
58
+ }
59
+ return overlayHeight;
60
+ }, [
61
+ fullScreen,
62
+ isDraggable,
63
+ adjustToContentHeight,
64
+ headerHeight,
65
+ childrenHeight,
66
+ windowHeight,
67
+ ]);
68
+ const modalStyle = [
69
+ styles.modal,
70
+ windowWidth > 640 ? styles.modalForLargeScreens : undefined,
71
+ { backgroundColor: getModalBackgroundColor(modalBackgroundColor) },
72
+ keyboardHeight > 0 && { marginBottom: 0 },
73
+ ];
74
+ const renderedChildren = renderChildren();
75
+ const renderedHeader = renderHeader();
76
+ const onCloseController = () => {
77
+ var _a;
78
+ if (!onBeforeExit) {
79
+ (_a = internalRef.current) === null || _a === void 0 ? void 0 : _a.close();
80
+ return true;
81
+ }
82
+ else {
83
+ onBeforeExit();
84
+ return false;
85
+ }
86
+ };
87
+ return (React.createElement(React.Fragment, null,
88
+ headerHeightKnown && childrenHeightKnown && (React.createElement(Modalize, { ref: callbackInternalRef, overlayStyle: styles.overlay, handleStyle: styles.handle, handlePosition: "inside", modalStyle: modalStyle, modalTopOffset: tokens["space-larger"], snapPoint: snapPoint, closeSnapPointStraightEnabled: false, withHandle: isDraggable, panGestureEnabled: isDraggable, adjustToContentHeight: adjustToContentHeight, disableScrollIfPossible: !adjustToContentHeight, onClose: onClose, onOpen: onOpen, keyboardAvoidingBehavior: keyboardAvoidingBehavior, avoidKeyboardLikeIOS: avoidKeyboardLikeIOS, childrenStyle: styles.childrenStyle, onBackButtonPress: onCloseController, closeOnOverlayTap: isCloseableOnOverlayTap, onOpened: () => {
89
+ if (overlayHeader.current) {
90
+ const reactTag = findNodeHandle(overlayHeader.current);
91
+ if (reactTag) {
92
+ AccessibilityInfo.setAccessibilityFocus(reactTag);
93
+ }
94
+ }
95
+ }, scrollViewProps: {
96
+ scrollEnabled,
97
+ showsVerticalScrollIndicator: false,
98
+ stickyHeaderIndices: Platform.OS === "android" ? [0] : undefined,
99
+ onScroll: handleOnScroll,
100
+ keyboardShouldPersistTaps: keyboardShouldPersistTaps
101
+ ? "handled"
102
+ : "never",
103
+ }, HeaderComponent: Platform.OS === "ios" ? renderedHeader : undefined, onPositionChange: setPosition },
104
+ Platform.OS === "android" ? renderedHeader : undefined,
105
+ renderedChildren)),
106
+ !childrenHeightKnown && (React.createElement(View, { style: [styles.hiddenContent, modalStyle] }, renderedChildren)),
107
+ !headerHeightKnown && (React.createElement(View, { style: [styles.hiddenContent, modalStyle] }, renderedHeader))));
108
+ function renderHeader() {
109
+ const closeOverlayA11YLabel = formatMessage(messages.closeOverlayA11YLabel, {
110
+ title: title,
111
+ });
112
+ const headerStyles = [
113
+ styles.header,
114
+ showHeaderShadow && styles.headerShadow,
115
+ { backgroundColor: getModalBackgroundColor(modalBackgroundColor) },
116
+ ];
117
+ return (React.createElement(View, { onLayout: handleHeaderLayout, testID: "ATL-Overlay-Header" },
118
+ React.createElement(View, { style: headerStyles },
119
+ React.createElement(View, { style: showDismiss ? styles.titleWithDismiss : styles.titleWithoutDimiss },
120
+ React.createElement(Heading, { level: "subtitle", variation: loading ? "subdued" : "heading" }, title)),
121
+ shouldShowDismiss && (React.createElement(View, { style: styles.dismissButton,
122
+ // @ts-expect-error tsc-ci
123
+ ref: overlayHeader, accessibilityLabel: accessibilityLabel || closeOverlayA11YLabel, accessible: true },
124
+ React.createElement(IconButton, { name: "cross", customColor: loading ? tokens["color-disabled"] : tokens["color-heading"], onPress: () => onCloseController(), accessibilityLabel: closeOverlayA11YLabel, testID: "ATL-Overlay-CloseButton" }))))));
125
+ }
126
+ function renderChildren() {
127
+ return (React.createElement(View, { style: { paddingBottom: insets.bottom }, onLayout: handleChildrenLayout, testID: "ATL-Overlay-Children" }, children));
128
+ }
129
+ function handleOnScroll({ nativeEvent, }) {
130
+ setShowHeaderShadow(nativeEvent.contentOffset.y > 0);
131
+ }
132
+ function getModalBackgroundColor(variation) {
133
+ switch (variation) {
134
+ case "surface":
135
+ return tokens["color-surface"];
136
+ case "background":
137
+ return tokens["color-surface--background"];
138
+ }
139
+ }
140
+ }
141
+ function ContentOverlayPortal(modalProps, ref) {
142
+ return (React.createElement(Portal, null,
143
+ React.createElement(ContentOverlayModal, Object.assign({ ref: ref }, modalProps))));
144
+ }
@@ -0,0 +1,56 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ const modalBorderRadius = tokens["radius-larger"];
4
+ const titleOffsetFromHandle = tokens["space-small"] + tokens["space-smallest"];
5
+ export const styles = StyleSheet.create({
6
+ handle: {
7
+ width: tokens["space-largest"],
8
+ height: tokens["space-smaller"] + tokens["space-smallest"],
9
+ backgroundColor: tokens["color-border"],
10
+ top: tokens["space-small"],
11
+ borderRadius: tokens["radius-circle"],
12
+ },
13
+ overlay: {
14
+ backgroundColor: tokens["color-overlay"],
15
+ },
16
+ modal: {
17
+ borderTopLeftRadius: modalBorderRadius,
18
+ borderTopRightRadius: modalBorderRadius,
19
+ },
20
+ modalForLargeScreens: {
21
+ width: 640,
22
+ alignSelf: "center",
23
+ },
24
+ header: {
25
+ flexDirection: "row",
26
+ backgroundColor: tokens["color-surface"],
27
+ paddingTop: titleOffsetFromHandle,
28
+ zIndex: tokens["elevation-base"],
29
+ borderTopLeftRadius: modalBorderRadius,
30
+ borderTopRightRadius: modalBorderRadius,
31
+ height: tokens["space-extravagant"],
32
+ },
33
+ headerShadow: Object.assign({}, tokens["shadow-base"]),
34
+ childrenStyle: {
35
+ // We need to explicity lower the zIndex because otherwise, the modal content slides over the header shadow.
36
+ zIndex: -1,
37
+ },
38
+ dismissButton: {
39
+ alignItems: "center",
40
+ },
41
+ hiddenContent: {
42
+ opacity: 0,
43
+ },
44
+ titleWithoutDimiss: {
45
+ flex: 1,
46
+ flexDirection: "row",
47
+ justifyContent: "center",
48
+ paddingTop: tokens["space-base"],
49
+ },
50
+ titleWithDismiss: {
51
+ flex: 1,
52
+ justifyContent: "center",
53
+ paddingLeft: tokens["space-base"],
54
+ paddingRight: tokens["space-smaller"],
55
+ },
56
+ });
@@ -0,0 +1,21 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Keyboard } from "react-native";
3
+ export function useKeyboardVisibility() {
4
+ const [isKeyboardVisible, setKeyboardVisible] = useState(false);
5
+ const [keyboardHeight, setKeyboardHeight] = useState(0);
6
+ useEffect(() => {
7
+ const keyboardDidShowListener = Keyboard.addListener("keyboardDidShow", (event) => {
8
+ setKeyboardVisible(true);
9
+ setKeyboardHeight(event.endCoordinates.height);
10
+ });
11
+ const keyboardDidHideListener = Keyboard.addListener("keyboardDidHide", () => {
12
+ setKeyboardVisible(false);
13
+ setKeyboardHeight(0);
14
+ });
15
+ return () => {
16
+ keyboardDidHideListener.remove();
17
+ keyboardDidShowListener.remove();
18
+ };
19
+ }, []);
20
+ return { isKeyboardVisible, keyboardHeight };
21
+ }
@@ -0,0 +1,10 @@
1
+ import { useState } from "react";
2
+ export function useViewLayoutHeight() {
3
+ const [heightKnown, setHeightKnown] = useState(false);
4
+ const [height, setHeight] = useState(0);
5
+ const handleLayout = ({ nativeEvent }) => {
6
+ setHeightKnown(true);
7
+ setHeight(nativeEvent.layout.height);
8
+ };
9
+ return { handleLayout, height, heightKnown };
10
+ }
@@ -0,0 +1 @@
1
+ export { ContentOverlay } from "./ContentOverlay";
@@ -0,0 +1,8 @@
1
+ import { defineMessages } from "react-intl";
2
+ export const messages = defineMessages({
3
+ closeOverlayA11YLabel: {
4
+ id: "closeOverlayA11yLabel",
5
+ defaultMessage: "Close {title} modal",
6
+ description: "Accessibility label for button to close the overlay modal",
7
+ },
8
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import React, { useState } from "react";
2
+ import { ScrollView, TouchableOpacity, View, } from "react-native";
3
+ import Reanimated, { Easing, useAnimatedStyle, useSharedValue, withTiming, } from "react-native-reanimated";
4
+ import { EASE_CUBIC_IN_OUT } from "./constants";
5
+ import { styles } from "./Disclosure.style";
6
+ import { tokens } from "../utils/design";
7
+ import { Icon } from "../Icon";
8
+ const ReanimatedView = Reanimated.createAnimatedComponent(View);
9
+ const ReanimatedScrollView = Reanimated.createAnimatedComponent(ScrollView);
10
+ export function Disclosure({ content, header, open, onToggle, isEmpty, animationDuration = tokens["timing-slowest"], }) {
11
+ return (React.createElement(View, { style: styles.container },
12
+ React.createElement(DisclosureHeader, Object.assign({}, { header, onToggle, isEmpty, open, animationDuration })),
13
+ React.createElement(DisclosureContent, Object.assign({}, { content, open, animationDuration }))));
14
+ }
15
+ function DisclosureHeader({ header, onToggle, isEmpty, open, animationDuration, }) {
16
+ const rotateZ = useSharedValue(0);
17
+ rotateZ.value = withTiming(open ? 0 : -180, {
18
+ easing: Easing.bezier(...EASE_CUBIC_IN_OUT),
19
+ duration: animationDuration,
20
+ });
21
+ const animatedStyle = useAnimatedStyle(() => {
22
+ return {
23
+ transform: [{ rotateZ: `${rotateZ.value}deg` }],
24
+ };
25
+ });
26
+ return (React.createElement(TouchableOpacity, { activeOpacity: tokens["opacity-pressed"], onPress: onToggle, disabled: isEmpty },
27
+ React.createElement(View, { style: styles.headerContainer },
28
+ header,
29
+ !isEmpty && (React.createElement(ReanimatedView, { style: [animatedStyle] },
30
+ React.createElement(Icon, { name: "arrowUp", color: "grey" }))))));
31
+ }
32
+ function DisclosureContent({ content, open, animationDuration, }) {
33
+ const [maxHeight, setMaxHeight] = useState(0);
34
+ const height = useSharedValue(0);
35
+ const onContentLayoutChange = (event) => {
36
+ const newHeight = event.nativeEvent.layout.height;
37
+ setMaxHeight(newHeight);
38
+ };
39
+ height.value = withTiming(open ? maxHeight : 0, {
40
+ duration: animationDuration,
41
+ easing: Easing.bezier(...EASE_CUBIC_IN_OUT),
42
+ });
43
+ const animatedStyle = useAnimatedStyle(() => {
44
+ return {
45
+ height: height.value,
46
+ };
47
+ }, []);
48
+ return (React.createElement(ReanimatedScrollView, { scrollEnabled: false, showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, style: [styles.contentContainer, animatedStyle] },
49
+ React.createElement(View, { testID: "content", onLayout: onContentLayoutChange }, content)));
50
+ }
@@ -0,0 +1,21 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ width: "100%",
6
+ },
7
+ headerContainer: {
8
+ flexDirection: "row",
9
+ alignItems: "flex-start",
10
+ justifyContent: "space-between",
11
+ },
12
+ countColumn: {
13
+ paddingRight: tokens["space-base"],
14
+ },
15
+ titleContainer: {
16
+ flexDirection: "row",
17
+ },
18
+ contentContainer: {
19
+ paddingTop: tokens["space-small"],
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export const EASE_CUBIC_IN_OUT = [0.645, 0.045, 0.355, 1.0];
@@ -0,0 +1 @@
1
+ export { Disclosure } from "./Disclosure";
@@ -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";