@terreno/ui 0.0.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/LICENSE +203 -0
- package/README.md +160 -0
- package/dist/Accordion.d.ts +3 -0
- package/dist/Accordion.js +30 -0
- package/dist/Accordion.js.map +1 -0
- package/dist/ActionSheet.d.ts +169 -0
- package/dist/ActionSheet.js +637 -0
- package/dist/ActionSheet.js.map +1 -0
- package/dist/AddressField.d.ts +3 -0
- package/dist/AddressField.js +18 -0
- package/dist/AddressField.js.map +1 -0
- package/dist/Avatar.d.ts +3 -0
- package/dist/Avatar.js +189 -0
- package/dist/Avatar.js.map +1 -0
- package/dist/Badge.d.ts +3 -0
- package/dist/Badge.js +100 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Banner.d.ts +4 -0
- package/dist/Banner.js +103 -0
- package/dist/Banner.js.map +1 -0
- package/dist/Body.d.ts +3 -0
- package/dist/Body.js +17 -0
- package/dist/Body.js.map +1 -0
- package/dist/BooleanField.d.ts +3 -0
- package/dist/BooleanField.js +89 -0
- package/dist/BooleanField.js.map +1 -0
- package/dist/Box.d.ts +3 -0
- package/dist/Box.js +289 -0
- package/dist/Box.js.map +1 -0
- package/dist/Button.d.ts +3 -0
- package/dist/Button.js +105 -0
- package/dist/Button.js.map +1 -0
- package/dist/Card.d.ts +2 -0
- package/dist/Card.js +18 -0
- package/dist/Card.js.map +1 -0
- package/dist/CheckBox.d.ts +3 -0
- package/dist/CheckBox.js +28 -0
- package/dist/CheckBox.js.map +1 -0
- package/dist/Common.d.ts +2325 -0
- package/dist/Common.js +47 -0
- package/dist/Common.js.map +1 -0
- package/dist/CommonIconTypes.d.ts +3 -0
- package/dist/CommonIconTypes.js +2 -0
- package/dist/CommonIconTypes.js.map +1 -0
- package/dist/Constants.d.ts +12685 -0
- package/dist/Constants.js +3310 -0
- package/dist/Constants.js.map +1 -0
- package/dist/CustomSelectField.d.ts +3 -0
- package/dist/CustomSelectField.js +59 -0
- package/dist/CustomSelectField.js.map +1 -0
- package/dist/DataTable.d.ts +3 -0
- package/dist/DataTable.js +190 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/DateTimeActionSheet.d.ts +2 -0
- package/dist/DateTimeActionSheet.js +270 -0
- package/dist/DateTimeActionSheet.js.map +1 -0
- package/dist/DateTimeField.d.ts +3 -0
- package/dist/DateTimeField.js +514 -0
- package/dist/DateTimeField.js.map +1 -0
- package/dist/DateUtilities.d.ts +57 -0
- package/dist/DateUtilities.js +308 -0
- package/dist/DateUtilities.js.map +1 -0
- package/dist/DecimalRangeActionSheet.d.ts +6 -0
- package/dist/DecimalRangeActionSheet.js +45 -0
- package/dist/DecimalRangeActionSheet.js.map +1 -0
- package/dist/DismissButton.d.ts +3 -0
- package/dist/DismissButton.js +12 -0
- package/dist/DismissButton.js.map +1 -0
- package/dist/EmailField.d.ts +3 -0
- package/dist/EmailField.js +48 -0
- package/dist/EmailField.js.map +1 -0
- package/dist/EmojiSelector.d.ts +113 -0
- package/dist/EmojiSelector.js +322 -0
- package/dist/EmojiSelector.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +19 -0
- package/dist/ErrorBoundary.js +30 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/ErrorPage.d.ts +6 -0
- package/dist/ErrorPage.js +15 -0
- package/dist/ErrorPage.js.map +1 -0
- package/dist/Field.d.ts +3 -0
- package/dist/Field.js +80 -0
- package/dist/Field.js.map +1 -0
- package/dist/FlatList.d.ts +2 -0
- package/dist/FlatList.js +3 -0
- package/dist/FlatList.js.map +1 -0
- package/dist/Heading.d.ts +3 -0
- package/dist/Heading.js +43 -0
- package/dist/Heading.js.map +1 -0
- package/dist/HeightActionSheet.d.ts +11 -0
- package/dist/HeightActionSheet.js +46 -0
- package/dist/HeightActionSheet.js.map +1 -0
- package/dist/Hyperlink.d.ts +30 -0
- package/dist/Hyperlink.js +144 -0
- package/dist/Hyperlink.js.map +1 -0
- package/dist/Icon.d.ts +3 -0
- package/dist/Icon.js +15 -0
- package/dist/Icon.js.map +1 -0
- package/dist/IconButton.d.ts +3 -0
- package/dist/IconButton.js +111 -0
- package/dist/IconButton.js.map +1 -0
- package/dist/Image.d.ts +8 -0
- package/dist/Image.js +37 -0
- package/dist/Image.js.map +1 -0
- package/dist/ImageBackground.d.ts +10 -0
- package/dist/ImageBackground.js +9 -0
- package/dist/ImageBackground.js.map +1 -0
- package/dist/InfoModalIcon.d.ts +3 -0
- package/dist/InfoModalIcon.js +10 -0
- package/dist/InfoModalIcon.js.map +1 -0
- package/dist/InfoTooltipButton.d.ts +3 -0
- package/dist/InfoTooltipButton.js +6 -0
- package/dist/InfoTooltipButton.js.map +1 -0
- package/dist/Link.d.ts +3 -0
- package/dist/Link.js +10 -0
- package/dist/Link.js.map +1 -0
- package/dist/MarkdownView.d.ts +5 -0
- package/dist/MarkdownView.js +44 -0
- package/dist/MarkdownView.js.map +1 -0
- package/dist/MediaQuery.d.ts +4 -0
- package/dist/MediaQuery.js +52 -0
- package/dist/MediaQuery.js.map +1 -0
- package/dist/MobileAddressAutoComplete.d.ts +2 -0
- package/dist/MobileAddressAutoComplete.js +54 -0
- package/dist/MobileAddressAutoComplete.js.map +1 -0
- package/dist/Modal.d.ts +3 -0
- package/dist/Modal.js +127 -0
- package/dist/Modal.js.map +1 -0
- package/dist/ModalSheet.d.ts +6 -0
- package/dist/ModalSheet.js +42 -0
- package/dist/ModalSheet.js.map +1 -0
- package/dist/MultiselectField.d.ts +3 -0
- package/dist/MultiselectField.js +45 -0
- package/dist/MultiselectField.js.map +1 -0
- package/dist/NumberField.d.ts +3 -0
- package/dist/NumberField.js +60 -0
- package/dist/NumberField.js.map +1 -0
- package/dist/NumberPickerActionSheet.d.ts +7 -0
- package/dist/NumberPickerActionSheet.js +22 -0
- package/dist/NumberPickerActionSheet.js.map +1 -0
- package/dist/OpenAPIContext.d.ts +4 -0
- package/dist/OpenAPIContext.js +53 -0
- package/dist/OpenAPIContext.js.map +1 -0
- package/dist/Page.d.ts +7 -0
- package/dist/Page.js +24 -0
- package/dist/Page.js.map +1 -0
- package/dist/Pagination.d.ts +3 -0
- package/dist/Pagination.js +106 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/PasswordField.d.ts +2 -0
- package/dist/PasswordField.js +6 -0
- package/dist/PasswordField.js.map +1 -0
- package/dist/Permissions.d.ts +2 -0
- package/dist/Permissions.js +35 -0
- package/dist/Permissions.js.map +1 -0
- package/dist/PhoneNumberField.d.ts +3 -0
- package/dist/PhoneNumberField.js +83 -0
- package/dist/PhoneNumberField.js.map +1 -0
- package/dist/PickerSelect.d.ts +46 -0
- package/dist/PickerSelect.js +306 -0
- package/dist/PickerSelect.js.map +1 -0
- package/dist/Radio.d.ts +3 -0
- package/dist/Radio.js +21 -0
- package/dist/Radio.js.map +1 -0
- package/dist/RadioField.d.ts +3 -0
- package/dist/RadioField.js +16 -0
- package/dist/RadioField.js.map +1 -0
- package/dist/ScrollView.d.ts +2 -0
- package/dist/ScrollView.js +3 -0
- package/dist/ScrollView.js.map +1 -0
- package/dist/SectionDivider.d.ts +2 -0
- package/dist/SectionDivider.js +12 -0
- package/dist/SectionDivider.js.map +1 -0
- package/dist/SegmentedControl.d.ts +3 -0
- package/dist/SegmentedControl.js +65 -0
- package/dist/SegmentedControl.js.map +1 -0
- package/dist/SelectBadge.d.ts +3 -0
- package/dist/SelectBadge.js +166 -0
- package/dist/SelectBadge.js.map +1 -0
- package/dist/SelectField.d.ts +3 -0
- package/dist/SelectField.js +16 -0
- package/dist/SelectField.js.map +1 -0
- package/dist/SideDrawer.d.ts +3 -0
- package/dist/SideDrawer.js +32 -0
- package/dist/SideDrawer.js.map +1 -0
- package/dist/Signature.d.ts +8 -0
- package/dist/Signature.js +21 -0
- package/dist/Signature.js.map +1 -0
- package/dist/Signature.native.d.ts +8 -0
- package/dist/Signature.native.js +26 -0
- package/dist/Signature.native.js.map +1 -0
- package/dist/SignatureField.d.ts +3 -0
- package/dist/SignatureField.js +42 -0
- package/dist/SignatureField.js.map +1 -0
- package/dist/Slider.d.ts +3 -0
- package/dist/Slider.js +78 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Spinner.d.ts +3 -0
- package/dist/Spinner.js +33 -0
- package/dist/Spinner.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -0
- package/dist/SplitPage.js +139 -0
- package/dist/SplitPage.js.map +1 -0
- package/dist/SplitPage.native.d.ts +2 -0
- package/dist/SplitPage.native.js +75 -0
- package/dist/SplitPage.native.js.map +1 -0
- package/dist/TapToEdit.d.ts +4 -0
- package/dist/TapToEdit.js +170 -0
- package/dist/TapToEdit.js.map +1 -0
- package/dist/TerrenoProvider.d.ts +6 -0
- package/dist/TerrenoProvider.js +10 -0
- package/dist/TerrenoProvider.js.map +1 -0
- package/dist/Text.d.ts +3 -0
- package/dist/Text.js +95 -0
- package/dist/Text.js.map +1 -0
- package/dist/TextArea.d.ts +3 -0
- package/dist/TextArea.js +6 -0
- package/dist/TextArea.js.map +1 -0
- package/dist/TextField.d.ts +3 -0
- package/dist/TextField.js +144 -0
- package/dist/TextField.js.map +1 -0
- package/dist/TextFieldNumberActionSheet.d.ts +7 -0
- package/dist/TextFieldNumberActionSheet.js +20 -0
- package/dist/TextFieldNumberActionSheet.js.map +1 -0
- package/dist/Theme.d.ts +96 -0
- package/dist/Theme.js +213 -0
- package/dist/Theme.js.map +1 -0
- package/dist/TimezonePicker.d.ts +11 -0
- package/dist/TimezonePicker.js +27 -0
- package/dist/TimezonePicker.js.map +1 -0
- package/dist/Toast.d.ts +23 -0
- package/dist/Toast.js +157 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Tooltip.d.ts +3 -0
- package/dist/Tooltip.js +289 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/UnifiedAddressAutoComplete.d.ts +2 -0
- package/dist/UnifiedAddressAutoComplete.js +23 -0
- package/dist/UnifiedAddressAutoComplete.js.map +1 -0
- package/dist/Unifier.d.ts +43 -0
- package/dist/Unifier.js +154 -0
- package/dist/Unifier.js.map +1 -0
- package/dist/Utilities.d.ts +56 -0
- package/dist/Utilities.js +193 -0
- package/dist/Utilities.js.map +1 -0
- package/dist/WebAddressAutocomplete.d.ts +3 -0
- package/dist/WebAddressAutocomplete.js +61 -0
- package/dist/WebAddressAutocomplete.js.map +1 -0
- package/dist/fieldElements/FieldError.d.ts +6 -0
- package/dist/fieldElements/FieldError.js +9 -0
- package/dist/fieldElements/FieldError.js.map +1 -0
- package/dist/fieldElements/FieldHelperText.d.ts +6 -0
- package/dist/fieldElements/FieldHelperText.js +8 -0
- package/dist/fieldElements/FieldHelperText.js.map +1 -0
- package/dist/fieldElements/FieldTitle.d.ts +6 -0
- package/dist/fieldElements/FieldTitle.js +16 -0
- package/dist/fieldElements/FieldTitle.js.map +1 -0
- package/dist/fieldElements/index.d.ts +3 -0
- package/dist/fieldElements/index.js +4 -0
- package/dist/fieldElements/index.js.map +1 -0
- package/dist/icons/MobileIcon.d.ts +2 -0
- package/dist/icons/MobileIcon.js +18 -0
- package/dist/icons/MobileIcon.js.map +1 -0
- package/dist/icons/OfflineIcon.d.ts +2 -0
- package/dist/icons/OfflineIcon.js +18 -0
- package/dist/icons/OfflineIcon.js.map +1 -0
- package/dist/icons/OnlineIcon.d.ts +2 -0
- package/dist/icons/OnlineIcon.js +19 -0
- package/dist/icons/OnlineIcon.js.map +1 -0
- package/dist/icons/OutOfficeIcon.d.ts +2 -0
- package/dist/icons/OutOfficeIcon.js +18 -0
- package/dist/icons/OutOfficeIcon.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +5 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +1328 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/table/Table.d.ts +3 -0
- package/dist/table/Table.js +53 -0
- package/dist/table/Table.js.map +1 -0
- package/dist/table/TableBadge.d.ts +6 -0
- package/dist/table/TableBadge.js +23 -0
- package/dist/table/TableBadge.js.map +1 -0
- package/dist/table/TableBoolean.d.ts +6 -0
- package/dist/table/TableBoolean.js +37 -0
- package/dist/table/TableBoolean.js.map +1 -0
- package/dist/table/TableDate.d.ts +3 -0
- package/dist/table/TableDate.js +27 -0
- package/dist/table/TableDate.js.map +1 -0
- package/dist/table/TableHeader.d.ts +6 -0
- package/dist/table/TableHeader.js +10 -0
- package/dist/table/TableHeader.js.map +1 -0
- package/dist/table/TableHeaderCell.d.ts +6 -0
- package/dist/table/TableHeaderCell.js +54 -0
- package/dist/table/TableHeaderCell.js.map +1 -0
- package/dist/table/TableIconButton.d.ts +3 -0
- package/dist/table/TableIconButton.js +39 -0
- package/dist/table/TableIconButton.js.map +1 -0
- package/dist/table/TableNumber.d.ts +3 -0
- package/dist/table/TableNumber.js +18 -0
- package/dist/table/TableNumber.js.map +1 -0
- package/dist/table/TableRow.d.ts +6 -0
- package/dist/table/TableRow.js +22 -0
- package/dist/table/TableRow.js.map +1 -0
- package/dist/table/TableText.d.ts +3 -0
- package/dist/table/TableText.js +18 -0
- package/dist/table/TableText.js.map +1 -0
- package/dist/table/TableTitle.d.ts +3 -0
- package/dist/table/TableTitle.js +21 -0
- package/dist/table/TableTitle.js.map +1 -0
- package/dist/table/tableContext.d.ts +5 -0
- package/dist/table/tableContext.js +38 -0
- package/dist/table/tableContext.js.map +1 -0
- package/dist/useStoredState.d.ts +1 -0
- package/dist/useStoredState.js +49 -0
- package/dist/useStoredState.js.map +1 -0
- package/package.json +123 -0
- package/src/Accordion.test.tsx +104 -0
- package/src/Accordion.tsx +81 -0
- package/src/ActionSheet.tsx +881 -0
- package/src/AddressField.test.tsx +120 -0
- package/src/AddressField.tsx +122 -0
- package/src/Avatar.test.tsx +163 -0
- package/src/Avatar.tsx +298 -0
- package/src/Badge.test.tsx +116 -0
- package/src/Badge.tsx +136 -0
- package/src/Banner.tsx +200 -0
- package/src/Body.tsx +34 -0
- package/src/BooleanField.tsx +141 -0
- package/src/Box.test.tsx +662 -0
- package/src/Box.tsx +368 -0
- package/src/Button.tsx +196 -0
- package/src/Card.tsx +19 -0
- package/src/CheckBox.tsx +45 -0
- package/src/Common.ts +2787 -0
- package/src/CommonIconTypes.ts +2030 -0
- package/src/Constants.ts +3311 -0
- package/src/CustomSelectField.tsx +115 -0
- package/src/DataTable.tsx +674 -0
- package/src/DateTimeActionSheet.tsx +559 -0
- package/src/DateTimeField.test.tsx +393 -0
- package/src/DateTimeField.tsx +777 -0
- package/src/DateUtilities.test.ts +440 -0
- package/src/DateUtilities.tsx +370 -0
- package/src/DecimalRangeActionSheet.tsx +85 -0
- package/src/DismissButton.tsx +31 -0
- package/src/EmailField.tsx +66 -0
- package/src/EmojiSelector.test.tsx +61 -0
- package/src/EmojiSelector.tsx +510 -0
- package/src/ErrorBoundary.tsx +37 -0
- package/src/ErrorPage.tsx +41 -0
- package/src/Field.tsx +101 -0
- package/src/FlatList.tsx +2 -0
- package/src/Heading.tsx +66 -0
- package/src/HeightActionSheet.tsx +91 -0
- package/src/Hyperlink.tsx +179 -0
- package/src/Icon.tsx +36 -0
- package/src/IconButton.tsx +217 -0
- package/src/Image.tsx +51 -0
- package/src/ImageBackground.tsx +14 -0
- package/src/InfoModalIcon.tsx +42 -0
- package/src/InfoTooltipButton.tsx +16 -0
- package/src/Link.tsx +22 -0
- package/src/MarkdownView.tsx +67 -0
- package/src/MediaQuery.ts +46 -0
- package/src/MobileAddressAutoComplete.tsx +126 -0
- package/src/Modal.tsx +300 -0
- package/src/ModalSheet.tsx +58 -0
- package/src/MultiselectField.tsx +112 -0
- package/src/NumberField.tsx +67 -0
- package/src/NumberPickerActionSheet.tsx +51 -0
- package/src/OpenAPIContext.tsx +74 -0
- package/src/Page.tsx +105 -0
- package/src/Pagination.tsx +169 -0
- package/src/PasswordField.tsx +7 -0
- package/src/Permissions.ts +43 -0
- package/src/PhoneNumberField.tsx +109 -0
- package/src/PickerSelect.tsx +571 -0
- package/src/Radio.tsx +33 -0
- package/src/RadioField.tsx +43 -0
- package/src/ScrollView.tsx +2 -0
- package/src/SectionDivider.tsx +18 -0
- package/src/SegmentedControl.tsx +126 -0
- package/src/SelectBadge.tsx +280 -0
- package/src/SelectField.tsx +41 -0
- package/src/SideDrawer.tsx +56 -0
- package/src/Signature.native.tsx +57 -0
- package/src/Signature.tsx +44 -0
- package/src/SignatureField.tsx +92 -0
- package/src/Slider.tsx +199 -0
- package/src/Spinner.tsx +35 -0
- package/src/SplitPage.native.tsx +163 -0
- package/src/SplitPage.tsx +304 -0
- package/src/TapToEdit.tsx +292 -0
- package/src/TerrenoProvider.tsx +31 -0
- package/src/Text.tsx +123 -0
- package/src/TextArea.test.tsx +255 -0
- package/src/TextArea.tsx +8 -0
- package/src/TextField.test.tsx +487 -0
- package/src/TextField.tsx +260 -0
- package/src/TextFieldNumberActionSheet.tsx +46 -0
- package/src/Theme.tsx +248 -0
- package/src/TimezonePicker.tsx +45 -0
- package/src/Toast.tsx +234 -0
- package/src/Tooltip.tsx +407 -0
- package/src/UnifiedAddressAutoComplete.tsx +66 -0
- package/src/Unifier.ts +172 -0
- package/src/Utilities.tsx +329 -0
- package/src/WebAddressAutocomplete.tsx +84 -0
- package/src/__snapshots__/Accordion.test.tsx.snap +126 -0
- package/src/__snapshots__/AddressField.test.tsx.snap +1197 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +57 -0
- package/src/__snapshots__/Badge.test.tsx.snap +55 -0
- package/src/__snapshots__/Box.test.tsx.snap +162 -0
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +422 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +521 -0
- package/src/__snapshots__/TextField.test.tsx.snap +569 -0
- package/src/bunSetup.ts +1235 -0
- package/src/fieldElements/FieldError.tsx +24 -0
- package/src/fieldElements/FieldHelperText.tsx +20 -0
- package/src/fieldElements/FieldTitle.tsx +31 -0
- package/src/fieldElements/index.tsx +3 -0
- package/src/icons/MobileIcon.tsx +40 -0
- package/src/icons/OfflineIcon.tsx +37 -0
- package/src/icons/OnlineIcon.tsx +39 -0
- package/src/icons/OutOfficeIcon.tsx +36 -0
- package/src/icons/index.ts +4 -0
- package/src/index.tsx +1375 -0
- package/src/polyfill.d.ts +11 -0
- package/src/table/Table.tsx +109 -0
- package/src/table/TableBadge.tsx +46 -0
- package/src/table/TableBoolean.tsx +70 -0
- package/src/table/TableDate.tsx +38 -0
- package/src/table/TableHeader.tsx +20 -0
- package/src/table/TableHeaderCell.tsx +94 -0
- package/src/table/TableIconButton.tsx +61 -0
- package/src/table/TableNumber.tsx +29 -0
- package/src/table/TableRow.tsx +67 -0
- package/src/table/TableText.tsx +29 -0
- package/src/table/TableTitle.tsx +31 -0
- package/src/table/tableContext.tsx +67 -0
- package/src/test-utils.tsx +27 -0
- package/src/types/react-native-swiper-flatlist.d.ts +56 -0
- package/src/useStoredState.test.tsx +143 -0
- package/src/useStoredState.ts +56 -0
package/src/Toast.tsx
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import {Platform, Pressable, View} from "react-native";
|
|
3
|
+
import {useToast as useRNToast} from "react-native-toast-notifications";
|
|
4
|
+
|
|
5
|
+
import type {IconName, SurfaceColor, TextColor, ToastProps} from "./Common";
|
|
6
|
+
import {Heading} from "./Heading";
|
|
7
|
+
import {Icon} from "./Icon";
|
|
8
|
+
import {Text} from "./Text";
|
|
9
|
+
import {useTheme} from "./Theme";
|
|
10
|
+
import {isAPIError, printAPIError} from "./Utilities";
|
|
11
|
+
|
|
12
|
+
const TOAST_DURATION_MS = 3 * 1000;
|
|
13
|
+
|
|
14
|
+
type UseToastVariantOptions = {
|
|
15
|
+
persistent?: ToastProps["persistent"];
|
|
16
|
+
secondary?: ToastProps["secondary"];
|
|
17
|
+
size?: ToastProps["size"];
|
|
18
|
+
onDismiss?: ToastProps["onDismiss"];
|
|
19
|
+
subtitle?: ToastProps["subtitle"];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type UseToastOptions = {variant?: ToastProps["variant"]} & UseToastVariantOptions;
|
|
23
|
+
|
|
24
|
+
export function useToast(): {
|
|
25
|
+
hide: (id: string) => void;
|
|
26
|
+
success: (title: string, options?: UseToastVariantOptions) => string;
|
|
27
|
+
info: (title: string, options?: UseToastVariantOptions) => string;
|
|
28
|
+
warn: (title: string, options?: UseToastVariantOptions) => string;
|
|
29
|
+
error: (title: string, options?: UseToastVariantOptions) => string;
|
|
30
|
+
show: (title: string, options?: UseToastOptions) => string;
|
|
31
|
+
catch: (error: any, message?: string, options?: UseToastVariantOptions) => void;
|
|
32
|
+
} {
|
|
33
|
+
const toast = useRNToast();
|
|
34
|
+
const show = (title: string, options?: UseToastOptions): string => {
|
|
35
|
+
const toastData = {
|
|
36
|
+
variant: "info",
|
|
37
|
+
...options,
|
|
38
|
+
title,
|
|
39
|
+
};
|
|
40
|
+
return toast.show(title, {
|
|
41
|
+
data: toastData,
|
|
42
|
+
// a duration of 0 keeps the toast up infinitely until hidden
|
|
43
|
+
duration: options?.persistent ? 0 : TOAST_DURATION_MS,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
catch: (error: any, message?: string, options?: UseToastVariantOptions): void => {
|
|
48
|
+
let exceptionMsg;
|
|
49
|
+
if (isAPIError(error)) {
|
|
50
|
+
// Get the error without details.
|
|
51
|
+
exceptionMsg = `${message}: ${printAPIError(error)}`;
|
|
52
|
+
console.error(exceptionMsg);
|
|
53
|
+
} else {
|
|
54
|
+
exceptionMsg = error?.message ?? error?.error ?? String(error);
|
|
55
|
+
console.error(`${message}: ${exceptionMsg}`);
|
|
56
|
+
}
|
|
57
|
+
show(exceptionMsg, {...options, variant: "error"});
|
|
58
|
+
},
|
|
59
|
+
error: (title: string, options?: UseToastVariantOptions): string => {
|
|
60
|
+
console.error(title);
|
|
61
|
+
return show(title, {...options, variant: "error"});
|
|
62
|
+
},
|
|
63
|
+
hide: (id: string) => toast.hide(id),
|
|
64
|
+
info: (title: string, options?: UseToastVariantOptions): string => {
|
|
65
|
+
console.info(title);
|
|
66
|
+
return show(title, {...options, variant: "info"});
|
|
67
|
+
},
|
|
68
|
+
show,
|
|
69
|
+
success: (title: string, options?: UseToastVariantOptions): string => {
|
|
70
|
+
console.info(title);
|
|
71
|
+
return show(title, {...options, variant: "success"});
|
|
72
|
+
},
|
|
73
|
+
warn: (title: string, options?: UseToastVariantOptions): string => {
|
|
74
|
+
console.warn(title);
|
|
75
|
+
return show(title, {...options, variant: "warning"});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// TODO: Support secondary version of Toast.
|
|
81
|
+
// TODO: Support dismissible version of Toast. Currently only persistent are dismissible.
|
|
82
|
+
// This may require a different library from react-native-toast-notifications.
|
|
83
|
+
export const Toast = ({
|
|
84
|
+
title,
|
|
85
|
+
variant = "info",
|
|
86
|
+
secondary,
|
|
87
|
+
size = "sm",
|
|
88
|
+
onDismiss,
|
|
89
|
+
persistent,
|
|
90
|
+
// TODO enforce these should only show if size is "lg" with type discrinimation
|
|
91
|
+
subtitle,
|
|
92
|
+
}: ToastProps): React.ReactElement => {
|
|
93
|
+
const {theme} = useTheme();
|
|
94
|
+
let color: SurfaceColor;
|
|
95
|
+
let textColor: TextColor;
|
|
96
|
+
let iconName: IconName;
|
|
97
|
+
|
|
98
|
+
if (secondary) {
|
|
99
|
+
throw new Error("Secondary not supported yet");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (persistent && !onDismiss) {
|
|
103
|
+
console.warn("Toast is persistent but no onDismiss callback provided");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (variant === "warning") {
|
|
107
|
+
color = "warning";
|
|
108
|
+
textColor = "inverted";
|
|
109
|
+
iconName = "triangle-exclamation";
|
|
110
|
+
} else if (variant === "error") {
|
|
111
|
+
color = "error";
|
|
112
|
+
textColor = "inverted";
|
|
113
|
+
iconName = "circle-exclamation";
|
|
114
|
+
} else if (variant === "success") {
|
|
115
|
+
color = "success";
|
|
116
|
+
textColor = "inverted";
|
|
117
|
+
iconName = "circle-check";
|
|
118
|
+
} else {
|
|
119
|
+
color = "neutralDark";
|
|
120
|
+
textColor = "inverted";
|
|
121
|
+
iconName = "circle-info";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<View
|
|
126
|
+
style={{
|
|
127
|
+
display: "flex",
|
|
128
|
+
flexDirection: "row",
|
|
129
|
+
flexGrow: 1,
|
|
130
|
+
justifyContent: "center",
|
|
131
|
+
marginTop: theme.spacing.sm,
|
|
132
|
+
maxWidth: Platform.OS === "web" ? 900 : "100%",
|
|
133
|
+
paddingLeft: Platform.OS === "web" ? "10%" : theme.spacing.sm,
|
|
134
|
+
paddingRight: Platform.OS === "web" ? "10%" : theme.spacing.sm,
|
|
135
|
+
width: "100%",
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<View
|
|
139
|
+
style={{
|
|
140
|
+
alignItems: "center",
|
|
141
|
+
alignSelf: "flex-start",
|
|
142
|
+
backgroundColor: theme.surface[color],
|
|
143
|
+
borderRadius: theme.radius.default,
|
|
144
|
+
display: "flex",
|
|
145
|
+
flexDirection: "row",
|
|
146
|
+
flexShrink: 1,
|
|
147
|
+
gap: 10,
|
|
148
|
+
maxWidth: "100%", // Ensure the content does not overflow
|
|
149
|
+
minHeight: size === "lg" ? 32 : undefined,
|
|
150
|
+
minWidth: 150,
|
|
151
|
+
paddingBottom: theme.spacing.xs,
|
|
152
|
+
paddingRight: theme.spacing.sm,
|
|
153
|
+
paddingTop: theme.spacing.xs,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<View
|
|
157
|
+
style={{
|
|
158
|
+
alignItems: "center",
|
|
159
|
+
display: "flex",
|
|
160
|
+
flexDirection: "row",
|
|
161
|
+
flexGrow: 1,
|
|
162
|
+
flexShrink: 1, // Ensure the content can shrink properly
|
|
163
|
+
gap: 12,
|
|
164
|
+
maxWidth: "100%",
|
|
165
|
+
paddingLeft: 8,
|
|
166
|
+
paddingRight: 8,
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
<View
|
|
170
|
+
style={{
|
|
171
|
+
alignItems: size === "lg" ? "center" : undefined,
|
|
172
|
+
alignSelf: size === "lg" ? "stretch" : undefined,
|
|
173
|
+
borderBottomLeftRadius: theme.radius.default,
|
|
174
|
+
borderTopLeftRadius: theme.radius.default,
|
|
175
|
+
display: "flex",
|
|
176
|
+
flexDirection: "row",
|
|
177
|
+
paddingBottom: size === "lg" ? 8 : 0,
|
|
178
|
+
paddingLeft: size === "lg" ? 4 : 0,
|
|
179
|
+
paddingRight: size === "lg" ? 4 : 0,
|
|
180
|
+
paddingTop: size === "lg" ? 8 : 0,
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
<Icon color={textColor} iconName={iconName} size={size === "lg" ? "2xl" : "md"} />
|
|
184
|
+
</View>
|
|
185
|
+
<View
|
|
186
|
+
style={{
|
|
187
|
+
alignItems: "flex-start",
|
|
188
|
+
alignSelf: "stretch",
|
|
189
|
+
display: "flex",
|
|
190
|
+
flexDirection: "column",
|
|
191
|
+
flexShrink: 1, // Ensure the content can shrink properly
|
|
192
|
+
flexWrap: "wrap",
|
|
193
|
+
gap: 2,
|
|
194
|
+
justifyContent: "center",
|
|
195
|
+
paddingBottom: 8,
|
|
196
|
+
paddingTop: 8,
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
{size === "lg" ? (
|
|
200
|
+
<Heading color={textColor} size="sm">
|
|
201
|
+
{title}
|
|
202
|
+
</Heading>
|
|
203
|
+
) : (
|
|
204
|
+
<Text bold color={textColor} size="md">
|
|
205
|
+
{title}
|
|
206
|
+
</Text>
|
|
207
|
+
)}
|
|
208
|
+
{Boolean(size === "lg" && subtitle) && (
|
|
209
|
+
<Text color={textColor} size="sm">
|
|
210
|
+
{subtitle}
|
|
211
|
+
</Text>
|
|
212
|
+
)}
|
|
213
|
+
</View>
|
|
214
|
+
</View>
|
|
215
|
+
{Boolean(persistent && onDismiss) && (
|
|
216
|
+
<Pressable
|
|
217
|
+
aria-role="button"
|
|
218
|
+
onPress={onDismiss}
|
|
219
|
+
style={{
|
|
220
|
+
alignItems: "center",
|
|
221
|
+
alignSelf: "center",
|
|
222
|
+
display: "flex",
|
|
223
|
+
gap: 12,
|
|
224
|
+
marginLeft: 10,
|
|
225
|
+
padding: size === "lg" ? 8 : 0,
|
|
226
|
+
}}
|
|
227
|
+
>
|
|
228
|
+
<Icon color={textColor} iconName="xmark" />
|
|
229
|
+
</Pressable>
|
|
230
|
+
)}
|
|
231
|
+
</View>
|
|
232
|
+
</View>
|
|
233
|
+
);
|
|
234
|
+
};
|
package/src/Tooltip.tsx
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import {type FC, useCallback, useEffect, useRef, useState} from "react";
|
|
2
|
+
import {
|
|
3
|
+
Dimensions,
|
|
4
|
+
type LayoutChangeEvent,
|
|
5
|
+
type LayoutRectangle,
|
|
6
|
+
Platform,
|
|
7
|
+
Pressable,
|
|
8
|
+
View,
|
|
9
|
+
type ViewStyle,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import {Portal} from "react-native-portalize";
|
|
12
|
+
|
|
13
|
+
import type {TooltipPosition, TooltipProps} from "./Common";
|
|
14
|
+
import {Text} from "./Text";
|
|
15
|
+
import {useTheme} from "./Theme";
|
|
16
|
+
|
|
17
|
+
const TOOLTIP_OFFSET = 6;
|
|
18
|
+
// How many pixels to leave between the tooltip and the edge of the screen
|
|
19
|
+
const TOOLTIP_OVERFLOW_PADDING = 20;
|
|
20
|
+
|
|
21
|
+
interface ChildrenMeasurement {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
pageX: number;
|
|
25
|
+
pageY: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// empty object is a fallback for when the tooltip is not measured yet
|
|
29
|
+
interface Measurement {
|
|
30
|
+
children: ChildrenMeasurement | {};
|
|
31
|
+
tooltip: LayoutRectangle | {};
|
|
32
|
+
measured: boolean;
|
|
33
|
+
idealPosition?: TooltipPosition;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ChildrenProps {
|
|
37
|
+
onClick?: () => void;
|
|
38
|
+
onHoverIn?: () => void;
|
|
39
|
+
onHoverOut?: () => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getTooltipPosition = ({
|
|
43
|
+
children,
|
|
44
|
+
tooltip,
|
|
45
|
+
measured,
|
|
46
|
+
idealPosition,
|
|
47
|
+
}: Measurement): {} | {left: number; top: number; finalPosition: TooltipPosition} => {
|
|
48
|
+
if (!measured) {
|
|
49
|
+
console.debug("No measurements for child yet, cannot show tooltip yet.");
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
pageY: childrenY,
|
|
55
|
+
height: childrenHeight,
|
|
56
|
+
pageX: childrenX,
|
|
57
|
+
width: childrenWidth,
|
|
58
|
+
}: ChildrenMeasurement = children as ChildrenMeasurement;
|
|
59
|
+
const {width: tooltipWidth, height: tooltipHeight} = tooltip as LayoutRectangle;
|
|
60
|
+
|
|
61
|
+
const horizontalCenter = childrenX + childrenWidth / 2;
|
|
62
|
+
const right = childrenX + childrenWidth + TOOLTIP_OFFSET;
|
|
63
|
+
const left = childrenX - tooltipWidth - TOOLTIP_OFFSET;
|
|
64
|
+
const top = childrenY - tooltipHeight - TOOLTIP_OFFSET;
|
|
65
|
+
const bottom = childrenY + childrenHeight + TOOLTIP_OFFSET;
|
|
66
|
+
const verticalCenter = childrenY + childrenHeight / 2 - tooltipHeight / 2;
|
|
67
|
+
|
|
68
|
+
const overflowTop = top < TOOLTIP_OVERFLOW_PADDING;
|
|
69
|
+
const overflowBottom =
|
|
70
|
+
bottom + tooltipHeight + TOOLTIP_OVERFLOW_PADDING > Dimensions.get("window").height;
|
|
71
|
+
const overflowLeft = left < TOOLTIP_OVERFLOW_PADDING;
|
|
72
|
+
const overflowRight =
|
|
73
|
+
right + tooltipWidth > Dimensions.get("window").width - TOOLTIP_OVERFLOW_PADDING;
|
|
74
|
+
let finalPosition: TooltipPosition = idealPosition || "top";
|
|
75
|
+
// Try to place the tooltip in the ideal position if possible
|
|
76
|
+
switch (idealPosition) {
|
|
77
|
+
case "left":
|
|
78
|
+
if (!overflowLeft) {
|
|
79
|
+
return {finalPosition, left, top: verticalCenter};
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case "right":
|
|
83
|
+
if (!overflowRight) {
|
|
84
|
+
return {finalPosition, left: right, top: verticalCenter};
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case "top":
|
|
88
|
+
case undefined:
|
|
89
|
+
if (!overflowTop) {
|
|
90
|
+
return {finalPosition, left: horizontalCenter - tooltipWidth / 2, top};
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case "bottom":
|
|
94
|
+
if (!overflowBottom) {
|
|
95
|
+
return {finalPosition, left: horizontalCenter - tooltipWidth / 2, top: bottom};
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Fallback to an alternate position if the ideal position overflows
|
|
101
|
+
if (!overflowBottom) {
|
|
102
|
+
finalPosition = "bottom";
|
|
103
|
+
return {finalPosition, left: horizontalCenter - tooltipWidth / 2, top: bottom};
|
|
104
|
+
} else if (!overflowTop) {
|
|
105
|
+
finalPosition = "top";
|
|
106
|
+
return {finalPosition, left: horizontalCenter - tooltipWidth / 2, top};
|
|
107
|
+
} else if (!overflowLeft) {
|
|
108
|
+
finalPosition = "left";
|
|
109
|
+
return {finalPosition, left, top: verticalCenter};
|
|
110
|
+
} else {
|
|
111
|
+
finalPosition = "right";
|
|
112
|
+
return {
|
|
113
|
+
finalPosition,
|
|
114
|
+
left: Dimensions.get("window").width - TOOLTIP_OVERFLOW_PADDING - tooltipWidth,
|
|
115
|
+
top: verticalCenter,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const Arrow: FC<{position: TooltipPosition; color: string}> = ({position, color}) => {
|
|
121
|
+
const getArrowStyle = (): ViewStyle => {
|
|
122
|
+
const arrowStyles = {
|
|
123
|
+
bottom: {
|
|
124
|
+
borderBottomWidth: 6,
|
|
125
|
+
borderLeftColor: "transparent",
|
|
126
|
+
borderLeftWidth: 6,
|
|
127
|
+
borderRightColor: "transparent",
|
|
128
|
+
borderRightWidth: 6,
|
|
129
|
+
borderTopColor: color,
|
|
130
|
+
marginTop: 8,
|
|
131
|
+
},
|
|
132
|
+
left: {
|
|
133
|
+
borderBottomColor: "transparent",
|
|
134
|
+
borderBottomWidth: 6,
|
|
135
|
+
borderLeftColor: color,
|
|
136
|
+
borderLeftWidth: 6,
|
|
137
|
+
borderTopColor: "transparent",
|
|
138
|
+
borderTopWidth: 6,
|
|
139
|
+
marginRight: 8,
|
|
140
|
+
},
|
|
141
|
+
right: {
|
|
142
|
+
borderBottomColor: "transparent",
|
|
143
|
+
borderBottomWidth: 6,
|
|
144
|
+
borderRightColor: color,
|
|
145
|
+
borderRightWidth: 6,
|
|
146
|
+
borderTopColor: "transparent",
|
|
147
|
+
borderTopWidth: 6,
|
|
148
|
+
marginLeft: 8,
|
|
149
|
+
},
|
|
150
|
+
top: {
|
|
151
|
+
borderBottomColor: color,
|
|
152
|
+
borderLeftColor: "transparent",
|
|
153
|
+
borderLeftWidth: 6,
|
|
154
|
+
borderRightColor: "transparent",
|
|
155
|
+
borderRightWidth: 6,
|
|
156
|
+
borderTopWidth: 6,
|
|
157
|
+
marginBottom: 8,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
alignSelf: "center",
|
|
162
|
+
borderStyle: "solid",
|
|
163
|
+
height: 0,
|
|
164
|
+
width: 0,
|
|
165
|
+
...arrowStyles[position],
|
|
166
|
+
} as ViewStyle;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const arrowStyle = getArrowStyle();
|
|
170
|
+
return <View style={arrowStyle} />;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const Tooltip: FC<TooltipProps> = ({text, children, idealPosition, includeArrow}) => {
|
|
174
|
+
const {theme} = useTheme();
|
|
175
|
+
const hoverDelay = 800;
|
|
176
|
+
const hoverEndDelay = 0;
|
|
177
|
+
const [visible, setVisible] = useState(false);
|
|
178
|
+
const [finalPosition, setFinalPosition] = useState<TooltipPosition>("top");
|
|
179
|
+
|
|
180
|
+
const [measurement, setMeasurement] = useState<Measurement>({
|
|
181
|
+
children: {},
|
|
182
|
+
measured: false,
|
|
183
|
+
tooltip: {},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const showTooltipTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
187
|
+
const hideTooltipTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
188
|
+
const childrenWrapperRef = useRef<View>(null);
|
|
189
|
+
const touched = useRef(false);
|
|
190
|
+
const isWeb = Platform.OS === "web";
|
|
191
|
+
const resetMeasurement = useCallback(() => {
|
|
192
|
+
setMeasurement({
|
|
193
|
+
children: {},
|
|
194
|
+
measured: false,
|
|
195
|
+
tooltip: {},
|
|
196
|
+
});
|
|
197
|
+
}, []);
|
|
198
|
+
const hideTooltip = useCallback(() => {
|
|
199
|
+
if (showTooltipTimer.current) {
|
|
200
|
+
clearTimeout(showTooltipTimer.current);
|
|
201
|
+
}
|
|
202
|
+
if (hideTooltipTimer.current) {
|
|
203
|
+
clearTimeout(hideTooltipTimer.current);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
touched.current = false;
|
|
207
|
+
setVisible(false);
|
|
208
|
+
resetMeasurement();
|
|
209
|
+
}, [resetMeasurement]);
|
|
210
|
+
|
|
211
|
+
// If the tooltip is visible, and the user clicks outside of the tooltip, hide it.
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
return () => {
|
|
214
|
+
// Hide tooltip on unmount to prevent it from staying stuck on screen
|
|
215
|
+
hideTooltip();
|
|
216
|
+
};
|
|
217
|
+
}, [hideTooltip]);
|
|
218
|
+
|
|
219
|
+
const getArrowContainerStyle = (): ViewStyle => {
|
|
220
|
+
if (!includeArrow) {
|
|
221
|
+
return {};
|
|
222
|
+
}
|
|
223
|
+
const containerStyles = {
|
|
224
|
+
bottom: {
|
|
225
|
+
left: "50%",
|
|
226
|
+
top: -12,
|
|
227
|
+
transform: [{translateX: -6}],
|
|
228
|
+
},
|
|
229
|
+
left: {
|
|
230
|
+
right: -12,
|
|
231
|
+
top: "50%",
|
|
232
|
+
transform: [{translateY: -6}],
|
|
233
|
+
},
|
|
234
|
+
right: {
|
|
235
|
+
left: -12,
|
|
236
|
+
top: "50%",
|
|
237
|
+
transform: [{translateY: -6}],
|
|
238
|
+
},
|
|
239
|
+
top: {
|
|
240
|
+
bottom: -12,
|
|
241
|
+
left: "50%",
|
|
242
|
+
transform: [{translateX: -6}],
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
return {position: "absolute", ...containerStyles[finalPosition]} as ViewStyle;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const arrowContainerStyles = getArrowContainerStyle();
|
|
249
|
+
|
|
250
|
+
const handleOnLayout = useCallback(
|
|
251
|
+
({nativeEvent: {layout}}: LayoutChangeEvent) => {
|
|
252
|
+
if (childrenWrapperRef?.current && !childrenWrapperRef?.current?.measure) {
|
|
253
|
+
console.error("Tooltip: childrenWrapperRef does not have a measure method.");
|
|
254
|
+
return;
|
|
255
|
+
} else if (!childrenWrapperRef?.current) {
|
|
256
|
+
console.error("Tooltip: childrenWrapperRef is null.");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
childrenWrapperRef?.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
260
|
+
setMeasurement({
|
|
261
|
+
children: {height, pageX, pageY, width},
|
|
262
|
+
measured: true,
|
|
263
|
+
tooltip: {...layout},
|
|
264
|
+
});
|
|
265
|
+
const position = getTooltipPosition({
|
|
266
|
+
children: {height, pageX, pageY, width},
|
|
267
|
+
idealPosition,
|
|
268
|
+
measured: true,
|
|
269
|
+
tooltip: {...layout},
|
|
270
|
+
});
|
|
271
|
+
if ("finalPosition" in position) {
|
|
272
|
+
setFinalPosition(position.finalPosition);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
[idealPosition]
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const handleTouchStart = useCallback(() => {
|
|
280
|
+
if (visible) {
|
|
281
|
+
hideTooltip();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (hideTooltipTimer.current) {
|
|
286
|
+
clearTimeout(hideTooltipTimer.current);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
showTooltipTimer.current = setTimeout(() => {
|
|
290
|
+
touched.current = true;
|
|
291
|
+
setVisible(true);
|
|
292
|
+
}, 100);
|
|
293
|
+
}, [hideTooltip, visible]);
|
|
294
|
+
|
|
295
|
+
const handleHoverIn = useCallback(() => {
|
|
296
|
+
if (hideTooltipTimer.current) {
|
|
297
|
+
clearTimeout(hideTooltipTimer.current);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
showTooltipTimer.current = setTimeout(() => {
|
|
301
|
+
touched.current = true;
|
|
302
|
+
setVisible(true);
|
|
303
|
+
}, hoverDelay);
|
|
304
|
+
}, []);
|
|
305
|
+
|
|
306
|
+
const handleHoverOut = useCallback(() => {
|
|
307
|
+
if (showTooltipTimer.current) {
|
|
308
|
+
clearTimeout(showTooltipTimer.current);
|
|
309
|
+
}
|
|
310
|
+
if (hideTooltipTimer.current) {
|
|
311
|
+
clearTimeout(hideTooltipTimer.current);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
hideTooltipTimer.current = setTimeout(() => {
|
|
315
|
+
hideTooltip();
|
|
316
|
+
}, hoverEndDelay);
|
|
317
|
+
}, [hideTooltip]);
|
|
318
|
+
|
|
319
|
+
const handleClick = useCallback(() => {
|
|
320
|
+
if (visible) {
|
|
321
|
+
hideTooltip();
|
|
322
|
+
}
|
|
323
|
+
}, [hideTooltip, visible]);
|
|
324
|
+
|
|
325
|
+
const mobilePressProps = {
|
|
326
|
+
onPress: useCallback(() => {
|
|
327
|
+
if (!touched.current) {
|
|
328
|
+
(children.props as ChildrenProps).onClick?.();
|
|
329
|
+
}
|
|
330
|
+
}, [children.props]),
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// Allow disabling tooltips when there is no string,
|
|
334
|
+
// otherwise you need to wrap the children in a function to determine if there should be a tooltip
|
|
335
|
+
// or not, which gets messy.
|
|
336
|
+
if (!text) {
|
|
337
|
+
return children;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return (
|
|
341
|
+
<View>
|
|
342
|
+
{visible && (
|
|
343
|
+
<Portal>
|
|
344
|
+
<View
|
|
345
|
+
onLayout={handleOnLayout}
|
|
346
|
+
style={{
|
|
347
|
+
position: "absolute",
|
|
348
|
+
zIndex: 999,
|
|
349
|
+
...getTooltipPosition({...(measurement as Measurement), idealPosition}),
|
|
350
|
+
}}
|
|
351
|
+
>
|
|
352
|
+
{includeArrow && isWeb && (
|
|
353
|
+
<View style={arrowContainerStyles as ViewStyle}>
|
|
354
|
+
<Arrow color={theme.surface.secondaryExtraDark} position={finalPosition} />
|
|
355
|
+
</View>
|
|
356
|
+
)}
|
|
357
|
+
<View
|
|
358
|
+
style={{
|
|
359
|
+
backgroundColor: theme.surface.secondaryExtraDark,
|
|
360
|
+
borderRadius: theme.radius.default,
|
|
361
|
+
display: "flex",
|
|
362
|
+
flexShrink: 1,
|
|
363
|
+
maxWidth: 320,
|
|
364
|
+
opacity: measurement.measured ? 1 : 0,
|
|
365
|
+
paddingHorizontal: 8,
|
|
366
|
+
paddingVertical: 2,
|
|
367
|
+
}}
|
|
368
|
+
>
|
|
369
|
+
<Pressable
|
|
370
|
+
accessibilityHint="Tooltip information"
|
|
371
|
+
aria-label={text}
|
|
372
|
+
aria-role="button"
|
|
373
|
+
onPress={hideTooltip}
|
|
374
|
+
style={{
|
|
375
|
+
backgroundColor: theme.surface.secondaryExtraDark,
|
|
376
|
+
borderRadius: theme.radius.default,
|
|
377
|
+
}}
|
|
378
|
+
testID="tooltip-container"
|
|
379
|
+
>
|
|
380
|
+
<Text color="inverted" size="sm">
|
|
381
|
+
{text}
|
|
382
|
+
</Text>
|
|
383
|
+
</Pressable>
|
|
384
|
+
</View>
|
|
385
|
+
</View>
|
|
386
|
+
</Portal>
|
|
387
|
+
)}
|
|
388
|
+
<View
|
|
389
|
+
hitSlop={{bottom: 10, left: 15, right: 15, top: 10}}
|
|
390
|
+
onPointerEnter={() => {
|
|
391
|
+
handleHoverIn();
|
|
392
|
+
(children.props as ChildrenProps).onHoverIn?.();
|
|
393
|
+
}}
|
|
394
|
+
onPointerLeave={() => {
|
|
395
|
+
handleHoverOut();
|
|
396
|
+
(children.props as ChildrenProps).onHoverOut?.();
|
|
397
|
+
}}
|
|
398
|
+
onPress={isWeb ? handleClick : undefined}
|
|
399
|
+
onTouchStart={handleTouchStart}
|
|
400
|
+
ref={childrenWrapperRef}
|
|
401
|
+
{...(!isWeb && mobilePressProps)}
|
|
402
|
+
>
|
|
403
|
+
{children}
|
|
404
|
+
</View>
|
|
405
|
+
</View>
|
|
406
|
+
);
|
|
407
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {useMemo} from "react";
|
|
2
|
+
|
|
3
|
+
import type {AddressAutocompleteProps} from "./Common";
|
|
4
|
+
import {isMobileDevice} from "./MediaQuery";
|
|
5
|
+
import {MobileAddressAutocomplete} from "./MobileAddressAutoComplete";
|
|
6
|
+
import {TextField} from "./TextField";
|
|
7
|
+
import {isNative, isValidGoogleApiKey} from "./Utilities";
|
|
8
|
+
import {WebAddressAutocomplete} from "./WebAddressAutocomplete";
|
|
9
|
+
|
|
10
|
+
export const UnifiedAddressAutoCompleteField = ({
|
|
11
|
+
disabled,
|
|
12
|
+
googleMapsApiKey,
|
|
13
|
+
googlePlacesMobileStyles,
|
|
14
|
+
includeCounty,
|
|
15
|
+
inputValue,
|
|
16
|
+
handleAddressChange,
|
|
17
|
+
handleAutoCompleteChange,
|
|
18
|
+
testID,
|
|
19
|
+
}: AddressAutocompleteProps) => {
|
|
20
|
+
const isWeb = typeof document !== "undefined";
|
|
21
|
+
const isValidatedGoogleApiKey = useMemo(
|
|
22
|
+
() => (googleMapsApiKey ? isValidGoogleApiKey(googleMapsApiKey) : false),
|
|
23
|
+
[googleMapsApiKey]
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (isWeb && isValidatedGoogleApiKey) {
|
|
27
|
+
return (
|
|
28
|
+
<WebAddressAutocomplete
|
|
29
|
+
disabled={disabled}
|
|
30
|
+
googleMapsApiKey={googleMapsApiKey}
|
|
31
|
+
handleAddressChange={handleAddressChange}
|
|
32
|
+
handleAutoCompleteChange={handleAutoCompleteChange}
|
|
33
|
+
includeCounty={includeCounty}
|
|
34
|
+
inputValue={inputValue}
|
|
35
|
+
testID={testID}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
} else if (isMobileDevice() && isNative() && isValidatedGoogleApiKey) {
|
|
39
|
+
return (
|
|
40
|
+
<MobileAddressAutocomplete
|
|
41
|
+
disabled={disabled}
|
|
42
|
+
googleMapsApiKey={googleMapsApiKey}
|
|
43
|
+
handleAddressChange={handleAddressChange}
|
|
44
|
+
handleAutoCompleteChange={handleAutoCompleteChange}
|
|
45
|
+
includeCounty={includeCounty}
|
|
46
|
+
inputValue={inputValue}
|
|
47
|
+
styles={googlePlacesMobileStyles}
|
|
48
|
+
testID={testID}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
} else {
|
|
52
|
+
return (
|
|
53
|
+
<TextField
|
|
54
|
+
disabled={disabled}
|
|
55
|
+
onChange={(value): void => {
|
|
56
|
+
handleAddressChange(value);
|
|
57
|
+
}}
|
|
58
|
+
placeholder="Enter an address"
|
|
59
|
+
testID={testID}
|
|
60
|
+
title="Street Address"
|
|
61
|
+
type="text"
|
|
62
|
+
value={inputValue}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|