react-native-international-phone-number 0.6.0 → 0.6.2

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 CHANGED
@@ -58,6 +58,7 @@
58
58
  - [Customizing Lib](#customizing-lib)
59
59
  - [Dark Mode](#dark-mode)
60
60
  - [Custom Lib Styles](#custom-lib-styles)
61
+ - [Custom Placeholders/Messages](#custom-placeholdersmessages)
61
62
  - [Custom Modal Height](#custom-modal-height)
62
63
  - [Country Modal Disabled Mode](#country-modal-disabled-mode)
63
64
  - [Phone Input Disabled Mode](#phone-input-disabled-mode)
@@ -66,6 +67,8 @@
66
67
  - [Custom Phone Mask](#custom-phone-mask)
67
68
  - [Custom Default Flag/Country](#custom-default-flagcountry)
68
69
  - [Default Phone Number Value](#default-phone-number-value)
70
+ - [Show Only Some Countries Inside Modal](#show-only-some-countries)
71
+ - [Exclude some countries Inside Modal](#exclude-some-countries)
69
72
  - [Lib Props](#component-props-phoneinputprops)
70
73
  - [Lib Functions](#functions)
71
74
  - [Supported languages](#🎌-supported-languages-🎌)
@@ -134,7 +137,7 @@ create a `react-native.config.js` file at the root of your react-native project
134
137
 
135
138
  ## Features
136
139
 
137
- - 📱 Works with iOS, Android (Cross-platform) and Expo;
140
+ - 📱 Works with iOS, Android (Cross-platform), Expo and Web;
138
141
  - 🎨 Lib with UI customizable;
139
142
  - 🌎 Phone Input Mask according with the selected country;
140
143
  - 👨‍💻 Functional and class component support;
@@ -453,7 +456,7 @@ export default function App() {
453
456
  backgroundColor: '#808080',
454
457
  justifyContent: 'center',
455
458
  },
456
- flag: {}
459
+ flag: {},
457
460
  callingCode: {
458
461
  fontSize: 16,
459
462
  fontWeight: 'bold',
@@ -506,6 +509,19 @@ export default function App() {
506
509
  ...
507
510
  ```
508
511
 
512
+ - ### Custom Placeholders/Messages:
513
+
514
+ ```jsx
515
+ ...
516
+ <PhoneInput
517
+ ...
518
+ placeholder="Custom Phone Input Placeholder"
519
+ modalSearchInputPlaceholder="Custom Modal Search Input Placeholder"
520
+ modalNotFoundCountryMessage="Custom Modal Not Found Country Message"
521
+ />
522
+ ...
523
+ ```
524
+
509
525
  - ### Custom Modal Height:
510
526
 
511
527
  ```jsx
@@ -601,6 +617,28 @@ export default function App() {
601
617
  > 1. You need to use a default value with the following format: `+(country callling code)(area code)(number phone)`
602
618
  > 2. The lib has the mechanism to set the flag and mask of the supplied `defaultValue`. However, if the supplied `defaultValue` does not match any international standard, the `input mask of the defaultValue` will be set to "BR" (please make sure that the default value is in the format mentioned above).
603
619
 
620
+ - ### Show Only Some Countries Inside Modal:
621
+
622
+ ```jsx
623
+ ...
624
+ <PhoneInput
625
+ ...
626
+ showOnly={['BR', 'PT', 'CA', 'US']}
627
+ />
628
+ ...
629
+ ```
630
+
631
+ - ### Exclude Some Countries Inside Modal:
632
+
633
+ ```jsx
634
+ ...
635
+ <PhoneInput
636
+ ...
637
+ excludedCountries={['BR', 'PT', 'CA', 'US']}
638
+ />
639
+ ...
640
+ ```
641
+
604
642
  </br>
605
643
 
606
644
  ## Component Props ([PhoneInputProps](lib/interfaces/phoneInputProps.ts))
@@ -610,14 +648,19 @@ export default function App() {
610
648
  - `defaultValue?:` string;
611
649
  - `value?:` string;
612
650
  - `onChangePhoneNumber?:` (phoneNumber: string) => void;
651
+ - `defaultCountry?:` [ICountryCca2](lib/interfaces/countryCca2.ts);
613
652
  - `selectedCountry?:` [ICountry](lib/interfaces/country.ts);
614
653
  - `onChangeSelectedCountry?:` (country: [ICountry](lib/interfaces/country.ts)) => void;
654
+ - `showOnly?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
655
+ - `excludedCountries?:` [ICountryCca2[]](lib/interfaces/countryCca2.ts);
615
656
  - `disabled?:` boolean;
616
657
  - `modalDisabled?:` boolean;
617
658
  - `modalHeight?:` number | string;
618
659
  - `theme?:` [ITheme](lib/interfaces/theme.ts);
619
- - `modalStyles?:` [IPhoneInputStyles](lib/interfaces/phoneInputStyles.ts);
660
+ - `phoneInputStyle?:` [IPhoneInputStyles](lib/interfaces/phoneInputStyles.ts);
620
661
  - `modalStyles?:` [IModalStyles](lib/interfaces/modalStyles.ts);
662
+ - `modalSearchInputPlaceholder?:` string;
663
+ - `modalNotFoundCountryMessage?:` string;
621
664
  - `ref?:` [Ref](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/663f439d11d78b65f1dfd38d120f3728ea2cc207/types/react/index.d.ts#L100)<[IPhoneInputRef](lib/interfaces/phoneInputRef.ts)>
622
665
 
623
666
  <br>
@@ -277,7 +277,13 @@ export const countries = [
277
277
  ua: 'Антарктида',
278
278
  zh: '南極洲',
279
279
  },
280
- phoneMasks: ['## ####'],
280
+ phoneMasks: [
281
+ '10 ####',
282
+ '11 ####',
283
+ '12 ####',
284
+ '13 ####',
285
+ '14 ####',
286
+ ],
281
287
  },
282
288
  {
283
289
  callingCode: '+54',
@@ -389,7 +395,12 @@ export const countries = [
389
395
  ua: 'Австралія',
390
396
  zh: '澳大利亞',
391
397
  },
392
- phoneMasks: ['# #### ####'],
398
+ phoneMasks: [
399
+ '2 #### ####',
400
+ '3 #### ####',
401
+ '4## ### ###',
402
+ '7 #### ####',
403
+ ],
393
404
  },
394
405
  {
395
406
  callingCode: '+297',
@@ -445,7 +456,7 @@ export const countries = [
445
456
  ua: 'Аландські острови',
446
457
  zh: '奧蘭群島',
447
458
  },
448
- phoneMasks: ['## ### ##', '## ## ## ##', '### ### ####'],
459
+ phoneMasks: ['18 ### ##', '18 ## ## ##'],
449
460
  },
450
461
  {
451
462
  callingCode: '+994',
@@ -753,7 +764,7 @@ export const countries = [
753
764
  ua: 'Сен-Бартелемі',
754
765
  zh: '聖巴托洛繆島',
755
766
  },
756
- phoneMasks: ['### ## ## ##'],
767
+ phoneMasks: ['690 ## ## ##'],
757
768
  },
758
769
  {
759
770
  callingCode: '+1',
@@ -1112,7 +1123,7 @@ export const countries = [
1112
1123
  ua: 'Кокосові (Кілінг) острови',
1113
1124
  zh: '科科斯(基林)群島',
1114
1125
  },
1115
- phoneMasks: ['# #### ####'],
1126
+ phoneMasks: ['8 9162 ####'],
1116
1127
  },
1117
1128
  {
1118
1129
  callingCode: '+243',
@@ -1504,7 +1515,7 @@ export const countries = [
1504
1515
  ua: 'Острів Різдва',
1505
1516
  zh: '聖誕島',
1506
1517
  },
1507
- phoneMasks: ['# #### ####'],
1518
+ phoneMasks: ['8 9164 ####'],
1508
1519
  },
1509
1520
  {
1510
1521
  callingCode: '+357',
@@ -1931,7 +1942,7 @@ export const countries = [
1931
1942
  ua: 'Фінляндія',
1932
1943
  zh: '芬蘭',
1933
1944
  },
1934
- phoneMasks: ['### ### ## ##'],
1945
+ phoneMasks: ['4## ### ## ##', '5## ### ## ##'],
1935
1946
  },
1936
1947
  {
1937
1948
  callingCode: '+679',
@@ -1987,7 +1998,7 @@ export const countries = [
1987
1998
  ua: 'Фолклендські острови (Мальвінські острови)',
1988
1999
  zh: '福 克蘭群島(馬爾維納斯)',
1989
2000
  },
1990
- phoneMasks: ['#####'],
2001
+ phoneMasks: ['5# ###', '6# ###'],
1991
2002
  },
1992
2003
  {
1993
2004
  callingCode: '+691',
@@ -2127,7 +2138,26 @@ export const countries = [
2127
2138
  ua: "Об'єднане Королівство",
2128
2139
  zh: '英國',
2129
2140
  },
2130
- phoneMasks: ['## #### ####'],
2141
+ phoneMasks: [
2142
+ '160## ####',
2143
+ '169## ####',
2144
+ '160## #####',
2145
+ '169## #####',
2146
+ '2# #### ####',
2147
+ '11# ### ####',
2148
+ '12# ### ####',
2149
+ '13# ### ####',
2150
+ '141 ### ####',
2151
+ '151 ### ####',
2152
+ '161 ### ####',
2153
+ '12## ## ####',
2154
+ '13## ## ####',
2155
+ '1642 ## ####',
2156
+ '17## ## ####',
2157
+ '18## ## ####',
2158
+ '19## ## ####',
2159
+ '1539# ## ###',
2160
+ ],
2131
2161
  },
2132
2162
  {
2133
2163
  callingCode: '+1',
@@ -2239,7 +2269,7 @@ export const countries = [
2239
2269
  ua: 'Гернсі',
2240
2270
  zh: '根西島',
2241
2271
  },
2242
- phoneMasks: ['## #### ######'],
2272
+ phoneMasks: ['1481 ######'],
2243
2273
  },
2244
2274
  {
2245
2275
  callingCode: '+233',
@@ -2407,7 +2437,7 @@ export const countries = [
2407
2437
  ua: 'Гваделупа',
2408
2438
  zh: '瓜德羅普島',
2409
2439
  },
2410
- phoneMasks: ['### ## ## ##'],
2440
+ phoneMasks: ['69# ## ## ##'],
2411
2441
  },
2412
2442
  {
2413
2443
  callingCode: '+240',
@@ -2491,7 +2521,7 @@ export const countries = [
2491
2521
  ua: 'Південна Джорджія та Південні Сандвічеві острови',
2492
2522
  zh: '南喬治亞島和南桑威奇群島',
2493
2523
  },
2494
- phoneMasks: ['#####'],
2524
+ phoneMasks: ['4####'],
2495
2525
  },
2496
2526
  {
2497
2527
  callingCode: '+502',
@@ -2861,7 +2891,7 @@ export const countries = [
2861
2891
  ua: 'Острів Мен',
2862
2892
  zh: '馬恩島',
2863
2893
  },
2864
- phoneMasks: ['#### ######'],
2894
+ phoneMasks: ['1624 ######'],
2865
2895
  },
2866
2896
  {
2867
2897
  callingCode: '+91',
@@ -3057,7 +3087,7 @@ export const countries = [
3057
3087
  ua: 'Джерсі',
3058
3088
  zh: '球衣',
3059
3089
  },
3060
- phoneMasks: ['#### ######'],
3090
+ phoneMasks: ['1534 ######'],
3061
3091
  },
3062
3092
  {
3063
3093
  callingCode: '+1',
@@ -3903,7 +3933,7 @@ export const countries = [
3903
3933
  ua: 'Святий Мартін',
3904
3934
  zh: '聖馬丁',
3905
3935
  },
3906
- phoneMasks: ['### ## ## ##'],
3936
+ phoneMasks: ['690 ## ## ##'],
3907
3937
  },
3908
3938
  {
3909
3939
  callingCode: '+261',
@@ -4519,7 +4549,7 @@ export const countries = [
4519
4549
  ua: 'Острів Норфолк',
4520
4550
  zh: '諾福克島',
4521
4551
  },
4522
- phoneMasks: ['# #####'],
4552
+ phoneMasks: ['3 2# ###', '3 5# ###'],
4523
4553
  },
4524
4554
  {
4525
4555
  callingCode: '+234',
@@ -4631,7 +4661,16 @@ export const countries = [
4631
4661
  ua: 'Норвегія',
4632
4662
  zh: '挪威',
4633
4663
  },
4634
- phoneMasks: ['### ## ###'],
4664
+ phoneMasks: [
4665
+ '4## ## ###',
4666
+ '9## ## ###',
4667
+ '2# ## ## ##',
4668
+ '3# ## ## ##',
4669
+ '5# ## ## ##',
4670
+ '6# ## ## ##',
4671
+ '7# ## ## ##',
4672
+ '2# ## ## ##',
4673
+ ],
4635
4674
  },
4636
4675
  {
4637
4676
  callingCode: '+977',
@@ -5219,7 +5258,7 @@ export const countries = [
5219
5258
  ua: 'Реюньйон',
5220
5259
  zh: '團圓',
5221
5260
  },
5222
- phoneMasks: ['### ## ## ##'],
5261
+ phoneMasks: ['6## ## ## ##'],
5223
5262
  },
5224
5263
  {
5225
5264
  callingCode: '+40',
@@ -5583,7 +5622,7 @@ export const countries = [
5583
5622
  ua: 'Шпіцберген та Ян Маєн',
5584
5623
  zh: '斯瓦爾巴和揚· 馬延',
5585
5624
  },
5586
- phoneMasks: ['## ## ## ##'],
5625
+ phoneMasks: ['79 ## ## ##'],
5587
5626
  },
5588
5627
  {
5589
5628
  callingCode: '+421',
@@ -7074,7 +7113,7 @@ export const countries = [
7074
7113
  ua: 'Майотта',
7075
7114
  zh: '馬約特島',
7076
7115
  },
7077
- phoneMasks: ['262 ### ###', '639 ### ###'],
7116
+ phoneMasks: ['269 ### ###', '639 ### ###'],
7078
7117
  },
7079
7118
  {
7080
7119
  callingCode: '+27',
package/lib/index.js CHANGED
@@ -51,6 +51,10 @@ const PhoneInput = forwardRef(
51
51
  selectedCountry,
52
52
  onChangeSelectedCountry,
53
53
  customMask,
54
+ showOnly,
55
+ excludedCountries,
56
+ modalSearchInputPlaceholder,
57
+ modalNotFoundCountryMessage,
54
58
  ...rest
55
59
  },
56
60
  ref
@@ -90,6 +94,10 @@ const PhoneInput = forwardRef(
90
94
  selectedCountry,
91
95
  onChangeSelectedCountry,
92
96
  customMask,
97
+ showOnly,
98
+ excludedCountries,
99
+ modalSearchInputPlaceholder,
100
+ modalNotFoundCountryMessage,
93
101
  ...rest,
94
102
  },
95
103
  };
@@ -245,17 +253,6 @@ const PhoneInput = forwardRef(
245
253
  defaultValue.replace(/\D/g, '').length +
246
254
  callingCode.length
247
255
  );
248
- } else if (
249
- callingCode === '+39' &&
250
- countryValue.cca2 === 'VA'
251
- ) {
252
- phoneNumber = defaultValue
253
- .replace(/\s/g, '')
254
- .substring(
255
- callingCode.length + 5,
256
- defaultValue.replace(/\D/g, '').length +
257
- callingCode.length
258
- );
259
256
  } else {
260
257
  phoneNumber = defaultValue
261
258
  .replace(/\s/g, '')
@@ -346,12 +343,14 @@ const PhoneInput = forwardRef(
346
343
  <CountryPicker
347
344
  show={show}
348
345
  lang={language}
349
- inputPlaceholder={getSearchInputPlaceholder(
350
- language || 'en'
351
- )}
352
- searchMessage={getCountryNotFoundMessage(
353
- language || 'en'
354
- )}
346
+ inputPlaceholder={
347
+ modalSearchInputPlaceholder ||
348
+ getSearchInputPlaceholder(language || 'en')
349
+ }
350
+ searchMessage={
351
+ modalNotFoundCountryMessage ||
352
+ getCountryNotFoundMessage(language || 'en')
353
+ }
355
354
  enableModalAvoiding
356
355
  style={getCountryPickerStyle(
357
356
  theme,
@@ -360,6 +359,8 @@ const PhoneInput = forwardRef(
360
359
  )}
361
360
  pickerButtonOnPress={onSelect}
362
361
  onBackdropPress={() => setShow(false)}
362
+ showOnly={showOnly}
363
+ excludedCountries={excludedCountries}
363
364
  />
364
365
  ) : null}
365
366
  </>
@@ -9,7 +9,7 @@ import { IModalStyles } from './modalStyles';
9
9
  import { IPhoneInputStyles } from './phoneInputStyles';
10
10
  import { IPhoneInputRef } from './phoneInputRef';
11
11
 
12
- interface IPhoneInputPropsWithoutRef extends TextInputProps {
12
+ interface BasePhoneInput extends TextInputProps {
13
13
  language?: ILanguage;
14
14
  placeholder?: string;
15
15
  placeholderTextColor?: string;
@@ -22,32 +22,26 @@ interface IPhoneInputPropsWithoutRef extends TextInputProps {
22
22
  modalHeight?: number | string;
23
23
  defaultCountry?: ICountryCca2;
24
24
  defaultValue?: string;
25
+ customMask?: Array<string>;
26
+ showOnly?: Array<ICountryCca2>;
27
+ excludedCountries?: Array<ICountryCca2>;
28
+ modalSearchInputPlaceholder?: string;
29
+ modalNotFoundCountryMessage?: string;
30
+ }
31
+
32
+ interface IPhoneInputPropsWithoutRef extends BasePhoneInput {
25
33
  value: string;
26
34
  onChangePhoneNumber: (phoneNumber: string) => void;
27
35
  selectedCountry: ICountry | undefined | null;
28
36
  onChangeSelectedCountry: (country: ICountry) => void;
29
- customMask?: Array<string>;
30
37
  ref?: never;
31
38
  }
32
39
 
33
- interface IPhoneInputPropsWithRef extends TextInputProps {
34
- language?: ILanguage;
35
- placeholder?: string;
36
- placeholderTextColor?: string;
37
- selectionColor?: string;
38
- phoneInputStyle?: IPhoneInputStyles;
39
- modalStyle?: IModalStyles;
40
- theme?: ITheme;
41
- disabled?: boolean;
42
- modalDisabled?: boolean;
43
- modalHeight?: number | string;
44
- defaultCountry?: ICountryCca2;
45
- defaultValue?: string;
40
+ interface IPhoneInputPropsWithRef extends BasePhoneInput {
46
41
  value?: never;
47
42
  onChangePhoneNumber?: never;
48
43
  selectedCountry?: never;
49
44
  onChangeSelectedCountry?: never;
50
- customMask?: Array<string>;
51
45
  ref: Ref<IPhoneInputRef>;
52
46
  }
53
47
 
@@ -13,10 +13,16 @@ export default function getInputMask(
13
13
  const phoneMask =
14
14
  (Array.isArray(customMask) && customMask) || item.phoneMasks;
15
15
 
16
- if (callingCode && callingCode.includes(newCode)) {
16
+ if (
17
+ item.cca2 === cca2 &&
18
+ callingCode &&
19
+ callingCode.includes(newCode)
20
+ ) {
17
21
  if (phoneMask.length === 1) {
18
- if (cca2 !== 'CA' && cca2 !== 'US' && cca2 !== 'IT') {
22
+ if (newCode === '+1' && cca2 !== 'CA' && cca2 !== 'US') {
19
23
  matrix = phoneMask[0].replace(/[0-9]/g, '').trim();
24
+ } else {
25
+ matrix = phoneMask[0].replace(/[0-9]/g, '#').trim();
20
26
  }
21
27
  } else if (phoneMask.length > 1) {
22
28
  let hasDifferentLengthsOfPhoneNumbers = false;
@@ -34,7 +40,7 @@ export default function getInputMask(
34
40
  if (cca2 === 'CA' || cca2 === 'US') {
35
41
  matrix = phoneMask[0].replace(/\d/g, '#').trim();
36
42
  } else {
37
- matrix = phoneMask[0].replace(/[0-9]/g, '').trim();
43
+ matrix = phoneMask[0].replace(/[0-9]/g, '#').trim();
38
44
  }
39
45
  } else {
40
46
  for (let i = 0; i < phoneMask.length; i++) {
@@ -42,7 +48,7 @@ export default function getInputMask(
42
48
  phoneNumber.length > phoneMask[i].length &&
43
49
  phoneMask[i + 1]
44
50
  ) {
45
- matrix = phoneMask[i + 1].replace(/[0-9]/g, '').trim();
51
+ matrix = phoneMask[i + 1].replace(/[0-9]/g, '#').trim();
46
52
  }
47
53
  }
48
54
  }
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.6.0",
4
+ "version": "0.6.2",
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",
@@ -44,7 +44,7 @@
44
44
  "react-native": "*"
45
45
  },
46
46
  "dependencies": {
47
- "react-native-country-codes-picker": "^2.3.3"
47
+ "react-native-country-codes-picker": "2.3.3"
48
48
  },
49
49
  "devDependencies": {
50
50
  "metro-react-native-babel-preset": "^0.61.0"