File

projects/maplander/shared/src/lib/components/country-code/country-code.component.ts

Implements

OnInit

Metadata

encapsulation ViewEncapsulation.None
selector lib-country-code
styleUrls ./country-code.component.scss
templateUrl ./country-code.component.html

Index

Properties
Methods

Constructor

constructor(_dialogRef: MatDialogRef)
Parameters :
Name Type Optional
_dialogRef MatDialogRef<CountryCodeComponent> No

Methods

Public close
close()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public search
search(event: any)
Parameters :
Name Type Optional
event any No
Returns : void
Public selectCountry
selectCountry(country: CountryCode)
Parameters :
Name Type Optional
country CountryCode No
Returns : void

Properties

Public _dialogRef
Type : MatDialogRef<CountryCodeComponent>
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.component.scss


.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
Component
Html element with directive

result-matching ""

    No results matching ""