ngx-dial-input 2.1.1 → 2.1.3

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 CHANGED
@@ -1,24 +1,218 @@
1
- # PhoneInput
1
+ # PhoneInputComponent
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.3.0.
3
+ > A powerful Angular phone input component with international country selection, automatic formatting, and validation.
4
4
 
5
- ## Code scaffolding
5
+ Part of **ngx-dial-input** library. See main [README](../../README.md) for general information.
6
6
 
7
- Run `ng generate component component-name --project phone-input` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project phone-input`.
8
- > Note: Don't forget to add `--project phone-input` or else it will be added to the default project in your `angular.json` file.
7
+ ## Component Inputs
9
8
 
10
- ## Build
9
+ | Input | Type | Default | Description |
10
+ |-------|------|---------|-------------|
11
+ | `defaultCountry` | `string` | `''` | ISO 2-letter country code (e.g., 'US', 'GB', 'IN') |
12
+ | `placeholder` | `string` | `''` | Placeholder text in the phone input field |
13
+ | `searchEnabled` | `boolean` | `true` | Enable/disable country search in dropdown |
14
+ | `numberFormat` | `'international' \| 'national'` | `'international'` | Phone number format: +12015551234 (international) or 2015551234 (national) |
15
+ | `setFirstCountry` | `string` | `''` | Pre-select a specific country |
11
16
 
12
- Run `ng build phone-input` to build the project. The build artifacts will be stored in the `dist/` directory.
17
+ ## Component Output
13
18
 
14
- ## Publishing
19
+ ### phoneChange Event
15
20
 
16
- After building your library with `ng build phone-input`, go to the dist folder `cd dist/phone-input` and run `npm publish`.
21
+ Emitted when phone value changes:
17
22
 
18
- ## Running unit tests
23
+ ```typescript
24
+ interface PhoneData {
25
+ e164Number: string; // '+12015551234' - International format for storage
26
+ nationalNumber: string; // '2015551234' - Just the digits
27
+ dialCode: string; // '+1' - Country dial code
28
+ countryCode: string; // 'us' - ISO 2-letter code (lowercase)
29
+ isValid: boolean; // true/false - Validation status
30
+ }
31
+ ```
19
32
 
20
- Run `ng test phone-input` to execute the unit tests via [Karma](https://karma-runner.github.io).
33
+ ## Usage Example
21
34
 
22
- ## Further help
35
+ ### Reactive Forms
23
36
 
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
37
+ ```typescript
38
+ import { Component } from '@angular/core';
39
+ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
40
+ import { PhoneInputModule } from 'ngx-dial-input';
41
+
42
+ @Component({
43
+ selector: 'app-contact-form',
44
+ template: `
45
+ <form [formGroup]="form" (ngSubmit)="submit()">
46
+ <div class="form-group">
47
+ <label>Phone Number</label>
48
+ <phone-input
49
+ [defaultCountry]="'US'"
50
+ [placeholder]="'Enter phone number'"
51
+ [searchEnabled]="true"
52
+ formControlName="phone"
53
+ (phoneChange)="onPhoneChange($event)">
54
+ </phone-input>
55
+ <small *ngIf="form.get('phone').invalid && form.get('phone').touched">
56
+ Please enter a valid phone number
57
+ </small>
58
+ </div>
59
+ <button type="submit" [disabled]="form.invalid">Submit</button>
60
+ </form>
61
+ `,
62
+ standalone: false
63
+ })
64
+ export class ContactFormComponent {
65
+ form: FormGroup;
66
+
67
+ constructor(private fb: FormBuilder) {
68
+ this.form = this.fb.group({
69
+ phone: [null, Validators.required]
70
+ });
71
+ }
72
+
73
+ onPhoneChange(data: any) {
74
+ if (data.isValid) {
75
+ console.log('Valid phone (e164):', data.e164Number);
76
+ }
77
+ }
78
+
79
+ submit() {
80
+ const phoneData = this.form.get('phone').value;
81
+ console.log('Phone to save:', phoneData.e164Number);
82
+ // API call to save phone
83
+ }
84
+ }
85
+ ```
86
+
87
+ ### With Default Country
88
+
89
+ ```html
90
+ <phone-input
91
+ [defaultCountry]="'GB'"
92
+ [setFirstCountry]="'GB'"
93
+ [numberFormat]="'national'"
94
+ formControlName="phone">
95
+ </phone-input>
96
+ ```
97
+
98
+ ## Validation Behavior
99
+
100
+ ### Empty Input
101
+ - Initial state with no input: `isValid = false` (but no validation error)
102
+ - Allows users to leave the field empty until they start typing
103
+
104
+ ### Partial Input
105
+ - Once user starts typing, validates against country's minimum length
106
+ - Phone with insufficient digits: `isValid = false`
107
+
108
+ ### Complete Input
109
+ - Phone matching country's required length: `isValid = true`
110
+ - Phone exceeding max length: `isValid = false`
111
+
112
+ ### Length Rules Used by the Component
113
+ - Validation checks `minLength` and `maxLength` from each country entry.
114
+ - `phoneLength` remains in the data model as a compatibility/reference field.
115
+ - Current runtime validity decisions are not based on `phoneLength`.
116
+
117
+ ### Syria Example
118
+ ```
119
+ Country: Syria (min: 9 digits, max: 10 digits)
120
+ - 8 digits: isValid = false
121
+ - 9 digits: isValid = true
122
+ - 10 digits: isValid = true
123
+ - 11 digits: isValid = false
124
+ ```
125
+
126
+ ### Example
127
+ ```
128
+ Country: United States (min: 10 digits, max: 10 digits)
129
+ - Empty (no input): isValid = false, no error
130
+ - Entering: '201' (3 digits): isValid = false, too short
131
+ - Complete: '2015551234' (10 digits): isValid = true
132
+ - Excess: '20155512345' (11 digits): isValid = false, too long
133
+ ```
134
+
135
+ ## Supported Features
136
+
137
+ ✅ **200+ Countries** with:
138
+ - Dial codes
139
+ - Flag images
140
+ - Min/max phone length
141
+ - Format patterns
142
+
143
+ ✅ **Smart Search**
144
+ - Search by country name
145
+ - Case-insensitive matching
146
+ - Fast filtering
147
+
148
+ ✅ **Animations**
149
+ - Smooth dropdown open/close
150
+ - Responsive to user interactions
151
+
152
+ ✅ **Keyboard Support**
153
+ - Arrow keys to navigate
154
+ - Enter to select
155
+ - Escape to close dropdown
156
+
157
+ ✅ **ControlValueAccessor**
158
+ - Works with `formControlName`
159
+ - Works with `[(ngModel)]`
160
+ - Works with Reactive Forms and Template Forms
161
+
162
+ ## Building & Testing
163
+
164
+ ```bash
165
+ # Build the library
166
+ ng build phone-input
167
+
168
+ # Run unit tests
169
+ ng test phone-input --watch
170
+
171
+ # Run tests (CI mode, no watch)
172
+ ng test phone-input --watch=false --browsers=ChromeHeadless
173
+
174
+ # Create distributable package
175
+ npm run build
176
+ ```
177
+
178
+ ## Output Structure
179
+
180
+ After building:
181
+ ```
182
+ dist/
183
+ phone-input/
184
+ lib/
185
+ phone-input.component.d.ts
186
+ phone-input.module.d.ts
187
+ package.json
188
+ README.md
189
+ LICENSE
190
+ phone-input.d.ts (public API)
191
+ ```
192
+
193
+ ## Browser Compatibility
194
+
195
+ - Chrome 90+
196
+ - Firefox 88+
197
+ - Safari 14+
198
+ - Edge 90+
199
+
200
+ ## Performance
201
+
202
+ - Component uses OnPush change detection
203
+ - Optimized country list filtering
204
+ - Minimal re-renders
205
+
206
+ ## Accessibility
207
+
208
+ - Semantic HTML structure
209
+ - Keyboard navigation support
210
+ - ARIA labels on country selector
211
+
212
+ ## Contributing
213
+
214
+ Issues and PRs are welcome on [GitHub](https://github.com/CroemInc/ngx-dial-input)
215
+
216
+ ## License
217
+
218
+ MIT © [CroemInc](https://github.com/CroemInc)
@@ -5,7 +5,7 @@ export interface CountriesPhoneInputData {
5
5
  dialCode: string;
6
6
  flag: string;
7
7
  format: string;
8
- phoneLength: number;
8
+ phoneLength?: number;
9
9
  minLength: number;
10
10
  maxLength: number;
11
11
  }