@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
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {AsYouType, parsePhoneNumberFromString} from "libphonenumber-js";
|
|
2
|
+
import {type FC, useCallback, useEffect, useState} from "react";
|
|
3
|
+
|
|
4
|
+
import type {PhoneNumberFieldProps} from "./Common";
|
|
5
|
+
import {TextField} from "./TextField";
|
|
6
|
+
|
|
7
|
+
export const PhoneNumberField: FC<PhoneNumberFieldProps> = ({
|
|
8
|
+
errorText,
|
|
9
|
+
iconName,
|
|
10
|
+
placeholder,
|
|
11
|
+
value,
|
|
12
|
+
onChange,
|
|
13
|
+
onBlur,
|
|
14
|
+
defaultCountryCode = "US",
|
|
15
|
+
...rest
|
|
16
|
+
}) => {
|
|
17
|
+
const [localValue, setLocalValue] = useState<string>(value || "");
|
|
18
|
+
const [error, setError] = useState<string | undefined>(errorText);
|
|
19
|
+
|
|
20
|
+
// Sync local state with incoming prop values
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
setLocalValue(value || "");
|
|
23
|
+
setError(errorText);
|
|
24
|
+
}, [value, errorText]);
|
|
25
|
+
|
|
26
|
+
const validatePhoneNumber = useCallback(
|
|
27
|
+
(phoneNumber: string): string | undefined => {
|
|
28
|
+
if (!phoneNumber || phoneNumber.trim() === "") {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const parsedNumber = parsePhoneNumberFromString(phoneNumber, defaultCountryCode);
|
|
32
|
+
if (!parsedNumber) {
|
|
33
|
+
return "Invalid phone number format";
|
|
34
|
+
}
|
|
35
|
+
if (!parsedNumber.isPossible()) {
|
|
36
|
+
return "Phone number is not possible";
|
|
37
|
+
}
|
|
38
|
+
if (!parsedNumber.isValid()) {
|
|
39
|
+
return "Phone number is not valid";
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
},
|
|
43
|
+
[defaultCountryCode]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const formatPhoneNumber = useCallback(
|
|
47
|
+
(phoneNumber: string): string => {
|
|
48
|
+
const asYouType = new AsYouType(defaultCountryCode);
|
|
49
|
+
return asYouType.input(phoneNumber);
|
|
50
|
+
},
|
|
51
|
+
[defaultCountryCode]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const handleBlur = useCallback(
|
|
55
|
+
(inputValue: string) => {
|
|
56
|
+
if (onBlur) {
|
|
57
|
+
onBlur(inputValue);
|
|
58
|
+
}
|
|
59
|
+
const validationError = validatePhoneNumber(inputValue);
|
|
60
|
+
if (validationError) {
|
|
61
|
+
setError(validationError);
|
|
62
|
+
} else {
|
|
63
|
+
setError(undefined);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
[onBlur, validatePhoneNumber]
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const handleChange = useCallback(
|
|
70
|
+
(inputValue: string) => {
|
|
71
|
+
const formattedValue = formatPhoneNumber(inputValue);
|
|
72
|
+
// By default, if a value is something like `"(123)"`
|
|
73
|
+
// then Backspace would only erase the rightmost brace
|
|
74
|
+
// becoming something like `"(123"`
|
|
75
|
+
// which would give the same `"123"` value
|
|
76
|
+
// which would then be formatted back to `"(123)"`
|
|
77
|
+
// and so a user wouldn't be able to erase the phone number.
|
|
78
|
+
// This is the workaround for that.
|
|
79
|
+
if (inputValue !== formattedValue && inputValue.length !== 4) {
|
|
80
|
+
setLocalValue(formattedValue);
|
|
81
|
+
} else {
|
|
82
|
+
setLocalValue(inputValue);
|
|
83
|
+
}
|
|
84
|
+
const validationError = validatePhoneNumber(formattedValue);
|
|
85
|
+
if (error && !validationError) {
|
|
86
|
+
setError(undefined);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Ensure invalid values don't propagate up
|
|
90
|
+
if (!validationError) {
|
|
91
|
+
onChange(formattedValue);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[onChange, error, validatePhoneNumber, formatPhoneNumber]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<TextField
|
|
99
|
+
errorText={error}
|
|
100
|
+
iconName={iconName}
|
|
101
|
+
onBlur={(inputValue) => handleBlur(inputValue)}
|
|
102
|
+
onChange={(inputValue) => handleChange(inputValue)}
|
|
103
|
+
placeholder={placeholder}
|
|
104
|
+
type="phoneNumber"
|
|
105
|
+
value={localValue}
|
|
106
|
+
{...rest}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
|
|
3
|
+
// Copyright (c) LawnStarter
|
|
4
|
+
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
|
|
23
|
+
// Forked 2021/11/26 by Josh Gachnang <josh@nang.io> from version 8.0.3 because it conflicted
|
|
24
|
+
// with react-native-picker in Expo, then converted to TS.
|
|
25
|
+
|
|
26
|
+
import {Picker} from "@react-native-picker/picker";
|
|
27
|
+
import isEqual from "lodash/isEqual";
|
|
28
|
+
import {useCallback, useEffect, useMemo, useState} from "react";
|
|
29
|
+
import {
|
|
30
|
+
Keyboard,
|
|
31
|
+
Modal,
|
|
32
|
+
Platform,
|
|
33
|
+
Pressable,
|
|
34
|
+
StyleSheet,
|
|
35
|
+
Text,
|
|
36
|
+
TextInput,
|
|
37
|
+
TouchableOpacity,
|
|
38
|
+
View,
|
|
39
|
+
} from "react-native";
|
|
40
|
+
|
|
41
|
+
import {Icon} from "./Icon";
|
|
42
|
+
import {useTheme} from "./Theme";
|
|
43
|
+
|
|
44
|
+
export const defaultStyles = StyleSheet.create({
|
|
45
|
+
chevron: {
|
|
46
|
+
backgroundColor: "transparent",
|
|
47
|
+
borderColor: "#a1a1a1",
|
|
48
|
+
borderRightWidth: 1.5,
|
|
49
|
+
borderTopWidth: 1.5,
|
|
50
|
+
height: 15,
|
|
51
|
+
width: 15,
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
chevronActive: {
|
|
55
|
+
borderColor: "#007aff",
|
|
56
|
+
},
|
|
57
|
+
viewContainer: {
|
|
58
|
+
alignItems: "center",
|
|
59
|
+
alignSelf: "stretch",
|
|
60
|
+
borderRadius: 4,
|
|
61
|
+
borderWidth: 1,
|
|
62
|
+
flexDirection: "row",
|
|
63
|
+
justifyContent: "center",
|
|
64
|
+
minHeight: 40,
|
|
65
|
+
width: "100%",
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export interface RNPickerSelectProps {
|
|
70
|
+
onValueChange: (value: any, index: any) => void;
|
|
71
|
+
items: any[];
|
|
72
|
+
value?: any;
|
|
73
|
+
placeholder?: any;
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
itemKey?: string | number;
|
|
76
|
+
children?: any;
|
|
77
|
+
onOpen?: () => void;
|
|
78
|
+
useNativeAndroidPickerStyle?: boolean;
|
|
79
|
+
fixAndroidTouchableBug?: boolean;
|
|
80
|
+
|
|
81
|
+
// Custom Modal props (iOS only)
|
|
82
|
+
doneText?: string;
|
|
83
|
+
onDonePress?: () => void;
|
|
84
|
+
onUpArrow?: () => void;
|
|
85
|
+
onDownArrow?: () => void;
|
|
86
|
+
onClose?: () => void;
|
|
87
|
+
|
|
88
|
+
// Modal props (iOS only)
|
|
89
|
+
modalProps?: any;
|
|
90
|
+
|
|
91
|
+
// TextInput props
|
|
92
|
+
textInputProps?: any;
|
|
93
|
+
|
|
94
|
+
// Touchable Done props (iOS only)
|
|
95
|
+
touchableDoneProps?: any;
|
|
96
|
+
|
|
97
|
+
// Touchable wrapper props
|
|
98
|
+
touchableWrapperProps?: any;
|
|
99
|
+
|
|
100
|
+
InputAccessoryView?: any;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function RNPickerSelect({
|
|
104
|
+
onValueChange,
|
|
105
|
+
value,
|
|
106
|
+
items,
|
|
107
|
+
placeholder,
|
|
108
|
+
disabled = false,
|
|
109
|
+
itemKey,
|
|
110
|
+
children,
|
|
111
|
+
useNativeAndroidPickerStyle = true,
|
|
112
|
+
fixAndroidTouchableBug = false,
|
|
113
|
+
doneText = "Done",
|
|
114
|
+
onDonePress,
|
|
115
|
+
onUpArrow,
|
|
116
|
+
onDownArrow,
|
|
117
|
+
onOpen,
|
|
118
|
+
onClose,
|
|
119
|
+
modalProps,
|
|
120
|
+
textInputProps,
|
|
121
|
+
touchableDoneProps,
|
|
122
|
+
touchableWrapperProps,
|
|
123
|
+
|
|
124
|
+
InputAccessoryView,
|
|
125
|
+
}: RNPickerSelectProps) {
|
|
126
|
+
const [selectedItem, setSelectedItem] = useState<any>();
|
|
127
|
+
const [showPicker, setShowPicker] = useState<boolean>(false);
|
|
128
|
+
const [animationType, setAnimationType] = useState(undefined);
|
|
129
|
+
const [orientation, setOrientation] = useState<"portrait" | "landscape">("portrait");
|
|
130
|
+
const [doneDepressed, setDoneDepressed] = useState<boolean>(false);
|
|
131
|
+
const {theme} = useTheme();
|
|
132
|
+
|
|
133
|
+
const options = useMemo(() => {
|
|
134
|
+
if (isEqual(placeholder, {})) {
|
|
135
|
+
return [...items];
|
|
136
|
+
} else {
|
|
137
|
+
return [placeholder, ...items];
|
|
138
|
+
}
|
|
139
|
+
}, [items, placeholder]);
|
|
140
|
+
|
|
141
|
+
const getSelectedItem = useCallback(
|
|
142
|
+
(key: any, val: any) => {
|
|
143
|
+
let idx = options.findIndex((item: any) => {
|
|
144
|
+
if (item.key && key) {
|
|
145
|
+
return isEqual(item.key, key);
|
|
146
|
+
}
|
|
147
|
+
return isEqual(item.value, val);
|
|
148
|
+
});
|
|
149
|
+
if (idx === -1) {
|
|
150
|
+
idx = 0;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
idx,
|
|
154
|
+
selectedItem: options[idx] || {},
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
[options]
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Set selected item
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
const item = getSelectedItem(itemKey, value);
|
|
163
|
+
setSelectedItem(item.selectedItem);
|
|
164
|
+
}, [getSelectedItem, itemKey, value]);
|
|
165
|
+
|
|
166
|
+
const onUpArrowEvent = () => {
|
|
167
|
+
togglePicker(false, onUpArrow);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const onDownArrowEvent = () => {
|
|
171
|
+
togglePicker(false, onDownArrow);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const onValueChangeEvent = (val: any, index: any) => {
|
|
175
|
+
const item = getSelectedItem(itemKey, val);
|
|
176
|
+
onValueChange(val, index);
|
|
177
|
+
setSelectedItem(item.selectedItem);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const onOrientationChange = ({nativeEvent}: any) => {
|
|
181
|
+
setOrientation(nativeEvent.orientation);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const triggerOpenCloseCallbacks = () => {
|
|
185
|
+
if (!showPicker && onOpen) {
|
|
186
|
+
onOpen();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (showPicker && onClose) {
|
|
190
|
+
onClose();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const togglePicker = (animate = false, postToggleCallback?: any) => {
|
|
195
|
+
if (disabled) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!showPicker) {
|
|
200
|
+
Keyboard.dismiss();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
setAnimationType(modalProps?.animationType ? modalProps?.animationType : "slide");
|
|
204
|
+
|
|
205
|
+
triggerOpenCloseCallbacks();
|
|
206
|
+
|
|
207
|
+
setAnimationType(animate ? animationType : undefined);
|
|
208
|
+
setShowPicker(!showPicker);
|
|
209
|
+
|
|
210
|
+
if (postToggleCallback) {
|
|
211
|
+
postToggleCallback();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const renderPickerItems = () => {
|
|
216
|
+
return options?.map((item: any) => {
|
|
217
|
+
return (
|
|
218
|
+
<Picker.Item
|
|
219
|
+
color={item.color}
|
|
220
|
+
key={item.key || item.label}
|
|
221
|
+
label={item.label}
|
|
222
|
+
value={item.value}
|
|
223
|
+
/>
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const renderInputAccessoryView = () => {
|
|
229
|
+
if (InputAccessoryView) {
|
|
230
|
+
return <InputAccessoryView testID="custom_input_accessory_view" />;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<View
|
|
235
|
+
style={{
|
|
236
|
+
alignItems: "center",
|
|
237
|
+
backgroundColor: "#f8f8f8",
|
|
238
|
+
borderTopColor: "#dedede",
|
|
239
|
+
borderTopWidth: 1,
|
|
240
|
+
flexDirection: "row",
|
|
241
|
+
height: 45,
|
|
242
|
+
justifyContent: "space-between",
|
|
243
|
+
paddingHorizontal: 10,
|
|
244
|
+
zIndex: 2,
|
|
245
|
+
}}
|
|
246
|
+
testID="input_accessory_view"
|
|
247
|
+
>
|
|
248
|
+
<View
|
|
249
|
+
style={{
|
|
250
|
+
flexDirection: "row",
|
|
251
|
+
}}
|
|
252
|
+
>
|
|
253
|
+
{Boolean(onUpArrow) && (
|
|
254
|
+
<TouchableOpacity
|
|
255
|
+
activeOpacity={onUpArrow ? 0.5 : 1}
|
|
256
|
+
aria-role="button"
|
|
257
|
+
onPress={onUpArrow ? onUpArrowEvent : undefined}
|
|
258
|
+
>
|
|
259
|
+
<View
|
|
260
|
+
// chevron up
|
|
261
|
+
style={[
|
|
262
|
+
defaultStyles.chevron,
|
|
263
|
+
{
|
|
264
|
+
marginLeft: 11,
|
|
265
|
+
transform: [{translateY: 4}, {rotate: "-45deg"}],
|
|
266
|
+
},
|
|
267
|
+
onUpArrow ? [defaultStyles.chevronActive] : {},
|
|
268
|
+
]}
|
|
269
|
+
/>
|
|
270
|
+
</TouchableOpacity>
|
|
271
|
+
)}
|
|
272
|
+
{Boolean(onDownArrow) && (
|
|
273
|
+
<TouchableOpacity
|
|
274
|
+
activeOpacity={onDownArrow ? 0.5 : 1}
|
|
275
|
+
aria-role="button"
|
|
276
|
+
onPress={onDownArrow ? onDownArrowEvent : undefined}
|
|
277
|
+
>
|
|
278
|
+
<View
|
|
279
|
+
// chevron down
|
|
280
|
+
style={[
|
|
281
|
+
defaultStyles.chevron,
|
|
282
|
+
{
|
|
283
|
+
marginLeft: 22,
|
|
284
|
+
transform: [{translateY: -5}, {rotate: "135deg"}],
|
|
285
|
+
},
|
|
286
|
+
onDownArrow ? [defaultStyles.chevronActive] : {},
|
|
287
|
+
]}
|
|
288
|
+
/>
|
|
289
|
+
</TouchableOpacity>
|
|
290
|
+
)}
|
|
291
|
+
</View>
|
|
292
|
+
<Pressable
|
|
293
|
+
hitSlop={{bottom: 4, left: 4, right: 4, top: 4}}
|
|
294
|
+
onPress={() => {
|
|
295
|
+
togglePicker(true, onDonePress);
|
|
296
|
+
}}
|
|
297
|
+
onPressIn={() => {
|
|
298
|
+
setDoneDepressed(true);
|
|
299
|
+
}}
|
|
300
|
+
onPressOut={() => {
|
|
301
|
+
setDoneDepressed(false);
|
|
302
|
+
}}
|
|
303
|
+
testID="done_button"
|
|
304
|
+
{...touchableDoneProps}
|
|
305
|
+
>
|
|
306
|
+
<View testID="needed_for_touchable">
|
|
307
|
+
<Text
|
|
308
|
+
allowFontScaling={false}
|
|
309
|
+
style={[
|
|
310
|
+
{
|
|
311
|
+
color: "#007aff",
|
|
312
|
+
fontSize: 17,
|
|
313
|
+
fontWeight: "600",
|
|
314
|
+
paddingRight: 11,
|
|
315
|
+
paddingTop: 1,
|
|
316
|
+
},
|
|
317
|
+
doneDepressed
|
|
318
|
+
? {
|
|
319
|
+
fontSize: 19,
|
|
320
|
+
}
|
|
321
|
+
: {},
|
|
322
|
+
]}
|
|
323
|
+
testID="done_text"
|
|
324
|
+
>
|
|
325
|
+
{doneText}
|
|
326
|
+
</Text>
|
|
327
|
+
</View>
|
|
328
|
+
</Pressable>
|
|
329
|
+
</View>
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const renderIcon = () => {
|
|
334
|
+
// Icon only needed for iOS, web and android use default icons
|
|
335
|
+
if (Platform.OS !== "ios") {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return (
|
|
340
|
+
<View style={{pointerEvents: "none"}} testID="icon_container">
|
|
341
|
+
<Icon color={disabled ? "secondaryLight" : "primary"} iconName="angle-down" size="sm" />
|
|
342
|
+
</View>
|
|
343
|
+
);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const renderTextInputOrChildren = () => {
|
|
347
|
+
if (children) {
|
|
348
|
+
return <View style={{pointerEvents: "box-only"}}>{children}</View>;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return (
|
|
352
|
+
<View
|
|
353
|
+
style={{
|
|
354
|
+
flexDirection: "row",
|
|
355
|
+
justifyContent: "space-between",
|
|
356
|
+
pointerEvents: "box-only",
|
|
357
|
+
width: "100%",
|
|
358
|
+
}}
|
|
359
|
+
>
|
|
360
|
+
<TextInput
|
|
361
|
+
readOnly
|
|
362
|
+
style={{color: disabled ? theme.text.secondaryLight : theme.text.primary}}
|
|
363
|
+
testID="text_input"
|
|
364
|
+
value={selectedItem?.inputLabel ? selectedItem?.inputLabel : selectedItem?.label}
|
|
365
|
+
{...textInputProps}
|
|
366
|
+
/>
|
|
367
|
+
{renderIcon()}
|
|
368
|
+
</View>
|
|
369
|
+
);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const renderIOS = () => {
|
|
373
|
+
return (
|
|
374
|
+
<View
|
|
375
|
+
style={[
|
|
376
|
+
defaultStyles.viewContainer,
|
|
377
|
+
{
|
|
378
|
+
backgroundColor: theme.surface.base,
|
|
379
|
+
borderColor: theme.border.dark,
|
|
380
|
+
},
|
|
381
|
+
disabled && {
|
|
382
|
+
backgroundColor: theme.surface.neutralLight,
|
|
383
|
+
},
|
|
384
|
+
]}
|
|
385
|
+
>
|
|
386
|
+
<Pressable
|
|
387
|
+
activeOpacity={1}
|
|
388
|
+
onPress={() => {
|
|
389
|
+
togglePicker(true);
|
|
390
|
+
}}
|
|
391
|
+
style={{
|
|
392
|
+
alignItems: "center",
|
|
393
|
+
flexDirection: "row",
|
|
394
|
+
justifyContent: "center",
|
|
395
|
+
minHeight: 40,
|
|
396
|
+
width: "95%",
|
|
397
|
+
}}
|
|
398
|
+
testID="ios_touchable_wrapper"
|
|
399
|
+
{...touchableWrapperProps}
|
|
400
|
+
>
|
|
401
|
+
{renderTextInputOrChildren()}
|
|
402
|
+
</Pressable>
|
|
403
|
+
<Modal
|
|
404
|
+
animationType={animationType}
|
|
405
|
+
onOrientationChange={onOrientationChange}
|
|
406
|
+
supportedOrientations={["portrait", "landscape"]}
|
|
407
|
+
testID="ios_modal"
|
|
408
|
+
transparent
|
|
409
|
+
visible={showPicker}
|
|
410
|
+
{...modalProps}
|
|
411
|
+
>
|
|
412
|
+
<Pressable
|
|
413
|
+
aria-role="button"
|
|
414
|
+
onPress={() => {
|
|
415
|
+
togglePicker(true);
|
|
416
|
+
}}
|
|
417
|
+
style={{
|
|
418
|
+
flex: 1,
|
|
419
|
+
}}
|
|
420
|
+
testID="ios_modal_top"
|
|
421
|
+
/>
|
|
422
|
+
{renderInputAccessoryView()}
|
|
423
|
+
<View
|
|
424
|
+
style={[
|
|
425
|
+
{
|
|
426
|
+
backgroundColor: "#d0d4da",
|
|
427
|
+
justifyContent: "center",
|
|
428
|
+
},
|
|
429
|
+
{height: orientation === "portrait" ? 215 : 162},
|
|
430
|
+
]}
|
|
431
|
+
>
|
|
432
|
+
<Picker
|
|
433
|
+
onValueChange={onValueChangeEvent}
|
|
434
|
+
selectedValue={selectedItem?.value}
|
|
435
|
+
testID="ios_picker"
|
|
436
|
+
>
|
|
437
|
+
{renderPickerItems()}
|
|
438
|
+
</Picker>
|
|
439
|
+
</View>
|
|
440
|
+
</Modal>
|
|
441
|
+
</View>
|
|
442
|
+
);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const renderAndroidHeadless = () => {
|
|
446
|
+
const Component: any = fixAndroidTouchableBug ? View : Pressable;
|
|
447
|
+
return (
|
|
448
|
+
<Component
|
|
449
|
+
activeOpacity={1}
|
|
450
|
+
onPress={onOpen}
|
|
451
|
+
testID="android_touchable_wrapper"
|
|
452
|
+
{...touchableWrapperProps}
|
|
453
|
+
>
|
|
454
|
+
<View>
|
|
455
|
+
{renderTextInputOrChildren()}
|
|
456
|
+
<Picker
|
|
457
|
+
enabled={!disabled}
|
|
458
|
+
onValueChange={onValueChangeEvent}
|
|
459
|
+
selectedValue={selectedItem?.value}
|
|
460
|
+
style={[
|
|
461
|
+
Platform.OS !== "web" ? {backgroundColor: "transparent"} : {}, // to hide native icon
|
|
462
|
+
{
|
|
463
|
+
color: "transparent",
|
|
464
|
+
height: "100%",
|
|
465
|
+
opacity: 0,
|
|
466
|
+
position: "absolute",
|
|
467
|
+
width: "100%",
|
|
468
|
+
},
|
|
469
|
+
]}
|
|
470
|
+
testID="android_picker_headless"
|
|
471
|
+
>
|
|
472
|
+
{renderPickerItems()}
|
|
473
|
+
</Picker>
|
|
474
|
+
</View>
|
|
475
|
+
</Component>
|
|
476
|
+
);
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const renderAndroidNativePickerStyle = () => {
|
|
480
|
+
return (
|
|
481
|
+
<View
|
|
482
|
+
style={[
|
|
483
|
+
defaultStyles.viewContainer,
|
|
484
|
+
{
|
|
485
|
+
backgroundColor: theme.surface.base,
|
|
486
|
+
borderColor: theme.border.dark,
|
|
487
|
+
height: 40,
|
|
488
|
+
},
|
|
489
|
+
disabled && {
|
|
490
|
+
backgroundColor: theme.surface.neutralLight,
|
|
491
|
+
},
|
|
492
|
+
]}
|
|
493
|
+
>
|
|
494
|
+
<Picker
|
|
495
|
+
enabled={!disabled}
|
|
496
|
+
onValueChange={onValueChangeEvent}
|
|
497
|
+
selectedValue={selectedItem?.value}
|
|
498
|
+
style={[
|
|
499
|
+
Platform.OS !== "web" ? {backgroundColor: "transparent"} : {}, // to hide native icon
|
|
500
|
+
{color: theme.text.primary, width: "100%"},
|
|
501
|
+
]}
|
|
502
|
+
testID="android_picker"
|
|
503
|
+
>
|
|
504
|
+
{renderPickerItems()}
|
|
505
|
+
</Picker>
|
|
506
|
+
</View>
|
|
507
|
+
);
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// TODO: Create custom React component for web in order to apply library style rules
|
|
511
|
+
const renderWeb = () => {
|
|
512
|
+
return (
|
|
513
|
+
<View
|
|
514
|
+
style={[
|
|
515
|
+
defaultStyles.viewContainer,
|
|
516
|
+
{
|
|
517
|
+
backgroundColor: theme.surface.base,
|
|
518
|
+
borderColor: theme.border.dark,
|
|
519
|
+
},
|
|
520
|
+
disabled && {
|
|
521
|
+
backgroundColor: theme.surface.neutralLight,
|
|
522
|
+
},
|
|
523
|
+
]}
|
|
524
|
+
>
|
|
525
|
+
<Picker
|
|
526
|
+
enabled={!disabled}
|
|
527
|
+
onValueChange={onValueChangeEvent}
|
|
528
|
+
selectedValue={selectedItem?.value}
|
|
529
|
+
style={[
|
|
530
|
+
{
|
|
531
|
+
backgroundColor: theme.surface.base,
|
|
532
|
+
borderColor: "black",
|
|
533
|
+
borderRadius: 4,
|
|
534
|
+
borderWidth: 0,
|
|
535
|
+
height: "100%",
|
|
536
|
+
paddingHorizontal: 8,
|
|
537
|
+
paddingVertical: 8,
|
|
538
|
+
width: "100%",
|
|
539
|
+
},
|
|
540
|
+
disabled && {
|
|
541
|
+
backgroundColor: theme.surface.neutralLight,
|
|
542
|
+
color: theme.text.secondaryLight,
|
|
543
|
+
opacity: 1,
|
|
544
|
+
},
|
|
545
|
+
]}
|
|
546
|
+
testID="web_picker"
|
|
547
|
+
>
|
|
548
|
+
{renderPickerItems()}
|
|
549
|
+
</Picker>
|
|
550
|
+
</View>
|
|
551
|
+
);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
const render = () => {
|
|
555
|
+
if (Platform.OS === "ios") {
|
|
556
|
+
return renderIOS();
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (Platform.OS === "web") {
|
|
560
|
+
return renderWeb();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (children || !useNativeAndroidPickerStyle) {
|
|
564
|
+
return renderAndroidHeadless();
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return renderAndroidNativePickerStyle();
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
return render();
|
|
571
|
+
}
|
package/src/Radio.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import {View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import type {RadioProps} from "./Common";
|
|
5
|
+
import {useTheme} from "./Theme";
|
|
6
|
+
|
|
7
|
+
export const Radio = ({selected}: RadioProps): React.ReactElement => {
|
|
8
|
+
const {theme} = useTheme();
|
|
9
|
+
return (
|
|
10
|
+
<View
|
|
11
|
+
style={{
|
|
12
|
+
alignItems: "center",
|
|
13
|
+
borderColor: theme.text.secondaryDark,
|
|
14
|
+
borderRadius: 12,
|
|
15
|
+
borderWidth: 1,
|
|
16
|
+
height: 16,
|
|
17
|
+
justifyContent: "center",
|
|
18
|
+
width: 16,
|
|
19
|
+
}}
|
|
20
|
+
>
|
|
21
|
+
{selected ? (
|
|
22
|
+
<View
|
|
23
|
+
style={{
|
|
24
|
+
backgroundColor: theme.text.secondaryDark,
|
|
25
|
+
borderRadius: 6,
|
|
26
|
+
height: 10,
|
|
27
|
+
width: 10,
|
|
28
|
+
}}
|
|
29
|
+
/>
|
|
30
|
+
) : null}
|
|
31
|
+
</View>
|
|
32
|
+
);
|
|
33
|
+
};
|