@jobber/components-native 0.15.0 → 0.17.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.
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+ import { IconColorNames, IconNames } from "@jobber/design";
3
+ interface IconButtonProps {
4
+ /**
5
+ * Press handler
6
+ */
7
+ onPress?(): void;
8
+ /** The icon to show. */
9
+ readonly name: IconNames;
10
+ /**
11
+ * Accessibilty label for the component. It's also used for testing
12
+ */
13
+ readonly accessibilityLabel: string;
14
+ /**
15
+ * Determines the color of the icon. If not specified, some icons have a default system colour
16
+ * like quotes, jobs, and invoices.
17
+ * Others that don't have a system colour fall back to greyBlue.
18
+ */
19
+ readonly color?: IconColorNames;
20
+ /**
21
+ * Sets a custom color for the icon. Can be a rgb() or hex value.
22
+ */
23
+ readonly customColor?: string;
24
+ /**
25
+ * a component that would render over the icon
26
+ * e.g. the number of notifications over the activity feed icon
27
+ */
28
+ readonly badge?: React.ReactNode;
29
+ /**
30
+ * Used to locate this button in tests
31
+ */
32
+ readonly testID?: string;
33
+ }
34
+ export declare function IconButton({ badge, name, color, customColor, onPress, accessibilityLabel, testID, }: IconButtonProps): JSX.Element;
35
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const styles: {
2
+ container: {
3
+ width: number;
4
+ height: number;
5
+ justifyContent: "center";
6
+ alignItems: "center";
7
+ };
8
+ };
@@ -0,0 +1 @@
1
+ export { IconButton } from "./IconButton";
@@ -1,17 +1,18 @@
1
- export * from "./Icon";
2
- export * from "./Divider";
3
- export * from "./Typography";
4
- export * from "./Text";
5
- export * from "./ErrorMessageWrapper";
1
+ export * from "./ActionItem";
6
2
  export * from "./ActionLabel";
7
- export * from "./Content";
8
3
  export * from "./ActivityIndicator";
9
- export * from "./Card";
10
- export * from "./StatusLabel";
11
4
  export * from "./AtlantisContext";
12
5
  export * from "./Button";
6
+ export * from "./Card";
7
+ export * from "./Chip";
8
+ export * from "./Content";
9
+ export * from "./Divider";
10
+ export * from "./ErrorMessageWrapper";
11
+ export * from "./Heading";
12
+ export * from "./Icon";
13
+ export * from "./IconButton";
13
14
  export * from "./InputFieldWrapper";
14
15
  export * from "./ProgressBar";
15
- export * from "./Heading";
16
- export * from "./Chip";
17
- export * from "./ActionItem";
16
+ export * from "./StatusLabel";
17
+ export * from "./Text";
18
+ export * from "./Typography";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.js",
@@ -21,7 +21,7 @@
21
21
  "build:clean": "rm -rf ./dist"
22
22
  },
23
23
  "dependencies": {
24
- "@jobber/design": "^0.39.0",
24
+ "@jobber/design": "^0.40.0",
25
25
  "react-hook-form": "^7.30.0",
26
26
  "react-intl": "^6.4.2",
27
27
  "react-native-gesture-handler": "^2.5.0",
@@ -47,5 +47,5 @@
47
47
  "react": "^18",
48
48
  "react-native": ">=0.69.2"
49
49
  },
50
- "gitHead": "3bb3bd6837e653ed965570d404324e625e2339ee"
50
+ "gitHead": "4f8524610aba80691217778e1824149409c65524"
51
51
  }
