@jobber/components-native 0.2.1 → 0.4.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/ActivityIndicator/ActivityIndicator.js +6 -0
  2. package/dist/src/ActivityIndicator/index.js +1 -0
  3. package/dist/src/Content/Content.js +24 -0
  4. package/dist/src/Content/ContentHorizontal.style.js +30 -0
  5. package/dist/src/Content/ContentSpaceAround.style.js +22 -0
  6. package/dist/src/Content/ContentVertical.style.js +30 -0
  7. package/dist/src/Content/index.js +1 -0
  8. package/dist/src/Text/Text.js +36 -0
  9. package/dist/src/Text/index.js +1 -0
  10. package/dist/src/index.js +3 -0
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/dist/types/src/ActivityIndicator/ActivityIndicator.d.ts +3 -0
  13. package/dist/types/src/ActivityIndicator/index.d.ts +1 -0
  14. package/dist/types/src/Content/Content.d.ts +18 -0
  15. package/dist/types/src/Content/ContentHorizontal.style.d.ts +28 -0
  16. package/dist/types/src/Content/ContentSpaceAround.style.d.ts +20 -0
  17. package/dist/types/src/Content/ContentVertical.style.d.ts +22 -0
  18. package/dist/types/src/Content/index.d.ts +2 -0
  19. package/dist/types/src/Text/Text.d.ts +56 -0
  20. package/dist/types/src/Text/index.d.ts +1 -0
  21. package/dist/types/src/index.d.ts +3 -0
  22. package/package.json +3 -2
  23. package/src/ActivityIndicator/ActivityIndicator.test.tsx +28 -0
  24. package/src/ActivityIndicator/ActivityIndicator.tsx +15 -0
  25. package/src/ActivityIndicator/index.ts +1 -0
  26. package/src/Content/Content.test.tsx +260 -0
  27. package/src/Content/Content.tsx +66 -0
  28. package/src/Content/ContentHorizontal.style.ts +38 -0
  29. package/src/Content/ContentSpaceAround.style.ts +28 -0
  30. package/src/Content/ContentVertical.style.ts +38 -0
  31. package/src/Content/index.ts +2 -0
  32. package/src/Text/Text.test.tsx +139 -0
  33. package/src/Text/Text.tsx +151 -0
  34. package/src/Text/__snapshots__/Text.test.tsx.snap +618 -0
  35. package/src/Text/index.ts +1 -0
  36. package/src/index.ts +3 -0
