react-native-phone-country-input 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +477 -0
- package/lib/commonjs/CountrySelector/CountrySelector.js +74 -0
- package/lib/commonjs/CountrySelector/CountrySelector.js.map +1 -0
- package/lib/commonjs/CountrySelector/CountrySelectorModal.js +267 -0
- package/lib/commonjs/CountrySelector/CountrySelectorModal.js.map +1 -0
- package/lib/commonjs/Keyboard/Keyboard.js +316 -0
- package/lib/commonjs/Keyboard/Keyboard.js.map +1 -0
- package/lib/commonjs/Keyboard/KeyboardToolbar.js +70 -0
- package/lib/commonjs/Keyboard/KeyboardToolbar.js.map +1 -0
- package/lib/commonjs/Keyboard/KeypadButton.js +66 -0
- package/lib/commonjs/Keyboard/KeypadButton.js.map +1 -0
- package/lib/commonjs/Keyboard/KeypadButtonContainer.js +65 -0
- package/lib/commonjs/Keyboard/KeypadButtonContainer.js.map +1 -0
- package/lib/commonjs/Keyboard/KeypadRow.js +34 -0
- package/lib/commonjs/Keyboard/KeypadRow.js.map +1 -0
- package/lib/commonjs/PhoneCountryInput/PhoneCountryInput.js +86 -0
- package/lib/commonjs/PhoneCountryInput/PhoneCountryInput.js.map +1 -0
- package/lib/commonjs/PhoneNumberField.js +36 -0
- package/lib/commonjs/PhoneNumberField.js.map +1 -0
- package/lib/commonjs/Styling/Colors.js +197 -0
- package/lib/commonjs/Styling/Colors.js.map +1 -0
- package/lib/commonjs/Styling/Sizing.js +111 -0
- package/lib/commonjs/Styling/Sizing.js.map +1 -0
- package/lib/commonjs/consts/KEYBOARD_LAYOUT.js +45 -0
- package/lib/commonjs/consts/KEYBOARD_LAYOUT.js.map +1 -0
- package/lib/commonjs/consts/regions.js +1503 -0
- package/lib/commonjs/consts/regions.js.map +1 -0
- package/lib/commonjs/enum/CountryIds.js +264 -0
- package/lib/commonjs/enum/CountryIds.js.map +1 -0
- package/lib/commonjs/hooks/UsePhoneFieldState.js +237 -0
- package/lib/commonjs/hooks/UsePhoneFieldState.js.map +1 -0
- package/lib/commonjs/index.js +56 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/characterDeletion.js +20 -0
- package/lib/commonjs/utils/characterDeletion.js.map +1 -0
- package/lib/commonjs/utils/characterInsert.js +20 -0
- package/lib/commonjs/utils/characterInsert.js.map +1 -0
- package/lib/commonjs/utils/fromMaskedNumberToUnmaskedSelection.js +14 -0
- package/lib/commonjs/utils/fromMaskedNumberToUnmaskedSelection.js.map +1 -0
- package/lib/commonjs/utils/fromUnmaskedToMaskedPosition.js +20 -0
- package/lib/commonjs/utils/fromUnmaskedToMaskedPosition.js.map +1 -0
- package/lib/commonjs/utils/generateCountryCodeList.js +23 -0
- package/lib/commonjs/utils/generateCountryCodeList.js.map +1 -0
- package/lib/commonjs/utils/getDefaultRegion.js +33 -0
- package/lib/commonjs/utils/getDefaultRegion.js.map +1 -0
- package/lib/commonjs/utils/maskToPhoneNumber.js +23 -0
- package/lib/commonjs/utils/maskToPhoneNumber.js.map +1 -0
- package/lib/commonjs/utils/matchCountryCode.js +27 -0
- package/lib/commonjs/utils/matchCountryCode.js.map +1 -0
- package/lib/module/CountrySelector/CountrySelector.js +70 -0
- package/lib/module/CountrySelector/CountrySelector.js.map +1 -0
- package/lib/module/CountrySelector/CountrySelectorModal.js +262 -0
- package/lib/module/CountrySelector/CountrySelectorModal.js.map +1 -0
- package/lib/module/Keyboard/Keyboard.js +310 -0
- package/lib/module/Keyboard/Keyboard.js.map +1 -0
- package/lib/module/Keyboard/KeyboardToolbar.js +65 -0
- package/lib/module/Keyboard/KeyboardToolbar.js.map +1 -0
- package/lib/module/Keyboard/KeypadButton.js +61 -0
- package/lib/module/Keyboard/KeypadButton.js.map +1 -0
- package/lib/module/Keyboard/KeypadButtonContainer.js +59 -0
- package/lib/module/Keyboard/KeypadButtonContainer.js.map +1 -0
- package/lib/module/Keyboard/KeypadRow.js +30 -0
- package/lib/module/Keyboard/KeypadRow.js.map +1 -0
- package/lib/module/PhoneCountryInput/PhoneCountryInput.js +80 -0
- package/lib/module/PhoneCountryInput/PhoneCountryInput.js.map +1 -0
- package/lib/module/PhoneNumberField.js +31 -0
- package/lib/module/PhoneNumberField.js.map +1 -0
- package/lib/module/Styling/Colors.js +193 -0
- package/lib/module/Styling/Colors.js.map +1 -0
- package/lib/module/Styling/Sizing.js +107 -0
- package/lib/module/Styling/Sizing.js.map +1 -0
- package/lib/module/consts/KEYBOARD_LAYOUT.js +41 -0
- package/lib/module/consts/KEYBOARD_LAYOUT.js.map +1 -0
- package/lib/module/consts/regions.js +1498 -0
- package/lib/module/consts/regions.js.map +1 -0
- package/lib/module/enum/CountryIds.js +260 -0
- package/lib/module/enum/CountryIds.js.map +1 -0
- package/lib/module/hooks/UsePhoneFieldState.js +232 -0
- package/lib/module/hooks/UsePhoneFieldState.js.map +1 -0
- package/lib/module/index.js +16 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/utils/characterDeletion.js +16 -0
- package/lib/module/utils/characterDeletion.js.map +1 -0
- package/lib/module/utils/characterInsert.js +16 -0
- package/lib/module/utils/characterInsert.js.map +1 -0
- package/lib/module/utils/fromMaskedNumberToUnmaskedSelection.js +10 -0
- package/lib/module/utils/fromMaskedNumberToUnmaskedSelection.js.map +1 -0
- package/lib/module/utils/fromUnmaskedToMaskedPosition.js +16 -0
- package/lib/module/utils/fromUnmaskedToMaskedPosition.js.map +1 -0
- package/lib/module/utils/generateCountryCodeList.js +19 -0
- package/lib/module/utils/generateCountryCodeList.js.map +1 -0
- package/lib/module/utils/getDefaultRegion.js +28 -0
- package/lib/module/utils/getDefaultRegion.js.map +1 -0
- package/lib/module/utils/maskToPhoneNumber.js +19 -0
- package/lib/module/utils/maskToPhoneNumber.js.map +1 -0
- package/lib/module/utils/matchCountryCode.js +23 -0
- package/lib/module/utils/matchCountryCode.js.map +1 -0
- package/lib/typescript/CountrySelector/CountrySelector.d.ts +19 -0
- package/lib/typescript/CountrySelector/CountrySelector.d.ts.map +1 -0
- package/lib/typescript/CountrySelector/CountrySelectorModal.d.ts +12 -0
- package/lib/typescript/CountrySelector/CountrySelectorModal.d.ts.map +1 -0
- package/lib/typescript/Keyboard/Keyboard.d.ts +25 -0
- package/lib/typescript/Keyboard/Keyboard.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeyboardToolbar.d.ts +9 -0
- package/lib/typescript/Keyboard/KeyboardToolbar.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeypadButton.d.ts +10 -0
- package/lib/typescript/Keyboard/KeypadButton.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeypadButtonContainer.d.ts +12 -0
- package/lib/typescript/Keyboard/KeypadButtonContainer.d.ts.map +1 -0
- package/lib/typescript/Keyboard/KeypadRow.d.ts +9 -0
- package/lib/typescript/Keyboard/KeypadRow.d.ts.map +1 -0
- package/lib/typescript/PhoneCountryInput/PhoneCountryInput.d.ts +16 -0
- package/lib/typescript/PhoneCountryInput/PhoneCountryInput.d.ts.map +1 -0
- package/lib/typescript/PhoneNumberField.d.ts +17 -0
- package/lib/typescript/PhoneNumberField.d.ts.map +1 -0
- package/lib/typescript/Styling/Colors.d.ts +189 -0
- package/lib/typescript/Styling/Colors.d.ts.map +1 -0
- package/lib/typescript/Styling/Sizing.d.ts +214 -0
- package/lib/typescript/Styling/Sizing.d.ts.map +1 -0
- package/lib/typescript/consts/KEYBOARD_LAYOUT.d.ts +18 -0
- package/lib/typescript/consts/KEYBOARD_LAYOUT.d.ts.map +1 -0
- package/lib/typescript/consts/regions.d.ts +10 -0
- package/lib/typescript/consts/regions.d.ts.map +1 -0
- package/lib/typescript/enum/CountryIds.d.ts +249 -0
- package/lib/typescript/enum/CountryIds.d.ts.map +1 -0
- package/lib/typescript/hooks/UsePhoneFieldState.d.ts +34 -0
- package/lib/typescript/hooks/UsePhoneFieldState.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +15 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/characterDeletion.d.ts +3 -0
- package/lib/typescript/utils/characterDeletion.d.ts.map +1 -0
- package/lib/typescript/utils/characterInsert.d.ts +3 -0
- package/lib/typescript/utils/characterInsert.d.ts.map +1 -0
- package/lib/typescript/utils/fromMaskedNumberToUnmaskedSelection.d.ts +2 -0
- package/lib/typescript/utils/fromMaskedNumberToUnmaskedSelection.d.ts.map +1 -0
- package/lib/typescript/utils/fromUnmaskedToMaskedPosition.d.ts +2 -0
- package/lib/typescript/utils/fromUnmaskedToMaskedPosition.d.ts.map +1 -0
- package/lib/typescript/utils/generateCountryCodeList.d.ts +3 -0
- package/lib/typescript/utils/generateCountryCodeList.d.ts.map +1 -0
- package/lib/typescript/utils/getDefaultRegion.d.ts +4 -0
- package/lib/typescript/utils/getDefaultRegion.d.ts.map +1 -0
- package/lib/typescript/utils/maskToPhoneNumber.d.ts +2 -0
- package/lib/typescript/utils/maskToPhoneNumber.d.ts.map +1 -0
- package/lib/typescript/utils/matchCountryCode.d.ts +3 -0
- package/lib/typescript/utils/matchCountryCode.d.ts.map +1 -0
- package/package.json +92 -0
- package/src/CountrySelector/CountrySelector.tsx +77 -0
- package/src/CountrySelector/CountrySelectorModal.tsx +280 -0
- package/src/Keyboard/Keyboard.tsx +322 -0
- package/src/Keyboard/KeyboardToolbar.tsx +53 -0
- package/src/Keyboard/KeypadButton.tsx +58 -0
- package/src/Keyboard/KeypadButtonContainer.tsx +67 -0
- package/src/Keyboard/KeypadRow.tsx +29 -0
- package/src/PhoneCountryInput/PhoneCountryInput.tsx +98 -0
- package/src/PhoneNumberField.tsx +46 -0
- package/src/Styling/Colors.ts +206 -0
- package/src/Styling/Sizing.ts +110 -0
- package/src/consts/KEYBOARD_LAYOUT.ts +34 -0
- package/src/consts/regions.ts +268 -0
- package/src/enum/CountryIds.ts +256 -0
- package/src/hooks/UsePhoneFieldState.tsx +268 -0
- package/src/index.ts +27 -0
- package/src/utils/characterDeletion.ts +16 -0
- package/src/utils/characterInsert.ts +20 -0
- package/src/utils/fromMaskedNumberToUnmaskedSelection.ts +10 -0
- package/src/utils/fromUnmaskedToMaskedPosition.ts +13 -0
- package/src/utils/generateCountryCodeList.ts +22 -0
- package/src/utils/getDefaultRegion.ts +30 -0
- package/src/utils/maskToPhoneNumber.ts +30 -0
- package/src/utils/matchCountryCode.ts +23 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CountryId", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _CountryIds.CountryId;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CountrySelector", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _CountrySelector.CountrySelector;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "CountrySelectorModal", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _CountrySelectorModal.CountrySelectorModal;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Keyboard", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _Keyboard.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "PhoneCountryInput", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _PhoneCountryInput.PhoneCountryInput;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "PhoneNumberField", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _PhoneNumberField.PhoneNumberField;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "usePhoneFieldState", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _UsePhoneFieldState.usePhoneFieldState;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var _PhoneCountryInput = require("./PhoneCountryInput/PhoneCountryInput");
|
|
49
|
+
var _PhoneNumberField = require("./PhoneNumberField");
|
|
50
|
+
var _CountrySelector = require("./CountrySelector/CountrySelector");
|
|
51
|
+
var _CountrySelectorModal = require("./CountrySelector/CountrySelectorModal");
|
|
52
|
+
var _Keyboard = _interopRequireDefault(require("./Keyboard/Keyboard"));
|
|
53
|
+
var _UsePhoneFieldState = require("./hooks/UsePhoneFieldState");
|
|
54
|
+
var _CountryIds = require("./enum/CountryIds");
|
|
55
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_PhoneCountryInput","require","_PhoneNumberField","_CountrySelector","_CountrySelectorModal","_Keyboard","_interopRequireDefault","_UsePhoneFieldState","_CountryIds","e","__esModule","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,kBAAA,GAAAC,OAAA;AAIA,IAAAC,iBAAA,GAAAD,OAAA;AAGA,IAAAE,gBAAA,GAAAF,OAAA;AAGA,IAAAG,qBAAA,GAAAH,OAAA;AAGA,IAAAI,SAAA,GAAAC,sBAAA,CAAAL,OAAA;AAIA,IAAAM,mBAAA,GAAAN,OAAA;AAQA,IAAAO,WAAA,GAAAP,OAAA;AAA8C,SAAAK,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.characterDeletion = characterDeletion;
|
|
7
|
+
function characterDeletion(phoneNumber, selection) {
|
|
8
|
+
const isRange = selection.start !== selection.end;
|
|
9
|
+
if (!selection.hasBeenSelected && !isRange && selection.start === 0) {
|
|
10
|
+
return phoneNumber.slice(0, -1);
|
|
11
|
+
}
|
|
12
|
+
if (isRange) {
|
|
13
|
+
// selection.start digits are before the selection; first selected char is at index start+1
|
|
14
|
+
return phoneNumber.slice(0, selection.start + 1) + phoneNumber.slice(selection.end + 1);
|
|
15
|
+
}
|
|
16
|
+
// backspace: delete the digit immediately to the left of cursor (at index start); clamp to protect '+'
|
|
17
|
+
const start = Math.max(selection.start, 1);
|
|
18
|
+
return phoneNumber.slice(0, start) + phoneNumber.slice(start + 1);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=characterDeletion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["characterDeletion","phoneNumber","selection","isRange","start","end","hasBeenSelected","slice","Math","max"],"sourceRoot":"../../../src","sources":["utils/characterDeletion.ts"],"mappings":";;;;;;AAEO,SAASA,iBAAiBA,CAACC,WAAmB,EAAEC,SAAyB,EAAU;EACxF,MAAMC,OAAO,GAAGD,SAAS,CAACE,KAAK,KAAKF,SAAS,CAACG,GAAG;EAEjD,IAAI,CAACH,SAAS,CAACI,eAAe,IAAI,CAACH,OAAO,IAAID,SAAS,CAACE,KAAK,KAAK,CAAC,EAAE;IACnE,OAAOH,WAAW,CAACM,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EACjC;EACA,IAAIJ,OAAO,EAAE;IACX;IACA,OAAOF,WAAW,CAACM,KAAK,CAAC,CAAC,EAAEL,SAAS,CAACE,KAAK,GAAG,CAAC,CAAC,GAAGH,WAAW,CAACM,KAAK,CAACL,SAAS,CAACG,GAAG,GAAG,CAAC,CAAC;EACzF;EACA;EACA,MAAMD,KAAK,GAAGI,IAAI,CAACC,GAAG,CAACP,SAAS,CAACE,KAAK,EAAE,CAAC,CAAC;EAC1C,OAAOH,WAAW,CAACM,KAAK,CAAC,CAAC,EAAEH,KAAK,CAAC,GAAGH,WAAW,CAACM,KAAK,CAACH,KAAK,GAAG,CAAC,CAAC;AACnE","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.characterInsert = characterInsert;
|
|
7
|
+
function characterInsert(phoneNumber, newChar, selection) {
|
|
8
|
+
const isARange = selection.start !== selection.end;
|
|
9
|
+
if (isARange) {
|
|
10
|
+
// selection.start digits are before the selection; first selected char is at index start+1
|
|
11
|
+
return phoneNumber.slice(0, selection.start + 1) + newChar + phoneNumber.slice(selection.end + 1);
|
|
12
|
+
} else if (selection.start === 0 && !selection.hasBeenSelected) {
|
|
13
|
+
return phoneNumber + newChar;
|
|
14
|
+
} else {
|
|
15
|
+
// cursor is after `start` digits; insert before char at index start+1; clamp to protect '+'
|
|
16
|
+
const start = Math.max(selection.start, 1);
|
|
17
|
+
return phoneNumber.slice(0, start + 1) + newChar + phoneNumber.slice(start + 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=characterInsert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["characterInsert","phoneNumber","newChar","selection","isARange","start","end","slice","hasBeenSelected","Math","max"],"sourceRoot":"../../../src","sources":["utils/characterInsert.ts"],"mappings":";;;;;;AAEO,SAASA,eAAeA,CAC7BC,WAAmB,EACnBC,OAAe,EACfC,SAAyB,EACjB;EACR,MAAMC,QAAQ,GAAGD,SAAS,CAACE,KAAK,KAAKF,SAAS,CAACG,GAAG;EAElD,IAAIF,QAAQ,EAAE;IACZ;IACA,OAAOH,WAAW,CAACM,KAAK,CAAC,CAAC,EAAEJ,SAAS,CAACE,KAAK,GAAG,CAAC,CAAC,GAAGH,OAAO,GAAGD,WAAW,CAACM,KAAK,CAACJ,SAAS,CAACG,GAAG,GAAG,CAAC,CAAC;EACnG,CAAC,MAAM,IAAIH,SAAS,CAACE,KAAK,KAAK,CAAC,IAAI,CAACF,SAAS,CAACK,eAAe,EAAE;IAC9D,OAAOP,WAAW,GAAGC,OAAO;EAC9B,CAAC,MAAM;IACL;IACA,MAAMG,KAAK,GAAGI,IAAI,CAACC,GAAG,CAACP,SAAS,CAACE,KAAK,EAAE,CAAC,CAAC;IAC1C,OAAOJ,WAAW,CAACM,KAAK,CAAC,CAAC,EAAEF,KAAK,GAAG,CAAC,CAAC,GAAGH,OAAO,GAAGD,WAAW,CAACM,KAAK,CAACF,KAAK,GAAG,CAAC,CAAC;EACjF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fromMaskedNumberToUnmaskedSelection = fromMaskedNumberToUnmaskedSelection;
|
|
7
|
+
function fromMaskedNumberToUnmaskedSelection(maskedValue, maskedPoint) {
|
|
8
|
+
let count = 0;
|
|
9
|
+
for (let i = 0; i < maskedPoint && i < maskedValue.length; i++) {
|
|
10
|
+
if (/\d/.test(maskedValue[i])) count++;
|
|
11
|
+
}
|
|
12
|
+
return count;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=fromMaskedNumberToUnmaskedSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fromMaskedNumberToUnmaskedSelection","maskedValue","maskedPoint","count","i","length","test"],"sourceRoot":"../../../src","sources":["utils/fromMaskedNumberToUnmaskedSelection.ts"],"mappings":";;;;;;AAAO,SAASA,mCAAmCA,CACjDC,WAAmB,EACnBC,WAAmB,EACX;EACR,IAAIC,KAAK,GAAG,CAAC;EACb,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,WAAW,IAAIE,CAAC,GAAGH,WAAW,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;IAC9D,IAAI,IAAI,CAACE,IAAI,CAACL,WAAW,CAACG,CAAC,CAAC,CAAC,EAAED,KAAK,EAAE;EACxC;EACA,OAAOA,KAAK;AACd","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fromUnmaskedToMaskedPosition = fromUnmaskedToMaskedPosition;
|
|
7
|
+
function fromUnmaskedToMaskedPosition(maskedValue, unmaskedPos) {
|
|
8
|
+
if (unmaskedPos <= 0) return 1;
|
|
9
|
+
let digitCount = 0;
|
|
10
|
+
for (let i = 0; i < maskedValue.length; i++) {
|
|
11
|
+
if (/\d/.test(maskedValue[i])) {
|
|
12
|
+
digitCount++;
|
|
13
|
+
if (digitCount === unmaskedPos) {
|
|
14
|
+
return i + 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return maskedValue.length;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=fromUnmaskedToMaskedPosition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fromUnmaskedToMaskedPosition","maskedValue","unmaskedPos","digitCount","i","length","test"],"sourceRoot":"../../../src","sources":["utils/fromUnmaskedToMaskedPosition.ts"],"mappings":";;;;;;AAAO,SAASA,4BAA4BA,CAACC,WAAmB,EAAEC,WAAmB,EAAU;EAC7F,IAAIA,WAAW,IAAI,CAAC,EAAE,OAAO,CAAC;EAC9B,IAAIC,UAAU,GAAG,CAAC;EAClB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,WAAW,CAACI,MAAM,EAAED,CAAC,EAAE,EAAE;IAC3C,IAAI,IAAI,CAACE,IAAI,CAACL,WAAW,CAACG,CAAC,CAAC,CAAC,EAAE;MAC7BD,UAAU,EAAE;MACZ,IAAIA,UAAU,KAAKD,WAAW,EAAE;QAC9B,OAAOE,CAAC,GAAG,CAAC;MACd;IACF;EACF;EACA,OAAOH,WAAW,CAACI,MAAM;AAC3B","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateCountryCodeList = generateCountryCodeList;
|
|
7
|
+
var _regions = require("../consts/regions");
|
|
8
|
+
function generateCountryCodeList(allowedCountryCodes, disallowedCountryCodes) {
|
|
9
|
+
return _regions.countryCodeList.filter(({
|
|
10
|
+
id
|
|
11
|
+
}) => {
|
|
12
|
+
if (allowedCountryCodes && !allowedCountryCodes.includes(id)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (disallowedCountryCodes && disallowedCountryCodes.includes(id)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
})
|
|
20
|
+
// sort by longer country codes first to ensure that we match the most specific country code when parsing the phone number
|
|
21
|
+
.sort((a, b) => b.code.length - a.code.length);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=generateCountryCodeList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_regions","require","generateCountryCodeList","allowedCountryCodes","disallowedCountryCodes","countryCodeList","filter","id","includes","sort","a","b","code","length"],"sourceRoot":"../../../src","sources":["utils/generateCountryCodeList.ts"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAGO,SAASC,uBAAuBA,CACrCC,mBAAiC,EACjCC,sBAAoC,EACpC;EACA,OACEC,wBAAe,CACZC,MAAM,CAAC,CAAC;IAAEC;EAAG,CAAC,KAAK;IAClB,IAAIJ,mBAAmB,IAAI,CAACA,mBAAmB,CAACK,QAAQ,CAACD,EAAE,CAAC,EAAE;MAC5D,OAAO,KAAK;IACd;IACA,IAAIH,sBAAsB,IAAIA,sBAAsB,CAACI,QAAQ,CAACD,EAAE,CAAC,EAAE;MACjE,OAAO,KAAK;IACd;IACA,OAAO,IAAI;EACb,CAAC;EACD;EAAA,CACCE,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKA,CAAC,CAACC,IAAI,CAACC,MAAM,GAAGH,CAAC,CAACE,IAAI,CAACC,MAAM,CAAC;AAEpD","ignoreList":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultRegion = getDefaultRegion;
|
|
7
|
+
exports.getDefaultRegionWithNullableState = getDefaultRegionWithNullableState;
|
|
8
|
+
var _expoLocalization = require("expo-localization");
|
|
9
|
+
function getDefaultRegion(filteredCountryCodes) {
|
|
10
|
+
const localization = (0, _expoLocalization.getLocales)();
|
|
11
|
+
// console.debug('localization', JSON.stringify(localization, null, 2));
|
|
12
|
+
const id = localization?.[0]?.regionCode;
|
|
13
|
+
if (id) {
|
|
14
|
+
const matchedCountry = filteredCountryCodes.find(country => country.id === id);
|
|
15
|
+
if (matchedCountry) {
|
|
16
|
+
return matchedCountry;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return filteredCountryCodes[0];
|
|
20
|
+
}
|
|
21
|
+
function getDefaultRegionWithNullableState(filteredCountryCodes) {
|
|
22
|
+
const localization = (0, _expoLocalization.getLocales)();
|
|
23
|
+
// console.debug('localization', JSON.stringify(localization, null, 2));
|
|
24
|
+
const id = localization?.[0]?.regionCode;
|
|
25
|
+
if (id) {
|
|
26
|
+
const matchedCountry = filteredCountryCodes.find(country => country.id === id);
|
|
27
|
+
if (matchedCountry) {
|
|
28
|
+
return matchedCountry;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=getDefaultRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_expoLocalization","require","getDefaultRegion","filteredCountryCodes","localization","getLocales","id","regionCode","matchedCountry","find","country","getDefaultRegionWithNullableState"],"sourceRoot":"../../../src","sources":["utils/getDefaultRegion.ts"],"mappings":";;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAGO,SAASC,gBAAgBA,CAACC,oBAAmC,EAAe;EACjF,MAAMC,YAAY,GAAG,IAAAC,4BAAU,EAAC,CAAC;EACjC;EACA,MAAMC,EAAE,GAAGF,YAAY,GAAG,CAAC,CAAC,EAAEG,UAAU;EACxC,IAAID,EAAE,EAAE;IACN,MAAME,cAAc,GAAGL,oBAAoB,CAACM,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACJ,EAAE,KAAKA,EAAE,CAAC;IAChF,IAAIE,cAAc,EAAE;MAClB,OAAOA,cAAc;IACvB;EACF;EACA,OAAOL,oBAAoB,CAAC,CAAC,CAAC;AAChC;AAEO,SAASQ,iCAAiCA,CAC/CR,oBAAmC,EACf;EACpB,MAAMC,YAAY,GAAG,IAAAC,4BAAU,EAAC,CAAC;EACjC;EACA,MAAMC,EAAE,GAAGF,YAAY,GAAG,CAAC,CAAC,EAAEG,UAAU;EACxC,IAAID,EAAE,EAAE;IACN,MAAME,cAAc,GAAGL,oBAAoB,CAACM,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACJ,EAAE,KAAKA,EAAE,CAAC;IAChF,IAAIE,cAAc,EAAE;MAClB,OAAOA,cAAc;IACvB;EACF;EACA,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.maskToPhoneNumber = maskToPhoneNumber;
|
|
7
|
+
function maskToPhoneNumber(rawInput, countryCode, mask) {
|
|
8
|
+
const justDigits = rawInput.replace(/\D/g, '');
|
|
9
|
+
const restOfNumber = justDigits.slice(countryCode.length, justDigits.length);
|
|
10
|
+
let digitIndex = 0;
|
|
11
|
+
let maskedPart = '';
|
|
12
|
+
for (const char of mask) {
|
|
13
|
+
console.debug('char', char, 'digitIndex', digitIndex, 'restOfNumber', restOfNumber, 'restOfNumber[digitIndex]', restOfNumber[digitIndex], 'Output', maskedPart);
|
|
14
|
+
if (digitIndex >= restOfNumber.length) break;
|
|
15
|
+
if (char === '#') {
|
|
16
|
+
maskedPart += restOfNumber[digitIndex++];
|
|
17
|
+
} else {
|
|
18
|
+
maskedPart += char;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return countryCode + maskedPart;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=maskToPhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["maskToPhoneNumber","rawInput","countryCode","mask","justDigits","replace","restOfNumber","slice","length","digitIndex","maskedPart","char","console","debug"],"sourceRoot":"../../../src","sources":["utils/maskToPhoneNumber.ts"],"mappings":";;;;;;AAAO,SAASA,iBAAiBA,CAACC,QAAgB,EAAEC,WAAmB,EAAEC,IAAY,EAAU;EAC7F,MAAMC,UAAU,GAAGH,QAAQ,CAACI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAC9C,MAAMC,YAAY,GAAGF,UAAU,CAACG,KAAK,CAACL,WAAW,CAACM,MAAM,EAAEJ,UAAU,CAACI,MAAM,CAAC;EAC5E,IAAIC,UAAU,GAAG,CAAC;EAClB,IAAIC,UAAU,GAAG,EAAE;EAEnB,KAAK,MAAMC,IAAI,IAAIR,IAAI,EAAE;IACvBS,OAAO,CAACC,KAAK,CACX,MAAM,EACNF,IAAI,EACJ,YAAY,EACZF,UAAU,EACV,cAAc,EACdH,YAAY,EACZ,0BAA0B,EAC1BA,YAAY,CAACG,UAAU,CAAC,EACxB,QAAQ,EACRC,UACF,CAAC;IAED,IAAID,UAAU,IAAIH,YAAY,CAACE,MAAM,EAAE;IACvC,IAAIG,IAAI,KAAK,GAAG,EAAE;MAChBD,UAAU,IAAIJ,YAAY,CAACG,UAAU,EAAE,CAAC;IAC1C,CAAC,MAAM;MACLC,UAAU,IAAIC,IAAI;IACpB;EACF;EAEA,OAAOT,WAAW,GAAGQ,UAAU;AACjC","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.matchCountryCode = matchCountryCode;
|
|
7
|
+
function matchCountryCode(filteredCountryCodes, rawInput) {
|
|
8
|
+
return filteredCountryCodes.find(({
|
|
9
|
+
code
|
|
10
|
+
}) => {
|
|
11
|
+
// intentional to use _value here instead of cleanedValue because we want to match against the raw input value that includes the '+' sign and any formatting characters, since country codes are typically prefixed with a '+' and may be followed by formatting characters like dashes or parentheses. Using cleanedValue would remove these characters and could lead to incorrect matching of country codes.
|
|
12
|
+
|
|
13
|
+
const phoneNumberWithoutPlus = rawInput.replace('+', '');
|
|
14
|
+
const CountryCodeWithoutPlus = code.replace('+', '');
|
|
15
|
+
const result = phoneNumberWithoutPlus.startsWith(CountryCodeWithoutPlus);
|
|
16
|
+
// console.debug(
|
|
17
|
+
// 'checking code',
|
|
18
|
+
// code,
|
|
19
|
+
// 'against cleanedValue',
|
|
20
|
+
// cleanedValue,
|
|
21
|
+
// 'result',
|
|
22
|
+
// result
|
|
23
|
+
// );
|
|
24
|
+
return result;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=matchCountryCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["matchCountryCode","filteredCountryCodes","rawInput","find","code","phoneNumberWithoutPlus","replace","CountryCodeWithoutPlus","result","startsWith"],"sourceRoot":"../../../src","sources":["utils/matchCountryCode.ts"],"mappings":";;;;;;AAEO,SAASA,gBAAgBA,CAC9BC,oBAAmC,EACnCC,QAAgB,EACS;EACzB,OAAOD,oBAAoB,CAACE,IAAI,CAAC,CAAC;IAAEC;EAAK,CAAC,KAAK;IAC7C;;IAEA,MAAMC,sBAAsB,GAAGH,QAAQ,CAACI,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;IACxD,MAAMC,sBAAsB,GAAGH,IAAI,CAACE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;IACpD,MAAME,MAAM,GAAGH,sBAAsB,CAACI,UAAU,CAACF,sBAAsB,CAAC;IACxE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,OAAOC,MAAM;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { Pressable, Text } from 'react-native';
|
|
5
|
+
import { CountrySelectorModal } from './CountrySelectorModal';
|
|
6
|
+
import { Feather } from '@expo/vector-icons';
|
|
7
|
+
|
|
8
|
+
// button for opening the country selector modal
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
//
|
|
11
|
+
|
|
12
|
+
function CountrySelectorButton(props) {
|
|
13
|
+
const Button = useMemo(() => {
|
|
14
|
+
if (props.underlineButton) {
|
|
15
|
+
console.debug('Using custom button for CountrySelectorButton');
|
|
16
|
+
return props.underlineButton;
|
|
17
|
+
}
|
|
18
|
+
console.debug('Using default Pressable for CountrySelectorButton');
|
|
19
|
+
return Pressable;
|
|
20
|
+
}, [props.underlineButton]);
|
|
21
|
+
return (
|
|
22
|
+
/*#__PURE__*/
|
|
23
|
+
// This could be a simple button that, when pressed, opens the country selector modal
|
|
24
|
+
_jsxs(Button, {
|
|
25
|
+
...props,
|
|
26
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
27
|
+
children: props.value ? props.value.flag : '🏴☠️'
|
|
28
|
+
}), /*#__PURE__*/_jsx(Feather, {
|
|
29
|
+
name: `chevron-${props.isOpen ? 'up' : 'down'}`,
|
|
30
|
+
size: 14,
|
|
31
|
+
color: "gray"
|
|
32
|
+
})]
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
export function CountrySelector(props) {
|
|
37
|
+
const [internalValue, setInternalValue] = useState(props.value);
|
|
38
|
+
const [internalIsOpen, setInternalIsOpen] = useState(false);
|
|
39
|
+
const {
|
|
40
|
+
filtedredCountryCodes,
|
|
41
|
+
onSelectCountry,
|
|
42
|
+
onOpenChange
|
|
43
|
+
} = props;
|
|
44
|
+
const isControlled = props.isOpen !== undefined;
|
|
45
|
+
const effectiveIsOpen = isControlled ? props.isOpen ?? false : internalIsOpen;
|
|
46
|
+
const toggle = useCallback(() => {
|
|
47
|
+
const next = !effectiveIsOpen;
|
|
48
|
+
if (!isControlled) setInternalIsOpen(next);
|
|
49
|
+
onOpenChange?.(next);
|
|
50
|
+
}, [effectiveIsOpen, isControlled, onOpenChange]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
setInternalValue(props.value);
|
|
53
|
+
}, [props.value]);
|
|
54
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
55
|
+
children: [/*#__PURE__*/_jsx(CountrySelectorButton, {
|
|
56
|
+
...props,
|
|
57
|
+
underlineButton: props.underlineButton,
|
|
58
|
+
value: internalValue,
|
|
59
|
+
isOpen: effectiveIsOpen,
|
|
60
|
+
onPress: toggle
|
|
61
|
+
}), /*#__PURE__*/_jsx(CountrySelectorModal, {
|
|
62
|
+
value: internalValue,
|
|
63
|
+
onSelectCountry: onSelectCountry ?? (() => {}),
|
|
64
|
+
UserCountryCodes: filtedredCountryCodes,
|
|
65
|
+
isOpen: effectiveIsOpen,
|
|
66
|
+
toggleModalVisablity: toggle
|
|
67
|
+
})]
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=CountrySelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","useState","Pressable","Text","CountrySelectorModal","Feather","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","CountrySelectorButton","props","Button","underlineButton","console","debug","children","value","flag","name","isOpen","size","color","CountrySelector","internalValue","setInternalValue","internalIsOpen","setInternalIsOpen","filtedredCountryCodes","onSelectCountry","onOpenChange","isControlled","undefined","effectiveIsOpen","toggle","next","onPress","UserCountryCodes","toggleModalVisablity"],"sourceRoot":"../../../src","sources":["CountrySelector/CountrySelector.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAEjE,SAAgBC,SAAS,EAAEC,IAAI,QAAQ,cAAc;AACrD,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,EAAAC,QAAA,IAAAC,SAAA;AAOA;;AAEA,SAASC,qBAAqBA,CAACC,KAAiC,EAAE;EAChE,MAAMC,MAAM,GAAGd,OAAO,CAAC,MAAM;IAC3B,IAAIa,KAAK,CAACE,eAAe,EAAE;MACzBC,OAAO,CAACC,KAAK,CAAC,+CAA+C,CAAC;MAC9D,OAAOJ,KAAK,CAACE,eAAe;IAC9B;IACAC,OAAO,CAACC,KAAK,CAAC,mDAAmD,CAAC;IAClE,OAAOf,SAAS;EAClB,CAAC,EAAE,CAACW,KAAK,CAACE,eAAe,CAAC,CAAC;EAC3B;IAAA;IACE;IACAN,KAAA,CAACK,MAAM;MAAA,GAAKD,KAAK;MAAAK,QAAA,gBACfX,IAAA,CAACJ,IAAI;QAAAe,QAAA,EAAEL,KAAK,CAACM,KAAK,GAAGN,KAAK,CAACM,KAAK,CAACC,IAAI,GAAG;MAAO,CAAO,CAAC,eACvDb,IAAA,CAACF,OAAO;QAACgB,IAAI,EAAE,WAAWR,KAAK,CAACS,MAAM,GAAG,IAAI,GAAG,MAAM,EAAG;QAACC,IAAI,EAAE,EAAG;QAACC,KAAK,EAAC;MAAM,CAAE,CAAC;IAAA,CAC7E;EAAC;AAEb;AASA,OAAO,SAASC,eAAeA,CAACZ,KAA2B,EAAE;EAC3D,MAAM,CAACa,aAAa,EAAEC,gBAAgB,CAAC,GAAG1B,QAAQ,CAACY,KAAK,CAACM,KAAK,CAAC;EAC/D,MAAM,CAACS,cAAc,EAAEC,iBAAiB,CAAC,GAAG5B,QAAQ,CAAC,KAAK,CAAC;EAC3D,MAAM;IAAE6B,qBAAqB;IAAEC,eAAe;IAAEC;EAAa,CAAC,GAAGnB,KAAK;EAEtE,MAAMoB,YAAY,GAAGpB,KAAK,CAACS,MAAM,KAAKY,SAAS;EAC/C,MAAMC,eAAe,GAAGF,YAAY,GAAIpB,KAAK,CAACS,MAAM,IAAI,KAAK,GAAIM,cAAc;EAE/E,MAAMQ,MAAM,GAAGtC,WAAW,CAAC,MAAM;IAC/B,MAAMuC,IAAI,GAAG,CAACF,eAAe;IAC7B,IAAI,CAACF,YAAY,EAAEJ,iBAAiB,CAACQ,IAAI,CAAC;IAC1CL,YAAY,GAAGK,IAAI,CAAC;EACtB,CAAC,EAAE,CAACF,eAAe,EAAEF,YAAY,EAAED,YAAY,CAAC,CAAC;EAEjDjC,SAAS,CAAC,MAAM;IACd4B,gBAAgB,CAACd,KAAK,CAACM,KAAK,CAAC;EAC/B,CAAC,EAAE,CAACN,KAAK,CAACM,KAAK,CAAC,CAAC;EAEjB,oBACEV,KAAA,CAAAE,SAAA;IAAAO,QAAA,gBACEX,IAAA,CAACK,qBAAqB;MAAA,GAChBC,KAAK;MACTE,eAAe,EAAEF,KAAK,CAACE,eAAgB;MACvCI,KAAK,EAAEO,aAAc;MACrBJ,MAAM,EAAEa,eAAgB;MACxBG,OAAO,EAAEF;IAAO,CACjB,CAAC,eACF7B,IAAA,CAACH,oBAAoB;MACnBe,KAAK,EAAEO,aAAc;MACrBK,eAAe,EAAEA,eAAe,KAAK,MAAM,CAAC,CAAC,CAAE;MAC/CQ,gBAAgB,EAAET,qBAAsB;MACxCR,MAAM,EAAEa,eAAgB;MACxBK,oBAAoB,EAAEJ;IAAO,CAC9B,CAAC;EAAA,CACF,CAAC;AAEP","ignoreList":[]}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
+
import { Modal, View, Text, StyleSheet, useWindowDimensions, TouchableWithoutFeedback, TextInput, SectionList, Pressable } from 'react-native';
|
|
5
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
6
|
+
import { Feather } from '@expo/vector-icons';
|
|
7
|
+
import { getDefaultRegionWithNullableState } from '../utils/getDefaultRegion';
|
|
8
|
+
import { spacing, borderWidth as borders, fontSize as fontSizes, padding, borderWidth, radius, SIDE_SCREEN_PADDING } from '../Styling/Sizing';
|
|
9
|
+
import { colors } from '../Styling/Colors';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const CLICK_COUNTS_KEY = '@country_selector_click_counts';
|
|
12
|
+
const RECENT_SECTION_COUNT = 4;
|
|
13
|
+
export function CountrySelectorModal(props) {
|
|
14
|
+
const {
|
|
15
|
+
height
|
|
16
|
+
} = useWindowDimensions();
|
|
17
|
+
const [searchValue, setSearchValue] = useState('');
|
|
18
|
+
const [clickCounts, setClickCounts] = useState({});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
AsyncStorage.getItem(CLICK_COUNTS_KEY).then(raw => {
|
|
21
|
+
if (raw) setClickCounts(JSON.parse(raw));
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
const recordClick = useCallback(async country => {
|
|
25
|
+
const updated = {
|
|
26
|
+
...clickCounts,
|
|
27
|
+
[country.id]: (clickCounts[country.id] ?? 0) + 1
|
|
28
|
+
};
|
|
29
|
+
setClickCounts(updated);
|
|
30
|
+
await AsyncStorage.setItem(CLICK_COUNTS_KEY, JSON.stringify(updated));
|
|
31
|
+
}, [clickCounts]);
|
|
32
|
+
const recentSection = useMemo(() => {
|
|
33
|
+
const allCountries = props.UserCountryCodes ?? [];
|
|
34
|
+
const defaultCountry = getDefaultRegionWithNullableState(allCountries);
|
|
35
|
+
const topClicked = Object.entries(clickCounts).sort(([, a], [, b]) => b - a).slice(0, RECENT_SECTION_COUNT).map(([id]) => allCountries.find(c => c.id === id)).filter(c => c != null);
|
|
36
|
+
if (!defaultCountry && topClicked.length === 0) return null;
|
|
37
|
+
const data = [];
|
|
38
|
+
if (defaultCountry) data.push(defaultCountry);
|
|
39
|
+
for (const c of topClicked) {
|
|
40
|
+
if (!data.some(d => d.id === c.id)) data.push(c);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
title: 'Recent Countries',
|
|
44
|
+
data
|
|
45
|
+
};
|
|
46
|
+
}, [clickCounts, props.UserCountryCodes]);
|
|
47
|
+
const sections = useMemo(() => {
|
|
48
|
+
const sorted = [...(props.UserCountryCodes ?? [])].sort((a, b) => a.name.localeCompare(b.name));
|
|
49
|
+
const filtered = searchValue.length < 1 ? sorted : sorted.filter(({
|
|
50
|
+
name,
|
|
51
|
+
code,
|
|
52
|
+
id
|
|
53
|
+
}) => name.toLowerCase().includes(searchValue.toLowerCase()) || code.includes(searchValue) || id.toLowerCase().includes(searchValue.toLowerCase()));
|
|
54
|
+
const grouped = filtered.reduce((acc, country) => {
|
|
55
|
+
let letter = country.name[0].toUpperCase();
|
|
56
|
+
if (letter === 'Å') {
|
|
57
|
+
letter = 'A';
|
|
58
|
+
}
|
|
59
|
+
if (!acc[letter]) acc[letter] = [];
|
|
60
|
+
acc[letter].push(country);
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
63
|
+
const alphaSections = Object.keys(grouped).sort().map(letter => ({
|
|
64
|
+
title: letter,
|
|
65
|
+
data: grouped[letter]
|
|
66
|
+
}));
|
|
67
|
+
return alphaSections;
|
|
68
|
+
}, [props.UserCountryCodes, searchValue]);
|
|
69
|
+
const allSections = useMemo(() => {
|
|
70
|
+
if (searchValue.length > 0 || !recentSection) return sections;
|
|
71
|
+
return [recentSection, ...sections];
|
|
72
|
+
}, [recentSection, sections, searchValue]);
|
|
73
|
+
const UserModal = useMemo(() => {
|
|
74
|
+
if (props.underlineModal) {
|
|
75
|
+
console.debug('underlineModal');
|
|
76
|
+
return props.underlineModal;
|
|
77
|
+
}
|
|
78
|
+
console.debug('underlineModal - underfine');
|
|
79
|
+
return undefined;
|
|
80
|
+
}, [props.underlineModal]);
|
|
81
|
+
if (UserModal) {
|
|
82
|
+
return /*#__PURE__*/_jsx(UserModal, {
|
|
83
|
+
...props
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return /*#__PURE__*/_jsx(Modal, {
|
|
87
|
+
animationType: "slide",
|
|
88
|
+
visible: props.isOpen,
|
|
89
|
+
transparent: true,
|
|
90
|
+
children: /*#__PURE__*/_jsxs(View, {
|
|
91
|
+
style: styles.overlay,
|
|
92
|
+
children: [/*#__PURE__*/_jsx(TouchableWithoutFeedback, {
|
|
93
|
+
onPress: () => {
|
|
94
|
+
props.toggleModalVisablity();
|
|
95
|
+
setSearchValue('');
|
|
96
|
+
},
|
|
97
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
98
|
+
style: StyleSheet.absoluteFillObject
|
|
99
|
+
})
|
|
100
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
101
|
+
style: [styles.container, {
|
|
102
|
+
height: height / 2.5
|
|
103
|
+
}],
|
|
104
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
105
|
+
style: {
|
|
106
|
+
backgroundColor: colors.white,
|
|
107
|
+
padding: padding[3],
|
|
108
|
+
borderTopLeftRadius: radius['3xl'],
|
|
109
|
+
borderTopRightRadius: radius['3xl']
|
|
110
|
+
},
|
|
111
|
+
children: /*#__PURE__*/_jsxs(View, {
|
|
112
|
+
style: styles.searchContainer,
|
|
113
|
+
children: [/*#__PURE__*/_jsx(Feather, {
|
|
114
|
+
name: "search",
|
|
115
|
+
size: 16,
|
|
116
|
+
color: "gray"
|
|
117
|
+
}), /*#__PURE__*/_jsx(TextInput, {
|
|
118
|
+
placeholder: "Country name or code",
|
|
119
|
+
style: styles.searchInput,
|
|
120
|
+
value: searchValue,
|
|
121
|
+
onChangeText: value => {
|
|
122
|
+
setSearchValue(value);
|
|
123
|
+
}
|
|
124
|
+
})]
|
|
125
|
+
})
|
|
126
|
+
}), /*#__PURE__*/_jsx(SectionList, {
|
|
127
|
+
ItemSeparatorComponent: () => /*#__PURE__*/_jsx(View, {
|
|
128
|
+
style: styles.divider
|
|
129
|
+
}),
|
|
130
|
+
sections: allSections,
|
|
131
|
+
keyExtractor: (item, index) => `${item.id}-${index}`,
|
|
132
|
+
style: {
|
|
133
|
+
borderTopLeftRadius: radius['lg'],
|
|
134
|
+
borderTopRightRadius: radius['lg']
|
|
135
|
+
},
|
|
136
|
+
renderSectionHeader: ({
|
|
137
|
+
section
|
|
138
|
+
}) => /*#__PURE__*/_jsx(View, {
|
|
139
|
+
style: styles.sectionHeader,
|
|
140
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
141
|
+
style: styles.sectionHeaderText,
|
|
142
|
+
children: section.title
|
|
143
|
+
})
|
|
144
|
+
}),
|
|
145
|
+
renderItem: ({
|
|
146
|
+
item,
|
|
147
|
+
index,
|
|
148
|
+
section
|
|
149
|
+
}) => {
|
|
150
|
+
const isSelected = item.id === props.value?.id;
|
|
151
|
+
const isFirst = index === 0;
|
|
152
|
+
const isLast = index === section.data.length - 1;
|
|
153
|
+
return /*#__PURE__*/_jsxs(Pressable, {
|
|
154
|
+
onPress: () => {
|
|
155
|
+
recordClick(item);
|
|
156
|
+
props.onSelectCountry(item);
|
|
157
|
+
props.toggleModalVisablity();
|
|
158
|
+
setSearchValue('');
|
|
159
|
+
},
|
|
160
|
+
style: {
|
|
161
|
+
padding: spacing[3],
|
|
162
|
+
gap: spacing[1],
|
|
163
|
+
marginHorizontal: SIDE_SCREEN_PADDING,
|
|
164
|
+
backgroundColor: isSelected ? colors.blue[50] : colors.white,
|
|
165
|
+
borderTopLeftRadius: isFirst ? radius.lg : 0,
|
|
166
|
+
borderTopRightRadius: isFirst ? radius.lg : 0,
|
|
167
|
+
borderBottomLeftRadius: isLast ? radius.lg : 0,
|
|
168
|
+
borderBottomRightRadius: isLast ? radius.lg : 0
|
|
169
|
+
},
|
|
170
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
171
|
+
style: {
|
|
172
|
+
flexDirection: 'row',
|
|
173
|
+
gap: spacing[1],
|
|
174
|
+
alignItems: 'center'
|
|
175
|
+
},
|
|
176
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
177
|
+
children: item.flag
|
|
178
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
179
|
+
style: [{
|
|
180
|
+
flexShrink: 1
|
|
181
|
+
}, isSelected ? {
|
|
182
|
+
fontWeight: '600'
|
|
183
|
+
} : undefined],
|
|
184
|
+
children: item.name
|
|
185
|
+
}), /*#__PURE__*/_jsxs(Text, {
|
|
186
|
+
children: ["(", item.code, ")"]
|
|
187
|
+
}), isSelected && /*#__PURE__*/_jsx(Feather, {
|
|
188
|
+
name: "check",
|
|
189
|
+
size: 14,
|
|
190
|
+
color: colors.blue[500],
|
|
191
|
+
style: {
|
|
192
|
+
marginLeft: 'auto'
|
|
193
|
+
}
|
|
194
|
+
})]
|
|
195
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
196
|
+
children: /*#__PURE__*/_jsxs(Text, {
|
|
197
|
+
style: {
|
|
198
|
+
fontSize: fontSizes.xs,
|
|
199
|
+
color: colors.gray[400],
|
|
200
|
+
paddingHorizontal: padding[0.5]
|
|
201
|
+
},
|
|
202
|
+
children: [item.code, " ", item.mask.replace(/\#/g, '_')]
|
|
203
|
+
})
|
|
204
|
+
})]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
})]
|
|
208
|
+
})]
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const styles = StyleSheet.create({
|
|
213
|
+
overlay: {
|
|
214
|
+
flex: 1,
|
|
215
|
+
justifyContent: 'flex-end'
|
|
216
|
+
},
|
|
217
|
+
container: {
|
|
218
|
+
backgroundColor: colors.gray[200],
|
|
219
|
+
// gap: gap[4],
|
|
220
|
+
borderTopLeftRadius: radius['3xl'],
|
|
221
|
+
borderTopRightRadius: radius['3xl'],
|
|
222
|
+
shadowColor: '#000',
|
|
223
|
+
shadowOffset: {
|
|
224
|
+
width: 0,
|
|
225
|
+
height: -4
|
|
226
|
+
},
|
|
227
|
+
shadowOpacity: 0.25,
|
|
228
|
+
shadowRadius: 8
|
|
229
|
+
},
|
|
230
|
+
searchContainer: {
|
|
231
|
+
height: 40,
|
|
232
|
+
flexDirection: 'row',
|
|
233
|
+
alignItems: 'center',
|
|
234
|
+
borderWidth: borders.DEFAULT,
|
|
235
|
+
borderColor: colors.gray[100],
|
|
236
|
+
paddingHorizontal: spacing[1],
|
|
237
|
+
backgroundColor: colors.gray[300],
|
|
238
|
+
borderRadius: radius['2xl']
|
|
239
|
+
},
|
|
240
|
+
searchInput: {
|
|
241
|
+
flex: 1,
|
|
242
|
+
padding: spacing[1]
|
|
243
|
+
},
|
|
244
|
+
divider: {
|
|
245
|
+
height: borderWidth.DEFAULT,
|
|
246
|
+
backgroundColor: colors.gray[200],
|
|
247
|
+
marginHorizontal: spacing[1.5]
|
|
248
|
+
},
|
|
249
|
+
sectionHeader: {
|
|
250
|
+
backgroundColor: colors.gray[200],
|
|
251
|
+
paddingHorizontal: SIDE_SCREEN_PADDING,
|
|
252
|
+
paddingVertical: spacing[2]
|
|
253
|
+
},
|
|
254
|
+
sectionHeaderText: {
|
|
255
|
+
fontSize: fontSizes.xs,
|
|
256
|
+
fontWeight: '700',
|
|
257
|
+
color: colors.gray[500],
|
|
258
|
+
textTransform: 'uppercase',
|
|
259
|
+
letterSpacing: 0.8
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
//# sourceMappingURL=CountrySelectorModal.js.map
|