ngxsmk-tel-input 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -264
- package/fesm2022/ngxsmk-tel-input.mjs +385 -0
- package/fesm2022/ngxsmk-tel-input.mjs.map +1 -0
- package/{projects/ngxsmk-tel-input/dist/lib → lib}/ngxsmk-tel-input.component.d.ts +31 -16
- package/lib/ngxsmk-tel-input.service.d.ts +12 -0
- package/package.json +33 -68
- package/.editorconfig +0 -17
- package/.vscode/extensions.json +0 -4
- package/.vscode/launch.json +0 -20
- package/.vscode/tasks.json +0 -42
- package/angular.json +0 -40
- package/projects/ngxsmk-tel-input/README.md +0 -63
- package/projects/ngxsmk-tel-input/dist/README.md +0 -63
- package/projects/ngxsmk-tel-input/dist/fesm2022/ngxsmk-tel-input.mjs +0 -377
- package/projects/ngxsmk-tel-input/dist/fesm2022/ngxsmk-tel-input.mjs.map +0 -1
- package/projects/ngxsmk-tel-input/dist/lib/ngxsmk-tel-input.service.d.ts +0 -56
- package/projects/ngxsmk-tel-input/ng-package.json +0 -5
- package/projects/ngxsmk-tel-input/package.json +0 -22
- package/projects/ngxsmk-tel-input/src/lib/ngxsmk-tel-input.component.spec.ts +0 -23
- package/projects/ngxsmk-tel-input/src/lib/ngxsmk-tel-input.component.ts +0 -279
- package/projects/ngxsmk-tel-input/src/lib/ngxsmk-tel-input.service.spec.ts +0 -16
- package/projects/ngxsmk-tel-input/src/lib/ngxsmk-tel-input.service.ts +0 -116
- package/projects/ngxsmk-tel-input/src/public-api.ts +0 -6
- package/projects/ngxsmk-tel-input/tsconfig.lib.json +0 -13
- package/projects/ngxsmk-tel-input/tsconfig.lib.prod.json +0 -9
- package/projects/ngxsmk-tel-input/tsconfig.spec.json +0 -13
- package/tsconfig.json +0 -30
- package/{projects/ngxsmk-tel-input/dist/index.d.ts → index.d.ts} +0 -0
- package/{projects/ngxsmk-tel-input/dist/public-api.d.ts → public-api.d.ts} +1 -1
package/README.md
CHANGED
|
@@ -1,295 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ngxsmkTelInput
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Wraps [`intl-tel-input`](https://github.com/jackocnr/intl-tel-input) for UI and uses [`libphonenumber-js`](https://github.com/catamphetamine/libphonenumber-js) for parsing & validation. Implements `ControlValueAccessor` so it plugs right into Angular Forms.
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.0.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Code scaffolding
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Features
|
|
11
|
-
|
|
12
|
-
* ✅ Country dropdown with flags
|
|
13
|
-
* ✅ E.164 output (configurable for national numbers)
|
|
14
|
-
* ✅ Works with Reactive/Template-driven Forms (`ControlValueAccessor`)
|
|
15
|
-
* ✅ Built-in validation (uses `libphonenumber-js`)
|
|
16
|
-
* ✅ SSR-friendly (lazy `intl-tel-input` import)
|
|
17
|
-
* ✅ Tiny API surface, easy to theme
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Requirements
|
|
22
|
-
|
|
23
|
-
* Angular **17+**
|
|
24
|
-
* Node **18+** / **20+**
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## Install
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
29
8
|
|
|
30
9
|
```bash
|
|
31
|
-
|
|
32
|
-
npm i ngxsmk-tel-input intl-tel-input libphonenumber-js
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Add styles & assets
|
|
36
|
-
|
|
37
|
-
`intl-tel-input` ships its own CSS and flag images. Add them to your app’s `angular.json`:
|
|
38
|
-
|
|
39
|
-
```jsonc
|
|
40
|
-
{
|
|
41
|
-
"projects": {
|
|
42
|
-
"your-app": {
|
|
43
|
-
"architect": {
|
|
44
|
-
"build": {
|
|
45
|
-
"options": {
|
|
46
|
-
"styles": [
|
|
47
|
-
"node_modules/intl-tel-input/build/css/intlTelInput.css"
|
|
48
|
-
],
|
|
49
|
-
"assets": [
|
|
50
|
-
{
|
|
51
|
-
"glob": "**/*",
|
|
52
|
-
"input": "node_modules/intl-tel-input/build/img",
|
|
53
|
-
"output": "assets/intl-tel-input/img"
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
10
|
+
ng generate component component-name
|
|
62
11
|
```
|
|
63
12
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## Quick start (Reactive Forms)
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
// app.component.ts
|
|
72
|
-
import { Component } from '@angular/core';
|
|
73
|
-
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
74
|
-
import { TelInputComponent } from 'ngxsmk-tel-input';
|
|
75
|
-
|
|
76
|
-
@Component({
|
|
77
|
-
selector: 'app-root',
|
|
78
|
-
standalone: true,
|
|
79
|
-
imports: [ReactiveFormsModule, TelInputComponent],
|
|
80
|
-
template: `
|
|
81
|
-
<form [formGroup]="fg" class="space-y-3">
|
|
82
|
-
<label for="phone">Phone</label>
|
|
83
|
-
<ngxsmk-tel-input
|
|
84
|
-
id="phone"
|
|
85
|
-
formControlName="phone"
|
|
86
|
-
[initialCountry]="'US'"
|
|
87
|
-
[preferredCountries]="['US','GB','AU']"
|
|
88
|
-
(countryChange)="onCountry($event)">
|
|
89
|
-
</ngxsmk-tel-input>
|
|
90
|
-
|
|
91
|
-
<p *ngIf="fg.get('phone')?.hasError('phoneInvalid') && fg.get('phone')?.touched">
|
|
92
|
-
Please enter a valid phone number.
|
|
93
|
-
</p>
|
|
94
|
-
|
|
95
|
-
<pre>Value: {{ fg.value | json }}</pre>
|
|
96
|
-
</form>
|
|
97
|
-
`
|
|
98
|
-
})
|
|
99
|
-
export class AppComponent {
|
|
100
|
-
fg = this.fb.group({
|
|
101
|
-
phone: ['', Validators.required] // control value will be E.164 string or null
|
|
102
|
-
});
|
|
103
|
-
constructor(private fb: FormBuilder) {}
|
|
104
|
-
onCountry(e: { iso2: any }) { console.log('Country changed:', e.iso2); }
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Result:** `form.get('phone')?.value` → `'+14155550123'` (E.164) when valid, or `null` while empty/invalid.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Template-driven usage
|
|
113
|
-
|
|
114
|
-
```html
|
|
115
|
-
<form #f="ngForm">
|
|
116
|
-
<ngxsmk-tel-input name="phone" [(ngModel)]="phone"></ngxsmk-tel-input>
|
|
117
|
-
</form>
|
|
118
|
-
|
|
119
|
-
<!-- phone is a string (E.164) or null -->
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## API
|
|
125
|
-
|
|
126
|
-
### Inputs
|
|
127
|
-
|
|
128
|
-
| Name | Type | Default | Description |
|
|
129
|
-
| -------------------- | ----------------------- | ---------------------- | --------------------------------------------------- |
|
|
130
|
-
| `initialCountry` | `CountryCode \| 'auto'` | `'auto'` | Starting country. `'auto'` uses the plugin default. |
|
|
131
|
-
| `preferredCountries` | `CountryCode[]` | `['US','GB']` | Pinned countries at the top. |
|
|
132
|
-
| `onlyCountries` | `CountryCode[]` | `undefined` | Restrict selectable countries. |
|
|
133
|
-
| `nationalMode` | `boolean` | `false` | If `true`, emits national numbers; otherwise E.164. |
|
|
134
|
-
| `placeholder` | `string` | `'Enter phone number'` | Input placeholder. |
|
|
135
|
-
| `autocomplete` | `string` | `'tel'` | Native autocomplete attribute. |
|
|
136
|
-
| `disabled` | `boolean` | `false` | Disables the input. |
|
|
137
|
-
|
|
138
|
-
> `CountryCode` is the ISO-2 uppercase code from `libphonenumber-js` (e.g., `US`, `GB`, `AU`).
|
|
139
|
-
|
|
140
|
-
### Outputs
|
|
141
|
-
|
|
142
|
-
| Event | Payload | Description |
|
|
143
|
-
| --------------- | ----------------------- | ---------------------------------------- |
|
|
144
|
-
| `countryChange` | `{ iso2: CountryCode }` | Fires when the selected country changes. |
|
|
145
|
-
|
|
146
|
-
### Value semantics
|
|
147
|
-
|
|
148
|
-
* **When valid:** emits **E.164** string (e.g., `+33123456789`) unless `nationalMode` is `true`.
|
|
149
|
-
* **When empty or invalid:** emits `null`.
|
|
150
|
-
* **Validation:** adds `phoneInvalid` error key when the input cannot be parsed as a valid number for the selected country.
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
## Validation examples
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
155
14
|
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
<div class="error" *ngIf="fg.get('phone')?.hasError('required')">
|
|
160
|
-
Phone is required
|
|
161
|
-
</div>
|
|
162
|
-
<div class="error" *ngIf="fg.get('phone')?.hasError('phoneInvalid')">
|
|
163
|
-
Please enter a valid phone number
|
|
164
|
-
</div>
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
165
17
|
```
|
|
166
18
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
## Accessibility
|
|
170
|
-
|
|
171
|
-
* Pair with a `<label for="phone">` or wrap the input and label together.
|
|
172
|
-
* The country dropdown is keyboard navigable (via `intl-tel-input`).
|
|
173
|
-
* Consider additional ARIA attributes if you customize the template.
|
|
174
|
-
|
|
175
|
-
---
|
|
19
|
+
## Building
|
|
176
20
|
|
|
177
|
-
|
|
21
|
+
To build the library, run:
|
|
178
22
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
```css
|
|
183
|
-
.ngxsmk-tel-input {
|
|
184
|
-
width: 100%;
|
|
185
|
-
padding: 0.5rem 0.75rem;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.iti {
|
|
189
|
-
width: 100%; /* make dropdown stretch */
|
|
190
|
-
}
|
|
23
|
+
```bash
|
|
24
|
+
ng build ngxsmk-tel-input
|
|
191
25
|
```
|
|
192
26
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
## SSR notes
|
|
196
|
-
|
|
197
|
-
This library lazily imports `intl-tel-input` **only in the browser**.
|
|
198
|
-
No special setup required for Angular Universal. If you still see SSR errors, ensure you’re not referencing `window` in your own wrappers.
|
|
199
|
-
|
|
200
|
-
---
|
|
201
|
-
|
|
202
|
-
## Troubleshooting
|
|
203
|
-
|
|
204
|
-
* **No flags / broken images**
|
|
205
|
-
Ensure `angular.json` asset mapping is present and that the output path matches your app’s `/assets` directory.
|
|
206
|
-
|
|
207
|
-
* **Styles not applied**
|
|
208
|
-
Add `"node_modules/intl-tel-input/build/css/intlTelInput.css"` to the `styles` array in `angular.json`.
|
|
209
|
-
|
|
210
|
-
* **Form value doesn’t update**
|
|
211
|
-
Use Angular Forms APIs (Reactive or Template-driven). For Reactive Forms, confirm the control is bound via `formControlName` and that `ReactiveFormsModule` is imported.
|
|
212
|
-
|
|
213
|
-
* **Always invalid**
|
|
214
|
-
Some numbers are only valid with the correct country selected. Try typing with the `+` international prefix or set `initialCountry` appropriately.
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
215
28
|
|
|
216
|
-
|
|
29
|
+
### Publishing the Library
|
|
217
30
|
|
|
218
|
-
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
219
32
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
> When using `nationalMode=true`, you’ll typically store the country code alongside the value, using `(countryChange)`.
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/ngxsmk-tel-input
|
|
36
|
+
```
|
|
226
37
|
|
|
227
|
-
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
228
42
|
|
|
229
|
-
##
|
|
43
|
+
## Running unit tests
|
|
230
44
|
|
|
231
|
-
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
232
46
|
|
|
233
47
|
```bash
|
|
234
|
-
|
|
235
|
-
ng build ngxsmk-tel-input
|
|
236
|
-
|
|
237
|
-
# (Optional) create a demo app and try it locally
|
|
238
|
-
ng g application demo
|
|
239
|
-
# import TelInputComponent in your demo app and test
|
|
48
|
+
ng test
|
|
240
49
|
```
|
|
241
50
|
|
|
242
|
-
|
|
51
|
+
## Running end-to-end tests
|
|
243
52
|
|
|
244
|
-
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
245
54
|
|
|
246
55
|
```bash
|
|
247
|
-
|
|
248
|
-
ng build ngxsmk-tel-input
|
|
249
|
-
cd dist/ngxsmk-tel-input
|
|
250
|
-
npm publish --access public
|
|
56
|
+
ng e2e
|
|
251
57
|
```
|
|
252
58
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
---
|
|
256
|
-
|
|
257
|
-
## Contributing
|
|
258
|
-
|
|
259
|
-
PRs welcome! Please:
|
|
260
|
-
|
|
261
|
-
1. Run `npm ci` and `ng build`.
|
|
262
|
-
2. Add/adjust unit or e2e tests if you change behavior.
|
|
263
|
-
3. Update this README for any API changes.
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
264
60
|
|
|
265
|
-
|
|
61
|
+
## Additional Resources
|
|
266
62
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
[MIT](./LICENSE)
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
## Credits
|
|
274
|
-
|
|
275
|
-
* UI powered by [`intl-tel-input`](https://github.com/jackocnr/intl-tel-input)
|
|
276
|
-
* Parsing/validation by [`libphonenumber-js`](https://github.com/catamphetamine/libphonenumber-js)
|
|
277
|
-
|
|
278
|
-
---
|
|
279
|
-
|
|
280
|
-
### Appendix: `angular.json` snippet (copy-paste)
|
|
281
|
-
|
|
282
|
-
```jsonc
|
|
283
|
-
{
|
|
284
|
-
"styles": [
|
|
285
|
-
"node_modules/intl-tel-input/build/css/intlTelInput.css"
|
|
286
|
-
],
|
|
287
|
-
"assets": [
|
|
288
|
-
{
|
|
289
|
-
"glob": "**/*",
|
|
290
|
-
"input": "node_modules/intl-tel-input/build/img",
|
|
291
|
-
"output": "assets/intl-tel-input/img"
|
|
292
|
-
}
|
|
293
|
-
]
|
|
294
|
-
}
|
|
295
|
-
```
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|