@jobber/components-native 0.92.0 → 0.94.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 (30) hide show
  1. package/dist/package.json +4 -2
  2. package/dist/src/BottomSheet/BottomSheet.js +58 -32
  3. package/dist/src/BottomSheet/BottomSheet.style.js +8 -9
  4. package/dist/src/BottomSheet/hooks/useBottomSheetBackHandler.js +26 -0
  5. package/dist/src/Content/ContentHorizontal.style.js +15 -0
  6. package/dist/src/Content/ContentSpaceAround.style.js +15 -0
  7. package/dist/src/Content/ContentVertical.style.js +15 -0
  8. package/dist/src/InputText/InputText.js +2 -2
  9. package/dist/tsconfig.build.tsbuildinfo +1 -1
  10. package/dist/types/src/BottomSheet/BottomSheet.d.ts +7 -3
  11. package/dist/types/src/BottomSheet/BottomSheet.style.d.ts +7 -14
  12. package/dist/types/src/BottomSheet/hooks/useBottomSheetBackHandler.d.ts +8 -0
  13. package/dist/types/src/Content/Content.d.ts +1 -1
  14. package/dist/types/src/Content/ContentHorizontal.style.d.ts +15 -0
  15. package/dist/types/src/Content/ContentSpaceAround.style.d.ts +15 -0
  16. package/dist/types/src/Content/ContentVertical.style.d.ts +15 -0
  17. package/dist/types/src/InputText/InputText.d.ts +1 -1
  18. package/package.json +4 -2
  19. package/src/BottomSheet/BottomSheet.stories.tsx +128 -0
  20. package/src/BottomSheet/BottomSheet.style.ts +7 -14
  21. package/src/BottomSheet/BottomSheet.test.tsx +19 -24
  22. package/src/BottomSheet/BottomSheet.tsx +112 -93
  23. package/src/BottomSheet/hooks/useBottomSheetBackHandler.test.ts +90 -0
  24. package/src/BottomSheet/hooks/useBottomSheetBackHandler.ts +41 -0
  25. package/src/Content/Content.tsx +6 -1
  26. package/src/Content/ContentHorizontal.style.ts +20 -0
  27. package/src/Content/ContentSpaceAround.style.ts +20 -0
  28. package/src/Content/ContentVertical.style.ts +20 -0
  29. package/src/InputText/InputText.tsx +3 -3
  30. 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.92.0",
3
+ "version": "0.94.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": "1ca01305080db58e135d5224ab329a8df4ad92ff"
99
+ "gitHead": "c781bba08e241b32046afba42dff63d213e4a7fd"
98
100
  }
