@rh-support/components 2.1.4 → 2.1.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAU3B,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;CACxB;AA0DD,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAqB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,eA+LvC"}
1
+ {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAU3B,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;CACxB;AA0DD,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAqB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,eAiNvC"}
@@ -70,7 +70,7 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
70
70
  });
71
71
  let pattern = '';
72
72
  let i = 0;
73
- for (let j = 0; j < localFormat.length && i < phone.length; j++) {
73
+ for (let j = 0; j < (localFormat === null || localFormat === void 0 ? void 0 : localFormat.length) && i < phone.length; j++) {
74
74
  if (localFormat[j] === '.') {
75
75
  pattern += phone[i];
76
76
  i++;
@@ -117,17 +117,30 @@ function PhoneInput(props) {
117
117
  });
118
118
  const setLocalFormat = (phoneNumber) => {
119
119
  let localPhone = phoneNumber.replace(PREFIX, '').trim();
120
+ localPhone = localPhone.replace('(', '').trim();
121
+ // if the user selects a value from the dropdown and the country code is the same as prev, iso2 values shouldn't override
122
+ if (!isEmpty_1.default(countryObj) && isEqual_1.default(localPhone, countryObj.dialCode)) {
123
+ return countryObj.format;
124
+ }
120
125
  let localFormat;
121
126
  // Guessing countries according to user input
122
127
  const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
123
128
  const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localPhone);
124
129
  if (!isEmpty_1.default(exactCountry)) {
130
+ if (isEqual_1.default(exactCountry[0].dialCode.toString(), countryObj.dialCode)) {
131
+ setIso2(countryObj.iso2);
132
+ return countryObj.format;
133
+ }
125
134
  setIso2(exactCountry[0].iso2.toString());
126
135
  localFormat = exactCountry[0].format.toString();
127
136
  onCountryCodeChange && onCountryCodeChange(PREFIX + exactCountry[0].dialCode.toString());
128
137
  setFormat(localFormat);
129
138
  }
130
139
  else if (!isEmpty_1.default(possibleCountries)) {
140
+ if (isEqual_1.default(possibleCountries[0].dialCode.toString(), countryObj.dialCode)) {
141
+ setIso2(countryObj.iso2);
142
+ return countryObj.format;
143
+ }
131
144
  setIso2(possibleCountries[0].iso2.toString());
132
145
  localFormat = possibleCountries[0].format.toString();
133
146
  onCountryCodeChange && onCountryCodeChange(PREFIX + possibleCountries[0].dialCode.toString());
@@ -156,7 +169,7 @@ function PhoneInput(props) {
156
169
  if (!phone.trim().startsWith(PREFIX) && regex.test(phone) && !isEqual_1.default(phone, '-')) {
157
170
  onPhoneValueChange(PREFIX + phone.trim());
158
171
  }
159
- else if (phone.length <= localFormat.length) {
172
+ else if (phone.length <= (localFormat === null || localFormat === void 0 ? void 0 : localFormat.length)) {
160
173
  onPhoneValueChange(phone);
161
174
  }
162
175
  };
@@ -217,6 +230,9 @@ function PhoneInput(props) {
217
230
  setFormattedNumber('');
218
231
  return;
219
232
  }
233
+ if (isEmpty_1.default(phoneValue) && isEmpty_1.default(iso2)) {
234
+ setCountryObj({ name: '', regions: [''], iso2: '', countryCode: '', dialCode: '', format: '' });
235
+ }
220
236
  if (isEmpty_1.default(phoneValue)) {
221
237
  setIso2('');
222
238
  setInvalid && setInvalid(false);
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAU3B,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;CACxB;AA0DD,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAqB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,eA+LvC"}
1
+ {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAU3B,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;CACxB;AA0DD,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAqB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,eAiNvC"}
@@ -45,7 +45,7 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
45
45
  });
46
46
  let pattern = '';
47
47
  let i = 0;
48
- for (let j = 0; j < localFormat.length && i < phone.length; j++) {
48
+ for (let j = 0; j < (localFormat === null || localFormat === void 0 ? void 0 : localFormat.length) && i < phone.length; j++) {
49
49
  if (localFormat[j] === '.') {
50
50
  pattern += phone[i];
51
51
  i++;
@@ -91,17 +91,30 @@ export function PhoneInput(props) {
91
91
  });
92
92
  const setLocalFormat = (phoneNumber) => {
93
93
  let localPhone = phoneNumber.replace(PREFIX, '').trim();
94
+ localPhone = localPhone.replace('(', '').trim();
95
+ // if the user selects a value from the dropdown and the country code is the same as prev, iso2 values shouldn't override
96
+ if (!isEmpty(countryObj) && isEqual(localPhone, countryObj.dialCode)) {
97
+ return countryObj.format;
98
+ }
94
99
  let localFormat;
95
100
  // Guessing countries according to user input
96
101
  const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
97
102
  const exactCountry = initializedCountries.filter((country) => country.dialCode.toString() === localPhone);
98
103
  if (!isEmpty(exactCountry)) {
104
+ if (isEqual(exactCountry[0].dialCode.toString(), countryObj.dialCode)) {
105
+ setIso2(countryObj.iso2);
106
+ return countryObj.format;
107
+ }
99
108
  setIso2(exactCountry[0].iso2.toString());
100
109
  localFormat = exactCountry[0].format.toString();
101
110
  onCountryCodeChange && onCountryCodeChange(PREFIX + exactCountry[0].dialCode.toString());
102
111
  setFormat(localFormat);
103
112
  }
104
113
  else if (!isEmpty(possibleCountries)) {
114
+ if (isEqual(possibleCountries[0].dialCode.toString(), countryObj.dialCode)) {
115
+ setIso2(countryObj.iso2);
116
+ return countryObj.format;
117
+ }
105
118
  setIso2(possibleCountries[0].iso2.toString());
106
119
  localFormat = possibleCountries[0].format.toString();
107
120
  onCountryCodeChange && onCountryCodeChange(PREFIX + possibleCountries[0].dialCode.toString());
@@ -130,7 +143,7 @@ export function PhoneInput(props) {
130
143
  if (!phone.trim().startsWith(PREFIX) && regex.test(phone) && !isEqual(phone, '-')) {
131
144
  onPhoneValueChange(PREFIX + phone.trim());
132
145
  }
133
- else if (phone.length <= localFormat.length) {
146
+ else if (phone.length <= (localFormat === null || localFormat === void 0 ? void 0 : localFormat.length)) {
134
147
  onPhoneValueChange(phone);
135
148
  }
136
149
  };
@@ -191,6 +204,9 @@ export function PhoneInput(props) {
191
204
  setFormattedNumber('');
192
205
  return;
193
206
  }
207
+ if (isEmpty(phoneValue) && isEmpty(iso2)) {
208
+ setCountryObj({ name: '', regions: [''], iso2: '', countryCode: '', dialCode: '', format: '' });
209
+ }
194
210
  if (isEmpty(phoneValue)) {
195
211
  setIso2('');
196
212
  setInvalid && setInvalid(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/components",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "Contains all reusabel components for support app",
5
5
  "author": "Vikas Rathee <vrathee@redhat.com>",
6
6
  "license": "ISC",
@@ -117,5 +117,5 @@
117
117
  "defaults and supports es6-module",
118
118
  "maintained node versions"
119
119
  ],
120
- "gitHead": "d0220cf8078eb0da56f34f1cf0598edad0704669"
120
+ "gitHead": "4de9544feb2e412e3f3fc6c95843cce2419a026c"
121
121
  }