@lbgm/phone-input
Version:
An Angular phone input module
1,611 lines (1,602 loc) • 49.4 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, EventEmitter, Directive, Input, Output, HostListener, Component, ViewChild, NgModule } from '@angular/core';
import parsePhoneNumber from 'libphonenumber-js';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@angular/forms';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
class PhoneInputService {
constructor() { }
}
PhoneInputService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
PhoneInputService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputService, providedIn: 'root' });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: function () { return []; } });
// Array of country objects for the flag dropdown.
const allCountries = [
[
'Afghanistan (افغانستان)',
'af',
'93',
],
[
'Albania (Shqipëri)',
'al',
'355',
],
[
'Algeria (الجزائر)',
'dz',
'213',
],
[
'American Samoa',
'as',
'1684',
],
[
'Andorra',
'ad',
'376',
],
[
'Angola',
'ao',
'244',
],
[
'Anguilla',
'ai',
'1264',
],
[
'Antigua and Barbuda',
'ag',
'1268',
],
[
'Argentina',
'ar',
'54',
],
[
'Armenia (Հայաստան)',
'am',
'374',
],
[
'Aruba',
'aw',
'297',
],
[
'Australia',
'au',
'61',
],
[
'Austria (Österreich)',
'at',
'43',
],
[
'Azerbaijan (Azərbaycan)',
'az',
'994',
],
[
'Bahamas',
'bs',
'1242',
],
[
'Bahrain (البحرين)',
'bh',
'973',
],
[
'Bangladesh (বাংলাদেশ)',
'bd',
'880',
],
[
'Barbados',
'bb',
'1246',
],
[
'Belarus (Беларусь)',
'by',
'375',
],
[
'Belgium (België)',
'be',
'32',
],
[
'Belize',
'bz',
'501',
],
[
'Benin (Bénin)',
'bj',
'229',
],
[
'Bermuda',
'bm',
'1441',
],
[
'Bhutan (འབྲུག)',
'bt',
'975',
],
[
'Bolivia',
'bo',
'591',
],
[
'Bosnia and Herzegovina (Босна и Херцеговина)',
'ba',
'387',
],
[
'Botswana',
'bw',
'267',
],
[
'Brazil (Brasil)',
'br',
'55',
],
[
'British Indian Ocean Territory',
'io',
'246',
],
[
'British Virgin Islands',
'vg',
'1284',
],
[
'Brunei',
'bn',
'673',
],
[
'Bulgaria (България)',
'bg',
'359',
],
[
'Burkina Faso',
'bf',
'226',
],
[
'Burundi (Uburundi)',
'bi',
'257',
],
[
'Cambodia (កម្ពុជា)',
'kh',
'855',
],
[
'Cameroon (Cameroun)',
'cm',
'237',
],
[
'Canada',
'ca',
'1',
],
[
'Cape Verde (Kabu Verdi)',
'cv',
'238',
],
[
'Caribbean Netherlands',
'bq',
'599',
],
[
'Cayman Islands',
'ky',
'1345',
],
[
'Central African Republic (République centrafricaine)',
'cf',
'236',
],
[
'Chad (Tchad)',
'td',
'235',
],
[
'Chile',
'cl',
'56',
],
[
'China (中国)',
'cn',
'86',
],
[
'Christmas Island',
'cx',
'61',
],
[
'Cocos (Keeling) Islands',
'cc',
'61',
],
[
'Colombia',
'co',
'57',
],
[
'Comoros (جزر القمر)',
'km',
'269',
],
[
'Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)',
'cd',
'243',
],
[
'Congo (Republic) (Congo-Brazzaville)',
'cg',
'242',
],
[
'Cook Islands',
'ck',
'682',
],
[
'Costa Rica',
'cr',
'506',
],
[
'Côte d’Ivoire',
'ci',
'225',
],
[
'Croatia (Hrvatska)',
'hr',
'385',
],
[
'Cuba',
'cu',
'53',
],
[
'Curaçao',
'cw',
'599',
],
[
'Cyprus (Κύπρος)',
'cy',
'357',
],
[
'Czech Republic (Česká republika)',
'cz',
'420',
],
[
'Denmark (Danmark)',
'dk',
'45',
],
[
'Djibouti',
'dj',
'253',
],
[
'Dominica',
'dm',
'1767',
],
[
'Dominican Republic (República Dominicana)',
'do',
'1',
],
[
'Ecuador',
'ec',
'593',
],
[
'Egypt (مصر)',
'eg',
'20',
],
[
'El Salvador',
'sv',
'503',
],
[
'Equatorial Guinea (Guinea Ecuatorial)',
'gq',
'240',
],
[
'Eritrea',
'er',
'291',
],
[
'Estonia (Eesti)',
'ee',
'372',
],
[
'Ethiopia',
'et',
'251',
],
[
'Falkland Islands (Islas Malvinas)',
'fk',
'500',
],
[
'Faroe Islands (Føroyar)',
'fo',
'298',
],
[
'Fiji',
'fj',
'679',
],
[
'Finland (Suomi)',
'fi',
'358',
],
[
'France',
'fr',
'33',
],
[
'French Guiana (Guyane française)',
'gf',
'594',
],
[
'French Polynesia (Polynésie française)',
'pf',
'689',
],
[
'Gabon',
'ga',
'241',
],
[
'Gambia',
'gm',
'220',
],
[
'Georgia (საქართველო)',
'ge',
'995',
],
[
'Germany (Deutschland)',
'de',
'49',
],
[
'Ghana (Gaana)',
'gh',
'233',
],
[
'Gibraltar',
'gi',
'350',
],
[
'Greece (Ελλάδα)',
'gr',
'30',
],
[
'Greenland (Kalaallit Nunaat)',
'gl',
'299',
],
[
'Grenada',
'gd',
'1473',
],
[
'Guadeloupe',
'gp',
'590',
],
[
'Guam',
'gu',
'1671',
],
[
'Guatemala',
'gt',
'502',
],
[
'Guernsey',
'gg',
'44',
1,
],
[
'Guinea (Guinée)',
'gn',
'224',
],
[
'Guinea-Bissau (Guiné Bissau)',
'gw',
'245',
],
[
'Guyana',
'gy',
'592',
],
[
'Haiti',
'ht',
'509',
],
[
'Honduras',
'hn',
'504',
],
[
'Hong Kong (香港)',
'hk',
'852',
],
[
'Hungary (Magyarország)',
'hu',
'36',
],
[
'Iceland (Ísland)',
'is',
'354',
],
[
'India (भारत)',
'in',
'91',
],
[
'Indonesia',
'id',
'62',
],
[
'Iran (ایران)',
'ir',
'98',
],
[
'Iraq (العراق)',
'iq',
'964',
],
[
'Ireland',
'ie',
'353',
],
[
'Isle of Man',
'im',
'44',
],
[
'Israel (ישראל)',
'il',
'972',
],
[
'Italy (Italia)',
'it',
'39',
],
[
'Jamaica',
'jm',
'1876',
],
[
'Japan (日本)',
'jp',
'81',
],
[
'Jersey',
'je',
'44',
],
[
'Jordan (الأردن)',
'jo',
'962',
],
[
'Kazakhstan (Казахстан)',
'kz',
'7',
],
[
'Kenya',
'ke',
'254',
],
[
'Kiribati',
'ki',
'686',
],
[
'Kosovo',
'xk',
'383',
],
[
'Kuwait (الكويت)',
'kw',
'965',
],
[
'Kyrgyzstan (Кыргызстан)',
'kg',
'996',
],
[
'Laos (ລາວ)',
'la',
'856',
],
[
'Latvia (Latvija)',
'lv',
'371',
],
[
'Lebanon (لبنان)',
'lb',
'961',
],
[
'Lesotho',
'ls',
'266',
],
[
'Liberia',
'lr',
'231',
],
[
'Libya (ليبيا)',
'ly',
'218',
],
[
'Liechtenstein',
'li',
'423',
],
[
'Lithuania (Lietuva)',
'lt',
'370',
],
[
'Luxembourg',
'lu',
'352',
],
[
'Macau (澳門)',
'mo',
'853',
],
[
'Macedonia (FYROM) (Македонија)',
'mk',
'389',
],
[
'Madagascar (Madagasikara)',
'mg',
'261',
],
[
'Malawi',
'mw',
'265',
],
[
'Malaysia',
'my',
'60',
],
[
'Maldives',
'mv',
'960',
],
[
'Mali',
'ml',
'223',
],
[
'Malta',
'mt',
'356',
],
[
'Marshall Islands',
'mh',
'692',
],
[
'Martinique',
'mq',
'596',
],
[
'Mauritania (موريتانيا)',
'mr',
'222',
],
[
'Mauritius (Moris)',
'mu',
'230',
],
[
'Mayotte',
'yt',
'262',
],
[
'Mexico (México)',
'mx',
'52',
],
[
'Micronesia',
'fm',
'691',
],
[
'Moldova (Republica Moldova)',
'md',
'373',
],
[
'Monaco',
'mc',
'377',
],
[
'Mongolia (Монгол)',
'mn',
'976',
],
[
'Montenegro (Crna Gora)',
'me',
'382',
],
[
'Montserrat',
'ms',
'1664',
],
[
'Morocco (المغرب)',
'ma',
'212',
],
[
'Mozambique (Moçambique)',
'mz',
'258',
],
[
'Myanmar (Burma) (မြန်မာ)',
'mm',
'95',
],
[
'Namibia (Namibië)',
'na',
'264',
],
[
'Nauru',
'nr',
'674',
],
[
'Nepal (नेपाल)',
'np',
'977',
],
[
'Netherlands (Nederland)',
'nl',
'31',
],
[
'New Caledonia (Nouvelle-Calédonie)',
'nc',
'687',
],
[
'New Zealand',
'nz',
'64',
],
[
'Nicaragua',
'ni',
'505',
],
[
'Niger (Nijar)',
'ne',
'227',
],
[
'Nigeria',
'ng',
'234',
],
[
'Niue',
'nu',
'683',
],
[
'Norfolk Island',
'nf',
'672',
],
[
'North Korea (조선 민주주의 인민 공화국)',
'kp',
'850',
],
[
'Northern Mariana Islands',
'mp',
'1670',
],
[
'Norway (Norge)',
'no',
'47',
],
[
'Oman (عُمان)',
'om',
'968',
],
[
'Pakistan (پاکستان)',
'pk',
'92',
],
[
'Palau',
'pw',
'680',
],
[
'Palestine (فلسطين)',
'ps',
'970',
],
[
'Panama (Panamá)',
'pa',
'507',
],
[
'Papua New Guinea',
'pg',
'675',
],
[
'Paraguay',
'py',
'595',
],
[
'Peru (Perú)',
'pe',
'51',
],
[
'Philippines',
'ph',
'63',
],
[
'Poland (Polska)',
'pl',
'48',
],
[
'Portugal',
'pt',
'351',
],
[
'Puerto Rico',
'pr',
'1',
],
[
'Qatar (قطر)',
'qa',
'974',
],
[
'Réunion (La Réunion)',
're',
'262',
],
[
'Romania (România)',
'ro',
'40',
],
[
'Russia (Россия)',
'ru',
'7',
],
[
'Rwanda',
'rw',
'250',
],
[
'Saint Barthélemy',
'bl',
'590',
],
[
'Saint Helena',
'sh',
'290',
],
[
'Saint Kitts and Nevis',
'kn',
'1869',
],
[
'Saint Lucia',
'lc',
'1758',
],
[
'Saint Martin (Saint-Martin (partie française))',
'mf',
'590',
],
[
'Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)',
'pm',
'508',
],
[
'Saint Vincent and the Grenadines',
'vc',
'1784',
],
[
'Samoa',
'ws',
'685',
],
[
'San Marino',
'sm',
'378',
],
[
'São Tomé and Príncipe (São Tomé e Príncipe)',
'st',
'239',
],
[
'Saudi Arabia (المملكة العربية السعودية)',
'sa',
'966',
],
[
'Senegal (Sénégal)',
'sn',
'221',
],
[
'Serbia (Србија)',
'rs',
'381',
],
[
'Seychelles',
'sc',
'248',
],
[
'Sierra Leone',
'sl',
'232',
],
[
'Singapore',
'sg',
'65',
],
[
'Sint Maarten',
'sx',
'1721',
],
[
'Slovakia (Slovensko)',
'sk',
'421',
],
[
'Slovenia (Slovenija)',
'si',
'386',
],
[
'Solomon Islands',
'sb',
'677',
],
[
'Somalia (Soomaaliya)',
'so',
'252',
],
[
'South Africa',
'za',
'27',
],
[
'South Korea (대한민국)',
'kr',
'82',
],
[
'South Sudan (جنوب السودان)',
'ss',
'211',
],
[
'Spain (España)',
'es',
'34',
],
[
'Sri Lanka (ශ්රී ලංකාව)',
'lk',
'94',
],
[
'Sudan (السودان)',
'sd',
'249',
],
[
'Suriname',
'sr',
'597',
],
[
'Svalbard and Jan Mayen',
'sj',
'47',
],
[
'Swaziland',
'sz',
'268',
],
[
'Sweden (Sverige)',
'se',
'46',
],
[
'Switzerland (Schweiz)',
'ch',
'41',
],
[
'Syria (سوريا)',
'sy',
'963',
],
[
'Taiwan (台灣)',
'tw',
'886',
],
[
'Tajikistan',
'tj',
'992',
],
[
'Tanzania',
'tz',
'255',
],
[
'Thailand (ไทย)',
'th',
'66',
],
[
'Timor-Leste',
'tl',
'670',
],
[
'Togo',
'tg',
'228',
],
[
'Tokelau',
'tk',
'690',
],
[
'Tonga',
'to',
'676',
],
[
'Trinidad and Tobago',
'tt',
'1868',
],
[
'Tunisia (تونس)',
'tn',
'216',
],
[
'Turkey (Türkiye)',
'tr',
'90',
],
[
'Turkmenistan',
'tm',
'993',
],
[
'Turks and Caicos Islands',
'tc',
'1649',
],
[
'Tuvalu',
'tv',
'688',
],
[
'U.S. Virgin Islands',
'vi',
'1340',
],
[
'Uganda',
'ug',
'256',
],
[
'Ukraine (Україна)',
'ua',
'380',
],
[
'United Arab Emirates (الإمارات العربية المتحدة)',
'ae',
'971',
],
[
'United Kingdom',
'gb',
'44',
],
[
'United States',
'us',
'1',
],
[
'Uruguay',
'uy',
'598',
],
[
'Uzbekistan (Oʻzbekiston)',
'uz',
'998',
],
[
'Vanuatu',
'vu',
'678',
],
[
'Vatican City (Città del Vaticano)',
'va',
'39',
],
[
'Venezuela',
've',
'58',
],
[
'Vietnam (Việt Nam)',
'vn',
'84',
],
[
'Wallis and Futuna (Wallis-et-Futuna)',
'wf',
'681',
],
[
'Western Sahara (الصحراء الغربية)',
'eh',
'212',
],
[
'Yemen (اليمن)',
'ye',
'967',
],
[
'Zambia',
'zm',
'260',
],
[
'Zimbabwe',
'zw',
'263',
],
[
'Åland Islands',
'ax',
'358',
],
];
var allCountries$1 = allCountries.map(([name, iso2, dialCode]) => ({
name,
iso2: String(iso2).toUpperCase(),
dialCode,
}));
class TypingDirective {
constructor(el) {
this.el = el;
this.inputInterval = 100;
this.run = new EventEmitter();
this.finish = new EventEmitter();
}
onType(e) {
const tping = () => {
this.run.emit();
};
const tpfinished = () => {
this.finish.emit();
};
if (e.type === "keyup") {
if (e.key !== "Backspace")
tping();
clearTimeout(this.inputTimer);
this.inputTimer = setTimeout(tpfinished, this.inputInterval);
}
else if (e.type === "keydown") {
clearTimeout(this.inputTimer);
}
}
}
TypingDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: TypingDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
TypingDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.16", type: TypingDirective, selector: "[inputTyping]", inputs: { inputInterval: "inputInterval" }, outputs: { run: "run", finish: "finish" }, host: { listeners: { "keydown": "onType($event)", "keyup": "onType($event)" } }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: TypingDirective, decorators: [{
type: Directive,
args: [{
selector: '[inputTyping]'
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { inputInterval: [{
type: Input
}], run: [{
type: Output
}], finish: [{
type: Output
}], onType: [{
type: HostListener,
args: ["keydown", ['$event']]
}, {
type: HostListener,
args: ["keyup", ['$event']]
}] } });
var FormControlEvent;
(function (FormControlEvent) {
FormControlEvent["INVALID"] = "INVALID";
FormControlEvent["VALID"] = "VALID";
})(FormControlEvent || (FormControlEvent = {}));
class PhoneInputComponent {
constructor(el, cd) {
this.el = el;
this.cd = cd;
this.value = "";
this.label = "";
this.hasError = false;
this.hasSuccess = false;
this.placeholder = "";
this.name = "lbgm-phone-input";
this.required = false;
this.defaultCountry = 'BJ';
this.arrow = true;
this.listHeight = 150;
this.allowed = ([]);
this.phoneEvent = new EventEmitter(true);
this.phoneData = new EventEmitter(true);
this.country = new EventEmitter(true);
this.countries = allCountries$1;
this.openSelect = false;
this.phone = "";
this.popupPos = "bottom";
this.focus = false;
}
/**
* TrackBy for *ngFor
* @param index
* @param item
* @returns
*/
trackByCountry(index, country) {
return index;
// you can also return item.X;
}
ngOnInit() {
// initialize default country selected
this.defaultSelected = this.formatPhoneInput(this.value);
}
ngOnChanges(changes) {
//
// watch changes on @Input() here
}
ngDoCheck() {
// this.cd.markForCheck();
}
ngAfterViewInit() {
this.emitAll();
// outside
document.addEventListener("click", (event) => {
var _a, _b;
if (((_a = this.basePhoneArrow) === null || _a === void 0 ? void 0 : _a.nativeElement) &&
!((_b = this.basePhoneArrow) === null || _b === void 0 ? void 0 : _b.nativeElement).contains(event.target)) {
this.openSelect = false;
}
});
}
/**
* used to send custom Event: usable in case of scroll turning off when popup is under
*/
cev_dash_select() {
var _a;
const event = new CustomEvent("CEV_SELECT_POPUP", {
detail: { opened: this.openSelect, target: (_a = this.selectPhone) === null || _a === void 0 ? void 0 : _a.nativeElement },
});
document.body.dispatchEvent(event);
}
/**
* filt allowedCountries from props
*/
get allowedCountries() {
const tbl = this.allowed.length !== 0
? this.countries.filter((o) => this.allowed.includes(o.iso2))
: this.countries;
return tbl;
}
get getGroup() {
return this.group;
}
get getName() {
return this.name;
}
get fieldError() {
var _a;
if (!this.controls)
return (_a = this.hasError) !== null && _a !== void 0 ? _a : false;
const f = this.controls[this.name];
return f.status === FormControlEvent.INVALID && f.touched && this.required;
}
get fieldSuccess() {
var _a;
if (!this.controls)
return (_a = this.hasSuccess) !== null && _a !== void 0 ? _a : false;
const f = this.controls[this.name];
return f.status === FormControlEvent.VALID && f.touched && this.required;
}
/**
* ToggleSelect
* to open countries list
*/
toggleSelect() {
var _a;
this.openSelect = !this.openSelect;
// calculate popup position: top or bottom
const selectRect = (_a = this.selectPhone) === null || _a === void 0 ? void 0 : _a.nativeElement.getBoundingClientRect();
// y
this.popupPos = selectRect.bottom < this.listHeight ? "top" : "bottom";
//
this.cev_dash_select();
}
;
/**
* formatPhoneInput
* used to format Phone Input
* @param val
*/
formatPhoneInput(val) {
var _a;
const phoneNumber = parsePhoneNumber(`+${val}`);
if (phoneNumber) {
this.phone = phoneNumber.nationalNumber;
return {
iso2: phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.country,
dialCode: phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.countryCallingCode,
name: (_a = this.countries.find((o) => o.iso2 === (phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.country))) === null || _a === void 0 ? void 0 : _a.name,
};
}
// else
return Object.assign({}, this.countries.find((o) => o.iso2 === this.defaultCountry));
}
;
/**
* emitPhone
* used to emit phone in internationalFormat
*/
emitPhone() {
if (this.phone)
this.phoneEvent.emit(`${this.defaultSelected.dialCode}${this.phone}`);
else
this.phoneEvent.emit("");
}
;
/**
* emitPhoneData
* Used to emit phoneData as an object
* @returns {}
*/
emitPhoneData(event) {
void event;
const ph = parsePhoneNumber(`+${this.defaultSelected.dialCode}${this.phone}`);
this.phoneData.emit({
country: ph === null || ph === void 0 ? void 0 : ph.country,
dialCode: ph === null || ph === void 0 ? void 0 : ph.countryCallingCode,
nationalNumber: ph === null || ph === void 0 ? void 0 : ph.nationalNumber,
number: ph === null || ph === void 0 ? void 0 : ph.number,
isValid: ph === null || ph === void 0 ? void 0 : ph.isValid(),
});
}
;
/**
* emitAll
* used to emit all event
*/
emitAll() {
this.country.emit(this.defaultSelected.iso2);
this.emitPhone();
this.emitPhoneData();
}
/**
* to select any country
* @param country
*/
choose(country) {
this.defaultSelected = country;
this.openSelect = false;
this.emitAll();
}
;
/**
* bind on input
* @param event
*/
onPhoneInput(event) {
event.target.value = this.phone = String(event.target.value).replace(/\D/g, "");
this.emitPhone();
}
;
focusOn(event) {
switch (event.type) {
case "mouseenter":
this.focus = true;
break;
case "mouseleave":
this.focus = false;
break;
default:
break;
}
}
}
PhoneInputComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
PhoneInputComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: PhoneInputComponent, selector: "lbgm-phone-input", inputs: { value: "value", label: "label", hasError: "hasError", hasSuccess: "hasSuccess", placeholder: "placeholder", name: "name", required: "required", defaultCountry: "defaultCountry", arrow: "arrow", listHeight: "listHeight", allowed: "allowed", group: "group", controls: "controls" }, outputs: { phoneEvent: "phoneEvent", phoneData: "phoneData", country: "country" }, host: { listeners: { "mouseleave": "focusOn($event)", "mouseenter": "focusOn($event)" } }, viewQueries: [{ propertyName: "basePhoneArrow", first: true, predicate: ["basePhoneArrow"], descendants: true }, { propertyName: "inputBase", first: true, predicate: ["inputBase"], descendants: true }, { propertyName: "arrowIcon", first: true, predicate: ["arrowIcon"], descendants: true, static: true }, { propertyName: "selectPhone", first: true, predicate: ["selectPhone"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<div\n #selectPhone\n data-widget-item=\"baseinput\"\n class=\"flex flex-col relative\"\n data-lbgm-phonenumberinput=\"component\"\n>\n <!--phone-number-input core-->\n <div\n data-children=\"core\"\n class=\"w-full flex flex-col relative\"\n >\n <!---->\n <label\n *ngIf=\"label\"\n class=\"cursor-pointer baseinput-label p-3px text-xs text-left leading-3 tracking-mz1px text-3dark font-medium select-none bg-white absolute left-2 -translate-y-2\"\n [ngClass]=\"{ 'text-red': fieldError, 'text-blue': focus || fieldSuccess }\"\n [for]=\"name\"\n data-children=\"label\"\n >\n <span data-children=\"labelText\">{{ label }}</span>\n <!---->\n <span\n *ngIf=\"required\"\n data-children=\"requiredStar\"\n class=\"text-left text-DA1414 font-semibold opacity-80 text-xs\"\n > *</span\n >\n </label>\n <!--input-->\n <div\n data-children=\"inputcore\"\n #selectPhoneButton\n class=\"bg-white baseinput-core border w-full border-3dark rounded-md py-2 px-4 flex flex-shrink flex-nowrap items-center space-x-2\"\n [ngClass]=\"{ 'border-red': fieldError, 'border-blue': fieldSuccess, 'border-blue-50': focus }\"\n >\n <span\n (click)=\"toggleSelect()\"\n class=\"inline-flex flex-nowrap items-center space-x-2 cursor-pointer\"\n #basePhoneArrow\n data-children=\"arrowGroup\"\n >\n <span *ngIf=\"arrow; then iconTemplate\"></span>\n <ng-template #iconTemplate>\n <span #arrowIcon [attr.data-arrow-icon]=\"arrowIcon.children.length\" class=\"inline-flex flex-shrink-0 select-none\">\n <ng-content select=\"[arrow]\"></ng-content>\n </span>\n <span *ngIf=\"!arrowIcon.children.length\" [attr.data-arrow-icon]=\"arrowIcon.children.length\" class=\"inline-flex flex-shrink-0\">\n <svg\n width=\"12\"\n height=\"6\"\n viewBox=\"0 0 12 6\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M0.96967 0.21967C1.26256 -0.0732233 1.73744 -0.0732233 2.03033 0.21967L6 4.18934L9.96967 0.21967C10.2626 -0.0732233 10.7374 -0.0732233 11.0303 0.21967C11.3232 0.512563 11.3232 0.987437 11.0303 1.28033L6.53033 5.78033C6.23744 6.07322 5.76256 6.07322 5.46967 5.78033L0.96967 1.28033C0.676777 0.987437 0.676777 0.512563 0.96967 0.21967Z\"\n [attr.fill]=\"focus ? 'rgb(29 144 237)' : 'rgba(51, 51, 51, 0.5)'\"\n />\n </svg>\n </span>\n </ng-template>\n <span\n class=\"opacity-80 select-none inline-flex flex-whrink-0 font-medium text-3dark text-left text-xs leading-4\"\n [ngClass]=\"{ 'text-blue': focus }\"\n >\n {{ '+' + defaultSelected.dialCode }}\n </span>\n </span>\n <!-- INPUT ELEMENT -->\n <span *ngIf=\"group; then withGroup; else withoutGroup;\"></span>\n <ng-template #withGroup>\n <div class=\"w-full\" [formGroup]=\"getGroup\">\n <input\n #inputBase\n inputTyping\n data-children=\"htmlInput\"\n [placeholder]=\"placeholder\"\n [formControlName]=\"getName\"\n [name]=\"name\"\n [id]=\"name\"\n [value]=\"phone\"\n [autocomplete]=\"'off'\"\n [inputInterval]=\"300\"\n (input)=\"onPhoneInput($event)\"\n (finish)=\"emitPhoneData()\"\n spellcheck=\"false\"\n class=\"border-0 outline-none appearance-none flex-shrink w-full bg-transparent text-3dark text-base\"\n [ngClass]=\"{ 'text-blue': focus }\"\n type=\"text\"\n />\n </div>\n </ng-template>\n\n <ng-template #withoutGroup>\n <input\n #inputBase\n inputTyping\n data-children=\"htmlInput\"\n [placeholder]=\"placeholder\"\n [name]=\"name\"\n [id]=\"name\"\n [value]=\"phone\"\n [autocomplete]=\"'off'\"\n [inputInterval]=\"300\"\n (input)=\"onPhoneInput($event)\"\n (finish)=\"emitPhoneData()\"\n spellcheck=\"false\"\n class=\"border-0 outline-none appearance-none flex-shrink w-full bg-transparent text-3dark text-base\"\n [ngClass]=\"{ 'text-blue': focus }\"\n type=\"text\"\n />\n </ng-template>\n </div>\n <!--select option-->\n <div\n #selectOptions\n class=\"w-full rounded border border-3dark-2 bg-white absolute z-1 lbgm-phone-scrll\"\n *ngIf=\"openSelect\"\n data-children=\"countriesList\"\n [ngClass]=\"{ 'bottom-0': popupPos === 'top', 'mt-z281rem top-full': popupPos === 'bottom' }\"\n [style.maxHeight]=\"listHeight + 'px'\"\n >\n <div\n class=\"w-full py-2 px-4 cursor-pointer text-left hover:bg-3dark-1\"\n *ngFor=\"let country of allowedCountries; let lastitr = last; trackBy: trackByCountry\"\n (click)=\"choose(country)\"\n [attr.data-country]=\"country.iso2\"\n >\n <span class=\"font-semibold text-xs text-3dark\">\n {{ country.name }}\n </span>\n </div>\n </div>\n <!-- end core-->\n </div>\n\n <!-- any slot -->\n <ng-content select=\"[slot]\"></ng-content>\n</div>", styles: ["*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:currentColor}:before,:after{--tw-content: \"\"}html{line-height:1.5;-webkit-text-size-adjust:100%;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::-webkit-backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.static{position:static}.absolute{position:absolute}.relative{position:relative}.bottom-0{bottom:0px}.left-2{left:.5rem}.top-full{top:100%}.z-1{z-index:1}.mt-z281rem{margin-top:.281rem}.flex{display:flex}.inline-flex{display:inline-flex}.w-full{width:100%}.flex-shrink{flex-shrink:1}.flex-shrink-0{flex-shrink:0}.-translate-y-2{--tw-translate-y: -.5rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;user-select:none}.appearance-none{-webkit-appearance:none;appearance:none}.flex-col{flex-direction:column}.flex-nowrap{flex-wrap:nowrap}.items-center{align-items:center}.space-x-2>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(.5rem * var(--tw-space-x-reverse));margin-left:calc(.5rem * calc(1 - var(--tw-space-x-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-0{border-width:0px}.border-3dark{border-color:#33333380}.border-3dark-2{border-color:#3333}.border-blue{--tw-border-opacity: 1;border-color:rgb(29 144 237/var(--tw-border-opacity))}.border-blue-50{border-color:#1d90ed80}.border-red{--tw-border-opacity: 1;border-color:rgb(255 0 0/var(--tw-border-opacity))}.bg-transparent{background-color:transparent}.bg-white{--tw-bg-opacity: 1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.p-3px{padding:3px}.px-4{padding-left:1rem;padding-right:1rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.text-left{text-align:left}.text-base{font-size:1rem;line-height:1.5rem}.text-xs{font-size:.75rem;line-height:1rem}.font-medium{font-weight:500}.font-semibold{font-weight:600}.leading-3{line-height:.75rem}.leading-4{line-height:1rem}.tracking-mz1px{letter-spacing:-.1px}.text-3dark{color:#33333380}.text-DA1414{--tw-text-opacity: 1;color:rgb(218 20 20/var(--tw-text-opacity))}.text-blue{--tw-text-opacity: 1;color:rgb(29 144 237/var(--tw-text-opacity))}.text-red{--tw-text-opacity: 1;color:rgb(255 0 0/var(--tw-text-opacity))}.opacity-80{opacity:.8}.outline-none{outline:2px solid transparent;outline-offset:2px}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.hover\\:bg-3dark-1:hover{background-color:#3333331a}\n", ":host{display:block;font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\";color:#333;box-sizing:border-box;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;position:relative}@media screen and (-webkit-min-device-pixel-ratio: 0){.lbgm-phone-scrll::-webkit-scrollbar{width:6px;height:6px}.lbgm-phone-scrll::-webkit-scrollbar-track{background:transparent}.lbgm-phone-scrll::-webkit-scrollbar-thumb{border-radius:6px;background:rgba(0,106,82,.8);border:0;display:none}.lbgm-phone-scrll:hover.lbgm-phone-scrll::-webkit-scrollbar-thumb{display:initial}.lbgm-phone-scrll::-webkit-scrollbar-corner{display:none}}@-moz-document url-prefix(){.lbgm-phone-scrll{scrollbar-color:rgba(0,106,82,.8) transparent;scrollbar-width:none}.lbgm-phone-scrll:hover{scrollbar-width:thin}}[data-widget-item=baseinput]{transition:all .2s ease-in-out}[data-widget-item=baseinput] *{box-sizing:border-box}[data-widget-item=baseinput] label.error{color:red}[data-widget-item=baseinput] label.success{color:#1d90ed}[data-widget-item=baseinput] [data-children=countriesList]{overflow-y:auto;filter:drop-shadow(0 5px 15px rgba(0,0,0,.15))}[data-widget-item=baseinput] [data-children=inputcore] input::placeholder{font-weight:normal;color:#333}[data-widget-item=baseinput] [data-children=inputcore] input:-webkit-autofill,[data-widget-item=baseinput] [data-children=inputcore] input:-webkit-autofill:hover,[data-widget-item=baseinput] [data-children=inputcore] input:-webkit-autofill:focus,[data-widget-item=baseinput] [data-children=inputcore] input:-webkit-autofill:active{-webkit-transition:background-color 5000s ease-in-out 0s;transition:background-color 5000s ease-in-out 0s}\n"], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i2.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: TypingDirective, selector: "[inputTyping]", inputs: ["inputInterval"], outputs: ["run", "finish"] }, { type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i2.FormControlName, selector: "[formControlName]", inputs: ["disabled", "formControlName", "ngModel"], outputs: ["ngModelChange"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputComponent, decorators: [{
type: Component,
args: [{
selector: 'lbgm-phone-input',
templateUrl: './phone-input.component.html',
styleUrls: [
'./tailwind.scss',
'./phone-input.component.scss',
]
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { value: [{
type: Input
}], label: [{
type: Input
}], hasError: [{
type: Input
}], hasSuccess: [{
type: Input
}], placeholder: [{
type: Input
}], name: [{
type: Input
}], required: [{
type: Input
}], defaultCountry: [{
type: Input
}], arrow: [{
type: Input
}], listHeight: [{
type: Input
}], allowed: [{
type: Input
}], group: [{
type: Input
}], controls: [{
type: Input
}], basePhoneArrow: [{
type: ViewChild,
args: ['basePhoneArrow']
}], inputBase: [{
type: ViewChild,
args: ['inputBase']
}], arrowIcon: [{
type: ViewChild,
args: ['arrowIcon', { static: true }]
}], selectPhone: [{
type: ViewChild,
args: ['selectPhone']
}], phoneEvent: [{
type: Output
}], phoneData: [{
type: Output
}], country: [{
type: Output
}], focusOn: [{
type: HostListener,
args: ['mouseleave', ['$event']]
}, {
type: HostListener,
args: ['mouseenter', ['$event']]
}] } });
class PhoneInputModule {
}
PhoneInputModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
PhoneInputModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputModule, declarations: [PhoneInputComponent,
TypingDirective], imports: [CommonModule,
ReactiveFormsModule,
FormsModule], exports: [PhoneInputComponent] });
PhoneInputModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputModule, providers: [
{
provide: Window,
useValue: window
}
], imports: [[
CommonModule,
ReactiveFormsModule,
FormsModule
]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: PhoneInputModule, decorators: [{
type: NgModule,
args: [{
declarations: [
PhoneInputComponent,
TypingDirective
],
imports: [
CommonModule,
ReactiveFormsModule,
FormsModule
],
exports: [
PhoneInputComponent
],
providers: [
{
provide: Window,
useValue: window
}
]
}]
}] });
/*
* Public API Surface of phone-input
*/
/**
* Generated bundle index. Do not edit.
*/
export { FormControlEvent, PhoneInputComponent, PhoneInputModule, PhoneInputService };
//# sourceMappingURL=lbgm-phone-input.js.map