forked from angular-material-extensions/select-country
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
1,368 additions
and
889 deletions.
There are no files selected for viewing
117 changes: 91 additions & 26 deletions
117
...ects/angular-material-extensions/select-country/src/lib/mat-select-country.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,93 @@ | ||
<mat-form-field [appearance]="appearance"> | ||
<mat-label *ngIf="label">{{label}}</mat-label> | ||
<mat-icon *ngIf="this.value" [svgIcon]="this.value?.alpha2Code?.toLowerCase()" class="mr-12 s-20 secondary-text" | ||
matSuffix></mat-icon> | ||
<input (blur)="onBlur()" (input)="inputChanged($event?.target?.value)" | ||
[class]="class" | ||
[matAutocomplete]="this.countryAutocomplete" | ||
[placeholder]="this.placeHolder" | ||
[readonly]="this.readonly" | ||
[tabIndex]="tabIndex" | ||
[value]="showCallingCode ? (this.value ? (this.value?.name + ' (' + this.value?.callingCode + ')') : '') : this.value?.name" | ||
[required]="this.required" | ||
[disabled]="this.disabled || this.loadingDB" | ||
[autocomplete]="this.autocomplete" | ||
[name]="this.name" | ||
aria-label="country" | ||
matInput type="text" | ||
#inputElement> | ||
<mat-progress-bar *ngIf="this.loadingDB || this.loading" mode="buffer"></mat-progress-bar> | ||
<mat-autocomplete #countryAutocomplete="matAutocomplete" (opened)="autocompleteScroll()" | ||
(optionSelected)="onOptionsSelected($event)"> | ||
<mat-option *ngFor="let country of filteredOptions" [value]="country?.name"> | ||
<mat-icon [svgIcon]="country?.alpha2Code?.toLowerCase()"></mat-icon> | ||
<small *ngIf="!showCallingCode">{{ [country?.name, country?.alpha3Code] | joinStrings }}</small> | ||
<small *ngIf="showCallingCode">{{ [country?.name, '(' + country?.callingCode + ')'] | joinStrings:' ' }}</small> | ||
</mat-option> | ||
</mat-autocomplete> | ||
<mat-label *ngIf="label">{{ label }}</mat-label> | ||
<mat-icon | ||
*ngIf="this.value" | ||
[svgIcon]="this.value?.alpha2Code?.toLowerCase()" | ||
class="mr-12 s-20 secondary-text" | ||
matSuffix | ||
></mat-icon> | ||
<input | ||
*ngIf="!!formControl" | ||
(blur)="onBlur()" | ||
(input)="inputChanged($event?.target?.value)" | ||
[class]="class" | ||
[matAutocomplete]="this.countryAutocomplete" | ||
[placeholder]="this.placeHolder" | ||
[readonly]="this.readonly" | ||
[tabIndex]="tabIndex" | ||
[value]="formControl.value?.name" | ||
[formControl]="formControl" | ||
[autocomplete]="this.autocomplete" | ||
[name]="this.name" | ||
aria-label="country" | ||
matInput | ||
type="text" | ||
#inputElement | ||
/> | ||
<input | ||
*ngIf="!formControl" | ||
(blur)="onBlur()" | ||
(input)="inputChanged($event?.target?.value)" | ||
[class]="class" | ||
[matAutocomplete]="this.countryAutocomplete" | ||
[placeholder]="this.placeHolder" | ||
[readonly]="this.readonly" | ||
[tabIndex]="tabIndex" | ||
[value]=" | ||
showCallingCode | ||
? this.value | ||
? this.value?.name + ' (' + this.value?.callingCode + ')' | ||
: '' | ||
: this.value?.name | ||
" | ||
[required]="this.required" | ||
[disabled]="this.disabled || this.loadingDB" | ||
[autocomplete]="this.autocomplete" | ||
[name]="this.name" | ||
aria-label="country" | ||
matInput | ||
type="text" | ||
#inputElement | ||
/> | ||
<mat-progress-bar | ||
*ngIf="this.loadingDB || this.loading" | ||
mode="buffer" | ||
></mat-progress-bar> | ||
<mat-autocomplete | ||
#countryAutocomplete="matAutocomplete" | ||
(opened)="autocompleteScroll()" | ||
(optionSelected)="onOptionsSelected($event)" | ||
> | ||
<mat-option *ngFor="let country of filteredOptions" [value]="country?.name"> | ||
<div class="d-flex"> | ||
<mat-icon [svgIcon]="country?.alpha2Code?.toLowerCase()"></mat-icon> | ||
<small | ||
class="country-list-item" | ||
[title]="[country?.name, country?.alpha3Code] | joinStrings" | ||
*ngIf="!showCallingCode" | ||
>{{ [country?.name, country?.alpha3Code] | joinStrings }}</small | ||
> | ||
<small | ||
class="country-list-item" | ||
[title]=" | ||
[country?.name, '(' + country?.callingCode + ')'] | ||
| joinStrings : ' ' | ||
" | ||
*ngIf="showCallingCode" | ||
>{{ | ||
[country?.name, "(" + country?.callingCode + ")"] | ||
| joinStrings : " " | ||
}}</small | ||
> | ||
</div> | ||
</mat-option> | ||
</mat-autocomplete> | ||
<mat-icon | ||
class="cursor-pointer pos-rel" | ||
matSuffix | ||
*ngIf="cleareable && !!value" | ||
(click)="clear()" | ||
>cancel</mat-icon | ||
> | ||
<mat-error *ngIf="formControl && formControl.invalid">{{ error }}</mat-error> | ||
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.cursor-pointer { | ||
cursor: pointer; | ||
} | ||
.pos-rel { | ||
position: relative; | ||
} | ||
.country-list-item { | ||
float: right; | ||
margin-left: 0.5rem; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
.d-flex { | ||
display: flex; | ||
width: 100%; | ||
} |
Oops, something went wrong.