@jobber/components-native 0.32.1 → 0.33.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,3 @@
1
+ /// <reference types="react" />
2
+ import { BannerProps } from "./types";
3
+ export declare function Banner({ action, details, text, type, }: BannerProps): JSX.Element;
@@ -0,0 +1,14 @@
1
+ export declare const styles: {
2
+ container: {
3
+ width: string;
4
+ };
5
+ error: {
6
+ backgroundColor: string;
7
+ };
8
+ warning: {
9
+ backgroundColor: string;
10
+ };
11
+ notice: {
12
+ backgroundColor: string;
13
+ };
14
+ };
@@ -0,0 +1,2 @@
1
+ import { BannerStyleProps } from "./types";
2
+ export declare const BannerTypeStyles: Record<string, BannerStyleProps>;
@@ -0,0 +1,2 @@
1
+ export { Banner } from "./Banner";
2
+ export type { BannerTypes } from "./types";
@@ -0,0 +1,42 @@
1
+ import { ReactNode } from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+ export type BannerTypes = "error" | "warning" | "notice";
4
+ export interface BannerStyleProps {
5
+ /**
6
+ * Styles applied to the main view of the banner. Styles are grabbed from Banner.style.ts file
7
+ */
8
+ readonly styles: StyleProp<ViewStyle>;
9
+ }
10
+ interface ActionProps {
11
+ /**
12
+ * The function that should be performed when the Banner is pressed
13
+ */
14
+ readonly onPress: () => void;
15
+ /**
16
+ * Helper text displayed for press action
17
+ */
18
+ readonly label: string;
19
+ }
20
+ export interface BannerProps {
21
+ /**
22
+ * The function that should be performed when the Banner is pressed
23
+ */
24
+ readonly action?: ActionProps;
25
+ /**
26
+ * Optional custom content that can be displayed below the text and details
27
+ */
28
+ readonly children?: ReactNode;
29
+ /**
30
+ * Text to display below the 'text' prop. Will display a single message or bullet points of messages if multiple are provided
31
+ */
32
+ readonly details?: string[];
33
+ /**
34
+ * The primary text to display in the banner
35
+ */
36
+ readonly text: string;
37
+ /**
38
+ * The primary theme of the banner, controls the things like the background color
39
+ */
40
+ readonly type: BannerTypes;
41
+ }
42
+ export {};
@@ -2,6 +2,7 @@ export * from "./ActionItem";
2
2
  export * from "./ActionLabel";
3
3
  export * from "./ActivityIndicator";
4
4
  export * from "./AtlantisContext";
5
+ export * from "./Banner";
5
6
  export * from "./BottomSheet";
6
7
  export * from "./Button";
7
8
  export * from "./ButtonGroup";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.32.1",
3
+ "version": "0.33.0",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -73,5 +73,5 @@
73
73
  "react": "^18",
74
74
  "react-native": ">=0.69.2"
75
75
  },
76
- "gitHead": "2a0c4b363808d19c8bd851461754fa70494d570e"
76
+ "gitHead": "1ed63d6aa25671ec81fd10f96ac95ba4986b3d7b"
77
77
  }
