@terreno/ui 57.1.0 → 57.3.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.
- package/.ai/guidelines/core.md +1 -1
- package/README.md +17 -8
- package/dist/ActionSheet.d.ts +3 -3
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +101 -34
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +119 -9
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +46 -12
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +203 -44
- package/dist/DataTable.js.map +1 -1
- package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
- package/dist/DataTableHeaderInfoMarkdown.js +7 -0
- package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
- package/dist/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/GPTChat.js +1 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +5 -2
- package/dist/Heading.js +6 -8
- package/dist/Heading.js.map +1 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Icon.d.ts +1 -2
- package/dist/Icon.js +4 -1
- package/dist/Icon.js.map +1 -1
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +45 -43
- package/dist/MarkdownView.js.map +1 -1
- package/dist/MediaQuery.d.ts +5 -3
- package/dist/MediaQuery.js +9 -40
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OpenAPIContext.js +7 -6
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.js +7 -1
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.js +8 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Popover.d.ts +12 -0
- package/dist/Popover.js +37 -0
- package/dist/Popover.js.map +1 -0
- package/dist/PortalHost.js +10 -1
- package/dist/PortalHost.js.map +1 -1
- package/dist/ResponsiveBreakpoint.d.ts +65 -0
- package/dist/ResponsiveBreakpoint.js +111 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.js +7 -12
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +2 -2
- package/dist/SplitPage.native.js +1 -6
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +12 -10
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoFontProvider.d.ts +7 -0
- package/dist/TerrenoFontProvider.js +27 -0
- package/dist/TerrenoFontProvider.js.map +1 -0
- package/dist/TerrenoProvider.js +4 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Text.d.ts +5 -2
- package/dist/Text.js +6 -11
- package/dist/Text.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +9 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Theme.js +10 -8
- package/dist/Theme.js.map +1 -1
- package/dist/ToastNotifications.d.ts +4 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +4 -3
- package/dist/Tooltip.js +14 -3
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +26 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +6 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +2 -13
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +1 -0
- package/dist/login/LoginScreen.js +4 -2
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/loginTypes.d.ts +2 -0
- package/package.json +41 -2
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +207 -0
- package/src/Button.tsx +146 -48
- package/src/Common.ts +124 -25
- package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
- package/src/ConsentFormScreen.test.tsx +145 -8
- package/src/ConsentFormScreen.tsx +74 -25
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DataTable.tsx +418 -147
- package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
- package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
- package/src/DataTableVirtualizationRegression.test.tsx +266 -0
- package/src/DateTimeField.test.tsx +54 -0
- package/src/EmojiSelector.test.tsx +33 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/FilterAccordion.test.tsx +37 -0
- package/src/FilterBoolean.test.tsx +96 -0
- package/src/FilterSelectMenu.test.tsx +23 -0
- package/src/GPTChat.test.tsx +696 -0
- package/src/GPTChat.tsx +2 -2
- package/src/GPTMemoryModal.test.tsx +67 -0
- package/src/Heading.tsx +8 -14
- package/src/HeightActionSheet.test.tsx +6 -9
- package/src/Hyperlink.tsx +5 -18
- package/src/Icon.tsx +6 -2
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownView.test.tsx +55 -11
- package/src/MarkdownView.tsx +149 -150
- package/src/MediaQuery.ts +30 -34
- package/src/OpenAPIContext.tsx +36 -29
- package/src/OpenAPIRenderRegression.test.tsx +200 -0
- package/src/P0RenderRegression.test.tsx +214 -0
- package/src/P1RenderRegression.test.tsx +141 -0
- package/src/P2ButtonRenderRegression.test.tsx +158 -0
- package/src/Page.test.tsx +13 -0
- package/src/Page.tsx +25 -5
- package/src/PickerSelect.test.tsx +38 -0
- package/src/PickerSelect.tsx +7 -0
- package/src/Popover.test.tsx +151 -0
- package/src/Popover.tsx +211 -0
- package/src/PortalHost.tsx +12 -6
- package/src/ResponsiveBreakpoint.test.tsx +184 -0
- package/src/ResponsiveBreakpoint.tsx +195 -0
- package/src/RootImportRegression.test.tsx +62 -0
- package/src/SplitPage.native.tsx +5 -9
- package/src/SplitPage.tsx +16 -19
- package/src/TapToEdit.test.tsx +45 -0
- package/src/TapToEdit.tsx +23 -18
- package/src/TerrenoFontProvider.test.tsx +38 -0
- package/src/TerrenoFontProvider.tsx +50 -0
- package/src/TerrenoProvider.tsx +6 -1
- package/src/Text.tsx +8 -21
- package/src/TextFieldNumberActionSheet.test.tsx +100 -0
- package/src/TextFieldNumberActionSheet.tsx +11 -2
- package/src/Theme.test.tsx +27 -0
- package/src/Theme.tsx +15 -10
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -4
- package/src/Tooltip.test.tsx +64 -0
- package/src/Tooltip.tsx +18 -4
- package/src/Unifier.ts +26 -3
- package/src/WebAddressAutocomplete.tsx +6 -2
- package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
- package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
- package/src/__snapshots__/Field.test.tsx.snap +7 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/Page.test.tsx.snap +13 -1
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/benchmarks/importGraph.test.ts +71 -0
- package/src/benchmarks/importGraph.ts +136 -0
- package/src/benchmarks/importTiming.test.ts +42 -0
- package/src/benchmarks/importTiming.ts +86 -0
- package/src/bunSetup.ts +174 -32
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +27 -13
- package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
- package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/loginTypes.ts +2 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
package/src/Text.tsx
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
Nunito_400Regular,
|
|
3
|
-
Nunito_400Regular_Italic,
|
|
4
|
-
Nunito_500Medium,
|
|
5
|
-
Nunito_500Medium_Italic,
|
|
6
|
-
Nunito_700Bold,
|
|
7
|
-
Nunito_700Bold_Italic,
|
|
8
|
-
useFonts,
|
|
9
|
-
} from "@expo-google-fonts/nunito";
|
|
10
|
-
import type React from "react";
|
|
1
|
+
import React from "react";
|
|
11
2
|
import {Text as NativeText, Platform, type TextStyle} from "react-native";
|
|
12
3
|
|
|
13
4
|
import type {TextProps} from "./Common";
|
|
14
5
|
import {Hyperlink} from "./Hyperlink";
|
|
6
|
+
import {useTerrenoFontsLoaded} from "./TerrenoFontProvider";
|
|
15
7
|
import {useTheme} from "./Theme";
|
|
16
8
|
|
|
17
9
|
const fontSizeAndWeightWeb = {
|
|
@@ -32,7 +24,7 @@ const fontSizeAndWeighMobile = {
|
|
|
32
24
|
|
|
33
25
|
const fontSizes = Platform.OS === "web" ? fontSizeAndWeightWeb : fontSizeAndWeighMobile;
|
|
34
26
|
|
|
35
|
-
|
|
27
|
+
const TextComponent = ({
|
|
36
28
|
align = "left",
|
|
37
29
|
bold,
|
|
38
30
|
children,
|
|
@@ -46,16 +38,7 @@ export const Text = ({
|
|
|
46
38
|
testID,
|
|
47
39
|
}: TextProps): React.ReactElement => {
|
|
48
40
|
const {theme} = useTheme();
|
|
49
|
-
|
|
50
|
-
useFonts({
|
|
51
|
-
text: Nunito_400Regular,
|
|
52
|
-
"text-bold": Nunito_700Bold,
|
|
53
|
-
"text-bold-italic": Nunito_700Bold_Italic,
|
|
54
|
-
"text-medium": Nunito_500Medium,
|
|
55
|
-
"text-medium-italic": Nunito_500Medium_Italic,
|
|
56
|
-
"text-regular": Nunito_400Regular,
|
|
57
|
-
"text-regular-italic": Nunito_400Regular_Italic,
|
|
58
|
-
});
|
|
41
|
+
useTerrenoFontsLoaded();
|
|
59
42
|
|
|
60
43
|
const style: TextStyle = {};
|
|
61
44
|
|
|
@@ -124,3 +107,7 @@ export const Text = ({
|
|
|
124
107
|
);
|
|
125
108
|
}
|
|
126
109
|
};
|
|
110
|
+
|
|
111
|
+
TextComponent.displayName = "Text";
|
|
112
|
+
|
|
113
|
+
export const Text = React.memo(TextComponent);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import {DateTime} from "luxon";
|
|
5
|
+
import {createRef} from "react";
|
|
6
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
7
|
+
|
|
8
|
+
import type {ActionSheet} from "./ActionSheet";
|
|
9
|
+
import {NumberPickerActionSheet} from "./TextFieldNumberActionSheet";
|
|
10
|
+
import {renderWithTheme} from "./test-utils";
|
|
11
|
+
|
|
12
|
+
describe("TextFieldNumberActionSheet date picker", () => {
|
|
13
|
+
it("emits UTC ISO so the stored value can be parsed with fromISO", () => {
|
|
14
|
+
const actionSheetRef = createRef<ActionSheet>();
|
|
15
|
+
const handleChange = mock((_val: string) => {});
|
|
16
|
+
const iso = "2024-06-15T12:00:00.000Z";
|
|
17
|
+
const {UNSAFE_getByProps} = renderWithTheme(
|
|
18
|
+
<NumberPickerActionSheet
|
|
19
|
+
actionSheetRef={actionSheetRef}
|
|
20
|
+
mode="date"
|
|
21
|
+
onChange={handleChange}
|
|
22
|
+
value={iso}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
const picker = UNSAFE_getByProps({testID: "dateTimePicker"});
|
|
26
|
+
const next = DateTime.fromISO("2024-07-01T18:30:00.000Z", {zone: "utc"}).toJSDate();
|
|
27
|
+
act(() => {
|
|
28
|
+
(picker as ReactTestInstance).props.onChange({}, next);
|
|
29
|
+
});
|
|
30
|
+
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
31
|
+
const emitted = handleChange.mock.calls[0]?.[0] as string;
|
|
32
|
+
expect(DateTime.fromISO(emitted).isValid).toBe(true);
|
|
33
|
+
expect(DateTime.fromISO(emitted).toUTC().toISO()).toBe("2024-07-01T18:30:00.000Z");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("ignores changes without a date and changes that produce no ISO string", () => {
|
|
37
|
+
const handleChange = mock((_val: string) => {});
|
|
38
|
+
const {UNSAFE_getByProps} = renderWithTheme(
|
|
39
|
+
<NumberPickerActionSheet
|
|
40
|
+
actionSheetRef={createRef<ActionSheet>()}
|
|
41
|
+
mode="time"
|
|
42
|
+
onChange={handleChange}
|
|
43
|
+
value="2024-06-15T12:00:00.000Z"
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
const picker = UNSAFE_getByProps({testID: "dateTimePicker"}) as ReactTestInstance;
|
|
47
|
+
act(() => {
|
|
48
|
+
picker.props.onChange({}, undefined);
|
|
49
|
+
picker.props.onChange({}, new Date(Number.NaN));
|
|
50
|
+
});
|
|
51
|
+
assert.equal(handleChange.mock.calls.length, 0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("falls back to now when the value is missing or unparseable", () => {
|
|
55
|
+
const before = DateTime.now().toMillis();
|
|
56
|
+
const renderWith = (value?: string): number => {
|
|
57
|
+
const {UNSAFE_getByProps} = renderWithTheme(
|
|
58
|
+
<NumberPickerActionSheet
|
|
59
|
+
actionSheetRef={createRef<ActionSheet>()}
|
|
60
|
+
mode="date"
|
|
61
|
+
onChange={() => {}}
|
|
62
|
+
value={value}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
const picker = UNSAFE_getByProps({testID: "dateTimePicker"}) as ReactTestInstance;
|
|
66
|
+
return (picker.props.value as Date).getTime();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
for (const value of [undefined, "not-a-date"]) {
|
|
70
|
+
const millis = renderWith(value);
|
|
71
|
+
assert.isAtLeast(millis, before);
|
|
72
|
+
assert.isAtMost(millis, DateTime.now().toMillis());
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("closes the action sheet when Save is pressed", async () => {
|
|
77
|
+
const setModalVisible = mock((_visible: boolean) => {});
|
|
78
|
+
const actionSheetRef = createRef<ActionSheet>();
|
|
79
|
+
const {getByText} = renderWithTheme(
|
|
80
|
+
<NumberPickerActionSheet
|
|
81
|
+
actionSheetRef={actionSheetRef}
|
|
82
|
+
mode="date"
|
|
83
|
+
onChange={() => {}}
|
|
84
|
+
value="2024-06-15T12:00:00.000Z"
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
const sheet = actionSheetRef.current;
|
|
88
|
+
if (!sheet) {
|
|
89
|
+
throw new Error("expected the action sheet ref to be attached after render");
|
|
90
|
+
}
|
|
91
|
+
sheet.setModalVisible = setModalVisible;
|
|
92
|
+
await act(async () => {
|
|
93
|
+
fireEvent.press(getByText("Save"));
|
|
94
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
95
|
+
});
|
|
96
|
+
await waitFor(() => {
|
|
97
|
+
assert.deepEqual(setModalVisible.mock.calls, [[false]]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import DateTimePicker, {type DateTimePickerEvent} from "@react-native-community/datetimepicker";
|
|
2
|
+
import {DateTime} from "luxon";
|
|
2
3
|
import React from "react";
|
|
3
4
|
|
|
4
5
|
import {ActionSheet} from "./ActionSheet";
|
|
@@ -13,6 +14,10 @@ export class NumberPickerActionSheet extends React.Component<
|
|
|
13
14
|
NumberPickerActionSheetState
|
|
14
15
|
> {
|
|
15
16
|
render(): React.ReactElement {
|
|
17
|
+
const parsedValue = this.props.value ? DateTime.fromISO(this.props.value) : undefined;
|
|
18
|
+
const pickerValue =
|
|
19
|
+
parsedValue?.isValid === true ? parsedValue.toJSDate() : DateTime.now().toJSDate();
|
|
20
|
+
|
|
16
21
|
return (
|
|
17
22
|
<ActionSheet bounceOnOpen gestureEnabled ref={this.props.actionSheetRef}>
|
|
18
23
|
<Box marginBottom={8} paddingX={4} width="100%">
|
|
@@ -34,10 +39,14 @@ export class NumberPickerActionSheet extends React.Component<
|
|
|
34
39
|
if (!date) {
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
|
-
|
|
42
|
+
const iso = DateTime.fromJSDate(date).toUTC().toISO();
|
|
43
|
+
if (!iso) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.props.onChange(iso);
|
|
38
47
|
}}
|
|
39
48
|
testID="dateTimePicker"
|
|
40
|
-
value={
|
|
49
|
+
value={pickerValue}
|
|
41
50
|
/>
|
|
42
51
|
</Box>
|
|
43
52
|
</ActionSheet>
|
package/src/Theme.test.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
import {act, render} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
3
4
|
import {Text, View} from "react-native";
|
|
4
5
|
|
|
5
6
|
import {ThemeProvider, useTheme} from "./Theme";
|
|
@@ -39,6 +40,32 @@ describe("Theme", () => {
|
|
|
39
40
|
// Default text.primary is neutral900 which maps to #1C1C1C
|
|
40
41
|
expect(getByTestId("text-primary").children[0]).toBe("#1C1C1C");
|
|
41
42
|
});
|
|
43
|
+
|
|
44
|
+
it("keeps context actions stable across parent rerenders", () => {
|
|
45
|
+
const capturedValues: ThemeContextValue[] = [];
|
|
46
|
+
const Capture = (): null => {
|
|
47
|
+
capturedValues.push(useTheme());
|
|
48
|
+
return null;
|
|
49
|
+
};
|
|
50
|
+
const result = render(
|
|
51
|
+
<ThemeProvider>
|
|
52
|
+
<Capture />
|
|
53
|
+
</ThemeProvider>
|
|
54
|
+
);
|
|
55
|
+
const initialValue = capturedValues.at(-1);
|
|
56
|
+
|
|
57
|
+
result.rerender(
|
|
58
|
+
<ThemeProvider>
|
|
59
|
+
<Capture />
|
|
60
|
+
</ThemeProvider>
|
|
61
|
+
);
|
|
62
|
+
const rerenderedValue = capturedValues.at(-1);
|
|
63
|
+
|
|
64
|
+
assert.strictEqual(rerenderedValue?.resetTheme, initialValue?.resetTheme);
|
|
65
|
+
assert.strictEqual(rerenderedValue?.setPrimitives, initialValue?.setPrimitives);
|
|
66
|
+
assert.strictEqual(rerenderedValue?.setTheme, initialValue?.setTheme);
|
|
67
|
+
assert.strictEqual(rerenderedValue?.theme, initialValue?.theme);
|
|
68
|
+
});
|
|
42
69
|
});
|
|
43
70
|
|
|
44
71
|
describe("useTheme", () => {
|
package/src/Theme.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React, {createContext, useMemo, useState} from "react";
|
|
1
|
+
import React, {createContext, useCallback, useMemo, useState} from "react";
|
|
2
2
|
|
|
3
3
|
import type {TerrenoTheme, TerrenoThemeConfig, ThemePrimitives} from "./Common";
|
|
4
|
+
import {TerrenoFontProvider} from "./TerrenoFontProvider";
|
|
4
5
|
|
|
5
6
|
const defaultPrimitives = {
|
|
6
7
|
accent000: "#FFFDF7",
|
|
@@ -220,11 +221,11 @@ export const ThemeProvider = ({children, initialPrimitives}: ThemeProviderProps)
|
|
|
220
221
|
[providerTheme, providerPrimitives]
|
|
221
222
|
);
|
|
222
223
|
|
|
223
|
-
const setPrimitives = (newPrimitives: Partial<ThemePrimitives>) => {
|
|
224
|
+
const setPrimitives = useCallback((newPrimitives: Partial<ThemePrimitives>): void => {
|
|
224
225
|
setProviderPrimitives((prev) => ({...prev, ...newPrimitives}));
|
|
225
|
-
};
|
|
226
|
+
}, []);
|
|
226
227
|
|
|
227
|
-
const setTheme = (newTheme: DeepPartial<TerrenoThemeConfig>) => {
|
|
228
|
+
const setTheme = useCallback((newTheme: DeepPartial<TerrenoThemeConfig>): void => {
|
|
228
229
|
setProviderTheme((prev) => {
|
|
229
230
|
const mergedTheme = {...prev};
|
|
230
231
|
|
|
@@ -246,17 +247,21 @@ export const ThemeProvider = ({children, initialPrimitives}: ThemeProviderProps)
|
|
|
246
247
|
|
|
247
248
|
return mergedTheme;
|
|
248
249
|
});
|
|
249
|
-
};
|
|
250
|
+
}, []);
|
|
250
251
|
|
|
251
|
-
const resetTheme = () => {
|
|
252
|
+
const resetTheme = useCallback((): void => {
|
|
252
253
|
setProviderTheme(defaultTheme);
|
|
253
254
|
setProviderPrimitives(defaultPrimitives);
|
|
254
|
-
};
|
|
255
|
+
}, []);
|
|
256
|
+
const contextValue = useMemo(
|
|
257
|
+
() => ({resetTheme, setPrimitives, setTheme, theme: computedTheme}),
|
|
258
|
+
[computedTheme, resetTheme, setPrimitives, setTheme]
|
|
259
|
+
);
|
|
255
260
|
|
|
256
261
|
return (
|
|
257
|
-
<
|
|
258
|
-
{children}
|
|
259
|
-
</
|
|
262
|
+
<TerrenoFontProvider>
|
|
263
|
+
<ThemeContext.Provider value={contextValue}>{children}</ThemeContext.Provider>
|
|
264
|
+
</TerrenoFontProvider>
|
|
260
265
|
);
|
|
261
266
|
};
|
|
262
267
|
|
package/src/Toast.tsx
CHANGED
|
@@ -52,7 +52,7 @@ export const useToast = (): {
|
|
|
52
52
|
console.warn("Toast not ready yet — provider ref may not be initialized");
|
|
53
53
|
return "";
|
|
54
54
|
}
|
|
55
|
-
const toastData = {
|
|
55
|
+
const toastData: Partial<ToastProps> & Record<string, unknown> = {
|
|
56
56
|
variant: "info",
|
|
57
57
|
...options,
|
|
58
58
|
title,
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
View,
|
|
57
57
|
type ViewStyle,
|
|
58
58
|
} from "react-native";
|
|
59
|
+
import type {ToastProps as TerrenoToastPayload} from "./Common";
|
|
59
60
|
|
|
60
61
|
// ============================================================================
|
|
61
62
|
// useDimensions hook
|
|
@@ -175,11 +176,10 @@ export interface ToastOptions {
|
|
|
175
176
|
onClose?(): void;
|
|
176
177
|
|
|
177
178
|
/**
|
|
178
|
-
* Payload
|
|
179
|
+
* Payload forwarded to {@link Toast} via TerrenoProvider's renderToast.
|
|
180
|
+
* Extra keys are allowed for custom renderToast implementations.
|
|
179
181
|
*/
|
|
180
|
-
|
|
181
|
-
// 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.
|
|
182
|
-
data?: any;
|
|
182
|
+
data?: Partial<TerrenoToastPayload> & Record<string, unknown>;
|
|
183
183
|
|
|
184
184
|
swipeEnabled?: boolean;
|
|
185
185
|
}
|
package/src/Tooltip.test.tsx
CHANGED
|
@@ -277,6 +277,70 @@ describe("Tooltip", () => {
|
|
|
277
277
|
}
|
|
278
278
|
});
|
|
279
279
|
|
|
280
|
+
it("keeps the tooltip off screen until the trigger has been measured", async () => {
|
|
281
|
+
const {getByTestId, UNSAFE_getAllByType, toJSON} = renderWithTheme(
|
|
282
|
+
<Tooltip idealPosition="top" text="Measured placement">
|
|
283
|
+
<Text>Trigger</Text>
|
|
284
|
+
</Tooltip>
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const tree = toJSON() as TestNode;
|
|
288
|
+
const root = tree.children?.[0] as TestNode;
|
|
289
|
+
|
|
290
|
+
await act(async () => {
|
|
291
|
+
root.props.onTouchStart?.({nativeEvent: {}});
|
|
292
|
+
});
|
|
293
|
+
await act(async () => {
|
|
294
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const {StyleSheet, View: ViewComp} = await import("react-native");
|
|
298
|
+
const findPlacementStyle = () => {
|
|
299
|
+
const positioned = UNSAFE_getAllByType(ViewComp).find(
|
|
300
|
+
(node: {props: {style?: unknown; onLayout?: unknown}}) =>
|
|
301
|
+
Boolean(node.props.onLayout) &&
|
|
302
|
+
StyleSheet.flatten(node.props.style)?.position === "absolute"
|
|
303
|
+
);
|
|
304
|
+
return StyleSheet.flatten(positioned?.props.style) as
|
|
305
|
+
| {left?: number; opacity?: number; top?: number}
|
|
306
|
+
| undefined;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// Before layout the trigger position is unknown, so the tooltip must stay hidden
|
|
310
|
+
// and out of the way rather than rendering in the corner of the screen.
|
|
311
|
+
const beforeLayout = findPlacementStyle();
|
|
312
|
+
expect(beforeLayout?.opacity).toBe(0);
|
|
313
|
+
expect(beforeLayout?.left).toBeLessThan(0);
|
|
314
|
+
expect(beforeLayout?.top).toBeLessThan(0);
|
|
315
|
+
|
|
316
|
+
const positionedView = UNSAFE_getAllByType(ViewComp).find(
|
|
317
|
+
(node: {props: {onLayout?: unknown}}) => Boolean(node.props.onLayout)
|
|
318
|
+
) as {props: TestNode["props"]} | undefined;
|
|
319
|
+
const wrapper = UNSAFE_getAllByType(ViewComp).find((node: {props: {hitSlop?: object}}) =>
|
|
320
|
+
Boolean(node.props.hitSlop)
|
|
321
|
+
);
|
|
322
|
+
const fiber = (wrapper as unknown as {_fiber?: {ref?: {current: unknown}}})?._fiber;
|
|
323
|
+
if (fiber?.ref && typeof fiber.ref === "object") {
|
|
324
|
+
(fiber.ref as {current: unknown}).current = {
|
|
325
|
+
measure: (callback: MeasureCallback) => {
|
|
326
|
+
callback(0, 0, 100, 40, 200, 300);
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
await act(async () => {
|
|
332
|
+
positionedView?.props.onLayout?.({
|
|
333
|
+
nativeEvent: {layout: {height: 30, width: 150, x: 0, y: 0}},
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const afterLayout = findPlacementStyle();
|
|
338
|
+
expect(afterLayout?.opacity).toBe(1);
|
|
339
|
+
expect(afterLayout?.top).toBe(300 - 30 - 6);
|
|
340
|
+
expect(afterLayout?.left).toBe(200 + 100 / 2 - 150 / 2);
|
|
341
|
+
expect(getByTestId("tooltip-container")).toBeTruthy();
|
|
342
|
+
});
|
|
343
|
+
|
|
280
344
|
it("getTooltipPosition returns empty when not measured", () => {
|
|
281
345
|
const result = getTooltipPosition({
|
|
282
346
|
children: {},
|
package/src/Tooltip.tsx
CHANGED
|
@@ -33,6 +33,12 @@ interface Measurement {
|
|
|
33
33
|
idealPosition?: TooltipPosition;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
interface TooltipPlacement {
|
|
37
|
+
finalPosition: TooltipPosition;
|
|
38
|
+
left: number;
|
|
39
|
+
top: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
interface ChildrenProps {
|
|
37
43
|
onClick?: () => void;
|
|
38
44
|
onHoverIn?: () => void;
|
|
@@ -44,7 +50,7 @@ export const getTooltipPosition = ({
|
|
|
44
50
|
tooltip,
|
|
45
51
|
measured,
|
|
46
52
|
idealPosition,
|
|
47
|
-
}: Measurement):
|
|
53
|
+
}: Measurement): Partial<TooltipPlacement> => {
|
|
48
54
|
if (!measured) {
|
|
49
55
|
console.debug("No measurements for child yet, cannot show tooltip yet.");
|
|
50
56
|
return {};
|
|
@@ -268,7 +274,7 @@ export const Tooltip: FC<TooltipProps> = ({text, children, idealPosition, includ
|
|
|
268
274
|
measured: true,
|
|
269
275
|
tooltip: {...layout},
|
|
270
276
|
});
|
|
271
|
-
if (
|
|
277
|
+
if (position.finalPosition) {
|
|
272
278
|
setFinalPosition(position.finalPosition);
|
|
273
279
|
}
|
|
274
280
|
});
|
|
@@ -337,6 +343,11 @@ export const Tooltip: FC<TooltipProps> = ({text, children, idealPosition, includ
|
|
|
337
343
|
return children;
|
|
338
344
|
}
|
|
339
345
|
|
|
346
|
+
const placement = measurement.measured
|
|
347
|
+
? getTooltipPosition({...(measurement as Measurement), idealPosition})
|
|
348
|
+
: {};
|
|
349
|
+
const isPositioned = placement.left !== undefined && placement.top !== undefined;
|
|
350
|
+
|
|
340
351
|
return (
|
|
341
352
|
<View>
|
|
342
353
|
{visible && (
|
|
@@ -344,9 +355,13 @@ export const Tooltip: FC<TooltipProps> = ({text, children, idealPosition, includ
|
|
|
344
355
|
<View
|
|
345
356
|
onLayout={handleOnLayout}
|
|
346
357
|
style={{
|
|
358
|
+
// The trigger is measured on the first layout pass, so keep the tooltip
|
|
359
|
+
// off screen until then instead of flashing it in the top left corner.
|
|
360
|
+
left: isPositioned ? placement.left : -9999,
|
|
361
|
+
opacity: isPositioned ? 1 : 0,
|
|
347
362
|
position: "absolute",
|
|
363
|
+
top: isPositioned ? placement.top : -9999,
|
|
348
364
|
zIndex: 999,
|
|
349
|
-
...getTooltipPosition({...(measurement as Measurement), idealPosition}),
|
|
350
365
|
}}
|
|
351
366
|
>
|
|
352
367
|
{includeArrow && isWeb && (
|
|
@@ -361,7 +376,6 @@ export const Tooltip: FC<TooltipProps> = ({text, children, idealPosition, includ
|
|
|
361
376
|
display: "flex",
|
|
362
377
|
flexShrink: 1,
|
|
363
378
|
maxWidth: 320,
|
|
364
|
-
opacity: measurement.measured ? 1 : 0,
|
|
365
379
|
paddingHorizontal: 8,
|
|
366
380
|
paddingVertical: 2,
|
|
367
381
|
}}
|
package/src/Unifier.ts
CHANGED
|
@@ -6,11 +6,34 @@ import {Dimensions, Keyboard, Linking, Platform, Vibration} from "react-native";
|
|
|
6
6
|
import type {PermissionKind} from "./Common";
|
|
7
7
|
import {requestPermissions} from "./Permissions";
|
|
8
8
|
|
|
9
|
+
export interface GooglePlacesAutocomplete {
|
|
10
|
+
addListener: (eventName: string, handler: () => void) => void;
|
|
11
|
+
getPlace: () => {
|
|
12
|
+
address_components?: Array<{long_name: string; short_name: string; types: string[]}>;
|
|
13
|
+
formatted_address?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GoogleMapsPlacesLibrary {
|
|
18
|
+
Autocomplete: new (
|
|
19
|
+
inputField: HTMLInputElement | null,
|
|
20
|
+
opts?: {
|
|
21
|
+
componentRestrictions?: {country: string | string[]};
|
|
22
|
+
fields?: string[];
|
|
23
|
+
types?: string[];
|
|
24
|
+
}
|
|
25
|
+
) => GooglePlacesAutocomplete;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GoogleMapsNamespace {
|
|
29
|
+
maps: {
|
|
30
|
+
places: GoogleMapsPlacesLibrary;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
9
34
|
declare global {
|
|
10
35
|
interface Window {
|
|
11
|
-
|
|
12
|
-
// biome-ignore lint/suspicious/noExplicitAny: Google Maps JS SDK global type is loaded dynamically and not bundled as a typed dependency
|
|
13
|
-
google: any;
|
|
36
|
+
google?: GoogleMapsNamespace;
|
|
14
37
|
}
|
|
15
38
|
}
|
|
16
39
|
|
|
@@ -48,8 +48,12 @@ export const WebAddressAutocomplete = ({
|
|
|
48
48
|
}
|
|
49
49
|
loadGooglePlacesScript(googleMapsApiKey, callbackName)
|
|
50
50
|
.then(() => {
|
|
51
|
-
const
|
|
52
|
-
|
|
51
|
+
const googleMaps = window.google;
|
|
52
|
+
if (!googleMaps?.maps?.places) {
|
|
53
|
+
throw new Error("Google Maps Places failed to load");
|
|
54
|
+
}
|
|
55
|
+
const autocomplete = new googleMaps.maps.places.Autocomplete(
|
|
56
|
+
autocompleteInputRef.current as unknown as HTMLInputElement | null,
|
|
53
57
|
{
|
|
54
58
|
componentRestrictions: {country: GOOGLE_PLACES_API_RESTRICTIONS.components.country},
|
|
55
59
|
fields: Object.values(GOOGLE_PLACES_API_RESTRICTIONS.fields),
|
|
@@ -212,12 +212,8 @@ exports[`ActionSheet renders correctly 1`] = `
|
|
|
212
212
|
"keyboardShouldPersistTaps": undefined,
|
|
213
213
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
214
214
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
215
|
-
"onScroll": [Function],
|
|
216
215
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
217
216
|
"onTouchEnd": [Function],
|
|
218
|
-
"ref": {
|
|
219
|
-
"current": null,
|
|
220
|
-
},
|
|
221
217
|
"scrollEnabled": false,
|
|
222
218
|
"scrollEventThrottle": 5,
|
|
223
219
|
"scrollsToTop": false,
|
|
@@ -501,12 +497,8 @@ exports[`ActionSheet renders with custom overlay color 1`] = `
|
|
|
501
497
|
"keyboardShouldPersistTaps": undefined,
|
|
502
498
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
503
499
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
504
|
-
"onScroll": [Function],
|
|
505
500
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
506
501
|
"onTouchEnd": [Function],
|
|
507
|
-
"ref": {
|
|
508
|
-
"current": null,
|
|
509
|
-
},
|
|
510
502
|
"scrollEnabled": false,
|
|
511
503
|
"scrollEventThrottle": 5,
|
|
512
504
|
"scrollsToTop": false,
|
|
@@ -811,12 +803,8 @@ exports[`ActionSheet renders with gesture enabled 1`] = `
|
|
|
811
803
|
"keyboardShouldPersistTaps": undefined,
|
|
812
804
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
813
805
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
814
|
-
"onScroll": [Function],
|
|
815
806
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
816
807
|
"onTouchEnd": [Function],
|
|
817
|
-
"ref": {
|
|
818
|
-
"current": null,
|
|
819
|
-
},
|
|
820
808
|
"scrollEnabled": false,
|
|
821
809
|
"scrollEventThrottle": 5,
|
|
822
810
|
"scrollsToTop": false,
|
|
@@ -1100,12 +1088,8 @@ exports[`ActionSheet renders with elevation prop 1`] = `
|
|
|
1100
1088
|
"keyboardShouldPersistTaps": undefined,
|
|
1101
1089
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
1102
1090
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
1103
|
-
"onScroll": [Function],
|
|
1104
1091
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
1105
1092
|
"onTouchEnd": [Function],
|
|
1106
|
-
"ref": {
|
|
1107
|
-
"current": null,
|
|
1108
|
-
},
|
|
1109
1093
|
"scrollEnabled": false,
|
|
1110
1094
|
"scrollEventThrottle": 5,
|
|
1111
1095
|
"scrollsToTop": false,
|
|
@@ -1389,12 +1373,8 @@ exports[`ActionSheet renders with indicator color 1`] = `
|
|
|
1389
1373
|
"keyboardShouldPersistTaps": undefined,
|
|
1390
1374
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
1391
1375
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
1392
|
-
"onScroll": [Function],
|
|
1393
1376
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
1394
1377
|
"onTouchEnd": [Function],
|
|
1395
|
-
"ref": {
|
|
1396
|
-
"current": null,
|
|
1397
|
-
},
|
|
1398
1378
|
"scrollEnabled": false,
|
|
1399
1379
|
"scrollEventThrottle": 5,
|
|
1400
1380
|
"scrollsToTop": false,
|
|
@@ -1678,12 +1658,8 @@ exports[`ActionSheet renders with initialOffsetFromBottom 1`] = `
|
|
|
1678
1658
|
"keyboardShouldPersistTaps": undefined,
|
|
1679
1659
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
1680
1660
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
1681
|
-
"onScroll": [Function],
|
|
1682
1661
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
1683
1662
|
"onTouchEnd": [Function],
|
|
1684
|
-
"ref": {
|
|
1685
|
-
"current": null,
|
|
1686
|
-
},
|
|
1687
1663
|
"scrollEnabled": false,
|
|
1688
1664
|
"scrollEventThrottle": 5,
|
|
1689
1665
|
"scrollsToTop": false,
|
|
@@ -1967,12 +1943,8 @@ exports[`ActionSheet renders with bottomOffset 1`] = `
|
|
|
1967
1943
|
"keyboardShouldPersistTaps": undefined,
|
|
1968
1944
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
1969
1945
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
1970
|
-
"onScroll": [Function],
|
|
1971
1946
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
1972
1947
|
"onTouchEnd": [Function],
|
|
1973
|
-
"ref": {
|
|
1974
|
-
"current": null,
|
|
1975
|
-
},
|
|
1976
1948
|
"scrollEnabled": false,
|
|
1977
1949
|
"scrollEventThrottle": 5,
|
|
1978
1950
|
"scrollsToTop": false,
|
|
@@ -2256,12 +2228,8 @@ exports[`ActionSheet renders with closable=false and persistent 1`] = `
|
|
|
2256
2228
|
"keyboardShouldPersistTaps": undefined,
|
|
2257
2229
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
2258
2230
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
2259
|
-
"onScroll": [Function],
|
|
2260
2231
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
2261
2232
|
"onTouchEnd": [Function],
|
|
2262
|
-
"ref": {
|
|
2263
|
-
"current": null,
|
|
2264
|
-
},
|
|
2265
2233
|
"scrollEnabled": false,
|
|
2266
2234
|
"scrollEventThrottle": 5,
|
|
2267
2235
|
"scrollsToTop": false,
|
|
@@ -2547,12 +2515,8 @@ exports[`ActionSheet renders with custom containerStyle 1`] = `
|
|
|
2547
2515
|
"keyboardShouldPersistTaps": undefined,
|
|
2548
2516
|
"onMomentumScrollBegin": [Function: AsyncFunction],
|
|
2549
2517
|
"onMomentumScrollEnd": [Function: AsyncFunction],
|
|
2550
|
-
"onScroll": [Function],
|
|
2551
2518
|
"onScrollBeginDrag": [Function: AsyncFunction],
|
|
2552
2519
|
"onTouchEnd": [Function],
|
|
2553
|
-
"ref": {
|
|
2554
|
-
"current": null,
|
|
2555
|
-
},
|
|
2556
2520
|
"scrollEnabled": false,
|
|
2557
2521
|
"scrollEventThrottle": 5,
|
|
2558
2522
|
"scrollsToTop": false,
|