@jobber/components-native 0.3.0 → 0.5.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 (35) hide show
  1. package/dist/src/ActionLabel/ActionLabel.js +27 -0
  2. package/dist/src/ActionLabel/index.js +1 -0
  3. package/dist/src/ActivityIndicator/ActivityIndicator.js +6 -0
  4. package/dist/src/ActivityIndicator/index.js +1 -0
  5. package/dist/src/Content/Content.js +24 -0
  6. package/dist/src/Content/ContentHorizontal.style.js +30 -0
  7. package/dist/src/Content/ContentSpaceAround.style.js +22 -0
  8. package/dist/src/Content/ContentVertical.style.js +30 -0
  9. package/dist/src/Content/index.js +1 -0
  10. package/dist/src/index.js +3 -0
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/dist/types/src/ActionLabel/ActionLabel.d.ts +28 -0
  13. package/dist/types/src/ActionLabel/index.d.ts +1 -0
  14. package/dist/types/src/ActivityIndicator/ActivityIndicator.d.ts +3 -0
  15. package/dist/types/src/ActivityIndicator/index.d.ts +1 -0
  16. package/dist/types/src/Content/Content.d.ts +18 -0
  17. package/dist/types/src/Content/ContentHorizontal.style.d.ts +28 -0
  18. package/dist/types/src/Content/ContentSpaceAround.style.d.ts +20 -0
  19. package/dist/types/src/Content/ContentVertical.style.d.ts +22 -0
  20. package/dist/types/src/Content/index.d.ts +2 -0
  21. package/dist/types/src/index.d.ts +3 -0
  22. package/package.json +3 -2
  23. package/src/ActionLabel/ActionLabel.test.tsx +129 -0
  24. package/src/ActionLabel/ActionLabel.tsx +88 -0
  25. package/src/ActionLabel/index.ts +1 -0
  26. package/src/ActivityIndicator/ActivityIndicator.test.tsx +28 -0
  27. package/src/ActivityIndicator/ActivityIndicator.tsx +15 -0
  28. package/src/ActivityIndicator/index.ts +1 -0
  29. package/src/Content/Content.test.tsx +260 -0
  30. package/src/Content/Content.tsx +66 -0
  31. package/src/Content/ContentHorizontal.style.ts +38 -0
  32. package/src/Content/ContentSpaceAround.style.ts +28 -0
  33. package/src/Content/ContentVertical.style.ts +38 -0
  34. package/src/Content/index.ts +2 -0
  35. package/src/index.ts +3 -0
