@rh-support/components 2.1.69 → 2.1.70
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/lib/esm/PhoneInput/PhoneInput.js +15 -13
- package/package.json +2 -2
|
@@ -57,6 +57,7 @@ const removeAllChars = (value) => {
|
|
|
57
57
|
};
|
|
58
58
|
// Formatting phone numbers according to country
|
|
59
59
|
const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
60
|
+
var _a;
|
|
60
61
|
if (isEmpty(fullPhoneNumber))
|
|
61
62
|
return '';
|
|
62
63
|
let localPhone = fullPhoneNumber === null || fullPhoneNumber === void 0 ? void 0 : fullPhoneNumber.replace(PREFIX, '');
|
|
@@ -67,7 +68,7 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
|
67
68
|
let phone = '';
|
|
68
69
|
[...fullPhoneNumber].forEach((ele) => {
|
|
69
70
|
if (ele >= '0' && ele <= '9') {
|
|
70
|
-
phone = phone.concat(ele);
|
|
71
|
+
phone = phone === null || phone === void 0 ? void 0 : phone.concat(ele);
|
|
71
72
|
}
|
|
72
73
|
});
|
|
73
74
|
let pattern = '';
|
|
@@ -81,26 +82,27 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
|
81
82
|
pattern += localFormat[j];
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
const isPatternWithPrefix = pattern.replace(/\s+/g, '').startsWith(PREFIX);
|
|
85
|
+
const isPatternWithPrefix = (_a = pattern.replace(/\s+/g, '')) === null || _a === void 0 ? void 0 : _a.startsWith(PREFIX);
|
|
85
86
|
pattern = isPatternWithPrefix ? pattern : !isEmpty(isPatternWithPrefix) ? PREFIX + pattern : '';
|
|
86
87
|
return pattern;
|
|
87
88
|
};
|
|
88
89
|
// return phoneline and countrycode for any given phone
|
|
89
90
|
export const getPhoneObj = (phoneNumber) => {
|
|
91
|
+
var _a, _b, _c;
|
|
90
92
|
let localPhone = removeAllChars(phoneNumber);
|
|
91
93
|
let countryCode = '';
|
|
92
94
|
// Guessing countries according to user input
|
|
93
95
|
const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
|
|
94
|
-
const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localPhone);
|
|
96
|
+
const exactCountry = initializedCountries.filter((country) => { var _a; return ((_a = country.dialCode) === null || _a === void 0 ? void 0 : _a.toString()) === localPhone; });
|
|
95
97
|
if (!isEmpty(exactCountry)) {
|
|
96
|
-
countryCode = PREFIX + exactCountry[0].dialCode.toString();
|
|
98
|
+
countryCode = PREFIX + ((_a = exactCountry[0]) === null || _a === void 0 ? void 0 : _a.dialCode.toString());
|
|
97
99
|
}
|
|
98
100
|
else if (!isEmpty(possibleCountries)) {
|
|
99
|
-
countryCode = PREFIX + possibleCountries[0].dialCode.toString();
|
|
101
|
+
countryCode = PREFIX + ((_b = possibleCountries[0]) === null || _b === void 0 ? void 0 : _b.dialCode.toString());
|
|
100
102
|
}
|
|
101
103
|
return {
|
|
102
104
|
countryCode: countryCode,
|
|
103
|
-
phoneLine: localPhone === null || localPhone === void 0 ? void 0 : localPhone.substring(trimAndReplacePlusFromPhone(countryCode).length, localPhone.length),
|
|
105
|
+
phoneLine: localPhone === null || localPhone === void 0 ? void 0 : localPhone.substring((_c = trimAndReplacePlusFromPhone(countryCode)) === null || _c === void 0 ? void 0 : _c.length, localPhone === null || localPhone === void 0 ? void 0 : localPhone.length),
|
|
104
106
|
};
|
|
105
107
|
};
|
|
106
108
|
export function PhoneInput(props) {
|
|
@@ -117,12 +119,12 @@ export function PhoneInput(props) {
|
|
|
117
119
|
let localFormat;
|
|
118
120
|
// Guessing countries according to user input
|
|
119
121
|
const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
|
|
120
|
-
const possibleCountriesPhoneInitials = possibleCountries.map((country) => country.phoneInitials);
|
|
122
|
+
const possibleCountriesPhoneInitials = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.map((country) => country.phoneInitials);
|
|
121
123
|
// Function to find the matching country index based on user phone input
|
|
122
124
|
const findMatchingIndex = (possibleCountry, phone) => {
|
|
123
|
-
for (let i = 0; i < possibleCountry.length; i++) {
|
|
125
|
+
for (let i = 0; i < (possibleCountry === null || possibleCountry === void 0 ? void 0 : possibleCountry.length); i++) {
|
|
124
126
|
const country = possibleCountry[i];
|
|
125
|
-
for (let j = 0; j < country.length; j++) {
|
|
127
|
+
for (let j = 0; j < (country === null || country === void 0 ? void 0 : country.length); j++) {
|
|
126
128
|
if (phone.startsWith(country[j])) {
|
|
127
129
|
return i;
|
|
128
130
|
}
|
|
@@ -131,7 +133,7 @@ export function PhoneInput(props) {
|
|
|
131
133
|
return -1; // Return -1 if no match is found
|
|
132
134
|
};
|
|
133
135
|
const countryMatchingIndex = findMatchingIndex(possibleCountriesPhoneInitials, localPhone);
|
|
134
|
-
const defaultCountry = possibleCountries.filter((country) => (localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString())) && isEqual(country.priority, 0));
|
|
136
|
+
const defaultCountry = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.filter((country) => (localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString())) && isEqual(country.priority, 0));
|
|
135
137
|
const possibleDefaultCountry = !isUndefined(defaultCountry[0]) ? defaultCountry[0] : []; // default country when phone didn't match with any country's area code
|
|
136
138
|
const exactCountry = countryMatchingIndex < 0 ? possibleDefaultCountry : possibleCountries[countryMatchingIndex];
|
|
137
139
|
if (!isEmpty(exactCountry)) {
|
|
@@ -159,11 +161,11 @@ export function PhoneInput(props) {
|
|
|
159
161
|
const localFormat = setLocalFormat(phone);
|
|
160
162
|
const _formattedNumber = formatNumber(phone, localFormat);
|
|
161
163
|
setFormattedNumber(_formattedNumber);
|
|
162
|
-
if (!phone.trim().startsWith(PREFIX) && regex.test(phone) && !isEqual(phone, '-')) {
|
|
163
|
-
onPhoneValueChange(PREFIX + phone.trim());
|
|
164
|
+
if (!(phone === null || phone === void 0 ? void 0 : phone.trim().startsWith(PREFIX)) && regex.test(phone) && !isEqual(phone, '-')) {
|
|
165
|
+
onPhoneValueChange(PREFIX + (phone === null || phone === void 0 ? void 0 : phone.trim()));
|
|
164
166
|
}
|
|
165
167
|
else {
|
|
166
|
-
onPhoneValueChange(phone.slice(0, localFormat.length));
|
|
168
|
+
onPhoneValueChange(phone === null || phone === void 0 ? void 0 : phone.slice(0, localFormat === null || localFormat === void 0 ? void 0 : localFormat.length));
|
|
167
169
|
}
|
|
168
170
|
};
|
|
169
171
|
const onToggle = (isOpen) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.70",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"defaults and supports es6-module",
|
|
110
110
|
"maintained node versions"
|
|
111
111
|
],
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "e840019f9485b934d8d2b5163b4a94c3fc4ae2d2"
|
|
113
113
|
}
|