@@ -0,0 +1,17 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+
4
+ export const styles = StyleSheet.create({
5
+ container: {
6
+ width: "100%",
7
+ },
8
+ error: {
9
+ backgroundColor: tokens["color-critical--surface"],
10
+ },
11
+ warning: {
12
+ backgroundColor: tokens["color-warning--surface"],
13
+ },
14
+ notice: {
15
+ backgroundColor: tokens["color-informative--surface"],
16
+ },
17
+ });
@@ -0,0 +1,51 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { Banner } from ".";
4
+ import { tokens } from "../utils/design";
5
+
6
+ describe("Banner", () => {
7
+ it("renders an error Banner", () => {
8
+ const { getByText, getByRole } = render(
9
+ <Banner type="error" text="An error happened" />,
10
+ );
11
+ const alertPressable = getByRole("alert");
12
+ expect(getByText("An error happened")).toBeDefined();
13
+ expect(alertPressable.props.style).toContainEqual({
14
+ backgroundColor: tokens["color-critical--surface"],
15
+ });
16
+ });
17
+
18
+ it("renders a warning Banner", () => {
19
+ const { getByText, getByRole } = render(
20
+ <Banner type="warning" text="Here is a warning" />,
21
+ );
22
+
23
+ const alertPressable = getByRole("alert");
24
+ expect(getByText("Here is a warning")).toBeDefined();
25
+ expect(alertPressable.props.style).toContainEqual({
26
+ backgroundColor: tokens["color-warning--surface"],
27
+ });
28
+ });
29
+
30
+ it("renders a Banner with details", () => {
31
+ const tree = render(
32
+ <Banner type="error" text="You are disconnected" details={["details"]} />,
33
+ );
34
+
35
+ expect(tree.getByText("You are disconnected")).toBeDefined();
36
+ expect(tree.getByText("details")).toBeDefined();
37
+ });
38
+
39
+ it("renders a Banner with multiple details", () => {
40
+ const tree = render(
41
+ <Banner
42
+ type="error"
43
+ text="You are disconnected"
44
+ details={["details", "etc"]}
45
+ />,
46
+ );
47
+
48
+ expect(tree.getByText("details")).toBeDefined();
49
+ expect(tree.getByText("etc")).toBeDefined();
50
+ });
51
+ });
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { Pressable } from "react-native";
3
+ import { BannerProps } from "./types";
4
+ import { BannerTypeStyles } from "./constants";
5
+ import { styles } from "./Banner.style";
6
+ import { Content } from "../Content";
7
+ import { Text } from "../Text";
8
+ import { TextList } from "../TextList";
9
+ import { ActionLabel } from "../ActionLabel";
10
+
11
+ export function Banner({
12
+ action,
13
+ details,
14
+ text,
15
+ type,
16
+ }: BannerProps): JSX.Element {
17
+ return (
18
+ <Pressable
19
+ style={[styles.container, BannerTypeStyles[type].styles]}
20
+ accessibilityRole="alert"
21
+ onPress={action?.onPress}
22
+ >
23
+ <Content childSpacing="small">
24
+ <Text level="textSupporting">{text}</Text>
25
+ {details && <TextList items={details} level="textSupporting" />}
26
+ {action && <ActionLabel align="start">{action.label}</ActionLabel>}
27
+ </Content>
28
+ </Pressable>
29
+ );
30
+ }
@@ -0,0 +1,14 @@
1
+ import { styles } from "./Banner.style";
2
+ import { BannerStyleProps } from "./types";
3
+
4
+ export const BannerTypeStyles: Record<string, BannerStyleProps> = {
5
+ error: {
6
+ styles: styles.error,
7
+ },
8
+ warning: {
9
+ styles: styles.warning,
10
+ },
11
+ notice: {
12
+ styles: styles.notice,
13
+ },
14
+ };
@@ -0,0 +1,2 @@
1
+ export { Banner } from "./Banner";
2
+ export type { BannerTypes } from "./types";
@@ -0,0 +1,50 @@
1
+ import { ReactNode } from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+
4
+ export type BannerTypes = "error" | "warning" | "notice";
5
+
6
+ export interface BannerStyleProps {
7
+ /**
8
+ * Styles applied to the main view of the banner. Styles are grabbed from Banner.style.ts file
9
+ */
10
+ readonly styles: StyleProp<ViewStyle>;
11
+ }
12
+
13
+ interface ActionProps {
14
+ /**
15
+ * The function that should be performed when the Banner is pressed
16
+ */
17
+ readonly onPress: () => void;
18
+
19
+ /**
20
+ * Helper text displayed for press action
21
+ */
22
+ readonly label: string;
23
+ }
24
+
25
+ export interface BannerProps {
26
+ /**
27
+ * The function that should be performed when the Banner is pressed
28
+ */
29
+ readonly action?: ActionProps;
30
+
31
+ /**
32
+ * Optional custom content that can be displayed below the text and details
33
+ */
34
+ readonly children?: ReactNode;
35
+
36
+ /**
37
+ * Text to display below the 'text' prop. Will display a single message or bullet points of messages if multiple are provided
38
+ */
39
+ readonly details?: string[];
40
+
41
+ /**
42
+ * The primary text to display in the banner
43
+ */
44
+ readonly text: string;
45
+
46
+ /**
47
+ * The primary theme of the banner, controls the things like the background color
48
+ */
49
+ readonly type: BannerTypes;
50
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./ActionItem";
2
2
  export * from "./ActionLabel";
3
3
  export * from "./ActivityIndicator";
4
4
  export * from "./AtlantisContext";
5
+ export * from "./Banner";
5
6
  export * from "./BottomSheet";
6
7
  export * from "./Button";
7
8
  export * from "./ButtonGroup";