@@ -0,0 +1,28 @@
1
+ /// <reference types="react" />
2
+ import { TextAlign, TextColor } from "../Typography";
3
+ export type ActionLabelVariation = Extract<TextColor, "interactive" | "destructive" | "learning" | "subtle" | "onPrimary">;
4
+ type ActionLabelType = "default" | "cardTitle";
5
+ interface ActionLabelProps {
6
+ /**
7
+ * Text to display
8
+ */
9
+ readonly children?: string;
10
+ /**
11
+ * Set the display text to disabled color
12
+ */
13
+ readonly disabled?: boolean;
14
+ /**
15
+ * The text color
16
+ */
17
+ readonly variation?: ActionLabelVariation;
18
+ /**
19
+ * Changes the appearance to match the style of where it's getting used
20
+ */
21
+ readonly type?: ActionLabelType;
22
+ /**
23
+ * Alignment of action label
24
+ */
25
+ readonly align?: TextAlign;
26
+ }
27
+ export declare function ActionLabel({ children, variation, type, disabled, align, }: ActionLabelProps): JSX.Element;
28
+ export {};
@@ -0,0 +1 @@
1
+ export { ActionLabel, ActionLabelVariation } from "./ActionLabel";
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { ActivityIndicatorProps } from "react-native";
3
+ export declare function JobberActivityIndicator(props: ActivityIndicatorProps): JSX.Element;
@@ -0,0 +1 @@
1
+ export { JobberActivityIndicator as ActivityIndicator } from "./ActivityIndicator";
@@ -0,0 +1,18 @@
1
+ import { ReactNode } from "react";
2
+ export type Spacing = "none" | "base" | "small" | "smaller" | "smallest" | "large";
3
+ export interface ContentProps {
4
+ /**
5
+ * The child or children that will be given spacing.
6
+ */
7
+ readonly children: ReactNode;
8
+ /**
9
+ * The amount of spacing that content will give.
10
+ */
11
+ readonly spacing?: Spacing;
12
+ /**
13
+ * The amount of spacing that will be applied between children.
14
+ */
15
+ readonly childSpacing?: Spacing;
16
+ readonly direction?: "horizontal" | "vertical";
17
+ }
18
+ export declare function Content({ children, spacing, childSpacing, direction, }: ContentProps): JSX.Element;
@@ -0,0 +1,28 @@
1
+ export declare const horizontalStyles: {
2
+ wrapper: {
3
+ flexDirection: "row";
4
+ };
5
+ childWrapper: {
6
+ flexGrow: number;
7
+ flexShrink: number;
8
+ flexBasis: number;
9
+ };
10
+ noneChildSpace: {
11
+ padding: number;
12
+ };
13
+ smallestChildSpace: {
14
+ paddingLeft: number;
15
+ };
16
+ smallerChildSpace: {
17
+ paddingLeft: number;
18
+ };
19
+ smallChildSpace: {
20
+ paddingLeft: number;
21
+ };
22
+ baseChildSpace: {
23
+ paddingLeft: number;
24
+ };
25
+ largeChildSpace: {
26
+ paddingLeft: number;
27
+ };
28
+ };
@@ -0,0 +1,20 @@
1
+ export declare const spaceStyles: {
2
+ noneSpace: {
3
+ padding: number;
4
+ };
5
+ smallestSpace: {
6
+ padding: number;
7
+ };
8
+ smallerSpace: {
9
+ padding: number;
10
+ };
11
+ smallSpace: {
12
+ padding: number;
13
+ };
14
+ baseSpace: {
15
+ padding: number;
16
+ };
17
+ largeSpace: {
18
+ padding: number;
19
+ };
20
+ };
@@ -0,0 +1,22 @@
1
+ export declare const verticalStyles: {
2
+ wrapper: {};
3
+ childWrapper: {};
4
+ noneChildSpace: {
5
+ padding: number;
6
+ };
7
+ smallestChildSpace: {
8
+ paddingTop: number;
9
+ };
10
+ smallerChildSpace: {
11
+ paddingTop: number;
12
+ };
13
+ smallChildSpace: {
14
+ paddingTop: number;
15
+ };
16
+ baseChildSpace: {
17
+ paddingTop: number;
18
+ };
19
+ largeChildSpace: {
20
+ paddingTop: number;
21
+ };
22
+ };
@@ -0,0 +1,2 @@
1
+ export { Content } from "./Content";
2
+ export type { Spacing } from "./Content";
@@ -2,3 +2,6 @@ export * from "./Icon";
2
2
  export * from "./Divider";
3
3
  export * from "./Typography";
4
4
  export * from "./Text";
5
+ export * from "./ActionLabel";
6
+ export * from "./Content";
7
+ export * from "./ActivityIndicator";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.js",
@@ -32,6 +32,7 @@
32
32
  "@types/react": "^18.0.28",
33
33
  "@types/react-native": "^0.71.6",
34
34
  "metro-react-native-babel-preset": "^0.76.0",
35
+ "react-test-renderer": "^18.2.0",
35
36
  "typescript": "^4.9.5"
36
37
  },
37
38
  "peerDependencies": {
@@ -39,5 +40,5 @@
39
40
  "react": "^18",
40
41
  "react-native": ">=0.69.2"
41
42
  },
42
- "gitHead": "ee03002fcb4de15bd75bfe817698ad95c2feae7a"
43
+ "gitHead": "28a0933c17617009875afd1895e58131f5036337"
43
44
  }
