File
Implements
Metadata
encapsulation |
ViewEncapsulation.None |
selector |
lib-country-code |
styleUrls |
./country-code.component.scss |
templateUrl |
./country-code.component.html |
Methods
Public
search
|
search(event: any)
|
|
Parameters :
Name |
Type |
Optional |
event |
any
|
No
|
|
Public
selectCountry
|
selectCountry(country: CountryCode)
|
|
Parameters :
Name |
Type |
Optional |
country |
CountryCode
|
No
|
|
Public
counties
|
Type : any[]
|
|
import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {MatDialogRef} from '@angular/material/dialog';
import {CountryCode} from '@maplander/types';
import {Constants} from '../../../utils/constants';
import {Utils} from '../../../utils/utils';
@Component({
selector: 'lib-country-code',
templateUrl: './country-code.component.html',
styleUrls: ['./country-code.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class CountryCodeComponent implements OnInit {
public counties: any[];
constructor(
public _dialogRef: MatDialogRef<CountryCodeComponent>
) {
}
ngOnInit() {
this.counties = Constants.CountryList;
}
public search(event: any): void {
const codesSearched = [];
const search = (event.srcElement.value).toLowerCase();
if (search === '') {
this.counties = Constants.CountryList;
} else {
this.counties.forEach((code: CountryCode) => {
const codeName = Utils.removeDiacritics(code.name).toLowerCase();
const codeNumber = code.code.toLowerCase();
const codeISO = code.iso.toLowerCase();
if (codeName.includes(search) || codeNumber.includes(search) || codeISO.includes(search)) {
codesSearched.push(code);
}
});
if (codesSearched.length > 0) {
this.counties = codesSearched;
} else {
this.counties = Constants.CountryList;
}
}
}
public selectCountry(country: CountryCode): void {
this._dialogRef.close(country);
}
public close(): void {
this._dialogRef.close(null);
}
}
<div id="country-code">
<mat-toolbar [color]="'primary'">
Selecciona una opción
<button type="button" mat-icon-button (click)="close()">
<mat-icon>close</mat-icon>
</button>
</mat-toolbar>
<div class="search">
<mat-form-field appearance="standard">
<input placeholder="Buscar" matInput type="text" label="Search country" (input)="search($event)">
</mat-form-field>
</div>
<mat-dialog-content>
<div class="container">
<div *ngFor="let country of counties" class="country">
<button mat-button (click)="selectCountry(country)">
<span>{{country.name}}</span>
<span>+{{country.code}}</span>
</button>
</div>
</div>
</mat-dialog-content>
</div>
.country-code-panel {
& mat-dialog-container {
width: 400px;
padding: 0;
@media screen and (max-width: 600px){
width: 100%;
}
}
}
#country-code{
mat-toolbar {
display: flex;
justify-content: space-between;
}
.search{
text-align: center;
mat-form-field{
width: 80%;
}
}
mat-dialog-content{
margin: 24px 0;
position: relative;
height: 200px;
.container{
.country{
width: 100%;
button{
width: 100%;
}
button span {
display: flex;
justify-content: space-between;
}
}
}
}
}
Legend
Html element with directive