Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lbgm/phone-input

An Angular phone input component module
https://github.com/lbgm/phone-input

angular angular-material angular12 component library phone-input phone-number phoneinput

Last synced: 4 days ago
JSON representation

An Angular phone input component module

Awesome Lists containing this project

README

        

# PhoneInput

An Angular phone input component module.
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.2.0.

![PhoneInput screenshot](https://user-images.githubusercontent.com/92580505/232258765-222d4527-6317-4bc4-a799-70582e351eaf.png)

## Install

```sh
npm i @lbgm/phone-input
```

## Props & Types

```ts
export type T_FormFieldControl = { [key: string]: AbstractControl; };

export interface PhoneDATA {
country?: string;
dialCode?: string | number;
nationalNumber?: string | number;
number?: string | number;
isValid?: boolean;
}

@Input() value?: string = ""; // like '22997000000'
@Input() label?: string = "";
@Input() hasError?: boolean = false;
@Input() hasSuccess?: boolean = false;
@Input() placeholder?: string = ""
@Input() name?: string = "lbgm-phone-input"
@Input() required?: boolean = false;
@Input() defaultCountry?: string = 'BJ';
@Input() arrow?: boolean = true; // to show or hide arrow
@Input() listHeight?: number = 150;
@Input() allowed?: string[] = ([]);

@Input() group?: FormGroup;
@Input() controls?: T_FormFieldControl;
```

- pass `value` on this format: `${dialCode}${nationalNumber}`
- `allowed` is an array of country iso2 (string).

## Slots

```html

```

## Use

```ts
// app.module.ts

import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { PhoneInputModule } from '@lbgm/phone-input'; // here

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
PhoneInputModule // here
],
providers: [
{
provide: Window,
useValue: window
}
],
bootstrap: [AppComponent]
})
export class AppModule { }
```

```html

```

- phoneEvent is string
- country is string
- phoneData is type [PhoneDATA](#props--types)

### Use with FormBuilder example

```ts
import { Component } from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
import { PhoneDATA } from '@lbgm/phone-input';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'phone-input';
form: FormGroup;
input?: string = "";
inputData?: PhoneDATA;
inputCountry: string = "";

constructor(private fb: FormBuilder) {
this.form = fb.group({
'phone': [
'',
[
Validators.required,
Validators.minLength(8)
]
]
})
}

onSubmit(): void {
this.form.markAllAsTouched();
}
}
```

## Error on field

![Error case screenshot](https://user-images.githubusercontent.com/92580505/232258806-5453bde3-d92a-42ad-b226-30a45c6624be.png)