@terreno/ui 57.2.0 → 57.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/AnnouncementBanner.d.ts +12 -0
- package/dist/AnnouncementBanner.js +61 -0
- package/dist/AnnouncementBanner.js.map +1 -0
- package/dist/AnnouncementNavigator.d.ts +11 -0
- package/dist/AnnouncementNavigator.js +189 -0
- package/dist/AnnouncementNavigator.js.map +1 -0
- package/dist/AnnouncementScreen.d.ts +12 -0
- package/dist/AnnouncementScreen.js +28 -0
- package/dist/AnnouncementScreen.js.map +1 -0
- package/dist/AreaChart.d.ts +5 -0
- package/dist/AreaChart.js +69 -0
- package/dist/AreaChart.js.map +1 -0
- package/dist/BarChart.d.ts +5 -0
- package/dist/BarChart.js +89 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +116 -35
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +215 -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/DashboardGrid.d.ts +4 -0
- package/dist/DashboardGrid.js +38 -0
- package/dist/DashboardGrid.js.map +1 -0
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +278 -47
- 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/DonutChart.d.ts +5 -0
- package/dist/DonutChart.js +84 -0
- package/dist/DonutChart.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/Filter.js +12 -2
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +28 -15
- 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/LineChart.d.ts +5 -0
- package/dist/LineChart.js +68 -0
- package/dist/LineChart.js.map +1 -0
- package/dist/MarkdownEmbed.d.ts +6 -0
- package/dist/MarkdownEmbed.js +17 -0
- package/dist/MarkdownEmbed.js.map +1 -0
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +81 -44
- 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/Modal.js +12 -10
- package/dist/Modal.js.map +1 -1
- package/dist/ModalSheet.d.ts +5 -1
- package/dist/ModalSheet.js +31 -13
- package/dist/ModalSheet.js.map +1 -1
- package/dist/MultiselectField.js +4 -9
- package/dist/MultiselectField.js.map +1 -1
- package/dist/NotificationBell.d.ts +16 -0
- package/dist/NotificationBell.js +15 -0
- package/dist/NotificationBell.js.map +1 -0
- package/dist/NotificationInbox.d.ts +21 -0
- package/dist/NotificationInbox.js +41 -0
- package/dist/NotificationInbox.js.map +1 -0
- package/dist/NotificationPreferences.d.ts +14 -0
- package/dist/NotificationPreferences.js +32 -0
- package/dist/NotificationPreferences.js.map +1 -0
- 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/TextField.js +83 -6
- package/dist/TextField.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/announcementBuildVersion.d.ts +6 -0
- package/dist/announcementBuildVersion.js +21 -0
- package/dist/announcementBuildVersion.js.map +1 -0
- package/dist/announcementFrequency.d.ts +42 -0
- package/dist/announcementFrequency.js +163 -0
- package/dist/announcementFrequency.js.map +1 -0
- package/dist/announcementPlatform.d.ts +2 -0
- package/dist/announcementPlatform.js +11 -0
- package/dist/announcementPlatform.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +12 -0
- package/dist/charts/ChartFrame.js +13 -0
- package/dist/charts/ChartFrame.js.map +1 -0
- package/dist/charts/bars.d.ts +18 -0
- package/dist/charts/bars.js +29 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/layout.d.ts +47 -0
- package/dist/charts/layout.js +56 -0
- package/dist/charts/layout.js.map +1 -0
- package/dist/charts/paths.d.ts +31 -0
- package/dist/charts/paths.js +52 -0
- package/dist/charts/paths.js.map +1 -0
- package/dist/charts/scales.d.ts +6 -0
- package/dist/charts/scales.js +43 -0
- package/dist/charts/scales.js.map +1 -0
- package/dist/charts/theme.d.ts +9 -0
- package/dist/charts/theme.js +15 -0
- package/dist/charts/theme.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +17 -0
- package/dist/charts/types/chartTypes.js +2 -0
- package/dist/charts/types/chartTypes.js.map +1 -0
- package/dist/dashboardGridLayout.d.ts +22 -0
- package/dist/dashboardGridLayout.js +33 -0
- package/dist/dashboardGridLayout.js.map +1 -0
- package/dist/dataTableFilters.d.ts +33 -0
- package/dist/dataTableFilters.js +221 -0
- package/dist/dataTableFilters.js.map +1 -0
- package/dist/dataTableListQuery.d.ts +42 -0
- package/dist/dataTableListQuery.js +161 -0
- package/dist/dataTableListQuery.js.map +1 -0
- 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 +30 -13
- package/dist/index.js +12 -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 +53 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +51 -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/dist/markdownEmbeds.d.ts +6 -0
- package/dist/markdownEmbeds.js +59 -0
- package/dist/markdownEmbeds.js.map +1 -0
- package/dist/testing/resolveTestId.js +2 -1
- package/dist/testing/resolveTestId.js.map +1 -1
- package/dist/testing/types.d.ts +3 -0
- package/dist/textFieldOscillationGuard.d.ts +25 -0
- package/dist/textFieldOscillationGuard.js +41 -0
- package/dist/textFieldOscillationGuard.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
- package/dist/useAcknowledgeAnnouncement.js +94 -0
- package/dist/useAcknowledgeAnnouncement.js.map +1 -0
- package/dist/useAnnouncements.d.ts +73 -0
- package/dist/useAnnouncements.js +66 -0
- package/dist/useAnnouncements.js.map +1 -0
- package/package.json +46 -18
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AnnouncementBanner.test.tsx +267 -0
- package/src/AnnouncementBanner.tsx +128 -0
- package/src/AnnouncementNavigator.test.tsx +759 -0
- package/src/AnnouncementNavigator.tsx +287 -0
- package/src/AnnouncementScreen.test.tsx +97 -0
- package/src/AnnouncementScreen.tsx +70 -0
- package/src/AreaChart.test.tsx +68 -0
- package/src/AreaChart.tsx +194 -0
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/BarChart.test.tsx +96 -0
- package/src/BarChart.tsx +208 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +273 -0
- package/src/Button.tsx +163 -50
- package/src/Common.ts +219 -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.test.tsx +55 -0
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DashboardGrid.test.tsx +75 -0
- package/src/DashboardGrid.tsx +69 -0
- package/src/DataTable.test.tsx +296 -1
- package/src/DataTable.tsx +623 -160
- 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/DonutChart.test.tsx +121 -0
- package/src/DonutChart.tsx +160 -0
- package/src/EmojiSelector.test.tsx +84 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/Field.test.tsx +18 -0
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/Filter.test.tsx +25 -0
- package/src/Filter.tsx +38 -7
- 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 +803 -0
- package/src/GPTChat.tsx +177 -87
- 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/LineChart.test.tsx +166 -0
- package/src/LineChart.tsx +190 -0
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownEmbed.test.tsx +34 -0
- package/src/MarkdownEmbed.tsx +43 -0
- package/src/MarkdownView.test.tsx +112 -11
- package/src/MarkdownView.tsx +197 -150
- package/src/MediaQuery.ts +30 -34
- package/src/Modal.test.tsx +107 -14
- package/src/Modal.tsx +20 -8
- package/src/ModalSheet.test.tsx +121 -9
- package/src/ModalSheet.tsx +46 -11
- package/src/MultiselectField.test.tsx +21 -0
- package/src/MultiselectField.tsx +11 -13
- package/src/NotificationBell.test.tsx +91 -0
- package/src/NotificationBell.tsx +77 -0
- package/src/NotificationInbox.test.tsx +130 -0
- package/src/NotificationInbox.tsx +144 -0
- package/src/NotificationPreferences.test.tsx +25 -0
- package/src/NotificationPreferences.tsx +75 -0
- 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 +82 -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/TextField.test.tsx +421 -0
- package/src/TextField.tsx +121 -4
- 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 +29 -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__/ModalSheet.test.tsx.snap +4 -1
- 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__/TextArea.test.tsx.snap +5 -5
- package/src/__snapshots__/TextField.test.tsx.snap +5 -5
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/announcementBuildVersion.test.ts +43 -0
- package/src/announcementBuildVersion.ts +21 -0
- package/src/announcementFrequency.test.ts +245 -0
- package/src/announcementFrequency.ts +246 -0
- package/src/announcementPlatform.test.ts +27 -0
- package/src/announcementPlatform.ts +13 -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/charts/ChartFrame.tsx +67 -0
- package/src/charts/bars.test.ts +56 -0
- package/src/charts/bars.ts +53 -0
- package/src/charts/layout.test.ts +80 -0
- package/src/charts/layout.ts +99 -0
- package/src/charts/paths.test.ts +79 -0
- package/src/charts/paths.ts +100 -0
- package/src/charts/scales.test.ts +59 -0
- package/src/charts/scales.ts +60 -0
- package/src/charts/theme.test.ts +22 -0
- package/src/charts/theme.ts +24 -0
- package/src/charts/types/chartTypes.ts +19 -0
- package/src/dashboardGridLayout.test.ts +90 -0
- package/src/dashboardGridLayout.ts +60 -0
- package/src/dataTableFilters.test.tsx +552 -0
- package/src/dataTableFilters.tsx +441 -0
- package/src/dataTableListQuery.test.ts +220 -0
- package/src/dataTableListQuery.ts +201 -0
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +48 -14
- 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 +134 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
- package/src/login/loginTypes.ts +2 -0
- package/src/markdownEmbeds.test.ts +53 -0
- package/src/markdownEmbeds.ts +62 -0
- package/src/pdfHtmlTemplate.test.ts +119 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
- package/src/testing/resolveTestId.test.ts +3 -0
- package/src/testing/resolveTestId.ts +1 -0
- package/src/testing/types.ts +3 -0
- package/src/textFieldOscillationGuard.test.ts +63 -0
- package/src/textFieldOscillationGuard.ts +89 -0
- package/src/types/react-native-markdown-display.d.ts +6 -0
- package/src/types/react-native-swiper-flatlist.d.ts +5 -5
- package/src/useAcknowledgeAnnouncement.test.ts +223 -0
- package/src/useAcknowledgeAnnouncement.ts +166 -0
- package/src/useAnnouncements.test.ts +226 -0
- package/src/useAnnouncements.ts +150 -0
package/src/TextField.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {getCalendars} from "expo-localization";
|
|
2
|
-
import {type FC, useMemo, useState} from "react";
|
|
2
|
+
import {type FC, useCallback, useMemo, useRef, useState} from "react";
|
|
3
3
|
import {
|
|
4
4
|
type DimensionValue,
|
|
5
5
|
type KeyboardTypeOptions,
|
|
@@ -18,6 +18,11 @@ import {FieldTitle} from "./fieldElements/FieldTitle";
|
|
|
18
18
|
import {Icon} from "./Icon";
|
|
19
19
|
import {useTheme} from "./Theme";
|
|
20
20
|
import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
|
|
21
|
+
import {
|
|
22
|
+
createTextFieldOscillationState,
|
|
23
|
+
recordTextFieldOscillation,
|
|
24
|
+
shouldSuppressTextFieldOscillation,
|
|
25
|
+
} from "./textFieldOscillationGuard";
|
|
21
26
|
|
|
22
27
|
const keyboardMap: {[id: string]: string | undefined} = {
|
|
23
28
|
date: "default",
|
|
@@ -58,6 +63,13 @@ const textContentMap: {
|
|
|
58
63
|
username: "username",
|
|
59
64
|
};
|
|
60
65
|
|
|
66
|
+
interface WebTextInputRef {
|
|
67
|
+
focus: () => void;
|
|
68
|
+
selectionEnd: number | null;
|
|
69
|
+
selectionStart: number | null;
|
|
70
|
+
setSelectionRange: (start: number, end: number) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
61
73
|
export const TextField: FC<TextFieldProps> = ({
|
|
62
74
|
title,
|
|
63
75
|
disabled,
|
|
@@ -71,6 +83,7 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
71
83
|
onIconClick,
|
|
72
84
|
trimOnBlur = true,
|
|
73
85
|
type = "text",
|
|
86
|
+
showVisibilityToggle = true,
|
|
74
87
|
autoComplete,
|
|
75
88
|
inputRef,
|
|
76
89
|
multiline,
|
|
@@ -97,6 +110,50 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
97
110
|
|
|
98
111
|
const [focused, setFocused] = useState(false);
|
|
99
112
|
const [height, setHeight] = useState(rows * 40);
|
|
113
|
+
const [isValueRevealed, setIsValueRevealed] = useState(false);
|
|
114
|
+
const textInputRef = useRef<TextInput | null>(null);
|
|
115
|
+
|
|
116
|
+
const isPasswordField = type === "password";
|
|
117
|
+
const hasVisibilityToggle = isPasswordField && showVisibilityToggle;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Toggles password visibility without blurring the input. Refocuses when the field was focused so
|
|
121
|
+
* trim-on-blur, parent blur handlers, and the native keyboard stay intact.
|
|
122
|
+
*/
|
|
123
|
+
const handleVisibilityTogglePress = useCallback((): void => {
|
|
124
|
+
if (disabled) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const wasFocused = focused;
|
|
128
|
+
const webInput =
|
|
129
|
+
Platform.OS === "web" ? (textInputRef.current as unknown as WebTextInputRef | null) : null;
|
|
130
|
+
const selection =
|
|
131
|
+
webInput?.selectionStart !== null &&
|
|
132
|
+
webInput?.selectionStart !== undefined &&
|
|
133
|
+
webInput.selectionEnd !== null
|
|
134
|
+
? {end: webInput.selectionEnd, start: webInput.selectionStart}
|
|
135
|
+
: undefined;
|
|
136
|
+
setIsValueRevealed((previous) => !previous);
|
|
137
|
+
if (wasFocused) {
|
|
138
|
+
const refocusInput = (): void => {
|
|
139
|
+
textInputRef.current?.focus();
|
|
140
|
+
if (selection && webInput) {
|
|
141
|
+
webInput.setSelectionRange(selection.start, selection.end);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
if (typeof requestAnimationFrame === "function") {
|
|
145
|
+
requestAnimationFrame(refocusInput);
|
|
146
|
+
} else {
|
|
147
|
+
setTimeout(refocusInput, 0);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}, [disabled, focused]);
|
|
151
|
+
|
|
152
|
+
const preventVisibilityToggleBlur = useCallback((event: {preventDefault: () => void}): void => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
}, []);
|
|
155
|
+
const visibilityToggleWebProps =
|
|
156
|
+
Platform.OS === "web" ? {onMouseDown: preventVisibilityToggleBlur} : {};
|
|
100
157
|
|
|
101
158
|
let borderColor = focused ? theme.border.focus : theme.border.dark;
|
|
102
159
|
if (disabled) {
|
|
@@ -139,8 +196,46 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
139
196
|
console.warn(`${type} is not yet supported`);
|
|
140
197
|
}
|
|
141
198
|
|
|
199
|
+
// RN Web browser autocorrect/spellcheck fights controlled `value` and can oscillate
|
|
200
|
+
// between variants (e.g. "reachthreshold" vs "reach threshold"), firing onChangeText forever.
|
|
142
201
|
const shouldAutocorrect =
|
|
143
|
-
|
|
202
|
+
Platform.OS !== "web" &&
|
|
203
|
+
["text", "textarea"].includes(type) &&
|
|
204
|
+
(!autoComplete || autoComplete === "on");
|
|
205
|
+
|
|
206
|
+
const valueRef = useRef(value);
|
|
207
|
+
const onChangeRef = useRef(onChange);
|
|
208
|
+
const oscillationRef = useRef(createTextFieldOscillationState());
|
|
209
|
+
valueRef.current = value;
|
|
210
|
+
onChangeRef.current = onChange;
|
|
211
|
+
|
|
212
|
+
const handleChangeText = useCallback((text: string): void => {
|
|
213
|
+
const currentValue = valueRef.current ?? "";
|
|
214
|
+
if (text === currentValue) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const now = performance.now();
|
|
219
|
+
const oscillationState = oscillationRef.current;
|
|
220
|
+
if (
|
|
221
|
+
shouldSuppressTextFieldOscillation({
|
|
222
|
+
currentValue,
|
|
223
|
+
now,
|
|
224
|
+
state: oscillationState,
|
|
225
|
+
text,
|
|
226
|
+
})
|
|
227
|
+
) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
recordTextFieldOscillation({
|
|
232
|
+
currentValue,
|
|
233
|
+
now,
|
|
234
|
+
state: oscillationState,
|
|
235
|
+
text,
|
|
236
|
+
});
|
|
237
|
+
onChangeRef.current(text);
|
|
238
|
+
}, []);
|
|
144
239
|
|
|
145
240
|
const keyboardType = keyboardMap[type];
|
|
146
241
|
const textContentType = textContentMap[type || "text"];
|
|
@@ -180,6 +275,7 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
180
275
|
}}
|
|
181
276
|
>
|
|
182
277
|
<TextInput
|
|
278
|
+
{...(Platform.OS === "web" ? {spellCheck: false} : {})}
|
|
183
279
|
accessibilityHint="Enter text here"
|
|
184
280
|
accessibilityState={{disabled}}
|
|
185
281
|
aria-label="Text input field"
|
|
@@ -208,7 +304,7 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
208
304
|
}
|
|
209
305
|
setFocused(false);
|
|
210
306
|
}}
|
|
211
|
-
onChangeText={
|
|
307
|
+
onChangeText={handleChangeText}
|
|
212
308
|
onContentSizeChange={(event) => {
|
|
213
309
|
if (!grow) {
|
|
214
310
|
return;
|
|
@@ -235,11 +331,12 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
235
331
|
placeholderTextColor={theme.text.secondaryLight}
|
|
236
332
|
readOnly={disabled}
|
|
237
333
|
ref={(ref) => {
|
|
334
|
+
textInputRef.current = ref;
|
|
238
335
|
if (inputRef) {
|
|
239
336
|
inputRef(ref);
|
|
240
337
|
}
|
|
241
338
|
}}
|
|
242
|
-
secureTextEntry={
|
|
339
|
+
secureTextEntry={isPasswordField && !isValueRevealed}
|
|
243
340
|
style={defaultTextInputStyles}
|
|
244
341
|
testID={fieldTestIDs.input}
|
|
245
342
|
textContentType={textContentType}
|
|
@@ -251,6 +348,26 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
251
348
|
<Icon iconName={iconName!} size="md" />
|
|
252
349
|
</Pressable>
|
|
253
350
|
)}
|
|
351
|
+
{hasVisibilityToggle && (
|
|
352
|
+
<Pressable
|
|
353
|
+
{...visibilityToggleWebProps}
|
|
354
|
+
accessibilityLabel={isValueRevealed ? "Hide password" : "Show password"}
|
|
355
|
+
accessibilityRole="button"
|
|
356
|
+
accessibilityState={{disabled, expanded: isValueRevealed}}
|
|
357
|
+
disabled={disabled}
|
|
358
|
+
hitSlop={8}
|
|
359
|
+
onPress={handleVisibilityTogglePress}
|
|
360
|
+
// Fixed width keeps the input from reflowing: the eye-slash glyph is wider than the eye.
|
|
361
|
+
style={{alignItems: "center", marginLeft: 8, width: 20}}
|
|
362
|
+
testID={fieldTestIDs.visibilityToggle}
|
|
363
|
+
>
|
|
364
|
+
<Icon
|
|
365
|
+
color={disabled ? "extraLight" : "link"}
|
|
366
|
+
iconName={isValueRevealed ? "eye-slash" : "eye"}
|
|
367
|
+
size="md"
|
|
368
|
+
/>
|
|
369
|
+
</Pressable>
|
|
370
|
+
)}
|
|
254
371
|
</View>
|
|
255
372
|
</View>
|
|
256
373
|
{Boolean(helperText) && <FieldHelperText testID={fieldTestIDs.helper} text={helperText!} />}
|
|
@@ -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),
|