@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
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
// useDimensions hook
|
|
62
62
|
// ============================================================================
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const useDimensions = () => {
|
|
65
65
|
const [dimensions, setDimensions] = useState(Dimensions.get("window"));
|
|
66
66
|
|
|
67
67
|
const onChange = useCallback(({window}: {window: ScaledSize}) => {
|
|
@@ -77,7 +77,7 @@ function useDimensions() {
|
|
|
77
77
|
}, [onChange]);
|
|
78
78
|
|
|
79
79
|
return dimensions;
|
|
80
|
-
}
|
|
80
|
+
};
|
|
81
81
|
|
|
82
82
|
// ============================================================================
|
|
83
83
|
// Toast Options and Props
|
|
@@ -177,10 +177,7 @@ export interface ToastOptions {
|
|
|
177
177
|
/**
|
|
178
178
|
* Payload data for custom toasts. You can pass whatever you want
|
|
179
179
|
*/
|
|
180
|
-
// noExplicitAny: This is the public API of a vendored 3rd-party library
|
|
181
|
-
// (react-native-toast-notifications); the `data` field is an opaque
|
|
182
|
-
// user-provided payload. Tightening to `unknown` breaks downstream consumers
|
|
183
|
-
// that spread `data` into `Toast` (e.g. TerrenoProvider) without refactor.
|
|
180
|
+
// biome-ignore lint/suspicious/noExplicitAny: This is the public API of a vendored 3rd-party library (react-native-toast-notifications); the data field is an opaque user-provided payload. Tightening to unknown breaks downstream consumers that spread data into Toast (e.g. TerrenoProvider) without refactor.
|
|
184
181
|
data?: any;
|
|
185
182
|
|
|
186
183
|
swipeEnabled?: boolean;
|
package/src/Tooltip.test.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {beforeAll, describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {afterEach, beforeAll, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
2
|
import {act} from "@testing-library/react-native";
|
|
3
|
-
import {View} from "react-native";
|
|
4
3
|
|
|
5
4
|
import {Text} from "./Text";
|
|
6
|
-
import {Tooltip} from "./Tooltip";
|
|
5
|
+
import {Arrow, getTooltipPosition, Tooltip} from "./Tooltip";
|
|
7
6
|
import {renderWithTheme} from "./test-utils";
|
|
8
7
|
|
|
9
8
|
// Minimal shape of the tree returned by toJSON() that we rely on here.
|
|
@@ -20,11 +19,14 @@ interface TestNode {
|
|
|
20
19
|
children: null | Array<TestNode | string>;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
type MeasureCallback = (
|
|
23
|
+
x: number,
|
|
24
|
+
y: number,
|
|
25
|
+
width: number,
|
|
26
|
+
height: number,
|
|
27
|
+
pageX: number,
|
|
28
|
+
pageY: number
|
|
29
|
+
) => void;
|
|
28
30
|
|
|
29
31
|
beforeAll(() => {
|
|
30
32
|
globalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {
|
|
@@ -274,6 +276,198 @@ describe("Tooltip", () => {
|
|
|
274
276
|
}
|
|
275
277
|
});
|
|
276
278
|
|
|
279
|
+
it("getTooltipPosition returns empty when not measured", () => {
|
|
280
|
+
const result = getTooltipPosition({
|
|
281
|
+
children: {},
|
|
282
|
+
measured: false,
|
|
283
|
+
tooltip: {},
|
|
284
|
+
});
|
|
285
|
+
expect(result).toEqual({});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("getTooltipPosition places tooltip at top (default) when space allows", () => {
|
|
289
|
+
const result = getTooltipPosition({
|
|
290
|
+
children: {height: 40, pageX: 200, pageY: 300, width: 100},
|
|
291
|
+
idealPosition: "top",
|
|
292
|
+
measured: true,
|
|
293
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
294
|
+
});
|
|
295
|
+
expect(result).toHaveProperty("finalPosition", "top");
|
|
296
|
+
expect(result).toHaveProperty("top");
|
|
297
|
+
expect(result).toHaveProperty("left");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("getTooltipPosition places tooltip at bottom when specified", () => {
|
|
301
|
+
const result = getTooltipPosition({
|
|
302
|
+
children: {height: 40, pageX: 200, pageY: 100, width: 100},
|
|
303
|
+
idealPosition: "bottom",
|
|
304
|
+
measured: true,
|
|
305
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
306
|
+
});
|
|
307
|
+
expect(result).toHaveProperty("finalPosition", "bottom");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("getTooltipPosition places tooltip at left when space allows", () => {
|
|
311
|
+
const result = getTooltipPosition({
|
|
312
|
+
children: {height: 40, pageX: 400, pageY: 200, width: 100},
|
|
313
|
+
idealPosition: "left",
|
|
314
|
+
measured: true,
|
|
315
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
316
|
+
});
|
|
317
|
+
expect(result).toHaveProperty("finalPosition", "left");
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("getTooltipPosition places tooltip at right when specified", () => {
|
|
321
|
+
const result = getTooltipPosition({
|
|
322
|
+
children: {height: 40, pageX: 50, pageY: 200, width: 100},
|
|
323
|
+
idealPosition: "right",
|
|
324
|
+
measured: true,
|
|
325
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
326
|
+
});
|
|
327
|
+
expect(result).toHaveProperty("finalPosition", "right");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("getTooltipPosition falls back to bottom when top overflows", () => {
|
|
331
|
+
const result = getTooltipPosition({
|
|
332
|
+
children: {height: 40, pageX: 200, pageY: 5, width: 100},
|
|
333
|
+
idealPosition: "top",
|
|
334
|
+
measured: true,
|
|
335
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
336
|
+
});
|
|
337
|
+
expect(result).toHaveProperty("finalPosition", "bottom");
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("getTooltipPosition falls back to top when bottom overflows", () => {
|
|
341
|
+
const {Dimensions} = require("react-native");
|
|
342
|
+
const origGet = Dimensions.get;
|
|
343
|
+
Dimensions.get = () => ({fontScale: 1, height: 200, scale: 1, width: 800});
|
|
344
|
+
try {
|
|
345
|
+
const result = getTooltipPosition({
|
|
346
|
+
children: {height: 40, pageX: 200, pageY: 160, width: 100},
|
|
347
|
+
idealPosition: "bottom",
|
|
348
|
+
measured: true,
|
|
349
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
350
|
+
});
|
|
351
|
+
expect(result).toHaveProperty("finalPosition", "top");
|
|
352
|
+
} finally {
|
|
353
|
+
Dimensions.get = origGet;
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("getTooltipPosition falls back to bottom when right overflows", () => {
|
|
358
|
+
const {Dimensions} = require("react-native");
|
|
359
|
+
const origGet = Dimensions.get;
|
|
360
|
+
Dimensions.get = () => ({fontScale: 1, height: 800, scale: 1, width: 300});
|
|
361
|
+
try {
|
|
362
|
+
const result = getTooltipPosition({
|
|
363
|
+
children: {height: 40, pageX: 200, pageY: 200, width: 100},
|
|
364
|
+
idealPosition: "right",
|
|
365
|
+
measured: true,
|
|
366
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
367
|
+
});
|
|
368
|
+
// Fallback order is: bottom -> top -> left -> right
|
|
369
|
+
expect(result).toHaveProperty("finalPosition", "bottom");
|
|
370
|
+
} finally {
|
|
371
|
+
Dimensions.get = origGet;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("getTooltipPosition falls back to left when right, bottom, and top overflow", () => {
|
|
376
|
+
const {Dimensions} = require("react-native");
|
|
377
|
+
const origGet = Dimensions.get;
|
|
378
|
+
Dimensions.get = () => ({fontScale: 1, height: 80, scale: 1, width: 300});
|
|
379
|
+
try {
|
|
380
|
+
const result = getTooltipPosition({
|
|
381
|
+
children: {height: 40, pageX: 200, pageY: 20, width: 40},
|
|
382
|
+
idealPosition: "right",
|
|
383
|
+
measured: true,
|
|
384
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
385
|
+
});
|
|
386
|
+
expect(result).toHaveProperty("finalPosition", "left");
|
|
387
|
+
} finally {
|
|
388
|
+
Dimensions.get = origGet;
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("getTooltipPosition falls back to right when all other directions overflow", () => {
|
|
393
|
+
const {Dimensions} = require("react-native");
|
|
394
|
+
const origGet = Dimensions.get;
|
|
395
|
+
Dimensions.get = () => ({fontScale: 1, height: 50, scale: 1, width: 50});
|
|
396
|
+
try {
|
|
397
|
+
const result = getTooltipPosition({
|
|
398
|
+
children: {height: 40, pageX: 5, pageY: 5, width: 40},
|
|
399
|
+
idealPosition: "top",
|
|
400
|
+
measured: true,
|
|
401
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
402
|
+
});
|
|
403
|
+
expect(result).toHaveProperty("finalPosition", "right");
|
|
404
|
+
} finally {
|
|
405
|
+
Dimensions.get = origGet;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("getTooltipPosition with no idealPosition defaults to top", () => {
|
|
410
|
+
const result = getTooltipPosition({
|
|
411
|
+
children: {height: 40, pageX: 200, pageY: 300, width: 100},
|
|
412
|
+
measured: true,
|
|
413
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
414
|
+
});
|
|
415
|
+
expect(result).toHaveProperty("finalPosition", "top");
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("getTooltipPosition falls back when left placement overflows", () => {
|
|
419
|
+
const result = getTooltipPosition({
|
|
420
|
+
children: {height: 40, pageX: 10, pageY: 200, width: 100},
|
|
421
|
+
idealPosition: "left",
|
|
422
|
+
measured: true,
|
|
423
|
+
tooltip: {height: 30, width: 150, x: 0, y: 0},
|
|
424
|
+
});
|
|
425
|
+
// Left overflows, should fall back to bottom (first available)
|
|
426
|
+
expect(result).toHaveProperty("finalPosition");
|
|
427
|
+
const pos = (result as {finalPosition: string}).finalPosition;
|
|
428
|
+
expect(["top", "bottom", "right"]).toContain(pos);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("Arrow renders for each position", () => {
|
|
432
|
+
const positions = ["top", "bottom", "left", "right"] as const;
|
|
433
|
+
for (const position of positions) {
|
|
434
|
+
const {toJSON} = renderWithTheme(<Arrow color="#333" position={position} />);
|
|
435
|
+
expect(toJSON()).toBeTruthy();
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("exercises handleClick to hide visible tooltip on web press", async () => {
|
|
440
|
+
const {queryByTestId, toJSON} = renderWithTheme(
|
|
441
|
+
<Tooltip text="Click hides">
|
|
442
|
+
<Text>Click me</Text>
|
|
443
|
+
</Tooltip>
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
const tree = toJSON() as TestNode;
|
|
447
|
+
const root = tree.children?.[0] as TestNode;
|
|
448
|
+
|
|
449
|
+
// Show the tooltip
|
|
450
|
+
await act(async () => {
|
|
451
|
+
root.props.onPointerEnter?.();
|
|
452
|
+
});
|
|
453
|
+
await act(async () => {
|
|
454
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
455
|
+
});
|
|
456
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
457
|
+
|
|
458
|
+
// Find the wrapper and trigger onPress (web click)
|
|
459
|
+
const treeAfter = toJSON() as TestNode;
|
|
460
|
+
const wrapper = (treeAfter.children as Array<TestNode | string>)[
|
|
461
|
+
(treeAfter.children as Array<TestNode | string>).length - 1
|
|
462
|
+
] as TestNode;
|
|
463
|
+
|
|
464
|
+
if (wrapper.props && "onPress" in wrapper.props) {
|
|
465
|
+
await act(async () => {
|
|
466
|
+
(wrapper.props as {onPress?: () => void}).onPress?.();
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
277
471
|
it("renders tooltip with arrow at all idealPositions", async () => {
|
|
278
472
|
const positions: Array<"top" | "bottom" | "left" | "right"> = [
|
|
279
473
|
"top",
|
|
@@ -308,4 +502,388 @@ describe("Tooltip", () => {
|
|
|
308
502
|
// No assertions needed - just ensuring no crashes on unmount.
|
|
309
503
|
expect(true).toBe(true);
|
|
310
504
|
});
|
|
505
|
+
|
|
506
|
+
it("hides tooltip when pressing on the tooltip container", async () => {
|
|
507
|
+
const {queryByTestId, toJSON, getByTestId} = renderWithTheme(
|
|
508
|
+
<Tooltip text="Click to hide">
|
|
509
|
+
<Text>Hover me</Text>
|
|
510
|
+
</Tooltip>
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const tree = toJSON() as TestNode;
|
|
514
|
+
const root = tree.children?.[0] as TestNode;
|
|
515
|
+
|
|
516
|
+
await act(async () => {
|
|
517
|
+
root.props.onPointerEnter?.();
|
|
518
|
+
});
|
|
519
|
+
await act(async () => {
|
|
520
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
521
|
+
});
|
|
522
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
523
|
+
|
|
524
|
+
const {fireEvent} = await import("@testing-library/react-native");
|
|
525
|
+
await act(async () => {
|
|
526
|
+
fireEvent.press(getByTestId("tooltip-container"));
|
|
527
|
+
});
|
|
528
|
+
expect(queryByTestId("tooltip-container")).toBeNull();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it("handleClick does nothing when tooltip is not visible", async () => {
|
|
532
|
+
const {queryByTestId, toJSON} = renderWithTheme(
|
|
533
|
+
<Tooltip text="Click test">
|
|
534
|
+
<Text>Click me</Text>
|
|
535
|
+
</Tooltip>
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
const tree = toJSON() as TestNode;
|
|
539
|
+
const root = tree.children?.[0] as TestNode;
|
|
540
|
+
|
|
541
|
+
// Call onPress when tooltip is not visible (no-op)
|
|
542
|
+
await act(async () => {
|
|
543
|
+
(root.props as {onPress?: () => void}).onPress?.();
|
|
544
|
+
});
|
|
545
|
+
expect(queryByTestId("tooltip-container")).toBeNull();
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it("handles onLayout with measure callback and sets position", async () => {
|
|
549
|
+
const {queryByTestId, toJSON, UNSAFE_getAllByType} = renderWithTheme(
|
|
550
|
+
<Tooltip idealPosition="top" includeArrow text="Layout position test">
|
|
551
|
+
<Text>Trigger</Text>
|
|
552
|
+
</Tooltip>
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
const tree = toJSON() as TestNode;
|
|
556
|
+
const root = tree.children?.[0] as TestNode;
|
|
557
|
+
|
|
558
|
+
// Show the tooltip first
|
|
559
|
+
await act(async () => {
|
|
560
|
+
root.props.onTouchStart?.({nativeEvent: {}});
|
|
561
|
+
});
|
|
562
|
+
await act(async () => {
|
|
563
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
564
|
+
});
|
|
565
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
566
|
+
|
|
567
|
+
const {View: ViewComp} = await import("react-native");
|
|
568
|
+
const allViews = UNSAFE_getAllByType(ViewComp);
|
|
569
|
+
for (const v of allViews) {
|
|
570
|
+
const props = v.props as TestNode["props"];
|
|
571
|
+
if (props.onLayout) {
|
|
572
|
+
await act(async () => {
|
|
573
|
+
props.onLayout?.({
|
|
574
|
+
nativeEvent: {
|
|
575
|
+
layout: {height: 40, width: 200, x: 0, y: 0},
|
|
576
|
+
},
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it("exercises getTooltipPosition with all ideal positions", async () => {
|
|
584
|
+
const positions: Array<"top" | "bottom" | "left" | "right"> = [
|
|
585
|
+
"top",
|
|
586
|
+
"bottom",
|
|
587
|
+
"left",
|
|
588
|
+
"right",
|
|
589
|
+
];
|
|
590
|
+
|
|
591
|
+
for (const pos of positions) {
|
|
592
|
+
const {queryByTestId, toJSON, UNSAFE_getAllByType, unmount} = renderWithTheme(
|
|
593
|
+
<Tooltip idealPosition={pos} includeArrow text={`${pos} test`}>
|
|
594
|
+
<Text>Position {pos}</Text>
|
|
595
|
+
</Tooltip>
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
const tree = toJSON() as TestNode;
|
|
599
|
+
const root = tree.children?.[0] as TestNode;
|
|
600
|
+
|
|
601
|
+
await act(async () => {
|
|
602
|
+
root.props.onTouchStart?.({nativeEvent: {}});
|
|
603
|
+
});
|
|
604
|
+
await act(async () => {
|
|
605
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
606
|
+
});
|
|
607
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
608
|
+
|
|
609
|
+
const {View: ViewComp} = await import("react-native");
|
|
610
|
+
const allViews = UNSAFE_getAllByType(ViewComp);
|
|
611
|
+
for (const v of allViews) {
|
|
612
|
+
const props = v.props as TestNode["props"];
|
|
613
|
+
if (props.onLayout) {
|
|
614
|
+
await act(async () => {
|
|
615
|
+
props.onLayout?.({
|
|
616
|
+
nativeEvent: {
|
|
617
|
+
layout: {height: 30, width: 100, x: 50, y: 50},
|
|
618
|
+
},
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
unmount();
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
it("renders arrow styles for all positions when tooltip is shown with arrow", async () => {
|
|
628
|
+
const positions: Array<"top" | "bottom" | "left" | "right"> = [
|
|
629
|
+
"top",
|
|
630
|
+
"bottom",
|
|
631
|
+
"left",
|
|
632
|
+
"right",
|
|
633
|
+
];
|
|
634
|
+
|
|
635
|
+
for (const pos of positions) {
|
|
636
|
+
const {queryByTestId, toJSON, unmount} = renderWithTheme(
|
|
637
|
+
<Tooltip idealPosition={pos} includeArrow text={`Arrow ${pos}`}>
|
|
638
|
+
<Text>Arrow</Text>
|
|
639
|
+
</Tooltip>
|
|
640
|
+
);
|
|
641
|
+
|
|
642
|
+
const tree = toJSON() as TestNode;
|
|
643
|
+
const root = tree.children?.[0] as TestNode;
|
|
644
|
+
|
|
645
|
+
await act(async () => {
|
|
646
|
+
root.props.onPointerEnter?.();
|
|
647
|
+
});
|
|
648
|
+
await act(async () => {
|
|
649
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
650
|
+
});
|
|
651
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
652
|
+
unmount();
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it("mobilePressProps fires children onClick when not touched", async () => {
|
|
657
|
+
const onClick = mock(() => {});
|
|
658
|
+
const TestChild: React.FC<{onClick?: () => void}> = () => <Text>Pressable child</Text>;
|
|
659
|
+
|
|
660
|
+
const {toJSON} = renderWithTheme(
|
|
661
|
+
<Tooltip text="Mobile test">
|
|
662
|
+
<TestChild onClick={onClick} />
|
|
663
|
+
</Tooltip>
|
|
664
|
+
);
|
|
665
|
+
|
|
666
|
+
const tree = toJSON() as TestNode;
|
|
667
|
+
const root = tree.children?.[0] as TestNode;
|
|
668
|
+
|
|
669
|
+
// Fire onPress (mobilePressProps) without having touched first
|
|
670
|
+
await act(async () => {
|
|
671
|
+
(root.props as {onPress?: () => void}).onPress?.();
|
|
672
|
+
});
|
|
673
|
+
expect(onClick).toHaveBeenCalled();
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
it("getArrowContainerStyle returns empty when includeArrow is false", async () => {
|
|
677
|
+
const {queryByTestId, toJSON} = renderWithTheme(
|
|
678
|
+
<Tooltip text="No arrow test">
|
|
679
|
+
<Text>No arrow</Text>
|
|
680
|
+
</Tooltip>
|
|
681
|
+
);
|
|
682
|
+
|
|
683
|
+
const tree = toJSON() as TestNode;
|
|
684
|
+
const root = tree.children?.[0] as TestNode;
|
|
685
|
+
|
|
686
|
+
await act(async () => {
|
|
687
|
+
root.props.onPointerEnter?.();
|
|
688
|
+
});
|
|
689
|
+
await act(async () => {
|
|
690
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
691
|
+
});
|
|
692
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
describe("web platform behavior", () => {
|
|
696
|
+
let Platform: {OS: string};
|
|
697
|
+
|
|
698
|
+
beforeEach(async () => {
|
|
699
|
+
const rn = await import("react-native");
|
|
700
|
+
Platform = rn.Platform;
|
|
701
|
+
Platform.OS = "web";
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
afterEach(() => {
|
|
705
|
+
Platform.OS = "ios";
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it("renders Arrow component when isWeb and includeArrow", async () => {
|
|
709
|
+
const {queryByTestId, toJSON} = renderWithTheme(
|
|
710
|
+
<Tooltip idealPosition="top" includeArrow text="Web arrow">
|
|
711
|
+
<Text>Arrow child</Text>
|
|
712
|
+
</Tooltip>
|
|
713
|
+
);
|
|
714
|
+
|
|
715
|
+
const tree = toJSON() as TestNode;
|
|
716
|
+
const root = tree.children?.[0] as TestNode;
|
|
717
|
+
|
|
718
|
+
await act(async () => {
|
|
719
|
+
root.props.onPointerEnter?.();
|
|
720
|
+
});
|
|
721
|
+
await act(async () => {
|
|
722
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
723
|
+
});
|
|
724
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it("renders Arrow for all positions on web", async () => {
|
|
728
|
+
const positions: Array<"top" | "bottom" | "left" | "right"> = [
|
|
729
|
+
"top",
|
|
730
|
+
"bottom",
|
|
731
|
+
"left",
|
|
732
|
+
"right",
|
|
733
|
+
];
|
|
734
|
+
for (const pos of positions) {
|
|
735
|
+
const {queryByTestId, toJSON, unmount} = renderWithTheme(
|
|
736
|
+
<Tooltip idealPosition={pos} includeArrow text={`Web ${pos}`}>
|
|
737
|
+
<Text>{pos}</Text>
|
|
738
|
+
</Tooltip>
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
const tree = toJSON() as TestNode;
|
|
742
|
+
const root = tree.children?.[0] as TestNode;
|
|
743
|
+
|
|
744
|
+
await act(async () => {
|
|
745
|
+
root.props.onTouchStart?.({nativeEvent: {}});
|
|
746
|
+
});
|
|
747
|
+
await act(async () => {
|
|
748
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
749
|
+
});
|
|
750
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
751
|
+
unmount();
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
it("handleClick hides tooltip on web when visible", async () => {
|
|
756
|
+
const {queryByTestId, toJSON} = renderWithTheme(
|
|
757
|
+
<Tooltip text="Web click hide">
|
|
758
|
+
<Text>Click me</Text>
|
|
759
|
+
</Tooltip>
|
|
760
|
+
);
|
|
761
|
+
|
|
762
|
+
const tree = toJSON() as TestNode;
|
|
763
|
+
const root = tree.children?.[0] as TestNode;
|
|
764
|
+
|
|
765
|
+
await act(async () => {
|
|
766
|
+
root.props.onPointerEnter?.();
|
|
767
|
+
});
|
|
768
|
+
await act(async () => {
|
|
769
|
+
await new Promise((resolve) => setTimeout(resolve, 900));
|
|
770
|
+
});
|
|
771
|
+
expect(queryByTestId("tooltip-container")).toBeTruthy();
|
|
772
|
+
|
|
773
|
+
// On web, onPress is handleClick which hides tooltip when visible
|
|
774
|
+
const treeAfter = toJSON() as TestNode;
|
|
775
|
+
const wrapper = (treeAfter.children as TestNode[]).find(
|
|
776
|
+
(c: TestNode) => c.props && (c.props as {hitSlop?: object}).hitSlop !== undefined
|
|
777
|
+
) as TestNode | undefined;
|
|
778
|
+
await act(async () => {
|
|
779
|
+
(wrapper?.props as {onPress?: () => void}).onPress?.();
|
|
780
|
+
});
|
|
781
|
+
expect(queryByTestId("tooltip-container")).toBeNull();
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
it("exercises measure callback and getTooltipPosition for all positions", async () => {
|
|
785
|
+
const positions: Array<"top" | "bottom" | "left" | "right"> = [
|
|
786
|
+
"top",
|
|
787
|
+
"bottom",
|
|
788
|
+
"left",
|
|
789
|
+
"right",
|
|
790
|
+
];
|
|
791
|
+
|
|
792
|
+
for (const pos of positions) {
|
|
793
|
+
const {toJSON, UNSAFE_getAllByType, unmount} = renderWithTheme(
|
|
794
|
+
<Tooltip idealPosition={pos} includeArrow text={`Measure ${pos}`}>
|
|
795
|
+
<Text>{pos}</Text>
|
|
796
|
+
</Tooltip>
|
|
797
|
+
);
|
|
798
|
+
|
|
799
|
+
const tree = toJSON() as TestNode;
|
|
800
|
+
const root = tree.children?.[0] as TestNode;
|
|
801
|
+
|
|
802
|
+
await act(async () => {
|
|
803
|
+
root.props.onTouchStart?.({nativeEvent: {}});
|
|
804
|
+
});
|
|
805
|
+
await act(async () => {
|
|
806
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
// Find the ref-holding View (has hitSlop) and inject measure via fiber ref
|
|
810
|
+
const {View: ViewComp} = await import("react-native");
|
|
811
|
+
const allViews = UNSAFE_getAllByType(ViewComp);
|
|
812
|
+
for (const v of allViews) {
|
|
813
|
+
if (!(v.props as {hitSlop?: object}).hitSlop) {
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
const fiber = (v as unknown as {_fiber?: {ref?: {current: unknown}}})._fiber;
|
|
817
|
+
if (fiber?.ref && typeof fiber.ref === "object") {
|
|
818
|
+
const pageX = pos === "left" ? 400 : pos === "right" ? 50 : 200;
|
|
819
|
+
const pageY = pos === "top" ? 400 : 100;
|
|
820
|
+
fiber.ref.current = {
|
|
821
|
+
measure: (cb: MeasureCallback) => {
|
|
822
|
+
cb(0, 0, 100, 40, pageX, pageY);
|
|
823
|
+
},
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// Trigger onLayout to invoke measure and getTooltipPosition
|
|
829
|
+
for (const v of allViews) {
|
|
830
|
+
const props = v.props as TestNode["props"];
|
|
831
|
+
if (props.onLayout) {
|
|
832
|
+
await act(async () => {
|
|
833
|
+
props.onLayout?.({
|
|
834
|
+
nativeEvent: {layout: {height: 30, width: 80, x: 0, y: 0}},
|
|
835
|
+
});
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
unmount();
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
it("getTooltipPosition fallback when all positions overflow", async () => {
|
|
844
|
+
const {toJSON, UNSAFE_getAllByType, unmount} = renderWithTheme(
|
|
845
|
+
<Tooltip idealPosition="top" text="Overflow">
|
|
846
|
+
<Text>Overflow</Text>
|
|
847
|
+
</Tooltip>
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
const tree = toJSON() as TestNode;
|
|
851
|
+
const root = tree.children?.[0] as TestNode;
|
|
852
|
+
|
|
853
|
+
await act(async () => {
|
|
854
|
+
root.props.onTouchStart?.({nativeEvent: {}});
|
|
855
|
+
});
|
|
856
|
+
await act(async () => {
|
|
857
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
const {View: ViewComp} = await import("react-native");
|
|
861
|
+
const allViews = UNSAFE_getAllByType(ViewComp);
|
|
862
|
+
for (const v of allViews) {
|
|
863
|
+
if (!(v.props as {hitSlop?: object}).hitSlop) {
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
const fiber = (v as unknown as {_fiber?: {ref?: {current: unknown}}})._fiber;
|
|
867
|
+
if (fiber?.ref && typeof fiber.ref === "object") {
|
|
868
|
+
fiber.ref.current = {
|
|
869
|
+
measure: (cb: MeasureCallback) => {
|
|
870
|
+
cb(0, 0, 900, 900, 0, 0);
|
|
871
|
+
},
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
for (const v of allViews) {
|
|
877
|
+
const props = v.props as TestNode["props"];
|
|
878
|
+
if (props.onLayout) {
|
|
879
|
+
await act(async () => {
|
|
880
|
+
props.onLayout?.({
|
|
881
|
+
nativeEvent: {layout: {height: 900, width: 900, x: 0, y: 0}},
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
unmount();
|
|
887
|
+
});
|
|
888
|
+
});
|
|
311
889
|
});
|
package/src/Tooltip.tsx
CHANGED
|
@@ -39,7 +39,7 @@ interface ChildrenProps {
|
|
|
39
39
|
onHoverOut?: () => void;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const getTooltipPosition = ({
|
|
42
|
+
export const getTooltipPosition = ({
|
|
43
43
|
children,
|
|
44
44
|
tooltip,
|
|
45
45
|
measured,
|
|
@@ -117,7 +117,7 @@ const getTooltipPosition = ({
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
const Arrow: FC<{position: TooltipPosition; color: string}> = ({position, color}) => {
|
|
120
|
+
export const Arrow: FC<{position: TooltipPosition; color: string}> = ({position, color}) => {
|
|
121
121
|
const getArrowStyle = (): ViewStyle => {
|
|
122
122
|
const arrowStyles = {
|
|
123
123
|
bottom: {
|