@jobber/components-native 0.22.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.
Files changed (42) hide show
  1. package/dist/src/Switch/Switch.js +16 -0
  2. package/dist/src/Switch/Switch.styles.js +20 -0
  3. package/dist/src/Switch/components/BaseSwitch/BaseSwitch.js +54 -0
  4. package/dist/src/Switch/components/BaseSwitch/index.js +1 -0
  5. package/dist/src/Switch/index.js +1 -0
  6. package/dist/src/Toast/Toast.js +64 -0
  7. package/dist/src/Toast/Toast.styles.js +30 -0
  8. package/dist/src/Toast/index.js +1 -0
  9. package/dist/src/Toast/messages.js +13 -0
  10. package/dist/src/index.js +2 -0
  11. package/dist/src/utils/test/MockSafeAreaProvider.js +10 -0
  12. package/dist/src/utils/test/index.js +1 -0
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/dist/types/src/Switch/Switch.d.ts +16 -0
  15. package/dist/types/src/Switch/Switch.styles.d.ts +18 -0
  16. package/dist/types/src/Switch/components/BaseSwitch/BaseSwitch.d.ts +28 -0
  17. package/dist/types/src/Switch/components/BaseSwitch/index.d.ts +2 -0
  18. package/dist/types/src/Switch/index.d.ts +1 -0
  19. package/dist/types/src/Toast/Toast.d.ts +28 -0
  20. package/dist/types/src/Toast/Toast.styles.d.ts +31 -0
  21. package/dist/types/src/Toast/index.d.ts +2 -0
  22. package/dist/types/src/Toast/messages.d.ts +12 -0
  23. package/dist/types/src/index.d.ts +2 -0
  24. package/dist/types/src/utils/test/MockSafeAreaProvider.d.ts +9 -0
  25. package/dist/types/src/utils/test/index.d.ts +1 -0
  26. package/package.json +4 -2
  27. package/src/Switch/Switch.styles.ts +21 -0
  28. package/src/Switch/Switch.test.tsx +98 -0
  29. package/src/Switch/Switch.tsx +58 -0
  30. package/src/Switch/components/BaseSwitch/BaseSwitch.test.tsx +62 -0
  31. package/src/Switch/components/BaseSwitch/BaseSwitch.tsx +107 -0
  32. package/src/Switch/components/BaseSwitch/__snapshots__/BaseSwitch.test.tsx.snap +217 -0
  33. package/src/Switch/components/BaseSwitch/index.ts +2 -0
  34. package/src/Switch/index.ts +1 -0
  35. package/src/Toast/Toast.styles.ts +31 -0
  36. package/src/Toast/Toast.test.tsx +74 -0
  37. package/src/Toast/Toast.tsx +128 -0
  38. package/src/Toast/index.ts +2 -0
  39. package/src/Toast/messages.ts +14 -0
  40. package/src/index.ts +2 -0
  41. package/src/utils/test/MockSafeAreaProvider.tsx +32 -0
  42. package/src/utils/test/index.ts +1 -0
@@ -0,0 +1,16 @@
1
+ import React, { useState } from "react";
2
+ import { View } from "react-native";
3
+ import { BaseSwitch } from "./components/BaseSwitch";
4
+ import { styles } from "./Switch.styles";
5
+ import { Text } from "../Text";
6
+ export function Switch(props) {
7
+ const switchProps = Object.assign(Object.assign({}, props), { accessibilityLabel: props.accessibilityLabel || props.label });
8
+ const [labelWidth, setLabelWidth] = useState();
9
+ return (React.createElement(View, { style: styles.container },
10
+ React.createElement(View, { style: styles.row },
11
+ props.label && (React.createElement(View, { style: styles.label, onLayout: event => setLabelWidth(event.nativeEvent.layout.width), testID: "switch-label-view" },
12
+ React.createElement(Text, { variation: props.disabled ? "disabled" : "base" }, props.label))),
13
+ React.createElement(BaseSwitch, Object.assign({}, switchProps))),
14
+ props.description && (React.createElement(View, { style: [styles.description, { maxWidth: labelWidth }], testID: "switch-description-view" },
15
+ React.createElement(Text, { level: "textSupporting", variation: "subdued" }, props.description)))));
16
+ }
@@ -0,0 +1,20 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ marginTop: tokens["space-base"],
6
+ marginBottom: tokens["space-base"],
7
+ },
8
+ row: {
9
+ flexDirection: "row",
10
+ width: "100%",
11
+ },
12
+ label: {
13
+ flex: 1,
14
+ justifyContent: "center",
15
+ marginRight: tokens["space-small"],
16
+ },
17
+ description: {
18
+ marginTop: tokens["space-smaller"],
19
+ },
20
+ });
@@ -0,0 +1,54 @@
1
+ import React from "react";
2
+ import { Platform } from "react-native";
3
+ import { Switch } from "react-native-gesture-handler";
4
+ import { useFormController } from "../../../hooks";
5
+ import { tokens } from "../../../utils/design";
6
+ export function BaseSwitch({ value, defaultValue, onValueChange, disabled = false, accessibilityLabel, name, }) {
7
+ const { field } = useFormController({
8
+ name,
9
+ value: value !== null && value !== void 0 ? value : defaultValue,
10
+ });
11
+ const internalValue = value !== null && value !== void 0 ? value : field.value;
12
+ function getThumbColor() {
13
+ if (Platform.OS === "android") {
14
+ if (disabled) {
15
+ return tokens["color-disabled"];
16
+ }
17
+ else if (internalValue) {
18
+ return tokens["color-interactive"];
19
+ }
20
+ else {
21
+ return tokens["color-surface--background"];
22
+ }
23
+ }
24
+ return undefined; //use default iOS
25
+ }
26
+ function getTrackColors() {
27
+ if (Platform.OS === "android") {
28
+ return {
29
+ true: disabled
30
+ ? tokens["color-disabled--secondary"]
31
+ : tokens["color-green--lighter"],
32
+ false: disabled
33
+ ? tokens["color-disabled--secondary"]
34
+ : tokens["color-disabled"],
35
+ };
36
+ }
37
+ else {
38
+ //iOS
39
+ return {
40
+ true: tokens["color-interactive"],
41
+ false: tokens["color-surface--background"],
42
+ };
43
+ }
44
+ }
45
+ return (React.createElement(Switch, { value: internalValue, onValueChange: (val) => {
46
+ if (!disabled) {
47
+ onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(val);
48
+ field.onChange(val);
49
+ }
50
+ }, disabled: disabled, thumbColor: getThumbColor(), trackColor: getTrackColors(), ios_backgroundColor: tokens["color-surface--background"], accessibilityLabel: accessibilityLabel, accessibilityRole: "switch", accessibilityState: {
51
+ disabled: disabled,
52
+ checked: internalValue,
53
+ } }));
54
+ }
@@ -0,0 +1 @@
1
+ export { BaseSwitch } from "./BaseSwitch";
@@ -0,0 +1 @@
1
+ export { Switch } from "./Switch";
@@ -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
@@ -18,5 +18,7 @@ export * from "./InputPressable";
18
18
  export * from "./InputText";
19
19
  export * from "./ProgressBar";
20
20
  export * from "./StatusLabel";
21
+ export * from "./Switch";
21
22
  export * from "./Text";
23
+ export * from "./Toast";
22
24
  export * from "./Typography";
@@ -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";