@rh-support/components 2.1.69 → 2.1.71
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.
|
@@ -12,6 +12,17 @@ interface IProps {
|
|
|
12
12
|
isDisabled?: boolean;
|
|
13
13
|
shouldNotSetCountryCode?: boolean;
|
|
14
14
|
}
|
|
15
|
+
export declare const getExactCountry: (phoneNumber: string) => any[] | {
|
|
16
|
+
name: string | number | string[];
|
|
17
|
+
regions: string | number | string[];
|
|
18
|
+
iso2: string | number | string[];
|
|
19
|
+
countryCode: string | number | string[];
|
|
20
|
+
dialCode: string | number | string[];
|
|
21
|
+
format: string;
|
|
22
|
+
priority: string | number | string[];
|
|
23
|
+
areaCode: string | number | string[];
|
|
24
|
+
phoneInitials: string[];
|
|
25
|
+
};
|
|
15
26
|
export declare const getPhoneObj: (phoneNumber: string) => {
|
|
16
27
|
countryCode: string;
|
|
17
28
|
phoneLine: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAO3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;
|
|
1
|
+
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAO3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;AAoDD,eAAO,MAAM,eAAe,gBAAiB,MAAM;;;;;;;;;;CAmClD,CAAC;AAqCF,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAgB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,qBAwLvC"}
|
|
@@ -55,8 +55,33 @@ const removeAllChars = (value) => {
|
|
|
55
55
|
// to remove all chars, brackets and have only digits
|
|
56
56
|
return value === null || value === void 0 ? void 0 : value.replace(/[^0-9]/g, '');
|
|
57
57
|
};
|
|
58
|
+
// guess exact country for any given phone
|
|
59
|
+
export const getExactCountry = (phoneNumber) => {
|
|
60
|
+
let localPhone = removeAllChars(phoneNumber);
|
|
61
|
+
// Guessing countries according to user input
|
|
62
|
+
const possibleCountries = initializedCountries === null || initializedCountries === void 0 ? void 0 : initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
|
|
63
|
+
const possibleCountriesPhoneInitials = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.map((country) => country.phoneInitials);
|
|
64
|
+
// Function to find the matching country index based on user phone input
|
|
65
|
+
const findMatchingIndex = (possibleCountry, phone) => {
|
|
66
|
+
for (let i = 0; i < (possibleCountry === null || possibleCountry === void 0 ? void 0 : possibleCountry.length); i++) {
|
|
67
|
+
const country = possibleCountry[i];
|
|
68
|
+
for (let j = 0; j < (country === null || country === void 0 ? void 0 : country.length); j++) {
|
|
69
|
+
if (phone.startsWith(country[j])) {
|
|
70
|
+
return i;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return -1; // Return -1 if no match is found
|
|
75
|
+
};
|
|
76
|
+
const countryMatchingIndex = findMatchingIndex(possibleCountriesPhoneInitials, localPhone);
|
|
77
|
+
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));
|
|
78
|
+
const possibleDefaultCountry = !isEmpty(defaultCountry[0]) && !isUndefined(defaultCountry[0]) ? defaultCountry[0] : []; // default country when phone didn't match with any country's area code
|
|
79
|
+
const exactCountry = countryMatchingIndex < 0 ? possibleDefaultCountry : possibleCountries[countryMatchingIndex];
|
|
80
|
+
return exactCountry;
|
|
81
|
+
};
|
|
58
82
|
// Formatting phone numbers according to country
|
|
59
83
|
const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
84
|
+
var _a;
|
|
60
85
|
if (isEmpty(fullPhoneNumber))
|
|
61
86
|
return '';
|
|
62
87
|
let localPhone = fullPhoneNumber === null || fullPhoneNumber === void 0 ? void 0 : fullPhoneNumber.replace(PREFIX, '');
|
|
@@ -67,7 +92,7 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
|
67
92
|
let phone = '';
|
|
68
93
|
[...fullPhoneNumber].forEach((ele) => {
|
|
69
94
|
if (ele >= '0' && ele <= '9') {
|
|
70
|
-
phone = phone.concat(ele);
|
|
95
|
+
phone = phone === null || phone === void 0 ? void 0 : phone.concat(ele);
|
|
71
96
|
}
|
|
72
97
|
});
|
|
73
98
|
let pattern = '';
|
|
@@ -81,26 +106,25 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
|
81
106
|
pattern += localFormat[j];
|
|
82
107
|
}
|
|
83
108
|
}
|
|
84
|
-
const isPatternWithPrefix = pattern.replace(/\s+/g, '').startsWith(PREFIX);
|
|
109
|
+
const isPatternWithPrefix = (_a = pattern.replace(/\s+/g, '')) === null || _a === void 0 ? void 0 : _a.startsWith(PREFIX);
|
|
85
110
|
pattern = isPatternWithPrefix ? pattern : !isEmpty(isPatternWithPrefix) ? PREFIX + pattern : '';
|
|
86
111
|
return pattern;
|
|
87
112
|
};
|
|
88
113
|
// return phoneline and countrycode for any given phone
|
|
89
114
|
export const getPhoneObj = (phoneNumber) => {
|
|
115
|
+
var _a;
|
|
90
116
|
let localPhone = removeAllChars(phoneNumber);
|
|
91
117
|
let countryCode = '';
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (!isEmpty(exactCountry)) {
|
|
96
|
-
countryCode = PREFIX + exactCountry[0].dialCode.toString();
|
|
118
|
+
const exactCountry = getExactCountry(localPhone);
|
|
119
|
+
if (!isEmpty(exactCountry) && !isEmpty(exactCountry['dialCode'].toString())) {
|
|
120
|
+
countryCode = PREFIX + exactCountry['dialCode'].toString();
|
|
97
121
|
}
|
|
98
|
-
else
|
|
99
|
-
countryCode =
|
|
122
|
+
else {
|
|
123
|
+
countryCode = '';
|
|
100
124
|
}
|
|
101
125
|
return {
|
|
102
126
|
countryCode: countryCode,
|
|
103
|
-
phoneLine: localPhone === null || localPhone === void 0 ? void 0 : localPhone.substring(trimAndReplacePlusFromPhone(countryCode).length, localPhone.length),
|
|
127
|
+
phoneLine: localPhone === null || localPhone === void 0 ? void 0 : localPhone.substring((_a = trimAndReplacePlusFromPhone(countryCode)) === null || _a === void 0 ? void 0 : _a.length, localPhone === null || localPhone === void 0 ? void 0 : localPhone.length),
|
|
104
128
|
};
|
|
105
129
|
};
|
|
106
130
|
export function PhoneInput(props) {
|
|
@@ -115,25 +139,7 @@ export function PhoneInput(props) {
|
|
|
115
139
|
return DEFAULT_FORMAT; // default format for portal phone without country code
|
|
116
140
|
}
|
|
117
141
|
let localFormat;
|
|
118
|
-
|
|
119
|
-
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);
|
|
121
|
-
// Function to find the matching country index based on user phone input
|
|
122
|
-
const findMatchingIndex = (possibleCountry, phone) => {
|
|
123
|
-
for (let i = 0; i < possibleCountry.length; i++) {
|
|
124
|
-
const country = possibleCountry[i];
|
|
125
|
-
for (let j = 0; j < country.length; j++) {
|
|
126
|
-
if (phone.startsWith(country[j])) {
|
|
127
|
-
return i;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return -1; // Return -1 if no match is found
|
|
132
|
-
};
|
|
133
|
-
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));
|
|
135
|
-
const possibleDefaultCountry = !isUndefined(defaultCountry[0]) ? defaultCountry[0] : []; // default country when phone didn't match with any country's area code
|
|
136
|
-
const exactCountry = countryMatchingIndex < 0 ? possibleDefaultCountry : possibleCountries[countryMatchingIndex];
|
|
142
|
+
const exactCountry = getExactCountry(localPhone);
|
|
137
143
|
if (!isEmpty(exactCountry)) {
|
|
138
144
|
setIso2(exactCountry['iso2'].toString());
|
|
139
145
|
localFormat = exactCountry['format'].toString();
|
|
@@ -159,11 +165,11 @@ export function PhoneInput(props) {
|
|
|
159
165
|
const localFormat = setLocalFormat(phone);
|
|
160
166
|
const _formattedNumber = formatNumber(phone, localFormat);
|
|
161
167
|
setFormattedNumber(_formattedNumber);
|
|
162
|
-
if (!phone.trim().startsWith(PREFIX) && regex.test(phone) && !isEqual(phone, '-')) {
|
|
163
|
-
onPhoneValueChange(PREFIX + phone.trim());
|
|
168
|
+
if (!(phone === null || phone === void 0 ? void 0 : phone.trim().startsWith(PREFIX)) && regex.test(phone) && !isEqual(phone, '-')) {
|
|
169
|
+
onPhoneValueChange(PREFIX + (phone === null || phone === void 0 ? void 0 : phone.trim()));
|
|
164
170
|
}
|
|
165
171
|
else {
|
|
166
|
-
onPhoneValueChange(phone.slice(0, localFormat.length));
|
|
172
|
+
onPhoneValueChange(phone === null || phone === void 0 ? void 0 : phone.slice(0, localFormat === null || localFormat === void 0 ? void 0 : localFormat.length));
|
|
167
173
|
}
|
|
168
174
|
};
|
|
169
175
|
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.71",
|
|
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": "9de4fff35aa1e2abec92656fa48e1b7b759a9e6c"
|
|
113
113
|
}
|