@roadtrip/components 3.11.2 → 3.12.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/dist/cjs/index-12592729.js +4 -4
- package/dist/cjs/index-fb57f684.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/road-phone-number-input.cjs.entry.js +114 -155
- package/dist/cjs/road-phone-number-input.cjs.entry.js.map +1 -1
- package/dist/cjs/road-progress-indicator-horizontal.cjs.entry.js +3 -2
- package/dist/cjs/road-progress-indicator-horizontal.cjs.entry.js.map +1 -1
- package/dist/cjs/road-rating.cjs.entry.js +5 -2
- package/dist/cjs/road-rating.cjs.entry.js.map +1 -1
- package/dist/cjs/road-select.cjs.entry.js +17 -0
- package/dist/cjs/road-select.cjs.entry.js.map +1 -1
- package/dist/cjs/roadtrip.cjs.js +1 -1
- package/dist/collection/components/global-navigation/global-navigation.stories.js +2 -1
- package/dist/collection/components/icon/svg/location-pin-outline-color.svg +1 -1
- package/dist/collection/components/icon/svg/social-whatsapp-badge.svg +1 -1
- package/dist/collection/components/icon/svg/social-whatsapp-color.svg +1 -1
- package/dist/collection/components/icon/svg/social-whatsapp-solid.svg +1 -1
- package/dist/collection/components/phone-number-input/interfaces/country.interface.js +2 -0
- package/dist/collection/components/phone-number-input/interfaces/country.interface.js.map +1 -0
- package/dist/collection/components/phone-number-input/interfaces/index.js +3 -0
- package/dist/collection/components/phone-number-input/interfaces/index.js.map +1 -0
- package/dist/collection/components/phone-number-input/interfaces/phone.interface.js +2 -0
- package/dist/collection/components/phone-number-input/interfaces/phone.interface.js.map +1 -0
- package/dist/collection/components/phone-number-input/phone-number-input.css +200 -1
- package/dist/collection/components/phone-number-input/phone-number-input.js +171 -229
- package/dist/collection/components/phone-number-input/phone-number-input.js.map +1 -1
- package/dist/collection/components/phone-number-input/phone-number-input.stories.js +30 -28
- package/dist/collection/components/progress-indicator-horizontal/progress-indicator-horizontal.js +21 -2
- package/dist/collection/components/progress-indicator-horizontal/progress-indicator-horizontal.js.map +1 -1
- package/dist/collection/components/progress-indicator-horizontal/progress-indicator-horizontal.stories.js +12 -5
- package/dist/collection/components/rating/rating.css +4 -0
- package/dist/collection/components/rating/rating.js +40 -1
- package/dist/collection/components/rating/rating.js.map +1 -1
- package/dist/collection/components/rating/rating.stories.js +17 -0
- package/dist/collection/components/select/select.js +18 -1
- package/dist/collection/components/select/select.js.map +1 -1
- package/dist/collection/components/select/select.stories.js +2 -2
- package/dist/esm/index-52302079.js +4 -4
- package/dist/esm/index-891decf5.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/road-phone-number-input.entry.js +114 -155
- package/dist/esm/road-phone-number-input.entry.js.map +1 -1
- package/dist/esm/road-progress-indicator-horizontal.entry.js +3 -2
- package/dist/esm/road-progress-indicator-horizontal.entry.js.map +1 -1
- package/dist/esm/road-rating.entry.js +5 -2
- package/dist/esm/road-rating.entry.js.map +1 -1
- package/dist/esm/road-select.entry.js +17 -0
- package/dist/esm/road-select.entry.js.map +1 -1
- package/dist/esm/roadtrip.js +1 -1
- package/dist/html.html-data.json +28 -12
- package/dist/icons/icons.svg +1 -1
- package/dist/icons/index.js +4 -4
- package/dist/roadtrip/{p-4f5e8cc2.entry.js → p-254ba3c4.entry.js} +2 -2
- package/dist/roadtrip/p-254ba3c4.entry.js.map +1 -0
- package/dist/roadtrip/p-73fe2357.js.map +1 -1
- package/dist/roadtrip/{p-995e1e53.entry.js → p-9173eb4b.entry.js} +2 -2
- package/dist/roadtrip/p-9173eb4b.entry.js.map +1 -0
- package/dist/roadtrip/{p-a2a9a650.entry.js → p-be8aee32.entry.js} +2 -2
- package/dist/roadtrip/p-be8aee32.entry.js.map +1 -0
- package/dist/roadtrip/p-cbc00bfb.entry.js +2 -0
- package/dist/roadtrip/p-cbc00bfb.entry.js.map +1 -0
- package/dist/roadtrip/roadtrip.css +1 -1
- package/dist/roadtrip/roadtrip.esm.js +1 -1
- package/dist/roadtrip/roadtrip.esm.js.map +1 -1
- package/dist/roadtrip/svg/location-pin-outline-color.svg +1 -1
- package/dist/roadtrip/svg/social-whatsapp-badge.svg +1 -1
- package/dist/roadtrip/svg/social-whatsapp-color.svg +1 -1
- package/dist/roadtrip/svg/social-whatsapp-solid.svg +1 -1
- package/dist/types/components/phone-number-input/interfaces/country.interface.d.ts +13 -0
- package/dist/types/components/phone-number-input/interfaces/index.d.ts +2 -0
- package/dist/types/components/phone-number-input/interfaces/phone.interface.d.ts +11 -0
- package/dist/types/components/phone-number-input/phone-number-input.d.ts +41 -75
- package/dist/types/components/progress-indicator-horizontal/progress-indicator-horizontal.d.ts +4 -0
- package/dist/types/components/rating/rating.d.ts +8 -0
- package/dist/types/components/select/select.d.ts +2 -0
- package/dist/types/components.d.ts +75 -44
- package/hydrate/index.js +155 -170
- package/icons/icons.svg +1 -1
- package/icons/index.js +4 -4
- package/package.json +2 -2
- package/dist/roadtrip/p-39d1c90a.entry.js +0 -2
- package/dist/roadtrip/p-39d1c90a.entry.js.map +0 -1
- package/dist/roadtrip/p-4f5e8cc2.entry.js.map +0 -1
- package/dist/roadtrip/p-995e1e53.entry.js.map +0 -1
- package/dist/roadtrip/p-a2a9a650.entry.js.map +0 -1
|
@@ -1,167 +1,138 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
2
|
import { PhoneNumberFormat, PhoneNumberType, PhoneNumberUtil, } from "google-libphonenumber";
|
|
3
|
+
let selectIds = 0;
|
|
3
4
|
export class RoadPhoneNumberInput {
|
|
4
5
|
constructor() {
|
|
6
|
+
this.disabled = false;
|
|
5
7
|
this.countryData = [];
|
|
6
8
|
this.language = 'fr';
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
9
|
+
this.codeLabel = '';
|
|
10
|
+
this.phoneLabel = '';
|
|
11
|
+
this.phoneValue = undefined;
|
|
12
|
+
this.countryCode = undefined;
|
|
13
|
+
this.errorMessage = '';
|
|
12
14
|
this.required = false;
|
|
13
|
-
this.selectedCountry =
|
|
15
|
+
this.selectedCountry = this.countryData[0].countryCode;
|
|
16
|
+
this.selectedCountryCode = this.countryData[0].phoneCode;
|
|
14
17
|
this.phoneNumber = '';
|
|
15
|
-
this.inputError = '';
|
|
16
18
|
this.countryOptions = [];
|
|
19
|
+
this.returnObject = {
|
|
20
|
+
isError: false,
|
|
21
|
+
phone: this.resetPhoneUtilData(),
|
|
22
|
+
};
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
}
|
|
21
|
-
updateCountryOptions() {
|
|
22
|
-
const validLanguage = this.language && this.countryData[0].translations[this.language] ? this.language : 'fr';
|
|
23
|
-
this.countryOptions = this.countryData.map(country => {
|
|
24
|
-
return {
|
|
25
|
-
value: country.phoneCode,
|
|
26
|
-
label: `${country.translations[validLanguage]} (+${country.phoneCode})`,
|
|
27
|
-
selected: country.countryCode === this.selectedCountry, // Ici, nous marquons l'option par défaut comme sélectionnée
|
|
28
|
-
};
|
|
29
|
-
});
|
|
24
|
+
updateMessagePosition() {
|
|
25
|
+
this.placeErrorMessage();
|
|
30
26
|
}
|
|
27
|
+
// On component load
|
|
31
28
|
componentWillLoad() {
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
var _a;
|
|
30
|
+
this.placeErrorMessage();
|
|
31
|
+
let fromSelect = false;
|
|
32
|
+
if (this.phoneValue) {
|
|
33
|
+
this.phoneNumber = this.phoneValue;
|
|
34
34
|
}
|
|
35
|
-
if (this.
|
|
36
|
-
this.selectedCountry = this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (this.countryData && this.countryData.length > 0) {
|
|
40
|
-
this.selectedCountry = this.countryData[0].countryCode;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (this.inputValue) {
|
|
44
|
-
// this.phoneNumber = this.inputValue;
|
|
45
|
-
// function recupererCaracteres(s: string ) {
|
|
46
|
-
// if (s.substring(0, 2) === "00") {
|
|
47
|
-
// return s.substring(2, 4);
|
|
48
|
-
// } else {
|
|
49
|
-
// return null;
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
52
|
-
// const chaine = this.inputValue;
|
|
53
|
-
// const resultat = recupererCaracteres(chaine);
|
|
54
|
-
// this.areaValue = resultat as string;
|
|
55
|
-
// this.selectedCountry = this.getPhoneCountryCode(this.areaValue);
|
|
56
|
-
this.handleInput({
|
|
57
|
-
detail: {
|
|
58
|
-
value: this.inputValue,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
35
|
+
if (this.countryCode) {
|
|
36
|
+
this.selectedCountry = this.countryCode;
|
|
37
|
+
this.updateSelectedCountryCode((_a = this.getPhoneCodeFromCountryCode(this.countryCode)) !== null && _a !== void 0 ? _a : '');
|
|
38
|
+
fromSelect = true;
|
|
61
39
|
}
|
|
62
40
|
this.updateCountryOptions();
|
|
41
|
+
this.createAndDispatchPhoneData(fromSelect);
|
|
63
42
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
43
|
+
// On user input
|
|
44
|
+
handleInput(event) {
|
|
45
|
+
this.phoneNumber = event.detail.value;
|
|
46
|
+
this.createAndDispatchPhoneData();
|
|
67
47
|
}
|
|
48
|
+
// On user select
|
|
68
49
|
handleSelect(event) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
50
|
+
const select = event.target;
|
|
51
|
+
if (select) {
|
|
52
|
+
this.updateSelectedCountry(select.value);
|
|
53
|
+
this.updateSelectedCountryCode(this.getPhoneCodeFromCountryCode(this.selectedCountry));
|
|
54
|
+
}
|
|
55
|
+
this.createAndDispatchPhoneData(true);
|
|
56
|
+
this.updateCountryOptions();
|
|
73
57
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const returnObject = {
|
|
77
|
-
isError: true,
|
|
78
|
-
phone: {
|
|
79
|
-
phoneNumberType: 'UNKNOWN',
|
|
80
|
-
countryCode: this.selectedCountry,
|
|
81
|
-
nationalNumber: this.phoneNumber,
|
|
82
|
-
phoneCode: (_b = (_a = this.countryData.find((country) => country.countryCode === this.selectedCountry)) === null || _a === void 0 ? void 0 : _a.phoneCode) !== null && _b !== void 0 ? _b : '',
|
|
83
|
-
internationalNumber: this.phoneNumber,
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
// create instance
|
|
58
|
+
createAndDispatchPhoneData(fromSelect) {
|
|
59
|
+
// Init phone util
|
|
87
60
|
const phoneUtil = PhoneNumberUtil.getInstance();
|
|
88
61
|
const PNF = PhoneNumberFormat;
|
|
89
|
-
//
|
|
62
|
+
// Reset the return object data
|
|
63
|
+
this.returnObject.phone = this.resetPhoneUtilData();
|
|
64
|
+
const tmpCountry = this.selectedCountry.length ? this.selectedCountry : this.countryData[0].countryCode;
|
|
90
65
|
try {
|
|
91
|
-
const parsedPhoneNumber = phoneUtil.parse(this.phoneNumber,
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
const parsedPhoneNumber = phoneUtil.parse(this.phoneNumber, tmpCountry);
|
|
67
|
+
this.returnObject.isError = !phoneUtil.isValidNumber(parsedPhoneNumber) && !this.isEmptyPhoneNumber();
|
|
68
|
+
this.returnObject.phone.nationalNumber = phoneUtil.format(parsedPhoneNumber, PNF.NATIONAL);
|
|
69
|
+
this.returnObject.phone.internationalNumber = phoneUtil.format(parsedPhoneNumber, PNF.INTERNATIONAL);
|
|
70
|
+
// Set the country code values depending on the event origin
|
|
94
71
|
if (phoneUtil.getRegionCodeForNumber(parsedPhoneNumber)) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const errorTranslation = {
|
|
100
|
-
fixed: {
|
|
101
|
-
fr: 'N° de fixe attendu',
|
|
102
|
-
en: 'Expected landline number',
|
|
103
|
-
es: 'Número de teléfono fijo esperado',
|
|
104
|
-
pt: 'Número de telefone fixo esperado',
|
|
105
|
-
nl: 'Verwacht vast nummer',
|
|
106
|
-
de: 'Erwartete Festnetznummer',
|
|
107
|
-
it: 'Numero di rete fissa previsto',
|
|
108
|
-
},
|
|
109
|
-
mobile: {
|
|
110
|
-
fr: 'N° de mobile attendu',
|
|
111
|
-
en: 'Expected mobile number',
|
|
112
|
-
es: 'Número de móvil esperado',
|
|
113
|
-
pt: 'Número de celular esperado',
|
|
114
|
-
nl: 'Verwacht mobiel nummer',
|
|
115
|
-
de: 'Erwartete Handynummer',
|
|
116
|
-
it: 'Numero di cellulare previsto',
|
|
117
|
-
},
|
|
118
|
-
default: {
|
|
119
|
-
fr: 'Numéro de téléphone non valide',
|
|
120
|
-
en: 'Invalid phone number',
|
|
121
|
-
es: 'Numero de telefono invalido',
|
|
122
|
-
pt: 'Número de telefone inválido',
|
|
123
|
-
nl: 'Ongeldig telefoonnummer',
|
|
124
|
-
de: 'Ungültige Telefonnummer',
|
|
125
|
-
it: 'Numero di telefono invalido',
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
if (parsedPhoneNumber && phoneUtil.isValidNumber(parsedPhoneNumber)) {
|
|
129
|
-
this.setAndPlaceErrorMessage('');
|
|
130
|
-
const phoneType = Object.entries(PhoneNumberType).find(entry => entry[1] === phoneUtil.getNumberType(parsedPhoneNumber));
|
|
131
|
-
returnObject.isError = false;
|
|
132
|
-
returnObject.phone = {
|
|
133
|
-
phoneNumberType: phoneType[0],
|
|
134
|
-
countryCode: phoneUtil.getRegionCodeForNumber(parsedPhoneNumber),
|
|
135
|
-
phoneCode,
|
|
136
|
-
nationalNumber: phoneUtil.format(parsedPhoneNumber, PNF.NATIONAL),
|
|
137
|
-
internationalNumber: phoneUtil.format(parsedPhoneNumber, PNF.E164),
|
|
138
|
-
};
|
|
139
|
-
if (phoneType[0] !== this.numberType) {
|
|
140
|
-
switch (this.numberType) {
|
|
141
|
-
case 'FIXED_LINE':
|
|
142
|
-
this.setAndPlaceErrorMessage(errorTranslation.fixed[this.language]);
|
|
143
|
-
break;
|
|
144
|
-
case 'MOBILE':
|
|
145
|
-
this.setAndPlaceErrorMessage(errorTranslation.mobile[this.language]);
|
|
146
|
-
break;
|
|
147
|
-
default:
|
|
148
|
-
this.setAndPlaceErrorMessage('');
|
|
149
|
-
}
|
|
72
|
+
if (fromSelect) {
|
|
73
|
+
this.returnObject.isError = !(phoneUtil.isValidNumber(parsedPhoneNumber) &&
|
|
74
|
+
phoneUtil.isValidNumberForRegion(parsedPhoneNumber, this.selectedCountry) &&
|
|
75
|
+
!this.isEmptyPhoneNumber());
|
|
150
76
|
}
|
|
77
|
+
else {
|
|
78
|
+
this.updateSelectedCountryCode(parsedPhoneNumber.getCountryCode().toString());
|
|
79
|
+
this.updateSelectedCountry(phoneUtil.getRegionCodeForNumber(parsedPhoneNumber));
|
|
80
|
+
this.returnObject.phone.countryCode = this.selectedCountry;
|
|
81
|
+
this.returnObject.phone.code = this.selectedCountryCode;
|
|
82
|
+
}
|
|
83
|
+
this.updateCountryOptions();
|
|
151
84
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
85
|
+
const phoneType = Object.entries(PhoneNumberType).find(entry => entry[1] === phoneUtil.getNumberType(parsedPhoneNumber));
|
|
86
|
+
this.returnObject.phone.numberType = phoneType[0];
|
|
155
87
|
}
|
|
156
|
-
catch (
|
|
88
|
+
catch (_a) { }
|
|
157
89
|
finally {
|
|
158
|
-
this.roadPhoneNumberInput.emit(returnObject);
|
|
159
|
-
// console.log(returnObject.phone.phoneCode);
|
|
160
|
-
// returnObject.phone.phoneCode = '';
|
|
90
|
+
this.roadPhoneNumberInput.emit(this.returnObject);
|
|
161
91
|
}
|
|
162
92
|
}
|
|
163
|
-
|
|
164
|
-
|
|
93
|
+
// utils
|
|
94
|
+
updateSelectedCountryCode(countryCode) {
|
|
95
|
+
this.selectedCountryCode = countryCode;
|
|
96
|
+
}
|
|
97
|
+
updateSelectedCountry(value) {
|
|
98
|
+
this.selectedCountry = value;
|
|
99
|
+
}
|
|
100
|
+
resetPhoneUtilData() {
|
|
101
|
+
return {
|
|
102
|
+
numberType: 'UNKNOWN',
|
|
103
|
+
countryCode: this.selectedCountry,
|
|
104
|
+
code: this.selectedCountryCode,
|
|
105
|
+
nationalNumber: this.phoneNumber,
|
|
106
|
+
internationalNumber: this.phoneNumber,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
isEmptyPhoneNumber() {
|
|
110
|
+
return !this.phoneNumber.length;
|
|
111
|
+
}
|
|
112
|
+
getPhoneCodeFromCountryCode(countryCode) {
|
|
113
|
+
var _a;
|
|
114
|
+
return (_a = this.countryData.find(country => country.countryCode === countryCode)) === null || _a === void 0 ? void 0 : _a.phoneCode;
|
|
115
|
+
}
|
|
116
|
+
updateCountryOptions() {
|
|
117
|
+
const validLanguage = this.countryData[0].translations[this.language] ? this.language : 'fr';
|
|
118
|
+
this.countryOptions = [
|
|
119
|
+
...this.countryData
|
|
120
|
+
.sort((a, b) => a.translations[validLanguage].localeCompare(b.translations[validLanguage]))
|
|
121
|
+
.map(country => ({
|
|
122
|
+
value: country.countryCode,
|
|
123
|
+
label: `${country.translations[validLanguage]} (+${country.phoneCode})`,
|
|
124
|
+
selected: country.countryCode === this.selectedCountry,
|
|
125
|
+
disabled: false,
|
|
126
|
+
})),
|
|
127
|
+
{
|
|
128
|
+
value: '',
|
|
129
|
+
label: '--',
|
|
130
|
+
selected: this.countryData.every((country) => country.countryCode !== this.selectedCountry),
|
|
131
|
+
disabled: true,
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
placeErrorMessage() {
|
|
165
136
|
this.waitForElementToExist('.invalid-feedback').then((messError) => {
|
|
166
137
|
messError.style.display = "block";
|
|
167
138
|
messError.style.marginTop = "-0.5rem";
|
|
@@ -186,23 +157,13 @@ export class RoadPhoneNumberInput {
|
|
|
186
157
|
});
|
|
187
158
|
});
|
|
188
159
|
}
|
|
189
|
-
handleInput(event) {
|
|
190
|
-
this.updateCountryOptions();
|
|
191
|
-
this.phoneNumber = event.detail.value;
|
|
192
|
-
this.createReturnObject();
|
|
193
|
-
}
|
|
194
|
-
extractCallingCode(countryString) {
|
|
195
|
-
const regex = /\(([^)]+)\)/;
|
|
196
|
-
const found = countryString.match(regex);
|
|
197
|
-
return found ? found[1] : '';
|
|
198
|
-
}
|
|
199
|
-
selectCountry(event) {
|
|
200
|
-
const countryString = event.detail.value; // Get the value from the custom event
|
|
201
|
-
this.selectedCountry = this.extractCallingCode(countryString);
|
|
202
|
-
this.el.querySelector('.form-select-area-value').innerHTML = countryString;
|
|
203
|
-
}
|
|
204
160
|
render() {
|
|
205
|
-
|
|
161
|
+
const selectId = `road-select-${selectIds++}`;
|
|
162
|
+
const labelId = selectId + '-label';
|
|
163
|
+
const valueId = selectId + '-value';
|
|
164
|
+
const isInvalidClass = this.errorMessage.length ? 'is-invalid' : '';
|
|
165
|
+
const isErrorClass = this.errorMessage.length ? 'is-error' : '';
|
|
166
|
+
return (h(Host, null, h("road-input-group", null, h("div", { class: `road-phone-input-select ${isErrorClass}`, slot: "prepend" }, h("select", { id: 'phone-number-input', class: `form-select-area has-value ${isInvalidClass}`, "aria-disabled": this.disabled ? 'true' : null, disabled: this.disabled, onChange: (event) => this.handleSelect(event) }, this.countryOptions && this.countryOptions.map(option => (h("option", { value: option.value, disabled: option.disabled, selected: option.selected }, option.label)))), h("label", { class: "form-select-area-label", id: labelId, htmlFor: selectId }, this.codeLabel), h("label", { class: "form-select-area-value", id: valueId, htmlFor: selectId }, "+", this.selectedCountryCode)), h("road-input", { id: "phone-number", sizes: "xl", label: this.phoneLabel, value: this.phoneValue, onRoadChange: (event) => this.handleInput(event), required: this.required, error: this.errorMessage }))));
|
|
206
167
|
}
|
|
207
168
|
static get is() { return "road-phone-number-input"; }
|
|
208
169
|
static get encapsulation() { return "scoped"; }
|
|
@@ -218,6 +179,24 @@ export class RoadPhoneNumberInput {
|
|
|
218
179
|
}
|
|
219
180
|
static get properties() {
|
|
220
181
|
return {
|
|
182
|
+
"disabled": {
|
|
183
|
+
"type": "boolean",
|
|
184
|
+
"mutable": false,
|
|
185
|
+
"complexType": {
|
|
186
|
+
"original": "boolean",
|
|
187
|
+
"resolved": "boolean",
|
|
188
|
+
"references": {}
|
|
189
|
+
},
|
|
190
|
+
"required": false,
|
|
191
|
+
"optional": false,
|
|
192
|
+
"docs": {
|
|
193
|
+
"tags": [],
|
|
194
|
+
"text": "Disable both fields"
|
|
195
|
+
},
|
|
196
|
+
"attribute": "disabled",
|
|
197
|
+
"reflect": false,
|
|
198
|
+
"defaultValue": "false"
|
|
199
|
+
},
|
|
221
200
|
"countryData": {
|
|
222
201
|
"type": "unknown",
|
|
223
202
|
"mutable": false,
|
|
@@ -226,8 +205,9 @@ export class RoadPhoneNumberInput {
|
|
|
226
205
|
"resolved": "CountryType[]",
|
|
227
206
|
"references": {
|
|
228
207
|
"CountryType": {
|
|
229
|
-
"location": "
|
|
230
|
-
"
|
|
208
|
+
"location": "import",
|
|
209
|
+
"path": "./interfaces",
|
|
210
|
+
"id": "src/components/phone-number-input/interfaces/index.ts::CountryType"
|
|
231
211
|
}
|
|
232
212
|
}
|
|
233
213
|
},
|
|
@@ -235,7 +215,7 @@ export class RoadPhoneNumberInput {
|
|
|
235
215
|
"optional": false,
|
|
236
216
|
"docs": {
|
|
237
217
|
"tags": [],
|
|
238
|
-
"text": "
|
|
218
|
+
"text": "List of countries displayed in the country selection. Countries will be automatically sorted by alphabetical order (see format in example)"
|
|
239
219
|
},
|
|
240
220
|
"defaultValue": "[]"
|
|
241
221
|
},
|
|
@@ -251,13 +231,13 @@ export class RoadPhoneNumberInput {
|
|
|
251
231
|
"optional": false,
|
|
252
232
|
"docs": {
|
|
253
233
|
"tags": [],
|
|
254
|
-
"text": "
|
|
234
|
+
"text": "Used to display countries with the right language"
|
|
255
235
|
},
|
|
256
236
|
"attribute": "language",
|
|
257
237
|
"reflect": false,
|
|
258
238
|
"defaultValue": "'fr'"
|
|
259
239
|
},
|
|
260
|
-
"
|
|
240
|
+
"codeLabel": {
|
|
261
241
|
"type": "string",
|
|
262
242
|
"mutable": false,
|
|
263
243
|
"complexType": {
|
|
@@ -269,15 +249,15 @@ export class RoadPhoneNumberInput {
|
|
|
269
249
|
"optional": false,
|
|
270
250
|
"docs": {
|
|
271
251
|
"tags": [],
|
|
272
|
-
"text": "
|
|
252
|
+
"text": "Country selection placeHolder"
|
|
273
253
|
},
|
|
274
|
-
"attribute": "
|
|
254
|
+
"attribute": "code-label",
|
|
275
255
|
"reflect": false,
|
|
276
|
-
"defaultValue": "'
|
|
256
|
+
"defaultValue": "''"
|
|
277
257
|
},
|
|
278
|
-
"
|
|
258
|
+
"phoneLabel": {
|
|
279
259
|
"type": "string",
|
|
280
|
-
"mutable":
|
|
260
|
+
"mutable": false,
|
|
281
261
|
"complexType": {
|
|
282
262
|
"original": "string",
|
|
283
263
|
"resolved": "string",
|
|
@@ -287,64 +267,63 @@ export class RoadPhoneNumberInput {
|
|
|
287
267
|
"optional": false,
|
|
288
268
|
"docs": {
|
|
289
269
|
"tags": [],
|
|
290
|
-
"text": "
|
|
270
|
+
"text": "Phone input placeHolder"
|
|
291
271
|
},
|
|
292
|
-
"attribute": "
|
|
272
|
+
"attribute": "phone-label",
|
|
293
273
|
"reflect": false,
|
|
294
274
|
"defaultValue": "''"
|
|
295
275
|
},
|
|
296
|
-
"
|
|
276
|
+
"phoneValue": {
|
|
297
277
|
"type": "string",
|
|
298
278
|
"mutable": false,
|
|
299
279
|
"complexType": {
|
|
300
280
|
"original": "string",
|
|
301
|
-
"resolved": "string",
|
|
281
|
+
"resolved": "string | undefined",
|
|
302
282
|
"references": {}
|
|
303
283
|
},
|
|
304
284
|
"required": false,
|
|
305
|
-
"optional":
|
|
285
|
+
"optional": true,
|
|
306
286
|
"docs": {
|
|
307
287
|
"tags": [],
|
|
308
|
-
"text": "
|
|
288
|
+
"text": "Value displayed in the phone input"
|
|
309
289
|
},
|
|
310
|
-
"attribute": "
|
|
311
|
-
"reflect": false
|
|
312
|
-
"defaultValue": "'Number'"
|
|
290
|
+
"attribute": "phone-value",
|
|
291
|
+
"reflect": false
|
|
313
292
|
},
|
|
314
|
-
"
|
|
293
|
+
"countryCode": {
|
|
315
294
|
"type": "string",
|
|
316
295
|
"mutable": false,
|
|
317
296
|
"complexType": {
|
|
318
297
|
"original": "string",
|
|
319
|
-
"resolved": "string",
|
|
298
|
+
"resolved": "string | undefined",
|
|
320
299
|
"references": {}
|
|
321
300
|
},
|
|
322
301
|
"required": false,
|
|
323
|
-
"optional":
|
|
302
|
+
"optional": true,
|
|
324
303
|
"docs": {
|
|
325
304
|
"tags": [],
|
|
326
|
-
"text": "
|
|
305
|
+
"text": "Selected country code"
|
|
327
306
|
},
|
|
328
|
-
"attribute": "
|
|
329
|
-
"reflect": false
|
|
330
|
-
"defaultValue": "''"
|
|
307
|
+
"attribute": "country-code",
|
|
308
|
+
"reflect": false
|
|
331
309
|
},
|
|
332
|
-
"
|
|
310
|
+
"errorMessage": {
|
|
333
311
|
"type": "string",
|
|
334
312
|
"mutable": false,
|
|
335
313
|
"complexType": {
|
|
336
314
|
"original": "string",
|
|
337
|
-
"resolved": "string
|
|
315
|
+
"resolved": "string",
|
|
338
316
|
"references": {}
|
|
339
317
|
},
|
|
340
318
|
"required": false,
|
|
341
|
-
"optional":
|
|
319
|
+
"optional": false,
|
|
342
320
|
"docs": {
|
|
343
321
|
"tags": [],
|
|
344
|
-
"text": "
|
|
322
|
+
"text": "Error message (displayed only if ther is a message)"
|
|
345
323
|
},
|
|
346
|
-
"attribute": "
|
|
347
|
-
"reflect": false
|
|
324
|
+
"attribute": "error-message",
|
|
325
|
+
"reflect": false,
|
|
326
|
+
"defaultValue": "''"
|
|
348
327
|
},
|
|
349
328
|
"required": {
|
|
350
329
|
"type": "boolean",
|
|
@@ -358,7 +337,7 @@ export class RoadPhoneNumberInput {
|
|
|
358
337
|
"optional": false,
|
|
359
338
|
"docs": {
|
|
360
339
|
"tags": [],
|
|
361
|
-
"text": "
|
|
340
|
+
"text": "Add a star in the phone input"
|
|
362
341
|
},
|
|
363
342
|
"attribute": "required",
|
|
364
343
|
"reflect": false,
|
|
@@ -369,9 +348,10 @@ export class RoadPhoneNumberInput {
|
|
|
369
348
|
static get states() {
|
|
370
349
|
return {
|
|
371
350
|
"selectedCountry": {},
|
|
351
|
+
"selectedCountryCode": {},
|
|
372
352
|
"phoneNumber": {},
|
|
373
|
-
"
|
|
374
|
-
"
|
|
353
|
+
"countryOptions": {},
|
|
354
|
+
"returnObject": {}
|
|
375
355
|
};
|
|
376
356
|
}
|
|
377
357
|
static get events() {
|
|
@@ -383,49 +363,11 @@ export class RoadPhoneNumberInput {
|
|
|
383
363
|
"composed": true,
|
|
384
364
|
"docs": {
|
|
385
365
|
"tags": [],
|
|
386
|
-
"text": "
|
|
387
|
-
},
|
|
388
|
-
"complexType": {
|
|
389
|
-
"original": "{\n isError: boolean;\n phone: PhoneReturnType;\n }",
|
|
390
|
-
"resolved": "{ isError: boolean; phone: PhoneReturnType; }",
|
|
391
|
-
"references": {
|
|
392
|
-
"PhoneReturnType": {
|
|
393
|
-
"location": "global",
|
|
394
|
-
"id": "global::PhoneReturnType"
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}, {
|
|
399
|
-
"method": "roadselected",
|
|
400
|
-
"name": "roadselected",
|
|
401
|
-
"bubbles": true,
|
|
402
|
-
"cancelable": true,
|
|
403
|
-
"composed": true,
|
|
404
|
-
"docs": {
|
|
405
|
-
"tags": [],
|
|
406
|
-
"text": "Emitted the value and label of the option selected."
|
|
407
|
-
},
|
|
408
|
-
"complexType": {
|
|
409
|
-
"original": "{\n value: string | undefined | null,\n label: string\n }",
|
|
410
|
-
"resolved": "{ value: string | null | undefined; label: string; }",
|
|
411
|
-
"references": {}
|
|
412
|
-
}
|
|
413
|
-
}, {
|
|
414
|
-
"method": "roadSelected",
|
|
415
|
-
"name": "roadSelected",
|
|
416
|
-
"bubbles": true,
|
|
417
|
-
"cancelable": true,
|
|
418
|
-
"composed": true,
|
|
419
|
-
"docs": {
|
|
420
|
-
"tags": [{
|
|
421
|
-
"name": "internal",
|
|
422
|
-
"text": undefined
|
|
423
|
-
}],
|
|
424
|
-
"text": ""
|
|
366
|
+
"text": "Computed phone data"
|
|
425
367
|
},
|
|
426
368
|
"complexType": {
|
|
427
|
-
"original": "{\n
|
|
428
|
-
"resolved": "{
|
|
369
|
+
"original": "{\n isError: boolean;\n phone: {\n numberType: string;\n countryCode: string;\n nationalNumber: string;\n code: string;\n internationalNumber: string;\n };\n }",
|
|
370
|
+
"resolved": "{ isError: boolean; phone: { numberType: string; countryCode: string; nationalNumber: string; code: string; internationalNumber: string; }; }",
|
|
429
371
|
"references": {}
|
|
430
372
|
}
|
|
431
373
|
}];
|
|
@@ -433,8 +375,8 @@ export class RoadPhoneNumberInput {
|
|
|
433
375
|
static get elementRef() { return "el"; }
|
|
434
376
|
static get watchers() {
|
|
435
377
|
return [{
|
|
436
|
-
"propName": "
|
|
437
|
-
"methodName": "
|
|
378
|
+
"propName": "errorMessage",
|
|
379
|
+
"methodName": "updateMessagePosition"
|
|
438
380
|
}];
|
|
439
381
|
}
|
|
440
382
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone-number-input.js","sourceRoot":"","sources":["../../../src/components/phone-number-input/phone-number-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAgB,MAAM,eAAe,CAAC;AACrG,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAsC/B,MAAM,OAAO,oBAAoB;;uBAeM,EAAE;oBAKZ,IAAI;qBAKH,SAAS;qBAKQ,EAAE;sBAKlB,QAAQ;sBAKR,EAAE;;oBAUZ,KAAK;2BAEW,EAAE;uBACN,EAAE;sBAEH,EAAE;0BAEiD,EAAE;;EAGnF,eAAe;IACb,IAAI,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GAEX,CACI,CACd,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Prop, Element, Host, State, h, Watch, Event, EventEmitter } from '@stencil/core';\nimport {\n PhoneNumberFormat,\n PhoneNumberType,\n PhoneNumberUtil,\n} from 'google-libphonenumber';\n\ntype CountryType = {\n translations: { [key: string]: string },\n countryCode: string,\n phoneCode: string\n};\n\ninterface PhoneReturnType {\n phoneNumberType: string;\n countryCode: string;\n nationalNumber: string;\n phoneCode: string;\n internationalNumber: string;\n}\n\ninterface Translations {\n fixed: TranslationLanguages;\n mobile: TranslationLanguages;\n default: TranslationLanguages;\n}\n\ninterface TranslationLanguages {\n fr: string;\n en: string;\n es: string;\n pt: string;\n nl: string;\n de: string;\n it: string;\n [key: string]: string;\n}\n\n@Component({\n tag: 'road-phone-number-input',\n styleUrl: 'phone-number-input.css',\n scoped: true,\n})\nexport class RoadPhoneNumberInput {\n\n /**\n * Emitt object data.\n */\n @Event() roadPhoneNumberInput!: EventEmitter<{\n isError: boolean;\n phone: PhoneReturnType;\n }>;\n\n @Element() el!: HTMLRoadPhoneNumberInputElement;\n\n /**\n * The country data \n */\n @Prop() countryData: CountryType[] = [];\n\n /**\n * The translation language of the countries\n */\n @Prop() language: string = 'fr';\n\n /**\n * The label display in the select area\n */\n @Prop() areaLabel: string = 'Country';\n\n /**\n * The indicatif display in the select area\n */\n @Prop({ mutable: true }) areaValue: string = '';\n\n /**\n * The label display in the input\n */\n @Prop() inputLabel: string = 'Number';\n\n /**\n * The value of the input\n */\n @Prop() inputValue: string = '';\n\n /**\n * Type of the phone number : FIXED_LINE, MOBILE\n */\n @Prop() numberType?: string;\n\n /**\n * If `true`, the user must fill in a value before submitting a form.\n */\n @Prop() required = false;\n\n @State() selectedCountry: string = '';\n @State() phoneNumber: string = '';\n\n @State() inputError: string = '';\n\n @State() countryOptions: { value: string; label: string; selected: boolean }[] = [];\n\n @Watch('language')\n languageChanged() {\n this.updateCountryOptions();\n }\n\n updateCountryOptions() {\n const validLanguage = this.language && this.countryData[0].translations[this.language] ? this.language : 'fr';\n this.countryOptions = this.countryData.map(country => {\n return {\n value: country.phoneCode,\n label: `${country.translations[validLanguage]} (+${country.phoneCode})`,\n selected: country.countryCode === this.selectedCountry, // Ici, nous marquons l'option par défaut comme sélectionnée\n };\n });\n }\n\n componentWillLoad() {\n if (this.numberType && this.numberType !== 'FIXED_LINE' && this.numberType !== 'MOBILE') {\n this.numberType = '';\n }\n\n if (this.areaValue) {\n this.selectedCountry = this.getPhoneCountryCode(this.areaValue);\n } else {\n if (this.countryData && this.countryData.length > 0) {\n this.selectedCountry = this.countryData[0].countryCode;\n }\n }\n\n if (this.inputValue) {\n // this.phoneNumber = this.inputValue;\n\n // function recupererCaracteres(s: string ) {\n // if (s.substring(0, 2) === \"00\") {\n // return s.substring(2, 4);\n // } else {\n // return null;\n // }\n // }\n \n // const chaine = this.inputValue;\n // const resultat = recupererCaracteres(chaine);\n \n // this.areaValue = resultat as string;\n // this.selectedCountry = this.getPhoneCountryCode(this.areaValue);\n\n this.handleInput({\n detail: {\n value: this.inputValue,\n },\n });\n }\n\n this.updateCountryOptions();\n }\n\n getPhoneCountryCode(phoneCode: string): string {\n return this.countryData.find((country) => country.phoneCode === phoneCode)?.countryCode ?? '';\n }\n\n handleSelect(event: any) {\n const receivedPhoneCode = event.detail.value.replace('+', '');\n const phoneCountryCode = this.getPhoneCountryCode(receivedPhoneCode);\n\n this.selectedCountry = phoneCountryCode;\n\n this.createReturnObject();\n }\n\n createReturnObject() {\n const returnObject = {\n isError: true,\n phone: {\n phoneNumberType: 'UNKNOWN',\n countryCode: this.selectedCountry,\n nationalNumber: this.phoneNumber,\n phoneCode: this.countryData.find((country) => country.countryCode === this.selectedCountry)?.phoneCode ?? '',\n internationalNumber: this.phoneNumber,\n },\n };\n\n // create instance\n const phoneUtil = PhoneNumberUtil.getInstance();\n const PNF = PhoneNumberFormat;\n\n // Parse and verify the phone number\n try {\n const parsedPhoneNumber = phoneUtil.parse(this.phoneNumber, this.selectedCountry as any);\n\n const phoneCode = parsedPhoneNumber.getCountryCode() as any;\n // get the phone's country code and updates the areaValue \n if (phoneUtil.getRegionCodeForNumber(parsedPhoneNumber)) {\n this.selectedCountry = phoneUtil.getRegionCodeForNumber(parsedPhoneNumber)!;\n\n const computedPhoneCode = this.countryData.find(country => country.countryCode == this.selectedCountry)?.phoneCode ?? '';\n\n this.areaValue = computedPhoneCode;\n }\n\n const errorTranslation: Translations = {\n fixed: {\n fr: 'N° de fixe attendu',\n en: 'Expected landline number',\n es: 'Número de teléfono fijo esperado',\n pt: 'Número de telefone fixo esperado',\n nl: 'Verwacht vast nummer',\n de: 'Erwartete Festnetznummer',\n it: 'Numero di rete fissa previsto',\n },\n mobile: {\n fr: 'N° de mobile attendu',\n en: 'Expected mobile number',\n es: 'Número de móvil esperado',\n pt: 'Número de celular esperado',\n nl: 'Verwacht mobiel nummer',\n de: 'Erwartete Handynummer',\n it: 'Numero di cellulare previsto',\n },\n default: {\n fr: 'Numéro de téléphone non valide',\n en: 'Invalid phone number',\n es: 'Numero de telefono invalido',\n pt: 'Número de telefone inválido',\n nl: 'Ongeldig telefoonnummer',\n de: 'Ungültige Telefonnummer',\n it: 'Numero di telefono invalido',\n },\n };\n\n if (parsedPhoneNumber && phoneUtil.isValidNumber(parsedPhoneNumber)) {\n this.setAndPlaceErrorMessage('');\n\n const phoneType = Object.entries(PhoneNumberType).find(entry => entry[1] === phoneUtil.getNumberType(parsedPhoneNumber))!;\n \n returnObject.isError = false;\n returnObject.phone = {\n phoneNumberType: phoneType[0],\n countryCode: phoneUtil.getRegionCodeForNumber(parsedPhoneNumber) as any,\n phoneCode,\n nationalNumber: phoneUtil.format(parsedPhoneNumber, PNF.NATIONAL),\n internationalNumber: phoneUtil.format(parsedPhoneNumber, PNF.E164),\n };\n \n if (phoneType[0] !== this.numberType) {\n switch(this.numberType) {\n case 'FIXED_LINE':\n this.setAndPlaceErrorMessage(errorTranslation.fixed[this.language]);\n break;\n case 'MOBILE':\n this.setAndPlaceErrorMessage(errorTranslation.mobile[this.language]);\n break;\n default:\n this.setAndPlaceErrorMessage('');\n }\n }\n }\n else {\n this.setAndPlaceErrorMessage(errorTranslation.default[this.language]);\n }\n }\n catch {}\n finally {\n this.roadPhoneNumberInput.emit(returnObject);\n // console.log(returnObject.phone.phoneCode);\n // returnObject.phone.phoneCode = '';\n \n }\n }\n\n setAndPlaceErrorMessage(message: string) {\n this.inputError = message;\n\n this.waitForElementToExist('.invalid-feedback').then((messError: HTMLElement) => {\n messError.style.display = \"block\";\n messError.style.marginTop = \"-0.5rem\";\n const phoneNumberInput = (this.el as HTMLRoadPhoneNumberInputElement);\n phoneNumberInput.appendChild(messError);\n });\n }\n\n waitForElementToExist(selector: string): Promise<HTMLElement> {\n return new Promise(resolve => {\n if (document.querySelector(selector)) {\n return resolve(document.querySelector(selector) as HTMLElement);\n }\n \n const observer = new MutationObserver(() => {\n if (document.querySelector(selector)) {\n resolve(document.querySelector(selector) as HTMLElement);\n observer.disconnect();\n }\n });\n \n observer.observe(document.body, {\n subtree: true,\n childList: true,\n });\n });\n }\n\n handleInput(event: any) {\n this.updateCountryOptions();\n\n this.phoneNumber = event.detail.value;\n this.createReturnObject();\n }\n\n /**\n * Emitted the value and label of the option selected.\n */\n @Event() roadselected!: EventEmitter<{\n value: string | undefined | null,\n label: string\n }>;\n /** @internal */\n @Event() roadSelected!: EventEmitter<{\n value: string | undefined | null,\n label: string\n }>;\n\n extractCallingCode(countryString: string) {\n const regex = /\\(([^)]+)\\)/;\n const found = countryString.match(regex);\n return found ? found[1] : '';\n }\n\n selectCountry(event: CustomEvent) {\n const countryString = event.detail.value; // Get the value from the custom event\n this.selectedCountry = this.extractCallingCode(countryString);\n (this.el.querySelector('.form-select-area-value') as HTMLElement).innerHTML = countryString;\n }\n\n render() {\n return (\n <Host\n numberType={this.numberType}>\n <road-input-group>\n <road-area-code\n slot=\"prepend\"\n class={`form-select has-value`}\n label={this.areaLabel}\n value={this.areaValue}\n sizes=\"xl\"\n options={this.countryOptions}\n onRoadchange={(event) => this.handleSelect(event)}\n ></road-area-code>\n <road-input\n id=\"phone-number\"\n sizes=\"xl\"\n label={this.inputLabel}\n value={this.inputValue}\n onRoadChange={(event) => this.handleInput(event)}\n required={this.required}\n error={this.inputError}\n >\n </road-input>\n </road-input-group>\n </Host>\n );\n }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"phone-number-input.js","sourceRoot":"","sources":["../../../src/components/phone-number-input/phone-number-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AACrG,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAI/B,IAAI,SAAS,GAAG,CAAC,CAAC;AAOlB,MAAM,OAAO,oBAAoB;;oBAiBH,KAAK;uBAGI,EAAE;oBAGZ,IAAI;qBAGH,EAAE;sBAGD,EAAE;;;wBASA,EAAE;oBAGd,KAAK;2BAEW,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW;+BAC3B,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;uBACrC,EAAE;0BACU,EAAE;wBACP;MACpC,OAAO,EAAE,KAAK;MACd,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE;KACjC;;EAGD,qBAAqB;IACnB,IAAI,CAAC,iBAAiB,EAAE,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Prop, Element, Host, State, h, Event, EventEmitter, Watch } from '@stencil/core';\nimport {\n PhoneNumberFormat,\n PhoneNumberType,\n PhoneNumberUtil,\n} from 'google-libphonenumber';\nimport { CountryOption, CountryType, PhoneReturnType, ReturnObject } from './interfaces';\nimport { RoadInputCustomEvent } from '../../components';\n\nlet selectIds = 0;\n\n@Component({\n tag: 'road-phone-number-input',\n styleUrl: 'phone-number-input.css',\n scoped: true,\n})\nexport class RoadPhoneNumberInput {\n\n /** Computed phone data */\n @Event() roadPhoneNumberInput!: EventEmitter<{\n isError: boolean;\n phone: {\n numberType: string;\n countryCode: string;\n nationalNumber: string;\n code: string;\n internationalNumber: string;\n };\n }>;\n\n @Element() el!: HTMLRoadPhoneNumberInputElement;\n\n /** Disable both fields */\n @Prop() disabled: boolean = false;\n\n /** List of countries displayed in the country selection. Countries will be automatically sorted by alphabetical order (see format in example) */\n @Prop() countryData: CountryType[] = [];\n\n /** Used to display countries with the right language */\n @Prop() language: string = 'fr';\n\n /** Country selection placeHolder */\n @Prop() codeLabel: string = '';\n\n /** Phone input placeHolder */\n @Prop() phoneLabel: string = '';\n\n /** Value displayed in the phone input */\n @Prop() phoneValue?: string;\n\n /** Selected country code */\n @Prop() countryCode?: string;\n\n /** Error message (displayed only if ther is a message) */\n @Prop() errorMessage: string = '';\n\n /** Add a star in the phone input */\n @Prop() required = false;\n\n @State() selectedCountry: string = this.countryData[0].countryCode;\n @State() selectedCountryCode: string = this.countryData[0].phoneCode;\n @State() phoneNumber: string = '';\n @State() countryOptions: CountryOption[] = [];\n @State() returnObject: ReturnObject = {\n isError: false,\n phone: this.resetPhoneUtilData(),\n };\n\n @Watch('errorMessage')\n updateMessagePosition() {\n this.placeErrorMessage();\n }\n\n // On component load\n componentWillLoad() {\n this.placeErrorMessage();\n let fromSelect = false;\n\n if (this.phoneValue) {\n this.phoneNumber = this.phoneValue;\n }\n\n if (this.countryCode) {\n this.selectedCountry = this.countryCode;\n this.updateSelectedCountryCode(this.getPhoneCodeFromCountryCode(this.countryCode) ?? '');\n fromSelect = true;\n }\n\n this.updateCountryOptions();\n this.createAndDispatchPhoneData(fromSelect);\n }\n\n // On user input\n handleInput(event: RoadInputCustomEvent<{\n value: string | null | undefined;\n }>) {\n this.phoneNumber = event.detail.value!;\n this.createAndDispatchPhoneData();\n }\n\n // On user select\n handleSelect(event: Event) {\n const select = event.target as HTMLSelectElement | null;\n if (select) {\n this.updateSelectedCountry(select.value);\n this.updateSelectedCountryCode(this.getPhoneCodeFromCountryCode(this.selectedCountry)!);\n }\n this.createAndDispatchPhoneData(true);\n this.updateCountryOptions();\n }\n\n createAndDispatchPhoneData(fromSelect?: boolean) {\n // Init phone util\n const phoneUtil = PhoneNumberUtil.getInstance();\n const PNF = PhoneNumberFormat;\n\n // Reset the return object data\n this.returnObject.phone = this.resetPhoneUtilData();\n\n const tmpCountry = this.selectedCountry.length ? this.selectedCountry : this.countryData[0].countryCode;\n\n try {\n const parsedPhoneNumber = phoneUtil.parse(this.phoneNumber, tmpCountry);\n this.returnObject.isError = !phoneUtil.isValidNumber(parsedPhoneNumber) && !this.isEmptyPhoneNumber();\n this.returnObject.phone.nationalNumber = phoneUtil.format(parsedPhoneNumber, PNF.NATIONAL);\n this.returnObject.phone.internationalNumber = phoneUtil.format(parsedPhoneNumber, PNF.INTERNATIONAL);\n\n // Set the country code values depending on the event origin\n if (phoneUtil.getRegionCodeForNumber(parsedPhoneNumber)) {\n if (fromSelect) {\n this.returnObject.isError = !(\n phoneUtil.isValidNumber(parsedPhoneNumber) &&\n phoneUtil.isValidNumberForRegion(parsedPhoneNumber, this.selectedCountry) &&\n !this.isEmptyPhoneNumber()\n );\n } else {\n this.updateSelectedCountryCode(parsedPhoneNumber.getCountryCode()!.toString());\n this.updateSelectedCountry(phoneUtil.getRegionCodeForNumber(parsedPhoneNumber)!);\n\n this.returnObject.phone.countryCode = this.selectedCountry;\n this.returnObject.phone.code = this.selectedCountryCode;\n }\n this.updateCountryOptions();\n }\n\n const phoneType = Object.entries(PhoneNumberType).find(entry => entry[1] === phoneUtil.getNumberType(parsedPhoneNumber))!;\n this.returnObject.phone.numberType = phoneType[0];\n } catch {} finally {\n this.roadPhoneNumberInput.emit(this.returnObject);\n }\n }\n\n // utils\n\n updateSelectedCountryCode(countryCode: string) {\n this.selectedCountryCode = countryCode;\n }\n\n updateSelectedCountry(value: string) {\n this.selectedCountry = value;\n }\n\n resetPhoneUtilData(): PhoneReturnType {\n return {\n numberType: 'UNKNOWN',\n countryCode: this.selectedCountry,\n code: this.selectedCountryCode,\n nationalNumber: this.phoneNumber,\n internationalNumber: this.phoneNumber,\n };\n }\n\n isEmptyPhoneNumber(): boolean {\n return !this.phoneNumber.length;\n }\n\n getPhoneCodeFromCountryCode(countryCode: string): string | undefined {\n return this.countryData.find(country => country.countryCode === countryCode)?.phoneCode;\n }\n\n updateCountryOptions() {\n const validLanguage = this.countryData[0].translations[this.language] ? this.language : 'fr';\n this.countryOptions = [\n ...this.countryData\n .sort((a, b) => a.translations[validLanguage].localeCompare(b.translations[validLanguage]))\n .map(country => ({\n value: country.countryCode,\n label: `${country.translations[validLanguage]} (+${country.phoneCode})`,\n selected: country.countryCode === this.selectedCountry,\n disabled: false,\n })\n ),\n {\n value: '',\n label: '--',\n selected: this.countryData.every((country) => country.countryCode !== this.selectedCountry),\n disabled: true,\n },\n ];\n }\n\n placeErrorMessage() {\n this.waitForElementToExist('.invalid-feedback').then((messError: HTMLElement) => {\n messError.style.display = \"block\";\n messError.style.marginTop = \"-0.5rem\";\n const phoneNumberInput = (this.el as HTMLRoadPhoneNumberInputElement);\n phoneNumberInput.appendChild(messError);\n });\n }\n\n waitForElementToExist(selector: string): Promise<HTMLElement> {\n return new Promise(resolve => {\n if (document.querySelector(selector)) {\n return resolve(document.querySelector(selector) as HTMLElement);\n }\n\n const observer = new MutationObserver(() => {\n if (document.querySelector(selector)) {\n resolve(document.querySelector(selector) as HTMLElement);\n observer.disconnect();\n }\n });\n\n observer.observe(document.body, {\n subtree: true,\n childList: true,\n });\n });\n }\n\n render() {\n const selectId = `road-select-${selectIds++}`;\n const labelId = selectId + '-label';\n const valueId = selectId + '-value';\n const isInvalidClass = this.errorMessage.length ? 'is-invalid' : '';\n const isErrorClass = this.errorMessage.length ? 'is-error' : '';\n\n return (\n <Host>\n <road-input-group>\n <div class={`road-phone-input-select ${isErrorClass}`} slot=\"prepend\">\n <select\n id='phone-number-input'\n class={`form-select-area has-value ${isInvalidClass}`}\n aria-disabled={this.disabled ? 'true' : null}\n disabled={this.disabled}\n onChange={(event) => this.handleSelect(event)}\n >\n {this.countryOptions && this.countryOptions.map(option => (\n <option value={option.value} disabled={option.disabled} selected={option.selected}>{option.label}</option>\n ))}\n </select>\n <label class=\"form-select-area-label\" id={labelId} htmlFor={selectId}>{this.codeLabel}</label>\n <label class=\"form-select-area-value\" id={valueId} htmlFor={selectId}>+{this.selectedCountryCode}</label>\n </div>\n <road-input\n id=\"phone-number\"\n sizes=\"xl\"\n label={this.phoneLabel}\n value={this.phoneValue}\n onRoadChange={(event) => this.handleInput(event)}\n required={this.required}\n error={this.errorMessage}\n >\n </road-input>\n </road-input-group>\n </Host>\n );\n }\n}\n\n\n"]}
|