@jobber/components-native 0.93.0 → 0.95.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/package.json +4 -2
- package/dist/src/BottomSheet/BottomSheet.js +58 -32
- package/dist/src/BottomSheet/BottomSheet.style.js +8 -9
- package/dist/src/BottomSheet/hooks/useBottomSheetBackHandler.js +26 -0
- package/dist/src/InputText/InputText.js +2 -2
- package/dist/src/ProgressBar/ProgressBar.js +10 -6
- package/dist/src/ProgressBar/ProgressBarInner.js +3 -12
- package/dist/src/ProgressBar/ProgressBarStepped.js +7 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/BottomSheet/BottomSheet.d.ts +7 -3
- package/dist/types/src/BottomSheet/BottomSheet.style.d.ts +7 -14
- package/dist/types/src/BottomSheet/hooks/useBottomSheetBackHandler.d.ts +8 -0
- package/dist/types/src/InputText/InputText.d.ts +1 -1
- package/dist/types/src/ProgressBar/ProgressBar.d.ts +1 -1
- package/dist/types/src/ProgressBar/ProgressBarInner.d.ts +4 -1
- package/dist/types/src/ProgressBar/ProgressBarStepped.d.ts +3 -1
- package/dist/types/src/ProgressBar/types.d.ts +20 -0
- package/package.json +4 -2
- package/src/BottomSheet/BottomSheet.stories.tsx +128 -0
- package/src/BottomSheet/BottomSheet.style.ts +7 -14
- package/src/BottomSheet/BottomSheet.test.tsx +19 -24
- package/src/BottomSheet/BottomSheet.tsx +112 -93
- package/src/BottomSheet/hooks/useBottomSheetBackHandler.test.ts +90 -0
- package/src/BottomSheet/hooks/useBottomSheetBackHandler.ts +41 -0
- package/src/InputText/InputText.tsx +3 -3
- package/src/ProgressBar/ProgressBar.test.tsx +109 -0
- package/src/ProgressBar/ProgressBar.tsx +17 -1
- package/src/ProgressBar/ProgressBarInner.tsx +7 -10
- package/src/ProgressBar/ProgressBarStepped.tsx +12 -1
- package/src/ProgressBar/__snapshots__/ProgressBar.test.tsx.snap +14 -0
- package/src/ProgressBar/types.ts +22 -0
- package/src/ThumbnailList/__snapshots__/ThumbnailList.test.tsx.snap +199 -1
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.95.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"ts-xor": "^1.1.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
+
"@gorhom/bottom-sheet": "^5.2.8",
|
|
56
57
|
"@react-native-community/datetimepicker": "^8.4.5",
|
|
57
58
|
"@react-native/babel-preset": "^0.82.1",
|
|
58
59
|
"@storybook/addon-a11y": "^9.1.2",
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
},
|
|
79
80
|
"peerDependencies": {
|
|
80
81
|
"@babel/core": "^7.4.5",
|
|
82
|
+
"@gorhom/bottom-sheet": "^5.2.8",
|
|
81
83
|
"@jobber/design": "*",
|
|
82
84
|
"@react-native-community/datetimepicker": ">=6.7.0",
|
|
83
85
|
"date-fns": "^2.30.0",
|
|
@@ -94,5 +96,5 @@
|
|
|
94
96
|
"react-native-safe-area-context": "^5.4.0",
|
|
95
97
|
"react-native-svg": ">=12.0.0"
|
|
96
98
|
},
|
|
97
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "ea9cbb709f05442a469763a4f12a332a59cb6350"
|
|
98
100
|
}
|
|
@@ -1,52 +1,78 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
1
|
+
import React, { useCallback, useImperativeHandle, useRef } from "react";
|
|
3
2
|
import { Keyboard, View } from "react-native";
|
|
4
|
-
import {
|
|
3
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
|
+
import RNBottomSheet, { BottomSheetBackdrop, BottomSheetView, } from "@gorhom/bottom-sheet";
|
|
5
|
+
import { tokens } from "@jobber/design";
|
|
5
6
|
import { useStyles } from "./BottomSheet.style";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { BottomSheetOption } from "./components/BottomSheetOption";
|
|
8
|
+
import { useBottomSheetBackHandler } from "./hooks/useBottomSheetBackHandler";
|
|
8
9
|
import { Divider } from "../Divider";
|
|
9
10
|
import { Heading } from "../Heading";
|
|
11
|
+
import { useIsScreenReaderEnabled } from "../hooks";
|
|
10
12
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
11
|
-
export
|
|
12
|
-
function BottomSheetInternal({ children, showCancel, loading = false, heading, onOpen, onClose, }, ref) {
|
|
13
|
-
const isScreenReaderEnabled = useIsScreenReaderEnabled();
|
|
14
|
-
const [open, setOpen] = useState(false);
|
|
13
|
+
export function BottomSheet({ children, showCancel, loading = false, heading, onOpen, onClose, ref, }) {
|
|
15
14
|
const styles = useStyles();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
15
|
+
const isScreenReaderEnabled = useIsScreenReaderEnabled();
|
|
16
|
+
const cancellable = (showCancel && !loading) || isScreenReaderEnabled;
|
|
17
|
+
const { t } = useAtlantisI18n();
|
|
18
|
+
const insets = useSafeAreaInsets();
|
|
19
|
+
const previousIndexRef = useRef(-1);
|
|
20
|
+
const bottomSheetRef = useRef(null);
|
|
21
|
+
const { handleSheetPositionChange } = useBottomSheetBackHandler(bottomSheetRef);
|
|
22
|
+
useImperativeHandle(ref, () => ({
|
|
23
|
+
open: () => {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.expand();
|
|
26
|
+
},
|
|
27
|
+
close: () => {
|
|
28
|
+
close();
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
const close = useCallback(() => {
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
34
|
+
}, []);
|
|
35
|
+
const handleChange = (index) => {
|
|
36
|
+
// Handle Android back button
|
|
37
|
+
handleSheetPositionChange(index);
|
|
38
|
+
const previousIndex = previousIndexRef.current;
|
|
39
|
+
if (previousIndex === -1 && index >= 0) {
|
|
40
|
+
// Transitioned from closed to open
|
|
41
|
+
dismissKeyboard();
|
|
42
|
+
onOpen === null || onOpen === void 0 ? void 0 : onOpen();
|
|
43
|
+
}
|
|
44
|
+
else if (previousIndex >= 0 && index === -1) {
|
|
45
|
+
// Transitioned from open to closed
|
|
46
|
+
dismissKeyboard();
|
|
47
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
48
|
+
}
|
|
49
|
+
previousIndexRef.current = index;
|
|
50
|
+
};
|
|
51
|
+
return (React.createElement(RNBottomSheet, { ref: bottomSheetRef, index: -1, backdropComponent: Backdrop, backgroundStyle: styles.background, enablePanDownToClose: true, onChange: handleChange, keyboardBlurBehavior: "restore", handleStyle: styles.handle },
|
|
52
|
+
React.createElement(BottomSheetView, { style: {
|
|
53
|
+
paddingBottom: insets.bottom + tokens["space-small"],
|
|
54
|
+
paddingTop: tokens["space-small"],
|
|
55
|
+
} },
|
|
56
|
+
heading && React.createElement(Header, { heading: heading, styles: styles }),
|
|
57
|
+
children,
|
|
58
|
+
cancellable && (React.createElement(Footer, { styles: styles, close: close, cancelLabel: t("cancel") })))));
|
|
32
59
|
}
|
|
33
60
|
function Header({ heading, styles, }) {
|
|
34
61
|
return (React.createElement(View, { style: styles.header },
|
|
35
62
|
React.createElement(Heading, { level: "subtitle" }, heading)));
|
|
36
63
|
}
|
|
37
|
-
function Footer({
|
|
38
|
-
|
|
39
|
-
const { t } = useAtlantisI18n();
|
|
40
|
-
return (React.createElement(View, { style: { marginBottom: insets.bottom } }, cancellable && (React.createElement(View, { style: styles.children },
|
|
64
|
+
function Footer({ styles, close, cancelLabel, }) {
|
|
65
|
+
return (React.createElement(View, null,
|
|
41
66
|
React.createElement(View, { style: styles.footerDivider },
|
|
42
67
|
React.createElement(Divider, null)),
|
|
43
|
-
React.createElement(BottomSheetOption, { text:
|
|
68
|
+
React.createElement(BottomSheetOption, { text: cancelLabel, icon: "remove", onPress: close })));
|
|
44
69
|
}
|
|
45
70
|
function dismissKeyboard() {
|
|
46
71
|
//Dismisses the keyboard before opening the bottom sheet.
|
|
47
72
|
//In the case where an input text field is focused we don't want to show the bottom sheet behind or above keyboard
|
|
48
73
|
Keyboard.dismiss();
|
|
49
74
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
75
|
+
function Backdrop(bottomSheetBackdropProps) {
|
|
76
|
+
const styles = useStyles();
|
|
77
|
+
return (React.createElement(BottomSheetBackdrop, Object.assign({}, bottomSheetBackdropProps, { appearsOnIndex: 0, disappearsOnIndex: -1, style: styles.backdrop, opacity: 1 })));
|
|
52
78
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { Dimensions, StyleSheet } from "react-native";
|
|
2
1
|
import { buildThemedStyles } from "../AtlantisThemeContext";
|
|
3
|
-
const { height } = Dimensions.get("window");
|
|
4
2
|
export const useStyles = buildThemedStyles(tokens => {
|
|
5
3
|
const modalBorderRadius = tokens["radius-larger"];
|
|
6
4
|
return {
|
|
7
|
-
|
|
8
|
-
backgroundColor: "
|
|
5
|
+
backdrop: {
|
|
6
|
+
backgroundColor: tokens["color-overlay"],
|
|
9
7
|
},
|
|
10
|
-
|
|
11
|
-
modal: {
|
|
8
|
+
background: {
|
|
12
9
|
borderTopLeftRadius: modalBorderRadius,
|
|
13
10
|
borderTopRightRadius: modalBorderRadius,
|
|
14
|
-
paddingTop: tokens["space-small"],
|
|
15
11
|
},
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
footerContainer: {
|
|
13
|
+
backgroundColor: tokens["color-surface"],
|
|
18
14
|
},
|
|
19
15
|
header: {
|
|
20
16
|
paddingHorizontal: tokens["space-base"],
|
|
@@ -26,5 +22,8 @@ export const useStyles = buildThemedStyles(tokens => {
|
|
|
26
22
|
marginTop: tokens["space-small"],
|
|
27
23
|
marginBottom: tokens["space-smaller"],
|
|
28
24
|
},
|
|
25
|
+
handle: {
|
|
26
|
+
display: "none",
|
|
27
|
+
},
|
|
29
28
|
};
|
|
30
29
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
import { BackHandler } from "react-native";
|
|
3
|
+
/**
|
|
4
|
+
* Hook that closes the bottom sheet on the hardware back button press if it is visible
|
|
5
|
+
* @param bottomSheetRef ref to the bottom sheet component
|
|
6
|
+
*/
|
|
7
|
+
export function useBottomSheetBackHandler(bottomSheetRef) {
|
|
8
|
+
const backHandlerSubscriptionRef = useRef(null);
|
|
9
|
+
const handleSheetPositionChange = useCallback((index) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const isBottomSheetVisible = index >= 0;
|
|
12
|
+
if (isBottomSheetVisible && !backHandlerSubscriptionRef.current) {
|
|
13
|
+
// Setup the back handler if the bottom sheet is right in front of the user
|
|
14
|
+
backHandlerSubscriptionRef.current = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = bottomSheetRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
17
|
+
return true;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else if (!isBottomSheetVisible) {
|
|
21
|
+
(_a = backHandlerSubscriptionRef.current) === null || _a === void 0 ? void 0 : _a.remove();
|
|
22
|
+
backHandlerSubscriptionRef.current = null;
|
|
23
|
+
}
|
|
24
|
+
}, [bottomSheetRef]);
|
|
25
|
+
return { handleSheetPositionChange };
|
|
26
|
+
}
|
|
@@ -93,10 +93,10 @@ function InputTextInternal({ invalid, disabled, readonly = false, name, placehol
|
|
|
93
93
|
_name && setFocusedInput(_name);
|
|
94
94
|
setFocused(true);
|
|
95
95
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
96
|
-
}, onBlur:
|
|
96
|
+
}, onBlur: event => {
|
|
97
97
|
_name && setFocusedInput("");
|
|
98
98
|
setFocused(false);
|
|
99
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
99
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
100
100
|
field.onBlur();
|
|
101
101
|
trimWhitespace(inputTransform(field.value), updateFormAndState);
|
|
102
102
|
}, ref: (instance) => {
|
|
@@ -6,17 +6,21 @@ import { ProgressBarStepped } from "./ProgressBarStepped";
|
|
|
6
6
|
import { sizeStyles } from "./ProgressBar.size.style";
|
|
7
7
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
8
8
|
import { useAtlantisTheme } from "../AtlantisThemeContext";
|
|
9
|
-
export function ProgressBar({ loading, total, current, inProgress = 0, reverseTheme = false, header, variation = "progress", size = "base", }) {
|
|
9
|
+
export function ProgressBar({ loading, total, current, inProgress = 0, reverseTheme = false, header, variation = "progress", size = "base", UNSAFE_style, }) {
|
|
10
10
|
const { t } = useAtlantisI18n();
|
|
11
11
|
const styles = useStyles();
|
|
12
12
|
const { tokens } = useAtlantisTheme();
|
|
13
|
-
return (React.createElement(View, { accessible: true, accessibilityRole: "progressbar", accessibilityLabel: getA11yLabel() },
|
|
13
|
+
return (React.createElement(View, { accessible: true, accessibilityRole: "progressbar", accessibilityLabel: getA11yLabel(), style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.container },
|
|
14
14
|
header,
|
|
15
|
-
variation === "stepped" ? (React.createElement(ProgressBarStepped, { total: total, current: current, color: reverseTheme ? undefined : tokens["color-interactive--background"], loading: loading, inProgress: inProgress })) : (React.createElement(View, {
|
|
16
|
-
|
|
15
|
+
variation === "stepped" ? (React.createElement(ProgressBarStepped, { total: total, current: current, color: reverseTheme ? undefined : tokens["color-interactive--background"], loading: loading, inProgress: inProgress, UNSAFE_style: UNSAFE_style })) : (React.createElement(View, { testID: "progressbar-container", style: [
|
|
16
|
+
styles.progressBarContainer,
|
|
17
|
+
sizeStyles[size],
|
|
18
|
+
UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.progressBarContainer,
|
|
19
|
+
] },
|
|
20
|
+
React.createElement(ProgressBarInner, { testID: "progressbar-track", width: 100, animationDuration: 0, color: reverseTheme ? undefined : tokens["color-interactive--background"], style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.track }),
|
|
17
21
|
!loading && (React.createElement(React.Fragment, null,
|
|
18
|
-
inProgress && inProgress > 0 ? (React.createElement(ProgressBarInner, { width: calculateWidth(total, current + inProgress), color: tokens["color-informative"], animationDuration: 800 })) : (React.createElement(React.Fragment, null)),
|
|
19
|
-
React.createElement(ProgressBarInner, { width: calculateWidth(total, current), color: tokens["color-interactive"], animationDuration: 600 })))))));
|
|
22
|
+
inProgress && inProgress > 0 ? (React.createElement(ProgressBarInner, { testID: "progressbar-inprogress", width: calculateWidth(total, current + inProgress), color: tokens["color-informative"], animationDuration: 800, style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.inProgressFill })) : (React.createElement(React.Fragment, null)),
|
|
23
|
+
React.createElement(ProgressBarInner, { testID: "progressbar-fill", width: calculateWidth(total, current), color: tokens["color-interactive"], animationDuration: 600, style: UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.fill })))))));
|
|
20
24
|
function getA11yLabel() {
|
|
21
25
|
const a11yLabelValues = {
|
|
22
26
|
current: String(current),
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
// import Reanimated from "react-native-reanimated";
|
|
4
|
-
// import { useTiming } from "utils/reanimated";
|
|
5
3
|
import { useStyles } from "./ProgressBar.style";
|
|
6
|
-
export function ProgressBarInner({ width,
|
|
7
|
-
// animationDuration = 0,
|
|
8
|
-
color, }) {
|
|
9
|
-
// Animation breaking on Android
|
|
10
|
-
// const [animatedOpacity] = useTiming({
|
|
11
|
-
// duration: animationDuration,
|
|
12
|
-
// fromValue: 0,
|
|
13
|
-
// toValue: 1,
|
|
14
|
-
// });
|
|
4
|
+
export function ProgressBarInner({ width, color, style, testID, }) {
|
|
15
5
|
const styles = useStyles();
|
|
16
|
-
return (React.createElement(View, { style: [
|
|
6
|
+
return (React.createElement(View, { testID: testID, style: [
|
|
17
7
|
styles.progressBarInner,
|
|
18
8
|
Object.assign({ width: `${width}%` }, (color && { backgroundColor: color })),
|
|
9
|
+
style,
|
|
19
10
|
] }));
|
|
20
11
|
}
|
|
21
12
|
export function calculateWidth(total, current) {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
import { useStyles } from "./ProgressBar.style";
|
|
4
|
-
export function ProgressBarStepped({ total, current, color, loading, inProgress, }) {
|
|
4
|
+
export function ProgressBarStepped({ total, current, color, loading, inProgress, UNSAFE_style, }) {
|
|
5
5
|
const styles = useStyles();
|
|
6
|
-
return (React.createElement(View, {
|
|
6
|
+
return (React.createElement(View, { testID: "progressbar-container", style: [
|
|
7
|
+
styles.progressBarContainer,
|
|
8
|
+
{ height: 10 },
|
|
9
|
+
UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.progressBarContainer,
|
|
10
|
+
] }, Array.from({ length: total }).map((_, index) => {
|
|
7
11
|
const step = index + 1;
|
|
8
12
|
const isCompleted = step <= current;
|
|
9
13
|
const lastStep = step === total;
|
|
@@ -17,6 +21,7 @@ export function ProgressBarStepped({ total, current, color, loading, inProgress,
|
|
|
17
21
|
step <= inProgressSteps &&
|
|
18
22
|
styles.inProgressStep,
|
|
19
23
|
lastStep && { marginRight: 0 },
|
|
24
|
+
UNSAFE_style === null || UNSAFE_style === void 0 ? void 0 : UNSAFE_style.step,
|
|
20
25
|
], testID: isCompleted
|
|
21
26
|
? "progress-step-completed"
|
|
22
27
|
: step <= inProgressSteps
|