@@ -0,0 +1,11 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+
4
+ export const styles = StyleSheet.create({
5
+ container: {
6
+ width: tokens["space-largest"],
7
+ height: tokens["space-largest"],
8
+ justifyContent: "center",
9
+ alignItems: "center",
10
+ },
11
+ });
@@ -0,0 +1,79 @@
1
+ import React from "react";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
+ import { IconButton } from "./IconButton";
4
+ import { Text } from "../Text";
5
+
6
+ describe("IconButton", () => {
7
+ it("renders an IconButton", () => {
8
+ const pressHandler = jest.fn();
9
+ const { getByTestId } = render(
10
+ <IconButton
11
+ onPress={pressHandler}
12
+ name="job"
13
+ accessibilityLabel="Job Button"
14
+ testID="JobButton"
15
+ />,
16
+ );
17
+
18
+ expect(getByTestId("JobButton")).toBeDefined();
19
+ });
20
+
21
+ it("should call the onPress", () => {
22
+ const pressHandler = jest.fn();
23
+ const { getByLabelText } = render(
24
+ <IconButton
25
+ onPress={pressHandler}
26
+ name="job"
27
+ accessibilityLabel={"Job Button"}
28
+ />,
29
+ );
30
+ fireEvent.press(getByLabelText("Job Button"));
31
+ expect(pressHandler).toHaveBeenCalled();
32
+ });
33
+
34
+ it("should render badge component", () => {
35
+ const pressHandler = jest.fn();
36
+ const badge = <Text>Hi</Text>;
37
+ const { getByText } = render(
38
+ <IconButton
39
+ onPress={pressHandler}
40
+ name="job"
41
+ badge={badge}
42
+ accessibilityLabel={"Job Button"}
43
+ />,
44
+ );
45
+ expect(getByText("Hi")).toBeDefined();
46
+ });
47
+
48
+ it("should render IconButton with custom color", () => {
49
+ const pressHandler = jest.fn();
50
+ const { getByLabelText } = render(
51
+ <IconButton
52
+ onPress={pressHandler}
53
+ name="job"
54
+ customColor="#f33323"
55
+ accessibilityLabel={"Job Button"}
56
+ />,
57
+ );
58
+ const iconBtnColorProp = getByLabelText("Job Button").findByProps({
59
+ customColor: "#f33323",
60
+ }).props.customColor;
61
+
62
+ expect(iconBtnColorProp).toEqual("#f33323");
63
+ });
64
+
65
+ it("should expose testID", () => {
66
+ const pressHandler = jest.fn();
67
+ const testID = "JobButton";
68
+ const { getByTestId } = render(
69
+ <IconButton
70
+ onPress={pressHandler}
71
+ name="job"
72
+ accessibilityLabel={"Job Button"}
73
+ testID={testID}
74
+ />,
75
+ );
76
+ fireEvent.press(getByTestId(testID));
77
+ expect(pressHandler).toHaveBeenCalled();
78
+ });
79
+ });
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import { TouchableOpacity } from "react-native";
3
+ import { IconColorNames, IconNames } from "@jobber/design";
4
+ import { styles } from "./IconButton.style";
5
+ import { Icon } from "../Icon";
6
+
7
+ interface IconButtonProps {
8
+ /**
9
+ * Press handler
10
+ */
11
+ onPress?(): void;
12
+
13
+ /** The icon to show. */
14
+ readonly name: IconNames;
15
+
16
+ /**
17
+ * Accessibilty label for the component. It's also used for testing
18
+ */
19
+ readonly accessibilityLabel: string;
20
+
21
+ /**
22
+ * Determines the color of the icon. If not specified, some icons have a default system colour
23
+ * like quotes, jobs, and invoices.
24
+ * Others that don't have a system colour fall back to greyBlue.
25
+ */
26
+ readonly color?: IconColorNames;
27
+
28
+ /**
29
+ * Sets a custom color for the icon. Can be a rgb() or hex value.
30
+ */
31
+ readonly customColor?: string;
32
+
33
+ /**
34
+ * a component that would render over the icon
35
+ * e.g. the number of notifications over the activity feed icon
36
+ */
37
+ readonly badge?: React.ReactNode;
38
+
39
+ /**
40
+ * Used to locate this button in tests
41
+ */
42
+ readonly testID?: string;
43
+ }
44
+
45
+ export function IconButton({
46
+ badge,
47
+ name,
48
+ color,
49
+ customColor,
50
+ onPress,
51
+ accessibilityLabel,
52
+ testID,
53
+ }: IconButtonProps): JSX.Element {
54
+ return (
55
+ <TouchableOpacity
56
+ onPress={onPress}
57
+ style={styles.container}
58
+ accessibilityLabel={accessibilityLabel}
59
+ accessibilityRole="button"
60
+ testID={testID}
61
+ >
62
+ {badge}
63
+ <Icon name={name} color={color} customColor={customColor} />
64
+ </TouchableOpacity>
65
+ );
66
+ }
@@ -0,0 +1 @@
1
+ export { IconButton } from "./IconButton";
package/src/index.ts CHANGED
@@ -1,17 +1,18 @@
1
- export * from "./Icon";
2
- export * from "./Divider";
3
- export * from "./Typography";
4
- export * from "./Text";
5
- export * from "./ErrorMessageWrapper";
1
+ export * from "./ActionItem";
6
2
  export * from "./ActionLabel";
7
- export * from "./Content";
8
3
  export * from "./ActivityIndicator";
9
- export * from "./Card";
10
- export * from "./StatusLabel";
11
4
  export * from "./AtlantisContext";
12
5
  export * from "./Button";
6
+ export * from "./Card";
7
+ export * from "./Chip";
8
+ export * from "./Content";
9
+ export * from "./Divider";
10
+ export * from "./ErrorMessageWrapper";
11
+ export * from "./Heading";
12
+ export * from "./Icon";
13
+ export * from "./IconButton";
13
14
  export * from "./InputFieldWrapper";
14
15
  export * from "./ProgressBar";
15
- export * from "./Heading";
16
- export * from "./Chip";
17
- export * from "./ActionItem";
16
+ export * from "./StatusLabel";
17
+ export * from "./Text";
18
+ export * from "./Typography";