@@ -12,6 +12,7 @@ import {
12
12
// @ts-ignore
13
13
import examples from ' libphonenumber-js/mobile/examples' ;
14
14
import { countries , type TCountryCode , getEmojiFlag } from ' countries-list' ;
15
+ import type { Select } from ' ember-power-select/components/power-select' ;
15
16
16
17
interface Signature {
17
18
Args: {};
@@ -55,9 +56,9 @@ const getCountryInfo = (countryCode: CountryCode): CountryInfo | undefined => {
55
56
56
57
export class PhoneInput extends Component <Signature > {
57
58
@tracked items: Array <CountryInfo > = [];
58
- @tracked selectedItem: CountryInfo | null = null ;
59
+ @tracked selectedItem: CountryInfo = getCountryInfo ( ' US ' ) ! ;
59
60
60
- @action onSelectItem(item : CountryInfo | null ): void {
61
+ @action onSelectItem(item : CountryInfo ): void {
61
62
this .selectedItem = item ;
62
63
}
63
64
@@ -72,20 +73,24 @@ export class PhoneInput extends Component<Signature> {
72
73
73
74
get placeholder(): string | undefined {
74
75
if (this .selectedItem ) {
75
- return ` +${ this .selectedItem .callingCode } ${ this . selectedItem . example ?.nationalNumber } ` ;
76
+ return this .selectedItem .example ?.nationalNumber ;
76
77
}
77
- return ' Select a country ' ;
78
+ return undefined ;
78
79
}
79
80
80
81
<template >
81
82
<BoxelInputGroup @ placeholder ={{this .placeholder }} >
82
83
<: before as | Accessories | >
83
84
<Accessories.Select
84
- @ placeholder =' Select a country '
85
+ @ placeholder ={{ this .placeholder }}
85
86
@ selected ={{this .selectedItem }}
86
87
@ onChange ={{this .onSelectItem }}
87
88
@ options ={{this .items }}
88
- aria-label =' Select an item'
89
+ @ selectedItemComponent ={{PhoneSelectedItem }}
90
+ @ searchEnabled ={{ true }}
91
+ @ searchField =' name'
92
+ @ matchTriggerWidth ={{ false }}
93
+ aria-label =' Select an country calling code'
89
94
as | item |
90
95
>
91
96
<div >{{item.flag }} {{item.name }} +{{item.callingCode }} </div >
@@ -94,3 +99,24 @@ export class PhoneInput extends Component<Signature> {
94
99
</BoxelInputGroup >
95
100
</template >
96
101
}
102
+
103
+ export interface SelectedItemSignature <ItemT > {
104
+ Args: {
105
+ option: any ;
106
+ select: Select & {
107
+ actions: {
108
+ remove: (item : ItemT ) => void ;
109
+ };
110
+ };
111
+ };
112
+ Blocks: {
113
+ default: [ItemT , Select ];
114
+ };
115
+ Element: HTMLDivElement ;
116
+ }
117
+
118
+ class PhoneSelectedItem <ItemT > extends Component <SelectedItemSignature <ItemT >> {
119
+ <template >
120
+ <div >{{@ option.flag }} +{{@ option.callingCode }} </div >
121
+ </template >
122
+ }
0 commit comments