react-native-international-phone-number 0.10.1 → 0.10.3
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/README.md +4 -0
- package/lib/index.js +64 -18
- package/lib/interfaces/phoneInputProps.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -468,6 +468,8 @@ export default function App() {
|
|
|
468
468
|
| `backdrop` | ViewStyle | Modal background overlay |
|
|
469
469
|
| `container` | ViewStyle | Modal main container |
|
|
470
470
|
| `content` | ViewStyle | Modal content area |
|
|
471
|
+
| `dragHandleContainer` | ViewStyle | Drag Handle area |
|
|
472
|
+
| `dragHandleIndicator` | ViewStyle | Drag Handle Indicator |
|
|
471
473
|
| `searchContainer` | ViewStyle | Search input wrapper |
|
|
472
474
|
| `searchInput` | TextStyle | Search input field |
|
|
473
475
|
| `list` | ViewStyle | Countries list container |
|
|
@@ -503,6 +505,7 @@ export default function App() {
|
|
|
503
505
|
| `modalStyles` | `ICountrySelectStyles` | Custom styles for country selection modal |
|
|
504
506
|
| `disabled` | `boolean` | Disable the entire phone input |
|
|
505
507
|
| `modalDisabled` | `boolean` | Disable only the country selection modal |
|
|
508
|
+
| `customMask` | `string` | Custom phone number mask (format like this: `(###) ###-####`) |
|
|
506
509
|
| `visibleCountries` | `ICountryCca2[]` | Array of country codes to show in modal |
|
|
507
510
|
| `hiddenCountries` | `ICountryCca2[]` | Array of country codes to hide from modal |
|
|
508
511
|
| `popularCountries` | `ICountryCca2[]` | Array of country codes to show in popular section |
|
|
@@ -510,6 +513,7 @@ export default function App() {
|
|
|
510
513
|
| `rtl` | `boolean` | Enable right-to-left layout |
|
|
511
514
|
| `isFullScreen` | `boolean` | Show modal in full screen mode |
|
|
512
515
|
| `modalType` | `'bottomSheet' \| 'popup'` | Type of modal presentation |
|
|
516
|
+
| `modalDragHandleIndicatorComponent` | `() => ReactNode` | Custom drag handle indicator component |
|
|
513
517
|
| `modalSearchInputPlaceholderTextColor` | `string` | Color of modal search placeholder text |
|
|
514
518
|
| `modalSearchInputPlaceholder` | `string` | Placeholder text for modal search input |
|
|
515
519
|
| `modalSearchInputSelectionColor` | `string` | Color of modal search text selection |
|
package/lib/index.js
CHANGED
|
@@ -43,6 +43,7 @@ const PhoneInput = forwardRef(
|
|
|
43
43
|
onChangePhoneNumber,
|
|
44
44
|
selectedCountry,
|
|
45
45
|
onChangeSelectedCountry,
|
|
46
|
+
customMask,
|
|
46
47
|
visibleCountries,
|
|
47
48
|
hiddenCountries,
|
|
48
49
|
popularCountries,
|
|
@@ -50,6 +51,7 @@ const PhoneInput = forwardRef(
|
|
|
50
51
|
rtl,
|
|
51
52
|
isFullScreen = false,
|
|
52
53
|
modalType = Platform.OS === 'web' ? 'popup' : 'bottomSheet',
|
|
54
|
+
modalDragHandleIndicatorComponent,
|
|
53
55
|
modalSearchInputPlaceholderTextColor,
|
|
54
56
|
modalSearchInputPlaceholder,
|
|
55
57
|
modalSearchInputSelectionColor,
|
|
@@ -106,6 +108,7 @@ const PhoneInput = forwardRef(
|
|
|
106
108
|
onChangePhoneNumber,
|
|
107
109
|
selectedCountry,
|
|
108
110
|
onChangeSelectedCountry,
|
|
111
|
+
customMask,
|
|
109
112
|
visibleCountries,
|
|
110
113
|
hiddenCountries,
|
|
111
114
|
popularCountries,
|
|
@@ -175,29 +178,35 @@ const PhoneInput = forwardRef(
|
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|
|
178
|
-
function
|
|
179
|
-
if (phoneNumber
|
|
180
|
-
|
|
181
|
+
function formatPhoneNumberWithCustomMask(phoneNumber) {
|
|
182
|
+
if (!customMask || !phoneNumber) {
|
|
183
|
+
return phoneNumber;
|
|
184
|
+
}
|
|
181
185
|
|
|
182
|
-
|
|
183
|
-
setDefaultCca2(matchingCountry.cca2);
|
|
186
|
+
const numbers = phoneNumber.replace(/\D/g, '');
|
|
184
187
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
updateRef('', matchingCountry);
|
|
188
|
-
} else {
|
|
189
|
-
onChangeSelectedCountry(matchingCountry);
|
|
190
|
-
}
|
|
188
|
+
let result = '';
|
|
189
|
+
let numberIndex = 0;
|
|
191
190
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
for (
|
|
192
|
+
let i = 0;
|
|
193
|
+
i < customMask.length && numberIndex < numbers.length;
|
|
194
|
+
i++
|
|
195
|
+
) {
|
|
196
|
+
if (customMask[i] === '#') {
|
|
197
|
+
result += numbers[numberIndex];
|
|
198
|
+
numberIndex++;
|
|
199
|
+
} else {
|
|
200
|
+
result += customMask[i];
|
|
196
201
|
}
|
|
197
|
-
|
|
198
|
-
return;
|
|
199
202
|
}
|
|
200
203
|
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function formatPhoneNumber(phoneNumber, callingCode) {
|
|
208
|
+
let formattedNumber = '';
|
|
209
|
+
|
|
201
210
|
const metadata = new Metadata();
|
|
202
211
|
metadata.selectNumberingPlan(selectedCountry.cca2);
|
|
203
212
|
const possibleLengths = metadata.possibleLengths();
|
|
@@ -210,7 +219,7 @@ const PhoneInput = forwardRef(
|
|
|
210
219
|
`${validCallingCode}${phoneNumber}`,
|
|
211
220
|
);
|
|
212
221
|
|
|
213
|
-
|
|
222
|
+
formattedNumber = res;
|
|
214
223
|
|
|
215
224
|
if (res.startsWith(0)) {
|
|
216
225
|
formattedNumber = parsePhoneNumber(res)?.formatNational();
|
|
@@ -225,9 +234,43 @@ const PhoneInput = forwardRef(
|
|
|
225
234
|
: possibleLengths.slice(-1)[0];
|
|
226
235
|
|
|
227
236
|
if (formattedNumber?.replace(/\D/g, '')?.length > possibleLength) {
|
|
237
|
+
return phoneNumber.slice(0, -1);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return formattedNumber;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function onChangeText(phoneNumber, callingCode) {
|
|
244
|
+
if (phoneNumber.includes('+')) {
|
|
245
|
+
const matchingCountry = getCountryByPhoneNumber(phoneNumber);
|
|
246
|
+
|
|
247
|
+
if (matchingCountry) {
|
|
248
|
+
setDefaultCca2(matchingCountry.cca2);
|
|
249
|
+
|
|
250
|
+
if (ref) {
|
|
251
|
+
setCountryValue(matchingCountry);
|
|
252
|
+
updateRef('', matchingCountry);
|
|
253
|
+
} else {
|
|
254
|
+
onChangeSelectedCountry(matchingCountry);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
onChangeText(
|
|
258
|
+
phoneNumber.replace(matchingCountry?.idd?.root, ''),
|
|
259
|
+
null,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
228
263
|
return;
|
|
229
264
|
}
|
|
230
265
|
|
|
266
|
+
let formattedNumber = '';
|
|
267
|
+
|
|
268
|
+
if (customMask) {
|
|
269
|
+
formattedNumber = formatPhoneNumberWithCustomMask(phoneNumber);
|
|
270
|
+
} else {
|
|
271
|
+
formattedNumber = formatPhoneNumber(phoneNumber, callingCode);
|
|
272
|
+
}
|
|
273
|
+
|
|
231
274
|
if (ref) {
|
|
232
275
|
setInputValue(formattedNumber);
|
|
233
276
|
updateRef(formattedNumber, countryValue);
|
|
@@ -464,6 +507,9 @@ const PhoneInput = forwardRef(
|
|
|
464
507
|
: modalSectionTitleComponent
|
|
465
508
|
}
|
|
466
509
|
countryItemComponent={modalCountryItemComponent}
|
|
510
|
+
modalDragHandleIndicatorComponent={
|
|
511
|
+
modalDragHandleIndicatorComponent
|
|
512
|
+
}
|
|
467
513
|
showCloseButton={showModalCloseButton}
|
|
468
514
|
closeButtonComponent={modalCloseButtonComponent}
|
|
469
515
|
disabledBackdropPress={disabledModalBackdropPress}
|
|
@@ -23,6 +23,7 @@ interface BasePhoneInput extends TextInputProps {
|
|
|
23
23
|
modalDisabled?: boolean;
|
|
24
24
|
defaultCountry?: ICountryCca2;
|
|
25
25
|
defaultValue?: string;
|
|
26
|
+
customMask?: string;
|
|
26
27
|
visibleCountries?: Array<ICountryCca2>;
|
|
27
28
|
hiddenCountries?: Array<ICountryCca2>;
|
|
28
29
|
popularCountries?: Array<ICountryCca2>;
|
|
@@ -30,6 +31,7 @@ interface BasePhoneInput extends TextInputProps {
|
|
|
30
31
|
rtl?: boolean;
|
|
31
32
|
isFullScreen?: boolean;
|
|
32
33
|
modalType?: 'bottomSheet' | 'popup';
|
|
34
|
+
modalDragHandleIndicatorComponent?: () => ReactNode;
|
|
33
35
|
modalSearchInputPlaceholderTextColor?: string;
|
|
34
36
|
modalSearchInputPlaceholder?: string;
|
|
35
37
|
modalSearchInputSelectionColor?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-international-phone-number",
|
|
3
3
|
"author": "AstrOOnauta (https://github.com/AstrOOnauta)",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.3",
|
|
5
5
|
"description": "International mobile phone input component with mask for React Native",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|