@terreno/ui 0.13.3 → 0.14.1
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/ActionSheet.d.ts +5 -5
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Avatar.js +1 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/Banner.js.map +1 -1
- package/dist/Box.js +2 -0
- package/dist/Box.js.map +1 -1
- package/dist/Button.d.ts +2 -2
- package/dist/Button.js +35 -23
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +16 -4
- package/dist/Common.js +4 -4
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +3 -3
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +1 -1
- package/dist/ConsentNavigator.js +2 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/CustomSelectField.js +3 -1
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/DataTable.js +1 -1
- package/dist/DataTable.js.map +1 -1
- package/dist/DateTimeActionSheet.js +2 -1
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DateTimeField.js +3 -2
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DateUtilities.d.ts +25 -25
- package/dist/DateUtilities.js +31 -32
- package/dist/DateUtilities.js.map +1 -1
- package/dist/HeightField.js.map +1 -1
- package/dist/Hyperlink.js +19 -9
- package/dist/Hyperlink.js.map +1 -1
- package/dist/IconButton.js.map +1 -1
- package/dist/ImageBackground.d.ts +2 -5
- package/dist/ImageBackground.js +1 -1
- package/dist/ImageBackground.js.map +1 -1
- package/dist/MediaQuery.d.ts +4 -4
- package/dist/MediaQuery.js +8 -8
- package/dist/MediaQuery.js.map +1 -1
- package/dist/ModalSheet.d.ts +3 -2
- package/dist/ModalSheet.js +1 -1
- package/dist/ModalSheet.js.map +1 -1
- package/dist/OfflineBanner.d.ts +21 -0
- package/dist/OfflineBanner.js +25 -0
- package/dist/OfflineBanner.js.map +1 -0
- package/dist/OpenAPIContext.js +1 -1
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.d.ts +1 -0
- package/dist/Page.js +7 -2
- package/dist/Page.js.map +1 -1
- package/dist/Pagination.js.map +1 -1
- package/dist/Permissions.js +3 -0
- package/dist/Permissions.js.map +1 -1
- package/dist/PickerSelect.d.ts +1 -1
- package/dist/PickerSelect.js +9 -6
- package/dist/PickerSelect.js.map +1 -1
- package/dist/SelectField.js +1 -1
- package/dist/SelectField.js.map +1 -1
- package/dist/SplitPage.js +7 -2
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.js +4 -1
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.d.ts +1 -1
- package/dist/TapToEdit.js +12 -14
- package/dist/TapToEdit.js.map +1 -1
- package/dist/Toast.js.map +1 -1
- package/dist/ToastNotifications.js +2 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +24 -1
- package/dist/Tooltip.js +2 -2
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +3 -3
- package/dist/Unifier.js +15 -12
- package/dist/Unifier.js.map +1 -1
- package/dist/Utilities.d.ts +12 -8
- package/dist/Utilities.js +13 -15
- package/dist/Utilities.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/signUp/PasswordRequirements.js +3 -3
- package/dist/signUp/PasswordRequirements.js.map +1 -1
- package/dist/table/TableHeaderCell.js +1 -9
- package/dist/table/TableHeaderCell.js.map +1 -1
- package/dist/table/tableContext.d.ts +1 -1
- package/dist/table/tableContext.js +2 -2
- package/dist/table/tableContext.js.map +1 -1
- package/package.json +2 -1
- package/src/ActionSheet.test.tsx +1 -0
- package/src/ActionSheet.tsx +8 -6
- package/src/Avatar.tsx +9 -2
- package/src/Badge.test.tsx +1 -0
- package/src/Banner.test.tsx +71 -0
- package/src/Banner.tsx +1 -1
- package/src/Box.test.tsx +1 -0
- package/src/Box.tsx +10 -6
- package/src/Button.test.tsx +35 -0
- package/src/Button.tsx +65 -34
- package/src/Common.ts +42 -19
- package/src/ConsentFormScreen.test.tsx +124 -0
- package/src/ConsentFormScreen.tsx +18 -6
- package/src/ConsentNavigator.test.tsx +1 -0
- package/src/ConsentNavigator.tsx +5 -3
- package/src/CustomSelectField.tsx +3 -1
- package/src/DataTable.test.tsx +218 -0
- package/src/DataTable.tsx +1 -1
- package/src/DateTimeActionSheet.tsx +7 -3
- package/src/DateTimeField.test.tsx +1 -0
- package/src/DateTimeField.tsx +3 -2
- package/src/DateUtilities.test.ts +111 -0
- package/src/DateUtilities.tsx +43 -44
- package/src/DecimalRangeActionSheet.test.tsx +28 -0
- package/src/ErrorBoundary.test.tsx +1 -0
- package/src/HeightActionSheet.test.tsx +16 -0
- package/src/HeightField.test.tsx +106 -1
- package/src/HeightField.tsx +2 -1
- package/src/Hyperlink.tsx +83 -52
- package/src/IconButton.tsx +1 -1
- package/src/ImageBackground.tsx +5 -6
- package/src/MediaQuery.ts +8 -8
- package/src/MobileAddressAutoComplete.test.tsx +20 -1
- package/src/ModalSheet.test.tsx +1 -5
- package/src/ModalSheet.tsx +15 -6
- package/src/NumberField.test.tsx +14 -0
- package/src/OfflineBanner.test.tsx +70 -0
- package/src/OfflineBanner.tsx +54 -0
- package/src/OpenAPIContext.tsx +3 -2
- package/src/Page.test.tsx +28 -0
- package/src/Page.tsx +18 -2
- package/src/Pagination.tsx +1 -1
- package/src/Permissions.ts +3 -0
- package/src/PickerSelect.tsx +20 -17
- package/src/SelectBadge.test.tsx +1 -0
- package/src/SelectField.tsx +1 -1
- package/src/Signature.test.tsx +1 -0
- package/src/SplitPage.native.tsx +2 -0
- package/src/SplitPage.tsx +6 -1
- package/src/TapToEdit.test.tsx +48 -0
- package/src/TapToEdit.tsx +13 -14
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.test.tsx +738 -0
- package/src/ToastNotifications.tsx +3 -6
- package/src/Tooltip.test.tsx +586 -8
- package/src/Tooltip.tsx +2 -2
- package/src/Unifier.ts +20 -16
- package/src/Utilities.tsx +20 -19
- package/src/WebAddressAutocomplete.test.tsx +138 -0
- package/src/WebDropdownMenu.test.tsx +23 -0
- package/src/__snapshots__/AddressField.test.tsx.snap +3 -1
- package/src/__snapshots__/Button.test.tsx.snap +92 -50
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +21 -7
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +14 -8
- package/src/__snapshots__/ErrorPage.test.tsx.snap +7 -4
- package/src/__snapshots__/Field.test.tsx.snap +18 -6
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +14 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +35 -20
- package/src/__snapshots__/InfoModalIcon.test.tsx.snap +28 -16
- package/src/__snapshots__/Modal.test.tsx.snap +19 -10
- package/src/__snapshots__/ModalSheet.test.tsx.snap +0 -1
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +14 -8
- package/src/__snapshots__/Page.test.tsx.snap +7 -4
- package/src/__snapshots__/SelectField.test.tsx.snap +18 -6
- package/src/__snapshots__/TerrenoProvider.test.tsx.snap +0 -2
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +18 -6
- package/src/bunSetup.ts +25 -2
- package/src/index.tsx +2 -1
- package/src/login/LoginScreen.test.tsx +23 -1
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +15 -6
- package/src/signUp/PasswordRequirements.tsx +9 -6
- package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +50 -2
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +35 -5
- package/src/table/TableHeaderCell.tsx +8 -11
- package/src/table/TableRow.test.tsx +31 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +3 -1
- package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +2 -0
- package/src/table/tableContext.tsx +2 -2
- package/src/types/react-native-swiper-flatlist.d.ts +1 -0
- package/src/useStoredState.test.tsx +47 -0
|
@@ -94,4 +94,32 @@ describe("DecimalRangeActionSheet", () => {
|
|
|
94
94
|
});
|
|
95
95
|
expect(handleChange).toHaveBeenCalled();
|
|
96
96
|
});
|
|
97
|
+
|
|
98
|
+
it("invokes actionSheetRef.setModalVisible(false) when Close is pressed", () => {
|
|
99
|
+
const actionSheetRef = createRef<ActionSheet>();
|
|
100
|
+
const {UNSAFE_getAllByProps} = render(
|
|
101
|
+
<ThemeProvider>
|
|
102
|
+
<DecimalRangeActionSheet
|
|
103
|
+
actionSheetRef={actionSheetRef}
|
|
104
|
+
max={10}
|
|
105
|
+
min={0}
|
|
106
|
+
onChange={() => {}}
|
|
107
|
+
value="5.5"
|
|
108
|
+
/>
|
|
109
|
+
</ThemeProvider>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// Spy on the ActionSheet instance's setModalVisible after React assigns the ref
|
|
113
|
+
const spy = mock(() => {});
|
|
114
|
+
if (actionSheetRef.current) {
|
|
115
|
+
actionSheetRef.current.setModalVisible = spy;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const closeButtons = UNSAFE_getAllByProps({text: "Close"});
|
|
119
|
+
const buttonOnClick = closeButtons[0].props.onClick as () => void;
|
|
120
|
+
act(() => {
|
|
121
|
+
buttonOnClick();
|
|
122
|
+
});
|
|
123
|
+
expect(spy).toHaveBeenCalledWith(false);
|
|
124
|
+
});
|
|
97
125
|
});
|
|
@@ -3,6 +3,7 @@ import {act, render} from "@testing-library/react-native";
|
|
|
3
3
|
import {createRef} from "react";
|
|
4
4
|
|
|
5
5
|
import type {ActionSheet} from "./ActionSheet";
|
|
6
|
+
import {Button} from "./Button";
|
|
6
7
|
import {HeightActionSheet} from "./HeightActionSheet";
|
|
7
8
|
import {ThemeProvider} from "./Theme";
|
|
8
9
|
|
|
@@ -86,4 +87,19 @@ describe("HeightActionSheet", () => {
|
|
|
86
87
|
});
|
|
87
88
|
expect(handleChange).toHaveBeenCalled();
|
|
88
89
|
});
|
|
90
|
+
|
|
91
|
+
it("calls the Done button onClick handler directly", () => {
|
|
92
|
+
const actionSheetRef = createRef<ActionSheet>();
|
|
93
|
+
const {UNSAFE_root} = render(
|
|
94
|
+
<ThemeProvider>
|
|
95
|
+
<HeightActionSheet actionSheetRef={actionSheetRef} onChange={() => {}} value="60" />
|
|
96
|
+
</ThemeProvider>
|
|
97
|
+
);
|
|
98
|
+
const buttons = UNSAFE_root.findAllByType(Button as never);
|
|
99
|
+
const doneBtn = buttons.find((b) => b.props.text === "Done");
|
|
100
|
+
expect(doneBtn).toBeTruthy();
|
|
101
|
+
act(() => {
|
|
102
|
+
doneBtn!.props.onClick();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
89
105
|
});
|
package/src/HeightField.test.tsx
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import {fireEvent} from "@testing-library/react-native";
|
|
3
3
|
import {HeightActionSheet} from "./HeightActionSheet";
|
|
4
4
|
import {HeightField} from "./HeightField";
|
|
5
5
|
import {renderWithTheme} from "./test-utils";
|
|
6
|
+
import * as Utilities from "./Utilities";
|
|
6
7
|
|
|
7
8
|
describe("HeightField", () => {
|
|
8
9
|
let mockOnChange: ReturnType<typeof mock>;
|
|
@@ -274,3 +275,107 @@ describe("HeightField - Android platform", () => {
|
|
|
274
275
|
expect(onChange).toHaveBeenCalledWith("63");
|
|
275
276
|
});
|
|
276
277
|
});
|
|
278
|
+
|
|
279
|
+
describe("HeightField - Desktop platform", () => {
|
|
280
|
+
const {Platform} = require("react-native") as {Platform: {OS: string}};
|
|
281
|
+
const originalOS = Platform.OS;
|
|
282
|
+
let isNativeSpy: ReturnType<typeof spyOn>;
|
|
283
|
+
|
|
284
|
+
beforeEach(() => {
|
|
285
|
+
Platform.OS = "web";
|
|
286
|
+
isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
afterEach(() => {
|
|
290
|
+
Platform.OS = originalOS;
|
|
291
|
+
isNativeSpy.mockRestore();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("fires handleBlur on HeightSegment and calls onChange", () => {
|
|
295
|
+
const onChange = mock(() => {});
|
|
296
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
297
|
+
const feetInput = getByLabelText("ft input");
|
|
298
|
+
fireEvent(feetInput, "blur");
|
|
299
|
+
expect(onChange).toHaveBeenCalled();
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("handles text input change in feet segment", () => {
|
|
303
|
+
const onChange = mock(() => {});
|
|
304
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
305
|
+
const feetInput = getByLabelText("ft input");
|
|
306
|
+
fireEvent.changeText(feetInput, "6");
|
|
307
|
+
expect(onChange).toHaveBeenCalled();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("handles clearing feet input to empty", () => {
|
|
311
|
+
const onChange = mock(() => {});
|
|
312
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
313
|
+
const feetInput = getByLabelText("ft input");
|
|
314
|
+
fireEvent.changeText(feetInput, "");
|
|
315
|
+
expect(onChange).toHaveBeenCalled();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("calls onChange with empty when both feet and inches are cleared", () => {
|
|
319
|
+
const onChange = mock(() => {});
|
|
320
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="" />);
|
|
321
|
+
const feetInput = getByLabelText("ft input");
|
|
322
|
+
fireEvent.changeText(feetInput, "");
|
|
323
|
+
expect(onChange).toHaveBeenCalledWith("");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("renders HeightSegment in disabled state", () => {
|
|
327
|
+
const onChange = mock(() => {});
|
|
328
|
+
const {getByLabelText} = renderWithTheme(
|
|
329
|
+
<HeightField disabled onChange={onChange} value="70" />
|
|
330
|
+
);
|
|
331
|
+
expect(getByLabelText("ft input")).toBeTruthy();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("renders HeightSegment with error text", () => {
|
|
335
|
+
const onChange = mock(() => {});
|
|
336
|
+
const {getByLabelText} = renderWithTheme(
|
|
337
|
+
<HeightField errorText="Required" onChange={onChange} value="70" />
|
|
338
|
+
);
|
|
339
|
+
expect(getByLabelText("ft input")).toBeTruthy();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("fires focus on feet segment", () => {
|
|
343
|
+
const onChange = mock(() => {});
|
|
344
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
345
|
+
const feetInput = getByLabelText("ft input");
|
|
346
|
+
fireEvent(feetInput, "focus");
|
|
347
|
+
expect(feetInput).toBeTruthy();
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("fires focus on inches segment", () => {
|
|
351
|
+
const onChange = mock(() => {});
|
|
352
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
353
|
+
const inInput = getByLabelText("in input");
|
|
354
|
+
fireEvent(inInput, "focus");
|
|
355
|
+
expect(inInput).toBeTruthy();
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("handles text input change in inches segment", () => {
|
|
359
|
+
const onChange = mock(() => {});
|
|
360
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
361
|
+
const inInput = getByLabelText("in input");
|
|
362
|
+
fireEvent.changeText(inInput, "3");
|
|
363
|
+
expect(onChange).toHaveBeenCalled();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("handles non-numeric input in HeightSegment", () => {
|
|
367
|
+
const onChange = mock(() => {});
|
|
368
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
369
|
+
const feetInput = getByLabelText("ft input");
|
|
370
|
+
fireEvent.changeText(feetInput, "abc");
|
|
371
|
+
expect(onChange).toHaveBeenCalled();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("clamps to max value in HeightSegment handleChange", () => {
|
|
375
|
+
const onChange = mock(() => {});
|
|
376
|
+
const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
|
|
377
|
+
const feetInput = getByLabelText("ft input");
|
|
378
|
+
fireEvent.changeText(feetInput, "99");
|
|
379
|
+
expect(feetInput).toBeTruthy();
|
|
380
|
+
});
|
|
381
|
+
});
|
package/src/HeightField.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {type FC, useCallback, useEffect, useMemo, useRef, useState} from "react";
|
|
2
2
|
import {Platform, Pressable, type StyleProp, TextInput, View} from "react-native";
|
|
3
3
|
|
|
4
|
+
import type {ActionSheet} from "./ActionSheet";
|
|
4
5
|
import {Box} from "./Box";
|
|
5
6
|
import type {HeightFieldProps, TextStyleWithOutline} from "./Common";
|
|
6
7
|
import {FieldError, FieldHelperText, FieldTitle} from "./fieldElements";
|
|
@@ -154,7 +155,7 @@ export const HeightField: FC<HeightFieldProps> = ({
|
|
|
154
155
|
max,
|
|
155
156
|
}) => {
|
|
156
157
|
const {theme} = useTheme();
|
|
157
|
-
const actionSheetRef
|
|
158
|
+
const actionSheetRef = useRef<ActionSheet | null>(null);
|
|
158
159
|
const isMobileOrNative = isMobileDevice() || isNative();
|
|
159
160
|
|
|
160
161
|
const minInches = min ?? DEFAULT_MIN_INCHES;
|
package/src/Hyperlink.tsx
CHANGED
|
@@ -36,73 +36,94 @@
|
|
|
36
36
|
|
|
37
37
|
import * as mdurl from "mdurl";
|
|
38
38
|
import React from "react";
|
|
39
|
-
import {Linking, Platform, Text, View} from "react-native";
|
|
39
|
+
import {Linking, Platform, type StyleProp, Text, type TextStyle, View} from "react-native";
|
|
40
40
|
|
|
41
41
|
import type {HyperlinkProps} from "./Common";
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
interface LinkifyMatch {
|
|
44
|
+
index: number;
|
|
45
|
+
lastIndex: number;
|
|
46
|
+
raw: string;
|
|
47
|
+
schema: string;
|
|
48
|
+
text: string;
|
|
49
|
+
url: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface LinkifyItLike {
|
|
53
|
+
pretest: (text: string) => boolean;
|
|
54
|
+
test: (text: string) => boolean;
|
|
55
|
+
match: (text: string) => LinkifyMatch[] | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const linkifyLib: LinkifyItLike = require("linkify-it")();
|
|
44
59
|
|
|
45
60
|
const {OS} = Platform;
|
|
46
61
|
|
|
47
62
|
// Leaving this as a class component because it was easier to handle the `parse(this)` in
|
|
48
63
|
// `render()`
|
|
49
64
|
class HyperlinkComponent extends React.Component<HyperlinkProps> {
|
|
50
|
-
isTextNested = (component:
|
|
65
|
+
isTextNested = (component: React.ReactElement) => {
|
|
51
66
|
if (!React.isValidElement(component)) throw new Error("Invalid component");
|
|
52
|
-
const
|
|
67
|
+
const componentType = (component.type as {displayName?: string} | undefined) ?? {};
|
|
68
|
+
const {displayName} = componentType;
|
|
53
69
|
if (displayName !== "Text") throw new Error("Not a Text component");
|
|
54
|
-
return typeof (component.props as
|
|
70
|
+
return typeof (component.props as {children?: unknown}).children !== "string";
|
|
55
71
|
};
|
|
56
72
|
|
|
57
|
-
linkify = (component:
|
|
73
|
+
linkify = (component: React.ReactElement<{children: string; style?: unknown}>) => {
|
|
58
74
|
const linkifyIt = this.props.linkify || linkifyLib;
|
|
59
75
|
|
|
60
76
|
if (!linkifyIt.pretest(component.props.children) || !linkifyIt.test(component.props.children))
|
|
61
77
|
return component;
|
|
62
78
|
|
|
63
|
-
const elements = [];
|
|
79
|
+
const elements: React.ReactNode[] = [];
|
|
64
80
|
let _lastIndex = 0;
|
|
65
81
|
|
|
66
|
-
const {key: _key, ref: _ref, ...componentProps} = component.props
|
|
82
|
+
const {key: _key, ref: _ref, ...componentProps} = component.props as Record<string, unknown>;
|
|
67
83
|
|
|
68
84
|
try {
|
|
69
|
-
linkifyIt
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
linkifyIt
|
|
86
|
+
.match(component.props.children)
|
|
87
|
+
?.forEach(({index, lastIndex, text, url}: LinkifyMatch) => {
|
|
88
|
+
const nonLinkedText = component.props.children.substring(_lastIndex, index);
|
|
89
|
+
nonLinkedText && elements.push(nonLinkedText);
|
|
90
|
+
_lastIndex = lastIndex;
|
|
91
|
+
if (this.props.linkText)
|
|
92
|
+
text =
|
|
93
|
+
typeof this.props.linkText === "function"
|
|
94
|
+
? this.props.linkText(url)
|
|
95
|
+
: this.props.linkText;
|
|
96
|
+
|
|
97
|
+
const clickHandlerProps: {onPress?: () => void; onLongPress?: () => void} = {};
|
|
98
|
+
if (OS !== "web") {
|
|
99
|
+
if (this.props.onLongPress) {
|
|
100
|
+
clickHandlerProps.onLongPress = () => this.props.onLongPress?.(url, text);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (this.props.onPress) {
|
|
104
|
+
// The HyperlinkProps onPress signature is (url) => void per Common.ts, but this forked
|
|
105
|
+
// component invokes it with both url and text. Cast to avoid arity mismatch.
|
|
106
|
+
const onPressFn = this.props.onPress as (url: string, text: string) => void;
|
|
107
|
+
clickHandlerProps.onPress = () => onPressFn(url, text);
|
|
83
108
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
{text}
|
|
103
|
-
</Text>
|
|
104
|
-
);
|
|
105
|
-
});
|
|
109
|
+
|
|
110
|
+
let injected: Record<string, unknown> = {};
|
|
111
|
+
if (this.props.injectViewProps) {
|
|
112
|
+
injected = this.props.injectViewProps(url);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
elements.push(
|
|
116
|
+
<Text
|
|
117
|
+
{...componentProps}
|
|
118
|
+
{...clickHandlerProps}
|
|
119
|
+
key={url + index}
|
|
120
|
+
style={[component.props.style, this.props.linkStyle]}
|
|
121
|
+
{...injected}
|
|
122
|
+
>
|
|
123
|
+
{text}
|
|
124
|
+
</Text>
|
|
125
|
+
);
|
|
126
|
+
});
|
|
106
127
|
elements.push(
|
|
107
128
|
component.props.children.substring(_lastIndex, component.props.children.length)
|
|
108
129
|
);
|
|
@@ -112,11 +133,13 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
|
|
|
112
133
|
}
|
|
113
134
|
};
|
|
114
135
|
|
|
115
|
-
parse = (component:
|
|
116
|
-
const
|
|
136
|
+
parse = (component: React.ReactElement): React.ReactElement => {
|
|
137
|
+
const props =
|
|
138
|
+
(component?.props as {children?: React.ReactNode; style?: StyleProp<TextStyle>}) ?? {};
|
|
139
|
+
const {children} = props;
|
|
117
140
|
if (!children) return component;
|
|
118
141
|
|
|
119
|
-
const {key: _key, ref: _ref, ...componentProps} = component.props
|
|
142
|
+
const {key: _key, ref: _ref, ...componentProps} = component.props as Record<string, unknown>;
|
|
120
143
|
|
|
121
144
|
const linkifyIt = this.props.linkify || linkifyLib;
|
|
122
145
|
|
|
@@ -124,15 +147,19 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
|
|
|
124
147
|
component,
|
|
125
148
|
componentProps,
|
|
126
149
|
React.Children.map(children, (child) => {
|
|
127
|
-
const
|
|
150
|
+
const childType = (child as React.ReactElement | null)?.type as
|
|
151
|
+
| {displayName?: string}
|
|
152
|
+
| undefined;
|
|
153
|
+
const displayName = childType?.displayName;
|
|
128
154
|
if (typeof child === "string" && linkifyIt.pretest(child))
|
|
129
155
|
return this.linkify(
|
|
130
|
-
<Text {...componentProps} style={
|
|
156
|
+
<Text {...componentProps} style={props.style}>
|
|
131
157
|
{child}
|
|
132
158
|
</Text>
|
|
133
159
|
);
|
|
134
|
-
if (displayName === "Text" && !this.isTextNested(child
|
|
135
|
-
|
|
160
|
+
if (displayName === "Text" && !this.isTextNested(child as React.ReactElement))
|
|
161
|
+
return this.linkify(child as React.ReactElement<{children: string; style?: unknown}>);
|
|
162
|
+
return this.parse(child as React.ReactElement);
|
|
136
163
|
})
|
|
137
164
|
);
|
|
138
165
|
};
|
|
@@ -148,7 +175,11 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
|
|
|
148
175
|
<View {...viewProps} style={this.props.style}>
|
|
149
176
|
{!this.props.onPress && !this.props.onLongPress && !this.props.linkStyle
|
|
150
177
|
? this.props.children
|
|
151
|
-
: (
|
|
178
|
+
: (
|
|
179
|
+
this.parse(this as unknown as React.ReactElement).props as {
|
|
180
|
+
children?: React.ReactNode;
|
|
181
|
+
}
|
|
182
|
+
).children}
|
|
152
183
|
</View>
|
|
153
184
|
);
|
|
154
185
|
}
|
package/src/IconButton.tsx
CHANGED
package/src/ImageBackground.tsx
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ImageBackground as ImageBackgroundNative,
|
|
4
|
+
type ImageBackgroundProps as NativeImageBackgroundProps,
|
|
5
|
+
} from "react-native";
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
children?: any;
|
|
6
|
-
style?: any;
|
|
7
|
-
source: any;
|
|
8
|
-
}
|
|
7
|
+
type ImageBackgroundProps = NativeImageBackgroundProps;
|
|
9
8
|
|
|
10
9
|
export class ImageBackground extends React.Component<ImageBackgroundProps, {}> {
|
|
11
10
|
render() {
|
package/src/MediaQuery.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Dimensions} from "react-native";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export const mediaQuery = (): "xs" | "sm" | "md" | "lg" => {
|
|
4
4
|
const width = Dimensions.get("window").width;
|
|
5
5
|
if (width < 576) {
|
|
6
6
|
return "xs";
|
|
@@ -11,9 +11,9 @@ export function mediaQuery(): "xs" | "sm" | "md" | "lg" {
|
|
|
11
11
|
} else {
|
|
12
12
|
return "lg";
|
|
13
13
|
}
|
|
14
|
-
}
|
|
14
|
+
};
|
|
15
15
|
|
|
16
|
-
export
|
|
16
|
+
export const mediaQueryLargerThan = (size: "xs" | "sm" | "md" | "lg"): boolean => {
|
|
17
17
|
const media = mediaQuery();
|
|
18
18
|
if (size === "xs") {
|
|
19
19
|
return true;
|
|
@@ -25,9 +25,9 @@ export function mediaQueryLargerThan(size: "xs" | "sm" | "md" | "lg"): boolean {
|
|
|
25
25
|
return ["lg"].includes(media);
|
|
26
26
|
}
|
|
27
27
|
return false;
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
29
|
|
|
30
|
-
export
|
|
30
|
+
export const mediaQuerySmallerThan = (size: "xs" | "sm" | "md" | "lg"): boolean => {
|
|
31
31
|
const media = mediaQuery();
|
|
32
32
|
if (size === "lg") {
|
|
33
33
|
return true;
|
|
@@ -39,8 +39,8 @@ export function mediaQuerySmallerThan(size: "xs" | "sm" | "md" | "lg"): boolean
|
|
|
39
39
|
return ["xs"].includes(media);
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
|
|
44
|
-
export
|
|
44
|
+
export const isMobileDevice = (): boolean => {
|
|
45
45
|
return !mediaQueryLargerThan("sm");
|
|
46
|
-
}
|
|
46
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
-
import {fireEvent} from "@testing-library/react-native";
|
|
2
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
3
|
import {forwardRef, useImperativeHandle, useRef} from "react";
|
|
4
4
|
import {Pressable, Text, View} from "react-native";
|
|
5
5
|
|
|
@@ -185,4 +185,23 @@ describe("MobileAddressAutocomplete", () => {
|
|
|
185
185
|
expect(wrapper).toBeTruthy();
|
|
186
186
|
expect(() => wrapper.props.onPress?.()).not.toThrow();
|
|
187
187
|
});
|
|
188
|
+
|
|
189
|
+
it("fires handleAddressChange from the fallback TextField onChange", () => {
|
|
190
|
+
const handleAddressChange = mock(() => {});
|
|
191
|
+
const {TextField} = require("./TextField") as {
|
|
192
|
+
TextField: React.ComponentType<{onChange?: (v: string) => void}>;
|
|
193
|
+
};
|
|
194
|
+
const {UNSAFE_getByType} = renderWithTheme(
|
|
195
|
+
<MobileAddressAutocomplete
|
|
196
|
+
handleAddressChange={handleAddressChange}
|
|
197
|
+
handleAutoCompleteChange={() => {}}
|
|
198
|
+
inputValue=""
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
const textField = UNSAFE_getByType(TextField);
|
|
202
|
+
act(() => {
|
|
203
|
+
textField.props.onChange?.("789 Elm St");
|
|
204
|
+
});
|
|
205
|
+
expect(handleAddressChange).toHaveBeenCalledWith("789 Elm St");
|
|
206
|
+
});
|
|
188
207
|
});
|
package/src/ModalSheet.test.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
2
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
3
|
import {forwardRef, useRef} from "react";
|
|
3
4
|
import {Text, View} from "react-native";
|
|
@@ -14,11 +15,6 @@ mock.module("react-native-modalize", () => ({
|
|
|
14
15
|
)),
|
|
15
16
|
}));
|
|
16
17
|
|
|
17
|
-
// Mock react-native-portalize
|
|
18
|
-
mock.module("react-native-portalize", () => ({
|
|
19
|
-
Portal: ({children}: {children: React.ReactNode}) => <View testID="portal">{children}</View>,
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
18
|
describe("ModalSheet", () => {
|
|
23
19
|
it("renders correctly with children", () => {
|
|
24
20
|
const {toJSON} = renderWithTheme(
|
package/src/ModalSheet.tsx
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
type MutableRefObject,
|
|
4
|
+
type ReactNode,
|
|
5
|
+
type Ref,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
2
9
|
import {Animated} from "react-native";
|
|
3
10
|
import {Modalize} from "react-native-modalize";
|
|
4
11
|
import {Portal} from "react-native-portalize";
|
|
5
12
|
|
|
6
|
-
export const useCombinedRefs = (
|
|
7
|
-
|
|
13
|
+
export const useCombinedRefs = <T,>(
|
|
14
|
+
...refs: Array<Ref<T> | undefined>
|
|
15
|
+
): MutableRefObject<T | null> => {
|
|
16
|
+
const targetRef = useRef<T | null>(null);
|
|
8
17
|
|
|
9
18
|
// Iterate through the refs array, and set the ref.current value to the targetRef
|
|
10
19
|
useEffect(() => {
|
|
11
|
-
refs.forEach((ref
|
|
20
|
+
refs.forEach((ref) => {
|
|
12
21
|
if (!ref) {
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
@@ -16,7 +25,7 @@ export const useCombinedRefs = (...refs: any) => {
|
|
|
16
25
|
if (typeof ref === "function") {
|
|
17
26
|
ref(targetRef.current);
|
|
18
27
|
} else {
|
|
19
|
-
ref.current = targetRef.current;
|
|
28
|
+
(ref as MutableRefObject<T | null>).current = targetRef.current;
|
|
20
29
|
}
|
|
21
30
|
});
|
|
22
31
|
}, [refs]);
|
|
@@ -25,7 +34,7 @@ export const useCombinedRefs = (...refs: any) => {
|
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
interface Props {
|
|
28
|
-
children:
|
|
37
|
+
children: ReactNode;
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
export const SimpleContent = forwardRef((props: Props, ref) => {
|
package/src/NumberField.test.tsx
CHANGED
|
@@ -110,6 +110,20 @@ describe("NumberField", () => {
|
|
|
110
110
|
expect(queryByText(/must be/)).toBeNull();
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
+
it("shows decimal error for non-numeric characters in decimal type", () => {
|
|
114
|
+
const {getByText} = renderWithTheme(
|
|
115
|
+
<NumberField label="Decimal" onChange={noOp} type="decimal" value="12abc" />
|
|
116
|
+
);
|
|
117
|
+
expect(getByText("Value must be a decimal")).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("shows decimal error for multiple decimal points", () => {
|
|
121
|
+
const {getByText} = renderWithTheme(
|
|
122
|
+
<NumberField label="Decimal" onChange={noOp} type="decimal" value="1.2.3" />
|
|
123
|
+
);
|
|
124
|
+
expect(getByText("Value must be a decimal")).toBeTruthy();
|
|
125
|
+
});
|
|
126
|
+
|
|
113
127
|
it("syncs value when prop changes", async () => {
|
|
114
128
|
const handleChange = mock((_value: string): void => {});
|
|
115
129
|
const {getByDisplayValue, unmount} = renderWithTheme(
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {OfflineBanner} from "./OfflineBanner";
|
|
4
|
+
import {renderWithTheme} from "./test-utils";
|
|
5
|
+
|
|
6
|
+
describe("OfflineBanner", () => {
|
|
7
|
+
it("renders nothing when online and not syncing", () => {
|
|
8
|
+
const {toJSON} = renderWithTheme(
|
|
9
|
+
<OfflineBanner isOnline={true} isSyncing={false} queueLength={0} />
|
|
10
|
+
);
|
|
11
|
+
expect(toJSON()).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("shows offline banner when not online", () => {
|
|
15
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
16
|
+
<OfflineBanner isOnline={false} isSyncing={false} queueLength={0} />
|
|
17
|
+
);
|
|
18
|
+
expect(getByTestId("offline-banner")).toBeTruthy();
|
|
19
|
+
expect(getByText("You're offline.")).toBeTruthy();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("shows queue count in offline banner text", () => {
|
|
23
|
+
const {getByText} = renderWithTheme(
|
|
24
|
+
<OfflineBanner isOnline={false} isSyncing={false} queueLength={5} />
|
|
25
|
+
);
|
|
26
|
+
expect(
|
|
27
|
+
getByText("You're offline. 5 pending changes will sync when you reconnect.")
|
|
28
|
+
).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("shows singular 'change' for 1 pending", () => {
|
|
32
|
+
const {getByText} = renderWithTheme(
|
|
33
|
+
<OfflineBanner isOnline={false} isSyncing={false} queueLength={1} />
|
|
34
|
+
);
|
|
35
|
+
expect(
|
|
36
|
+
getByText("You're offline. 1 pending change will sync when you reconnect.")
|
|
37
|
+
).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("shows plural 'changes' for multiple pending", () => {
|
|
41
|
+
const {getByText} = renderWithTheme(
|
|
42
|
+
<OfflineBanner isOnline={false} isSyncing={false} queueLength={3} />
|
|
43
|
+
);
|
|
44
|
+
expect(
|
|
45
|
+
getByText("You're offline. 3 pending changes will sync when you reconnect.")
|
|
46
|
+
).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("shows syncing banner when isSyncing is true", () => {
|
|
50
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
51
|
+
<OfflineBanner isOnline={false} isSyncing={true} queueLength={2} />
|
|
52
|
+
);
|
|
53
|
+
expect(getByTestId("offline-banner")).toBeTruthy();
|
|
54
|
+
expect(getByText("Syncing offline changes...")).toBeTruthy();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("uses custom testID prop", () => {
|
|
58
|
+
const {getByTestId} = renderWithTheme(
|
|
59
|
+
<OfflineBanner isOnline={false} isSyncing={false} queueLength={0} testID="custom-banner" />
|
|
60
|
+
);
|
|
61
|
+
expect(getByTestId("custom-banner")).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("uses custom testID prop while syncing", () => {
|
|
65
|
+
const {getByTestId} = renderWithTheme(
|
|
66
|
+
<OfflineBanner isOnline={false} isSyncing={true} queueLength={2} testID="custom-banner" />
|
|
67
|
+
);
|
|
68
|
+
expect(getByTestId("custom-banner")).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
});
|