@jobber/components-native 0.10.0 → 0.12.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 (36) hide show
  1. package/dist/src/Button/Button.js +78 -0
  2. package/dist/src/Button/Button.style.js +92 -0
  3. package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.js +36 -0
  4. package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.style.js +4 -0
  5. package/dist/src/Button/components/InternalButtonLoading/index.js +1 -0
  6. package/dist/src/Button/index.js +1 -0
  7. package/dist/src/Button/types.js +1 -0
  8. package/dist/src/Heading/Heading.js +51 -0
  9. package/dist/src/Heading/index.js +1 -0
  10. package/dist/src/index.js +2 -0
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/dist/types/src/Button/Button.d.ts +71 -0
  13. package/dist/types/src/Button/Button.style.d.ts +86 -0
  14. package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.d.ts +11 -0
  15. package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.style.d.ts +4 -0
  16. package/dist/types/src/Button/components/InternalButtonLoading/index.d.ts +1 -0
  17. package/dist/types/src/Button/index.d.ts +2 -0
  18. package/dist/types/src/Button/types.d.ts +3 -0
  19. package/dist/types/src/Heading/Heading.d.ts +37 -0
  20. package/dist/types/src/Heading/index.d.ts +2 -0
  21. package/dist/types/src/index.d.ts +2 -0
  22. package/package.json +3 -2
  23. package/src/Button/Button.style.ts +116 -0
  24. package/src/Button/Button.test.tsx +298 -0
  25. package/src/Button/Button.tsx +223 -0
  26. package/src/Button/components/InternalButtonLoading/InternalButtonLoading.style.ts +5 -0
  27. package/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.tsx +39 -0
  28. package/src/Button/components/InternalButtonLoading/InternalButtonLoading.tsx +77 -0
  29. package/src/Button/components/InternalButtonLoading/index.ts +1 -0
  30. package/src/Button/index.ts +2 -0
  31. package/src/Button/types.ts +3 -0
  32. package/src/Heading/Heading.test.tsx +83 -0
  33. package/src/Heading/Heading.tsx +132 -0
  34. package/src/Heading/__snapshots__/Heading.test.tsx.snap +270 -0
  35. package/src/Heading/index.ts +2 -0
  36. package/src/index.ts +2 -0
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import { TouchableHighlight, View } from "react-native";
3
+ import { styles } from "./Button.style";
4
+ // eslint-disable-next-line import/no-internal-modules
5
+ import { InternalButtonLoading } from "./components/InternalButtonLoading";
6
+ import { ActionLabel } from "../ActionLabel";
7
+ import { Icon } from "../Icon";
8
+ import { tokens } from "../utils/design";
9
+ export function Button({ label, onPress, variation = "work", type = "primary", fullHeight = false, fullWidth = true, disabled = false, loading = false, size = "base", accessibilityLabel, accessibilityHint, icon, }) {
10
+ const buttonStyle = [
11
+ styles.button,
12
+ styles[variation],
13
+ styles[type],
14
+ styles[size],
15
+ disabled && styles.disabled,
16
+ fullHeight && styles.fullHeight,
17
+ fullWidth && styles.reducedPaddingForFullWidth,
18
+ ];
19
+ // attempts to use Pressable caused problems. When a ScrollView contained
20
+ // an InputText that was focused, it required two presses to activate the
21
+ // Pressable. Using a TouchableHighlight made things register correctly
22
+ // in a single press
23
+ return (React.createElement(TouchableHighlight, { onPress: onPress, testID: accessibilityLabel || label, accessibilityLabel: accessibilityLabel || label, accessibilityHint: accessibilityHint, accessibilityRole: "button", accessibilityState: { disabled, busy: loading }, disabled: disabled || loading, underlayColor: tokens["color-greyBlue--dark"], activeOpacity: tokens["opacity-pressed"], style: [
24
+ styles.touchable,
25
+ fullWidth && styles.fullWidth,
26
+ fullHeight && styles.fullHeight,
27
+ ] },
28
+ React.createElement(View, { style: buttonStyle },
29
+ loading && React.createElement(InternalButtonLoading, { variation: variation, type: type }),
30
+ React.createElement(View, { style: getContentStyles(label, icon) },
31
+ icon && (React.createElement(View, { style: styles.iconStyle },
32
+ React.createElement(Icon, { name: icon, color: getIconColorVariation(variation, type, disabled) }))),
33
+ label && (React.createElement(View, { style: styles.labelStyle },
34
+ React.createElement(ActionLabel, { variation: getActionLabelVariation(variation, type), disabled: disabled, align: icon ? "start" : undefined }, label)))))));
35
+ }
36
+ function getActionLabelVariation(variation, type) {
37
+ if (type === "primary" && variation !== "cancel") {
38
+ return "onPrimary";
39
+ }
40
+ switch (variation) {
41
+ case "learning":
42
+ return "learning";
43
+ case "destructive":
44
+ return "destructive";
45
+ case "cancel":
46
+ return "subtle";
47
+ default:
48
+ return "interactive";
49
+ }
50
+ }
51
+ function getIconColorVariation(variation, type, disabled) {
52
+ if (disabled) {
53
+ return "disabled";
54
+ }
55
+ if (type === "primary" && variation !== "cancel") {
56
+ return "white";
57
+ }
58
+ switch (variation) {
59
+ case "learning":
60
+ return "informative";
61
+ case "destructive":
62
+ return "destructive";
63
+ case "cancel":
64
+ return "interactiveSubtle";
65
+ default:
66
+ return "interactive";
67
+ }
68
+ }
69
+ function getContentStyles(label, icon) {
70
+ if (label && !icon) {
71
+ return undefined;
72
+ }
73
+ return [
74
+ styles.content,
75
+ icon && !!label && styles.iconPaddingOffset,
76
+ !!label && styles.contentWithLabel,
77
+ ];
78
+ }
@@ -0,0 +1,92 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ const iconTranslateY = tokens["space-large"] / 2;
4
+ const buttonRadius = tokens["radius-large"];
5
+ export const baseButtonHeight = tokens["space-base"] * 3.5;
6
+ export const smallButtonHeight = tokens["space-base"] * 2.25;
7
+ export const styles = StyleSheet.create({
8
+ fullHeight: {
9
+ flexGrow: 1,
10
+ flexShrink: 0,
11
+ },
12
+ fullWidth: {
13
+ alignSelf: "stretch",
14
+ },
15
+ touchable: {
16
+ borderRadius: buttonRadius,
17
+ },
18
+ button: {
19
+ justifyContent: "center",
20
+ alignItems: "center",
21
+ alignSelf: "stretch",
22
+ flexDirection: "row",
23
+ overflow: "hidden",
24
+ margin: 0,
25
+ borderRadius: buttonRadius,
26
+ borderWidth: tokens["border-base"],
27
+ paddingVertical: tokens["space-small"],
28
+ },
29
+ base: {
30
+ minHeight: baseButtonHeight,
31
+ paddingHorizontal: tokens["space-base"],
32
+ },
33
+ small: {
34
+ minHeight: smallButtonHeight,
35
+ paddingHorizontal: tokens["space-small"] + tokens["space-smaller"],
36
+ },
37
+ reducedPaddingForFullWidth: {
38
+ paddingHorizontal: tokens["space-smaller"],
39
+ },
40
+ iconPaddingOffset: {
41
+ paddingRight: tokens["space-smaller"],
42
+ },
43
+ content: {
44
+ paddingLeft: tokens["space-large"],
45
+ height: "100%",
46
+ },
47
+ contentWithLabel: {
48
+ paddingLeft: tokens["space-large"] + tokens["space-small"],
49
+ },
50
+ iconStyle: {
51
+ position: "absolute",
52
+ top: "50%",
53
+ left: 0,
54
+ transform: [{ translateY: -iconTranslateY }],
55
+ },
56
+ labelStyle: {
57
+ flexGrow: 1,
58
+ justifyContent: "center",
59
+ },
60
+ /* Variations */
61
+ work: {
62
+ backgroundColor: tokens["color-interactive"],
63
+ borderColor: tokens["color-interactive"],
64
+ },
65
+ learning: {
66
+ backgroundColor: tokens["color-informative"],
67
+ borderColor: tokens["color-informative"],
68
+ },
69
+ destructive: {
70
+ backgroundColor: tokens["color-destructive"],
71
+ borderColor: tokens["color-destructive"],
72
+ },
73
+ /* Cancel is special because, by default, it's styled as a secondary button */
74
+ cancel: {
75
+ backgroundColor: tokens["color-surface"],
76
+ borderColor: tokens["color-interactive--subtle"],
77
+ },
78
+ /* Types */
79
+ primary: {},
80
+ secondary: {
81
+ backgroundColor: tokens["color-surface"],
82
+ },
83
+ tertiary: {
84
+ backgroundColor: tokens["color-surface"],
85
+ borderColor: tokens["color-surface"],
86
+ },
87
+ /* Disabled */
88
+ disabled: {
89
+ borderColor: tokens["color-disabled--secondary"],
90
+ backgroundColor: tokens["color-disabled--secondary"],
91
+ },
92
+ });
@@ -0,0 +1,36 @@
1
+ import React from "react";
2
+ import { ImageBackground, PixelRatio } from "react-native";
3
+ import Animated, { Easing, useAnimatedStyle, useSharedValue, withDelay, withRepeat, withTiming, } from "react-native-reanimated";
4
+ import { styles } from "./InternalButtonLoading.style";
5
+ import { tokens } from "../../../utils/design";
6
+ const imageWidth = 96;
7
+ const offset = PixelRatio.roundToNearestPixel(imageWidth / PixelRatio.get());
8
+ const leftOffset = -1 * offset;
9
+ const AnimatedImage = Animated.createAnimatedComponent(ImageBackground);
10
+ function InternalButtonLoadingInternal({ variation, type, }) {
11
+ const translateX = useSharedValue(0);
12
+ translateX.value = withRepeat(withTiming(offset, {
13
+ duration: tokens["timing-loading"],
14
+ easing: Easing.linear,
15
+ }), -1);
16
+ const opacity = useSharedValue(0);
17
+ opacity.value = withDelay(tokens["timing-quick"], withTiming(1, {
18
+ duration: tokens["timing-base"],
19
+ easing: Easing.linear,
20
+ }));
21
+ const animations = useAnimatedStyle(() => ({
22
+ opacity: opacity.value,
23
+ transform: [{ translateX: translateX.value }],
24
+ }));
25
+ return (React.createElement(AnimatedImage, { testID: "loadingImage", source: { uri: getLoadingPattern({ variation, type }) }, resizeMode: "repeat", style: [styles.image, { left: leftOffset }, animations] }));
26
+ }
27
+ export const darkPattern = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgAgMAAACf9p+rAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJcEhZcwAAITgAACE4AUWWMWAAAAAMUExURQAAAEdwTAAAAAAAAKDh18UAAAAEdFJOUxkADQwimkzpAAAAtUlEQVRIx+3NqxHDQBRDUc0YuxyXokxgSkmT7sdgP++3YoYrqAsOYDto+7gfpwtfHy4Xfj7cLvw3sYlNbOINAoI4IIgTgrggiBuCIAThQyB8CIQLkXAhEi5EwoVIWEiEhURYSISFRMyQiRkyMUMmZsjECIUYoRAjFGKEQvRQiR4q0UMleqhECwuihQXRwoJoYUEQgiAEQQiCEAQhCEIQhCAIQRCCIARBCIIQBCEIQhCEIAhB8AEuzZ5wHe17xgAAAABJRU5ErkJggg==";
28
+ export const lightPattern = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgAgMAAACf9p+rAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJcEhZcwAAITgAACE4AUWWMWAAAAAJUExURf///0dwTP///0SistEAAAADdFJOU0AAILGCadYAAAC0SURBVEjH7c2pFcNAFENRHTMX4pKUE5hS0oT7NZjlbyNmOIJ64AK2g7aP+3G68PXhcuHnw+3CfxOb2MQm3iAgiAOCOCGIC4K4IQhCED4EwodAuBAJFyLhQiRciISFRFhIhIVEWEjEDJmYIRMzZGKGTIxQiBEKMUIhRihED5XooRI9VKKHSrSwIFpYEC0siBYWBCEIQhCEIAhBEIIgBEEIghAEIQhCEIQgCEEQgiAEQQiCEAQfva6WeBniVLgAAAAASUVORK5CYII=";
29
+ function getLoadingPattern({ variation, type, }) {
30
+ if (variation === "cancel")
31
+ return darkPattern;
32
+ if (type === "primary")
33
+ return lightPattern;
34
+ return darkPattern;
35
+ }
36
+ export const InternalButtonLoading = React.memo(InternalButtonLoadingInternal);
@@ -0,0 +1,4 @@
1
+ import { StyleSheet } from "react-native";
2
+ export const styles = StyleSheet.create({
3
+ image: StyleSheet.absoluteFillObject,
4
+ });
@@ -0,0 +1 @@
1
+ export { InternalButtonLoading } from "./InternalButtonLoading";
@@ -0,0 +1 @@
1
+ export { Button } from "./Button";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import React from "react";
2
+ import { Typography, } from "../Typography";
3
+ import { tokens } from "../utils/design";
4
+ const maxScaledFontSize = {
5
+ subHeading: tokens["typography--fontSize-base"] * 1.375,
6
+ heading: tokens["typography--fontSize-base"] * 1.5,
7
+ subtitle: tokens["typography--fontSize-base"] * 1.5,
8
+ title: tokens["typography--fontSize-base"] * 2.125,
9
+ };
10
+ export function Heading({ children, level, variation = "heading", reverseTheme = false, align, maxLines = "unlimited", allowFontScaling = true, selectable, }) {
11
+ const headingStyle = getHeadingStyle(level, variation);
12
+ const accessibilityRole = "header";
13
+ return (React.createElement(Typography, Object.assign({}, Object.assign(Object.assign({}, headingStyle), { accessibilityRole,
14
+ reverseTheme,
15
+ align,
16
+ maxLines,
17
+ allowFontScaling }), { maxFontScaleSize: maxScaledFontSize[level], selectable: selectable }), children));
18
+ }
19
+ function getHeadingStyle(level = "heading", variation) {
20
+ const headingLevelToStyle = {
21
+ title: {
22
+ fontFamily: "display",
23
+ fontWeight: "black",
24
+ size: "jumbo",
25
+ lineHeight: "jumbo",
26
+ color: variation,
27
+ },
28
+ subtitle: {
29
+ fontFamily: "display",
30
+ fontWeight: "extraBold",
31
+ size: "largest",
32
+ lineHeight: "largest",
33
+ color: variation,
34
+ },
35
+ heading: {
36
+ fontFamily: "display",
37
+ fontWeight: "extraBold",
38
+ size: "larger",
39
+ lineHeight: "large",
40
+ color: variation,
41
+ },
42
+ subHeading: {
43
+ fontFamily: "base",
44
+ fontWeight: "semiBold",
45
+ size: "default",
46
+ lineHeight: "base",
47
+ color: variation,
48
+ },
49
+ };
50
+ return headingLevelToStyle[level];
51
+ }
@@ -0,0 +1 @@
1
+ export { Heading } from "./Heading";
package/dist/src/index.js CHANGED
@@ -9,4 +9,6 @@ export * from "./ActivityIndicator";
9
9
  export * from "./Card";
10
10
  export * from "./StatusLabel";
11
11
  export * from "./AtlantisContext";
12
+ export * from "./Button";
12
13
  export * from "./InputFieldWrapper";
14
+ export * from "./Heading";