@jobber/components-native 0.23.0 → 0.24.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.
- package/dist/src/Toast/Toast.js +64 -0
- package/dist/src/Toast/Toast.styles.js +30 -0
- package/dist/src/Toast/index.js +1 -0
- package/dist/src/Toast/messages.js +13 -0
- package/dist/src/index.js +1 -0
- package/dist/src/utils/test/MockSafeAreaProvider.js +10 -0
- package/dist/src/utils/test/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Toast/Toast.d.ts +28 -0
- package/dist/types/src/Toast/Toast.styles.d.ts +31 -0
- package/dist/types/src/Toast/index.d.ts +2 -0
- package/dist/types/src/Toast/messages.d.ts +12 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/utils/test/MockSafeAreaProvider.d.ts +9 -0
- package/dist/types/src/utils/test/index.d.ts +1 -0
- package/package.json +4 -2
- package/src/Toast/Toast.styles.ts +31 -0
- package/src/Toast/Toast.test.tsx +74 -0
- package/src/Toast/Toast.tsx +128 -0
- package/src/Toast/index.ts +2 -0
- package/src/Toast/messages.ts +14 -0
- package/src/index.ts +1 -0
- package/src/utils/test/MockSafeAreaProvider.tsx +32 -0
- package/src/utils/test/index.ts +1 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Toast from "react-native-toast-message";
|
|
3
|
+
import { AccessibilityInfo, TouchableOpacity, View } from "react-native";
|
|
4
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
|
+
import { useIntl } from "react-intl";
|
|
6
|
+
import { styles } from "./Toast.styles";
|
|
7
|
+
import { messages } from "./messages";
|
|
8
|
+
import { tokens } from "../utils/design";
|
|
9
|
+
import { Text } from "../Text";
|
|
10
|
+
import { IconButton } from "../IconButton";
|
|
11
|
+
const MAX_TOAST_MESSAGE_LENGTH = 60;
|
|
12
|
+
const ANNOUNCEMENT_DELAY = 100;
|
|
13
|
+
function DefaultToast({ text1 }) {
|
|
14
|
+
const { bottom } = useSafeAreaInsets();
|
|
15
|
+
const { formatMessage } = useIntl();
|
|
16
|
+
const toastContainerStyles = [styles.container, { paddingBottom: bottom }];
|
|
17
|
+
return (React.createElement(View, { style: toastContainerStyles },
|
|
18
|
+
React.createElement(View, { style: styles.toast },
|
|
19
|
+
React.createElement(TouchableOpacity, { style: styles.toastMessage, accessibilityRole: "alert", accessibilityLabel: formatMessage(messages.toastNotificationLabel) },
|
|
20
|
+
React.createElement(Text, { reverseTheme: true }, text1)),
|
|
21
|
+
React.createElement(View, { style: styles.toastIcon },
|
|
22
|
+
React.createElement(IconButton, { onPress: Toast.hide, name: "remove", customColor: tokens["color-greyBlue--light"], accessibilityLabel: formatMessage(messages.dismissA11yLabel) })))));
|
|
23
|
+
}
|
|
24
|
+
const toastConfig = {
|
|
25
|
+
default: DefaultToast,
|
|
26
|
+
};
|
|
27
|
+
export function JobberToast({ bottomOffset }) {
|
|
28
|
+
return React.createElement(Toast, { bottomOffset: bottomOffset, config: toastConfig });
|
|
29
|
+
}
|
|
30
|
+
export function showToast({ message, bottomTabsVisible, position = "bottom", }) {
|
|
31
|
+
const bottomOffset = getBottomTabsOffset(bottomTabsVisible);
|
|
32
|
+
const maxDuration = 10000;
|
|
33
|
+
const minDuration = 5000;
|
|
34
|
+
let visibilityTime = message.length * 200;
|
|
35
|
+
if (visibilityTime > maxDuration) {
|
|
36
|
+
visibilityTime = maxDuration;
|
|
37
|
+
}
|
|
38
|
+
else if (visibilityTime < minDuration) {
|
|
39
|
+
visibilityTime = minDuration;
|
|
40
|
+
}
|
|
41
|
+
if (message.length > MAX_TOAST_MESSAGE_LENGTH) {
|
|
42
|
+
console.warn(`Jobber Design Warning: Message length limit exceeded, your current length is ${message.length}, the maximum allowed is ${MAX_TOAST_MESSAGE_LENGTH}. please talk with your designer`);
|
|
43
|
+
}
|
|
44
|
+
Toast.show({
|
|
45
|
+
type: "default",
|
|
46
|
+
text1: message,
|
|
47
|
+
visibilityTime,
|
|
48
|
+
bottomOffset,
|
|
49
|
+
position,
|
|
50
|
+
onShow: () => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
AccessibilityInfo.announceForAccessibility(message || "");
|
|
53
|
+
}, ANNOUNCEMENT_DELAY);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function getBottomTabsOffset(bottomTabsVisible) {
|
|
58
|
+
const navBarHeight = tokens["space-largest"] + tokens["space-small"];
|
|
59
|
+
const navBarBorderTopWidth = tokens["space-minuscule"];
|
|
60
|
+
if (bottomTabsVisible) {
|
|
61
|
+
return navBarHeight + navBarBorderTopWidth + tokens["space-base"];
|
|
62
|
+
}
|
|
63
|
+
return tokens["space-base"];
|
|
64
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
export const styles = StyleSheet.create({
|
|
4
|
+
container: {
|
|
5
|
+
flexDirection: "row",
|
|
6
|
+
paddingHorizontal: tokens["space-base"],
|
|
7
|
+
paddingBottom: tokens["space-base"],
|
|
8
|
+
},
|
|
9
|
+
toast: {
|
|
10
|
+
flexDirection: "row",
|
|
11
|
+
justifyContent: "space-between",
|
|
12
|
+
width: "100%",
|
|
13
|
+
maxWidth: 540,
|
|
14
|
+
paddingVertical: tokens["space-small"],
|
|
15
|
+
backgroundColor: tokens["color-blue"],
|
|
16
|
+
borderRadius: 6,
|
|
17
|
+
shadowOffset: { width: 0, height: 0 },
|
|
18
|
+
shadowOpacity: 0.1,
|
|
19
|
+
shadowRadius: 6,
|
|
20
|
+
},
|
|
21
|
+
toastMessage: {
|
|
22
|
+
justifyContent: "center",
|
|
23
|
+
paddingLeft: tokens["space-base"],
|
|
24
|
+
paddingVertical: tokens["space-small"],
|
|
25
|
+
flexShrink: 1,
|
|
26
|
+
},
|
|
27
|
+
toastIcon: {
|
|
28
|
+
justifyContent: "center",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { JobberToast as Toast, showToast } from "./Toast";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineMessages } from "react-intl";
|
|
2
|
+
export const messages = defineMessages({
|
|
3
|
+
toastNotificationLabel: {
|
|
4
|
+
id: "toastNotificationLabel",
|
|
5
|
+
defaultMessage: "Toast Notification",
|
|
6
|
+
description: "Accessibility label for the Toast",
|
|
7
|
+
},
|
|
8
|
+
dismissA11yLabel: {
|
|
9
|
+
id: "dismissA11yLabel",
|
|
10
|
+
defaultMessage: "Dismiss toast notification",
|
|
11
|
+
description: "Accessibility label to dismiss the toast when pressing X",
|
|
12
|
+
},
|
|
13
|
+
});
|
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SafeAreaProvider, } from "react-native-safe-area-context";
|
|
3
|
+
export function MockSafeAreaProvider({ frame, insets, children, }) {
|
|
4
|
+
const initialFrame = { x: 0, y: 0, width: 0, height: 0 };
|
|
5
|
+
const initialInsets = { bottom: 50, top: 50, left: 0, right: 0 };
|
|
6
|
+
return (React.createElement(SafeAreaProvider, { initialMetrics: {
|
|
7
|
+
frame: frame || initialFrame,
|
|
8
|
+
insets: insets || initialInsets,
|
|
9
|
+
} }, children));
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MockSafeAreaProvider } from "./MockSafeAreaProvider";
|