@@ -1,52 +1,78 @@
1
- import React, { forwardRef, useState } from "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 { BottomSheetOption } from "./components/BottomSheetOption";
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 { UNSAFE_WrappedModalize } from "../ContentOverlay/UNSAFE_WrappedModalize";
7
- import { useIsScreenReaderEnabled } from "../hooks";
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 const BottomSheet = forwardRef(BottomSheetInternal);
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
- return (React.createElement(React.Fragment, null,
17
- open && React.createElement(Overlay, { styles: styles }),
18
- React.createElement(UNSAFE_WrappedModalize, { ref: ref, adjustToContentHeight: true, modalStyle: styles.modal, overlayStyle: styles.overlayModalize, HeaderComponent: heading && React.createElement(Header, { heading: heading, styles: styles }), FooterComponent: React.createElement(Footer, { cancellable: (showCancel && !loading) || isScreenReaderEnabled, onCancel: () => {
19
- var _a;
20
- (_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.close();
21
- }, styles: styles }), withHandle: false, withReactModal: isScreenReaderEnabled, onOpen: openModal, onClose: closeModal },
22
- React.createElement(View, { style: !showCancel && !isScreenReaderEnabled ? styles.children : undefined }, children))));
23
- function openModal() {
24
- onOpen === null || onOpen === void 0 ? void 0 : onOpen();
25
- setOpen(true);
26
- dismissKeyboard();
27
- }
28
- function closeModal() {
29
- onClose === null || onClose === void 0 ? void 0 : onClose();
30
- setOpen(false);
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({ cancellable, onCancel, styles, }) {
38
- const insets = useSafeAreaInsets();
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: t("cancel"), icon: "remove", onPress: onCancel })))));
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 Overlay({ styles, }) {
51
- return React.createElement(View, { style: styles.overlay });
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
- overlayModalize: {
8
- backgroundColor: "transparent",
5
+ backdrop: {
6
+ backgroundColor: tokens["color-overlay"],
9
7
  },
10
- overlay: Object.assign(Object.assign({}, StyleSheet.absoluteFillObject), { backgroundColor: tokens["color-overlay"], height }),
11
- modal: {
8
+ background: {
12
9
  borderTopLeftRadius: modalBorderRadius,
13
10
  borderTopRightRadius: modalBorderRadius,
14
- paddingTop: tokens["space-small"],
15
11
  },
16
- children: {
17
- paddingBottom: tokens["space-small"],
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
+ }
@@ -12,6 +12,9 @@ export const useHorizontalStyles = buildThemedStyles(tokens => {
12
12
  noneChildSpace: {
13
13
  padding: 0,
14
14
  },
15
+ minusculeChildSpace: {
16
+ paddingLeft: tokens["space-minuscule"],
17
+ },
15
18
  smallestChildSpace: {
16
19
  paddingLeft: tokens["space-smallest"],
17
20
  },
@@ -21,11 +24,23 @@ export const useHorizontalStyles = buildThemedStyles(tokens => {
21
24
  smallChildSpace: {
22
25
  paddingLeft: tokens["space-small"],
23
26
  },
27
+ slimChildSpace: {
28
+ paddingLeft: tokens["space-slim"],
29
+ },
24
30
  baseChildSpace: {
25
31
  paddingLeft: tokens["space-base"],
26
32
  },
27
33
  largeChildSpace: {
28
34
  paddingLeft: tokens["space-large"],
29
35
  },
36
+ largerChildSpace: {
37
+ paddingLeft: tokens["space-larger"],
38
+ },
39
+ largestChildSpace: {
40
+ paddingLeft: tokens["space-largest"],
41
+ },
42
+ extravagantChildSpace: {
43
+ paddingLeft: tokens["space-extravagant"],
44
+ },
30
45
  };
31
46
  });
@@ -4,6 +4,9 @@ export const useSpaceAroundStyles = buildThemedStyles(tokens => {
4
4
  noneSpace: {
5
5
  padding: 0,
6
6
  },
7
+ minusculeSpace: {
8
+ padding: tokens["space-minuscule"],
9
+ },
7
10
  smallestSpace: {
8
11
  padding: tokens["space-smallest"],
9
12
  },
@@ -13,11 +16,23 @@ export const useSpaceAroundStyles = buildThemedStyles(tokens => {
13
16
  smallSpace: {
14
17
  padding: tokens["space-small"],
15
18
  },
19
+ slimSpace: {
20
+ padding: tokens["space-slim"],
21
+ },
16
22
  baseSpace: {
17
23
  padding: tokens["space-base"],
18
24
  },
19
25
  largeSpace: {
20
26
  padding: tokens["space-large"],
21
27
  },
28
+ largerSpace: {
29
+ padding: tokens["space-larger"],
30
+ },
31
+ largestSpace: {
32
+ padding: tokens["space-largest"],
33
+ },
34
+ extravagantSpace: {
35
+ padding: tokens["space-extravagant"],
36
+ },
22
37
  };
23
38
  });
@@ -12,6 +12,9 @@ export const useVerticalStyles = buildThemedStyles(tokens => {
12
12
  noneChildSpace: {
13
13
  padding: 0,
14
14
  },
15
+ minusculeChildSpace: {
16
+ paddingTop: tokens["space-minuscule"],
17
+ },
15
18
  smallestChildSpace: {
16
19
  paddingTop: tokens["space-smallest"],
17
20
  },
@@ -21,11 +24,23 @@ export const useVerticalStyles = buildThemedStyles(tokens => {
21
24
  smallChildSpace: {
22
25
  paddingTop: tokens["space-small"],
23
26
  },
27
+ slimChildSpace: {
28
+ paddingTop: tokens["space-slim"],
29
+ },
24
30
  baseChildSpace: {
25
31
  paddingTop: tokens["space-base"],
26
32
  },
27
33
  largeChildSpace: {
28
34
  paddingTop: tokens["space-large"],
29
35
  },
36
+ largerChildSpace: {
37
+ paddingTop: tokens["space-larger"],
38
+ },
39
+ largestChildSpace: {
40
+ paddingTop: tokens["space-largest"],
41
+ },
42
+ extravagantChildSpace: {
43
+ paddingTop: tokens["space-extravagant"],
44
+ },
30
45
  };
31
46
  });
@@ -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) => {