@@ -0,0 +1,139 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { Text } from ".";
4
+
5
+ it("renders text with no additional props", () => {
6
+ const text = render(<Text>Test Text</Text>);
7
+ expect(text.toJSON()).toMatchSnapshot();
8
+ });
9
+
10
+ it("renders text with base variation", () => {
11
+ const text = render(<Text variation="base">Test Text</Text>);
12
+ expect(text.toJSON()).toMatchSnapshot();
13
+ });
14
+
15
+ it("renders text with success variation", () => {
16
+ const text = render(<Text variation="success">Test Text</Text>);
17
+ expect(text.toJSON()).toMatchSnapshot();
18
+ });
19
+
20
+ it("renders text with error variation", () => {
21
+ const text = render(<Text variation="error">Test Text</Text>);
22
+ expect(text.toJSON()).toMatchSnapshot();
23
+ });
24
+
25
+ it("renders text with warn variation", () => {
26
+ const text = render(<Text variation="warn">Test Text</Text>);
27
+ expect(text.toJSON()).toMatchSnapshot();
28
+ });
29
+
30
+ it("renders text with info variation", () => {
31
+ const text = render(<Text variation="info">Test Text</Text>);
32
+ expect(text.toJSON()).toMatchSnapshot();
33
+ });
34
+
35
+ it("renders text with subdued variation", () => {
36
+ const text = render(<Text variation="subdued">Test Text</Text>);
37
+ expect(text.toJSON()).toMatchSnapshot();
38
+ });
39
+
40
+ it("renders text with success variation reverseTheme true", () => {
41
+ const text = render(
42
+ <Text variation="success" reverseTheme={true}>
43
+ Test Text
44
+ </Text>,
45
+ );
46
+ expect(text.toJSON()).toMatchSnapshot();
47
+ });
48
+
49
+ it("renders text with error variation reverseTheme true", () => {
50
+ const text = render(
51
+ <Text variation="error" reverseTheme={true}>
52
+ Test Text
53
+ </Text>,
54
+ );
55
+ expect(text.toJSON()).toMatchSnapshot();
56
+ });
57
+
58
+ it("renders text supporting with no additional props", () => {
59
+ const text = render(<Text level="textSupporting">Test Text</Text>);
60
+ expect(text.toJSON()).toMatchSnapshot();
61
+ });
62
+
63
+ it("renders text supporting with variation success", () => {
64
+ const text = render(
65
+ <Text level="textSupporting" variation="success">
66
+ Test Text
67
+ </Text>,
68
+ );
69
+ expect(text.toJSON()).toMatchSnapshot();
70
+ });
71
+
72
+ it("renders text supporting with variation success reverseTheme true", () => {
73
+ const text = render(
74
+ <Text level="textSupporting" variation="success" reverseTheme={true}>
75
+ Test Text
76
+ </Text>,
77
+ );
78
+ expect(text.toJSON()).toMatchSnapshot();
79
+ });
80
+
81
+ it("renders text with right alignment", () => {
82
+ const text = render(<Text align="end">Test Text</Text>);
83
+ expect(text.toJSON()).toMatchSnapshot();
84
+ });
85
+
86
+ it("renders text with center alignment", () => {
87
+ const text = render(<Text align="center">Test Text</Text>);
88
+ expect(text.toJSON()).toMatchSnapshot();
89
+ });
90
+
91
+ it("renders text with left alignment", () => {
92
+ const text = render(<Text align="start">Test Text</Text>);
93
+ expect(text.toJSON()).toMatchSnapshot();
94
+ });
95
+
96
+ it("renders text that is scaled down with adjustsFontSize true", () => {
97
+ const text = render(
98
+ <Text maxLines="base" adjustsFontSizeToFit={true}>
99
+ The quick brown fox jumped over the lazy dog. The quick brown fox jumped
100
+ over the lazy dog. The quick brown fox jumped over the lazy dog. The quick
101
+ brown fox jumped over the lazy dog. The quick brown fox jumped over the
102
+ lazy dog. The quick brown fox jumped over the lazy dog
103
+ </Text>,
104
+ );
105
+ expect(text.toJSON()).toMatchSnapshot();
106
+ });
107
+
108
+ it("renders text that is not scaled down with adjustsFontSize false", () => {
109
+ const text = render(
110
+ <Text maxLines="base" adjustsFontSizeToFit={false}>
111
+ The quick brown fox jumped over the lazy dog. The quick brown fox jumped
112
+ over the lazy dog. The quick brown fox jumped over the lazy dog. The quick
113
+ brown fox jumped over the lazy dog. The quick brown fox jumped over the
114
+ lazy dog. The quick brown fox jumped over the lazy dog
115
+ </Text>,
116
+ );
117
+ expect(text.toJSON()).toMatchSnapshot();
118
+ });
119
+
120
+ it("renders text with accessibilityRole set as text", () => {
121
+ const text = render(<Text>Test Text</Text>);
122
+ expect(text.getByRole("text")).toBeDefined();
123
+ });
124
+
125
+ it("renders with strikethrough styling", () => {
126
+ const text = render(<Text strikeThrough={true}>Test Text</Text>);
127
+ expect(text.toJSON()).toMatchSnapshot();
128
+ });
129
+
130
+ it("renders text that is inaccessible", () => {
131
+ const text = render(<Text hideFromScreenReader={true}>Test Text</Text>);
132
+ expect(text.root.props).toEqual(
133
+ expect.objectContaining({
134
+ accessibilityRole: "none",
135
+ accessible: false,
136
+ importantForAccessibility: "no-hide-descendants",
137
+ }),
138
+ );
139
+ });
@@ -0,0 +1,151 @@
1
+ import React from "react";
2
+ import {
3
+ BaseWeight,
4
+ LineHeight,
5
+ TextAccessibilityRole,
6
+ TextAlign,
7
+ TextSize,
8
+ TextVariation,
9
+ TruncateLength,
10
+ Typography,
11
+ TypographyProps,
12
+ } from "../Typography";
13
+ import { tokens } from "../utils/design";
14
+
15
+ interface TextProps
16
+ extends Pick<TypographyProps<"base">, "maxFontScaleSize" | "selectable"> {
17
+ /**
18
+ * Visual hierarchy of the text
19
+ */
20
+ readonly level?: TextLevel;
21
+
22
+ /**
23
+ * Color variation of text
24
+ */
25
+ readonly variation?: TextVariation;
26
+
27
+ /**
28
+ * Change the appearance of the text
29
+ */
30
+ readonly emphasis?: "strong";
31
+
32
+ /**
33
+ * Allow text to be resized based on user's device display scale
34
+ */
35
+ readonly allowFontScaling?: boolean;
36
+
37
+ /**
38
+ * Determines whether text should be scaled down to fit based on maxLines prop
39
+ */
40
+ readonly adjustsFontSizeToFit?: boolean;
41
+
42
+ /**
43
+ * The maximum amount of lines the text can occupy before being truncated with "...".
44
+ * Uses predefined string values that correspond to a doubling scale for the amount of lines.
45
+ */
46
+ readonly maxLines?: TruncateLength;
47
+
48
+ /**
49
+ * Alignment of text
50
+ */
51
+ readonly align?: TextAlign;
52
+
53
+ /**
54
+ * Text to display
55
+ */
56
+ readonly children?: string;
57
+
58
+ /**
59
+ * Reverse theme for better display on dark background
60
+ */
61
+ readonly reverseTheme?: boolean;
62
+
63
+ /**
64
+ * Have text styled with strike through
65
+ */
66
+ readonly strikeThrough?: boolean;
67
+
68
+ /**
69
+ * This will make the text inaccessible to the screen reader.
70
+ * This should be avoided unless there is a good reason.
71
+ * For example this is used in InputText to make it so the label isn't
72
+ * selectable because it is already read from the accessibilityLabel
73
+ * of the TextInput
74
+ */
75
+ readonly hideFromScreenReader?: boolean;
76
+ }
77
+
78
+ export type TextLevel = "text" | "textSupporting";
79
+
80
+ interface LevelStyle {
81
+ readonly size: TextSize;
82
+ readonly lineHeight: LineHeight;
83
+ }
84
+
85
+ const levelStyles: Record<TextLevel, LevelStyle> = {
86
+ text: {
87
+ size: "default",
88
+ lineHeight: "base",
89
+ },
90
+ textSupporting: {
91
+ size: "small",
92
+ lineHeight: "tight",
93
+ },
94
+ };
95
+
96
+ const MAX_TEXT_FONT_SIZE_SCALE = 50;
97
+ const maxScaledFontSize: Record<TextLevel, number> = {
98
+ text: MAX_TEXT_FONT_SIZE_SCALE,
99
+ textSupporting: tokens["typography--fontSize-base"],
100
+ };
101
+
102
+ export function Text({
103
+ level = "text",
104
+ variation = "base",
105
+ emphasis,
106
+ allowFontScaling = true,
107
+ adjustsFontSizeToFit = false,
108
+ maxLines = "unlimited",
109
+ align,
110
+ children,
111
+ reverseTheme = false,
112
+ strikeThrough = false,
113
+ hideFromScreenReader = false,
114
+ maxFontScaleSize,
115
+ selectable,
116
+ }: TextProps): JSX.Element {
117
+ const accessibilityRole: TextAccessibilityRole = "text";
118
+
119
+ return (
120
+ <Typography
121
+ color={variation}
122
+ fontFamily="base"
123
+ fontStyle="regular"
124
+ fontWeight={getFontWeight({ level, emphasis })}
125
+ maxFontScaleSize={maxFontScaleSize || maxScaledFontSize[level]}
126
+ selectable={selectable}
127
+ {...{
128
+ ...levelStyles[level],
129
+ allowFontScaling,
130
+ align,
131
+ adjustsFontSizeToFit,
132
+ accessibilityRole,
133
+ reverseTheme,
134
+ maxLines,
135
+ strikeThrough,
136
+ hideFromScreenReader,
137
+ }}
138
+ >
139
+ {children}
140
+ </Typography>
141
+ );
142
+ }
143
+
144
+ function getFontWeight({
145
+ level,
146
+ emphasis,
147
+ }: Pick<TextProps, "level" | "emphasis">): BaseWeight {
148
+ if (emphasis === "strong") return "semiBold";
149
+ if (level === "textSupporting") return "medium";
150
+ return "regular";
151
+ }