@@ -0,0 +1,129 @@
1
+ import React, { CSSProperties } from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { ReactTestInstance } from "react-test-renderer";
4
+ import { ActionLabel } from "./ActionLabel";
5
+ import { tokens } from "../utils/design";
6
+
7
+ const defaultStyles = {
8
+ fontFamily: "inter-extrabold",
9
+ color: tokens["color-interactive"],
10
+ textAlign: "center",
11
+ fontSize: tokens["typography--fontSize-base"],
12
+ lineHeight: tokens["typography--lineHeight-tight"],
13
+ letterSpacing: tokens["typography--letterSpacing-loose"],
14
+ };
15
+
16
+ describe("ActionLabel", () => {
17
+ it("renders the default action label", () => {
18
+ const text = "Default Action Label";
19
+ const { getByText } = render(<ActionLabel>{text}</ActionLabel>);
20
+
21
+ const el = getByText(text);
22
+ expect(el).toBeDefined();
23
+ expect(getStyleObject(el)).toMatchObject(defaultStyles);
24
+ });
25
+
26
+ describe("Variations", () => {
27
+ it("renders a destructive variation", () => {
28
+ const text = "Destructive Action Label";
29
+ const { getByText } = render(
30
+ <ActionLabel variation="destructive">{text}</ActionLabel>,
31
+ );
32
+
33
+ expect(getStyleObject(getByText(text))).toMatchObject({
34
+ ...defaultStyles,
35
+ color: tokens["color-destructive"],
36
+ });
37
+ });
38
+
39
+ it("renders a learning variation", () => {
40
+ const text = "Learning Action Label";
41
+ const { getByText } = render(
42
+ <ActionLabel variation="learning">{text}</ActionLabel>,
43
+ );
44
+
45
+ expect(getStyleObject(getByText(text))).toMatchObject({
46
+ ...defaultStyles,
47
+ color: tokens["color-informative"],
48
+ });
49
+ });
50
+
51
+ it("renders a subtle variation", () => {
52
+ const text = "Subtle Action Label";
53
+ const { getByText } = render(
54
+ <ActionLabel variation="subtle">{text}</ActionLabel>,
55
+ );
56
+
57
+ expect(getStyleObject(getByText(text))).toMatchObject({
58
+ ...defaultStyles,
59
+ color: tokens["color-interactive--subtle"],
60
+ });
61
+ });
62
+
63
+ it("renders an onPrimary variation", () => {
64
+ const text = "onPrimary Action Label";
65
+ const { getByText } = render(
66
+ <ActionLabel variation="onPrimary">{text}</ActionLabel>,
67
+ );
68
+
69
+ expect(getStyleObject(getByText(text))).toMatchObject({
70
+ ...defaultStyles,
71
+ color: tokens["color-surface"],
72
+ });
73
+ });
74
+ });
75
+
76
+ describe("when action label is disabled", () => {
77
+ it("renders text with disabled color, overriding variation", () => {
78
+ const text = "Disabled Action Label";
79
+ const { getByText } = render(
80
+ <ActionLabel disabled variation="destructive">
81
+ {text}
82
+ </ActionLabel>,
83
+ );
84
+
85
+ const styles = getStyleObject(getByText(text));
86
+ expect(styles).toMatchObject({
87
+ ...defaultStyles,
88
+ color: tokens["color-disabled"],
89
+ });
90
+ expect(styles).not.toHaveProperty("color", tokens["color-destructive"]);
91
+ });
92
+ });
93
+
94
+ describe("when action label is aligned", () => {
95
+ it("renders text with left alignment", () => {
96
+ const text = "Left Aligned Action Label";
97
+ const { getByText } = render(
98
+ <ActionLabel align="start">{text}</ActionLabel>,
99
+ );
100
+
101
+ expect(getStyleObject(getByText(text))).toMatchObject({
102
+ ...defaultStyles,
103
+ textAlign: "left",
104
+ });
105
+ });
106
+
107
+ it("renders text with right alignment", () => {
108
+ const text = "Right Aligned Action Label";
109
+ const { getByText } = render(
110
+ <ActionLabel align="end">{text}</ActionLabel>,
111
+ );
112
+
113
+ expect(getStyleObject(getByText(text))).toMatchObject({
114
+ ...defaultStyles,
115
+ textAlign: "right",
116
+ });
117
+ });
118
+ });
119
+ });
120
+
121
+ function getStyleObject(el: ReactTestInstance) {
122
+ return el.props.style.reduce(
123
+ (mergedStyles: CSSProperties, additionalStyles: CSSProperties) => ({
124
+ ...mergedStyles,
125
+ ...additionalStyles,
126
+ }),
127
+ {},
128
+ );
129
+ }
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import { tokens } from "../utils/design";
3
+ import { TextAlign, TextColor, Typography } from "../Typography";
4
+
5
+ export type ActionLabelVariation = Extract<
6
+ TextColor,
7
+ "interactive" | "destructive" | "learning" | "subtle" | "onPrimary"
8
+ >;
9
+
10
+ type ActionLabelType = "default" | "cardTitle";
11
+
12
+ interface ActionLabelProps {
13
+ /**
14
+ * Text to display
15
+ */
16
+ readonly children?: string;
17
+
18
+ /**
19
+ * Set the display text to disabled color
20
+ */
21
+ readonly disabled?: boolean;
22
+
23
+ /**
24
+ * The text color
25
+ */
26
+ readonly variation?: ActionLabelVariation;
27
+
28
+ /**
29
+ * Changes the appearance to match the style of where it's getting used
30
+ */
31
+ readonly type?: ActionLabelType;
32
+
33
+ /**
34
+ * Alignment of action label
35
+ */
36
+ readonly align?: TextAlign;
37
+ }
38
+
39
+ export function ActionLabel({
40
+ children,
41
+ variation = "interactive",
42
+ type = "default",
43
+ disabled = false,
44
+ align = "center",
45
+ }: ActionLabelProps): JSX.Element {
46
+ return (
47
+ <Typography
48
+ color={getColor(variation, disabled)}
49
+ fontFamily="base"
50
+ size="default"
51
+ fontWeight={getFontWeight(type)}
52
+ align={align}
53
+ lineHeight="tight"
54
+ letterSpacing={getLetterSpacing(type)}
55
+ maxFontScaleSize={tokens["typography--fontSize-large"]}
56
+ selectable={false}
57
+ >
58
+ {children}
59
+ </Typography>
60
+ );
61
+ }
62
+
63
+ function getColor(variation: ActionLabelVariation, disabled: boolean) {
64
+ if (disabled) {
65
+ return "disabled";
66
+ }
67
+ if (variation) {
68
+ return variation;
69
+ }
70
+
71
+ return "interactive";
72
+ }
73
+
74
+ function getFontWeight(type: ActionLabelType) {
75
+ if (type === "cardTitle") {
76
+ return "bold";
77
+ }
78
+
79
+ return "extraBold";
80
+ }
81
+
82
+ function getLetterSpacing(type: ActionLabelType) {
83
+ if (type === "cardTitle") {
84
+ return "base";
85
+ }
86
+
87
+ return "loose";
88
+ }
@@ -0,0 +1 @@
1
+ export { ActionLabel, ActionLabelVariation } from "./ActionLabel";
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { ActivityIndicator } from "./index";
4
+ import { tokens } from "../utils/design";
5
+
6
+ const testId = "ActivityIndicator";
7
+ describe("ActivityIndicator", () => {
8
+ it("renders with the default color when no props are provided", () => {
9
+ const { getByTestId } = render(<ActivityIndicator />);
10
+ expect(getByTestId(testId).props.color).toBe(tokens["color-greyBlue"]);
11
+ });
12
+
13
+ it("renders with a custom color", () => {
14
+ const color = "red";
15
+ const { getByTestId } = render(<ActivityIndicator color={color} />);
16
+ expect(getByTestId(testId).props.color).toBe(color);
17
+ });
18
+
19
+ it("renders with large size", () => {
20
+ const size = "large";
21
+ const color = "red";
22
+ const { getByTestId } = render(
23
+ <ActivityIndicator color={color} size={size} />,
24
+ );
25
+ expect(getByTestId(testId).props.size).toBe(size);
26
+ expect(getByTestId(testId).props.color).toBe(color);
27
+ });
28
+ });
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import { ActivityIndicator, ActivityIndicatorProps } from "react-native";
3
+ import { tokens } from "../utils/design";
4
+
5
+ export function JobberActivityIndicator(
6
+ props: ActivityIndicatorProps,
7
+ ): JSX.Element {
8
+ return (
9
+ <ActivityIndicator
10
+ {...props}
11
+ color={props.color || tokens["color-greyBlue"]}
12
+ testID={props.testID || "ActivityIndicator"}
13
+ />
14
+ );
15
+ }
@@ -0,0 +1 @@
1
+ export { JobberActivityIndicator as ActivityIndicator } from "./ActivityIndicator";