@jobber/components-native 0.82.0 → 0.82.1-JOB-131123-e5eeb18.39
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.
- package/dist/package.json +2 -2
- package/dist/src/Text/Text.js +2 -2
- package/dist/src/Typography/Typography.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Text/Text.d.ts +6 -2
- package/dist/types/src/Typography/Typography.d.ts +3 -1
- package/dist/types/src/Typography/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/Text/Text.test.tsx +34 -6
- package/src/Text/Text.tsx +8 -0
- package/src/Text/__snapshots__/Text.test.tsx.snap +1 -1
- package/src/Typography/Typography.test.tsx +32 -1
- package/src/Typography/Typography.tsx +6 -0
- package/src/Typography/index.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextAlign, TextVariation, TruncateLength, TypographyProps } from "../Typography";
|
|
1
|
+
import { OnTextLayoutEvent, TextAlign, TextVariation, TruncateLength, TypographyProps } from "../Typography";
|
|
2
2
|
import { TypographyUnsafeStyle } from "../Typography/Typography";
|
|
3
3
|
export interface TextProps extends Pick<TypographyProps<"base">, "maxFontScaleSize" | "selectable"> {
|
|
4
4
|
/**
|
|
@@ -66,7 +66,11 @@ export interface TextProps extends Pick<TypographyProps<"base">, "maxFontScaleSi
|
|
|
66
66
|
* More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
|
|
67
67
|
*/
|
|
68
68
|
readonly UNSAFE_style?: TypographyUnsafeStyle;
|
|
69
|
+
/**
|
|
70
|
+
* Callback that is called when the text is laid out.
|
|
71
|
+
*/
|
|
72
|
+
readonly onTextLayout?: OnTextLayoutEvent;
|
|
69
73
|
}
|
|
70
74
|
export type TextLevel = "text" | "textSupporting";
|
|
71
75
|
export declare const TEXT_MAX_SCALED_FONT_SIZES: Record<TextLevel, number>;
|
|
72
|
-
export declare function Text({ level, variation, emphasis, allowFontScaling, adjustsFontSizeToFit, maxLines, align, children, reverseTheme, strikeThrough, italic, hideFromScreenReader, maxFontScaleSize, UNSAFE_style, underline, selectable, }: TextProps): JSX.Element;
|
|
76
|
+
export declare function Text({ level, variation, emphasis, allowFontScaling, adjustsFontSizeToFit, maxLines, align, children, reverseTheme, strikeThrough, italic, hideFromScreenReader, maxFontScaleSize, UNSAFE_style, underline, selectable, onTextLayout, }: TextProps): JSX.Element;
|
|
@@ -86,12 +86,13 @@ export interface TypographyProps<T extends FontFamily> extends Pick<TextProps, "
|
|
|
86
86
|
*/
|
|
87
87
|
readonly strikeThrough?: boolean;
|
|
88
88
|
readonly UNSAFE_style?: TypographyUnsafeStyle;
|
|
89
|
+
readonly onTextLayout?: OnTextLayoutEvent;
|
|
89
90
|
}
|
|
90
91
|
export interface TypographyUnsafeStyle {
|
|
91
92
|
textStyle?: StyleProp<TextStyle>;
|
|
92
93
|
}
|
|
93
94
|
export declare const Typography: React.MemoExoticComponent<typeof InternalTypography>;
|
|
94
|
-
declare function InternalTypography<T extends FontFamily = "base">({ fontFamily, fontStyle, fontWeight, transform, color, align, size, children, maxLines, allowFontScaling, maxFontScaleSize, adjustsFontSizeToFit, lineHeight, letterSpacing, reverseTheme, hideFromScreenReader, accessibilityRole, strikeThrough, underline, UNSAFE_style, selectable, }: TypographyProps<T>): JSX.Element;
|
|
95
|
+
declare function InternalTypography<T extends FontFamily = "base">({ fontFamily, fontStyle, fontWeight, transform, color, align, size, children, maxLines, allowFontScaling, maxFontScaleSize, adjustsFontSizeToFit, lineHeight, letterSpacing, reverseTheme, hideFromScreenReader, accessibilityRole, strikeThrough, underline, UNSAFE_style, selectable, onTextLayout, }: TypographyProps<T>): JSX.Element;
|
|
95
96
|
export type FontFamily = "base" | "display";
|
|
96
97
|
export type FontStyle = "regular" | "italic";
|
|
97
98
|
export type FontWeight = "regular" | "medium" | "bold" | "semiBold" | "extraBold" | "black";
|
|
@@ -108,4 +109,5 @@ export type LineHeight = "extravagant" | "jumbo" | "largest" | "larger" | "large
|
|
|
108
109
|
export type LetterSpacing = "base" | "loose";
|
|
109
110
|
export type TextAccessibilityRole = "text" | "header";
|
|
110
111
|
export type TruncateLength = "single" | "small" | "base" | "large" | "extraLarge" | "unlimited";
|
|
112
|
+
export type OnTextLayoutEvent = Exclude<TextProps["onTextLayout"], undefined>;
|
|
111
113
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Typography } from "./Typography";
|
|
2
|
-
export type { FontFamily, FontStyle, FontWeight, BaseWeight, DisplayWeight, BaseStyle, DisplayStyle, TextColor, TextTransform, TextSize, TextAlign, LineHeight, LetterSpacing, TextAccessibilityRole, TextVariation, TypographyProps, TruncateLength, } from "./Typography";
|
|
2
|
+
export type { FontFamily, FontStyle, FontWeight, BaseWeight, DisplayWeight, BaseStyle, DisplayStyle, TextColor, TextTransform, TextSize, TextAlign, LineHeight, LetterSpacing, TextAccessibilityRole, TextVariation, TypographyProps, TruncateLength, OnTextLayoutEvent, } from "./Typography";
|
|
3
3
|
export { getTypographyStyles, useTypographyStyles } from "./Typography.style";
|
|
4
4
|
export { typographyStyles } from "./Typography.style";
|
|
5
5
|
export { TypographyGestureDetector } from "./TypographyGestureDetector";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.82.
|
|
3
|
+
"version": "0.82.1-JOB-131123-e5eeb18.39+e5eeb18c",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"react-native-safe-area-context": "^5.4.0",
|
|
80
80
|
"react-native-svg": ">=12.0.0"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "e5eeb18c68dd0ac545e56ef87cd7ca8f1edac8e9"
|
|
83
83
|
}
|
package/src/Text/Text.test.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render } from "@testing-library/react-native";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react-native";
|
|
3
3
|
import { Text } from ".";
|
|
4
4
|
import { tokens } from "../utils/design";
|
|
5
5
|
|
|
@@ -135,6 +135,7 @@ it("renders with italic styling", () => {
|
|
|
135
135
|
|
|
136
136
|
it("renders text that is inaccessible", () => {
|
|
137
137
|
const text = render(<Text hideFromScreenReader={true}>Test Text</Text>);
|
|
138
|
+
|
|
138
139
|
expect(text.root.props).toEqual(
|
|
139
140
|
expect.objectContaining({
|
|
140
141
|
accessibilityRole: "none",
|
|
@@ -145,7 +146,7 @@ it("renders text that is inaccessible", () => {
|
|
|
145
146
|
});
|
|
146
147
|
|
|
147
148
|
it("renders text with underline styling", () => {
|
|
148
|
-
const text = render(<Text underline="
|
|
149
|
+
const text = render(<Text underline="dotted">Test Text</Text>);
|
|
149
150
|
|
|
150
151
|
expect(text.toJSON()).toMatchSnapshot();
|
|
151
152
|
});
|
|
@@ -159,12 +160,39 @@ describe("UNSAFE_style", () => {
|
|
|
159
160
|
},
|
|
160
161
|
};
|
|
161
162
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
165
|
-
const textElement = getByRole("text");
|
|
163
|
+
render(<Text UNSAFE_style={customStyle}>Test Text</Text>);
|
|
164
|
+
const textElement = screen.getByRole("text");
|
|
166
165
|
expect(textElement.props.style).toContainEqual(
|
|
167
166
|
expect.objectContaining(customStyle.textStyle),
|
|
168
167
|
);
|
|
169
168
|
});
|
|
170
169
|
});
|
|
170
|
+
|
|
171
|
+
describe("onTextLayout", () => {
|
|
172
|
+
it("calls onTextLayout callback when text layout event occurs", () => {
|
|
173
|
+
const onTextLayoutMock = jest.fn();
|
|
174
|
+
render(<Text onTextLayout={onTextLayoutMock}>Test Text</Text>);
|
|
175
|
+
|
|
176
|
+
const textElement = screen.getByRole("text");
|
|
177
|
+
const mockEvent = {
|
|
178
|
+
nativeEvent: {
|
|
179
|
+
lines: [
|
|
180
|
+
{
|
|
181
|
+
text: "Test Text",
|
|
182
|
+
x: 0,
|
|
183
|
+
y: 0,
|
|
184
|
+
width: 100,
|
|
185
|
+
height: 20,
|
|
186
|
+
ascender: 15,
|
|
187
|
+
descender: -5,
|
|
188
|
+
capHeight: 14,
|
|
189
|
+
xHeight: 10,
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
fireEvent(textElement, "onTextLayout", mockEvent);
|
|
195
|
+
expect(onTextLayoutMock).toHaveBeenCalledTimes(1);
|
|
196
|
+
expect(onTextLayoutMock).toHaveBeenCalledWith(mockEvent);
|
|
197
|
+
});
|
|
198
|
+
});
|
package/src/Text/Text.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import React from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
BaseWeight,
|
|
4
4
|
LineHeight,
|
|
5
|
+
OnTextLayoutEvent,
|
|
5
6
|
TextAccessibilityRole,
|
|
6
7
|
TextAlign,
|
|
7
8
|
TextSize,
|
|
@@ -93,6 +94,11 @@ export interface TextProps
|
|
|
93
94
|
* More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
|
|
94
95
|
*/
|
|
95
96
|
readonly UNSAFE_style?: TypographyUnsafeStyle;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Callback that is called when the text is laid out.
|
|
100
|
+
*/
|
|
101
|
+
readonly onTextLayout?: OnTextLayoutEvent;
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
export type TextLevel = "text" | "textSupporting";
|
|
@@ -136,6 +142,7 @@ export function Text({
|
|
|
136
142
|
UNSAFE_style,
|
|
137
143
|
underline,
|
|
138
144
|
selectable,
|
|
145
|
+
onTextLayout,
|
|
139
146
|
}: TextProps): JSX.Element {
|
|
140
147
|
const accessibilityRole: TextAccessibilityRole = "text";
|
|
141
148
|
|
|
@@ -149,6 +156,7 @@ export function Text({
|
|
|
149
156
|
maxFontScaleSize={maxFontScaleSize || TEXT_MAX_SCALED_FONT_SIZES[level]}
|
|
150
157
|
selectable={selectable}
|
|
151
158
|
underline={underline}
|
|
159
|
+
onTextLayout={onTextLayout}
|
|
152
160
|
{...{
|
|
153
161
|
...levelStyles[level],
|
|
154
162
|
allowFontScaling,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render } from "@testing-library/react-native";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
3
|
import { I18nManager } from "react-native";
|
|
4
4
|
import { Typography } from "./Typography";
|
|
5
5
|
|
|
@@ -251,3 +251,34 @@ describe("underline", () => {
|
|
|
251
251
|
},
|
|
252
252
|
);
|
|
253
253
|
});
|
|
254
|
+
|
|
255
|
+
describe("onTextLayout", () => {
|
|
256
|
+
it("calls onTextLayout callback when text layout event occurs", () => {
|
|
257
|
+
const onTextLayoutMock = jest.fn();
|
|
258
|
+
const { getByRole } = render(
|
|
259
|
+
<Typography onTextLayout={onTextLayoutMock}>Test Text</Typography>,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const textElement = getByRole("text");
|
|
263
|
+
const mockEvent = {
|
|
264
|
+
nativeEvent: {
|
|
265
|
+
lines: [
|
|
266
|
+
{
|
|
267
|
+
text: "Test Text",
|
|
268
|
+
x: 0,
|
|
269
|
+
y: 0,
|
|
270
|
+
width: 100,
|
|
271
|
+
height: 20,
|
|
272
|
+
ascender: 15,
|
|
273
|
+
descender: -5,
|
|
274
|
+
capHeight: 14,
|
|
275
|
+
xHeight: 10,
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
fireEvent(textElement, "onTextLayout", mockEvent);
|
|
281
|
+
expect(onTextLayoutMock).toHaveBeenCalledTimes(1);
|
|
282
|
+
expect(onTextLayoutMock).toHaveBeenCalledWith(mockEvent);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
@@ -120,6 +120,8 @@ export interface TypographyProps<T extends FontFamily>
|
|
|
120
120
|
readonly strikeThrough?: boolean;
|
|
121
121
|
|
|
122
122
|
readonly UNSAFE_style?: TypographyUnsafeStyle;
|
|
123
|
+
|
|
124
|
+
readonly onTextLayout?: OnTextLayoutEvent;
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
const maxNumberOfLines = {
|
|
@@ -160,6 +162,7 @@ function InternalTypography<T extends FontFamily = "base">({
|
|
|
160
162
|
underline,
|
|
161
163
|
UNSAFE_style,
|
|
162
164
|
selectable = true,
|
|
165
|
+
onTextLayout,
|
|
163
166
|
}: TypographyProps<T>): JSX.Element {
|
|
164
167
|
const styles = useTypographyStyles();
|
|
165
168
|
const sizeAndHeight = getSizeAndHeightStyle(size, styles, lineHeight);
|
|
@@ -217,6 +220,7 @@ function InternalTypography<T extends FontFamily = "base">({
|
|
|
217
220
|
)}
|
|
218
221
|
selectable={selectable}
|
|
219
222
|
selectionColor={tokens["color-brand--highlight"]}
|
|
223
|
+
onTextLayout={onTextLayout}
|
|
220
224
|
>
|
|
221
225
|
{text}
|
|
222
226
|
</Text>
|
|
@@ -477,3 +481,5 @@ export type TruncateLength =
|
|
|
477
481
|
| "large"
|
|
478
482
|
| "extraLarge"
|
|
479
483
|
| "unlimited";
|
|
484
|
+
|
|
485
|
+
export type OnTextLayoutEvent = Exclude<TextProps["onTextLayout"], undefined>;
|
package/src/Typography/index.ts
CHANGED