19.2.1 β€’ Published 2 months ago

ngx-material-intl-tel-input v19.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

All Contributors

npm version npm downloads total npm downloads monthly

NgxMaterialIntlTelInput

https://github.com/juanjotorres90/ngx-material-intl-tel-input

Introducing an Angular library designed to streamline the input and validation of international telephone numbers. Integrates a searchable material select component for convenient country code selection. Moreover, it automatically detects the user's country, dynamically presenting a relevant placeholder for enhanced user experience. With built-in formatting and validation functionalities, this library ensures accuracy and consistency in handling telephone numbers across diverse global contexts.

Check out the Demo

Compatibility:

Validation with google-libphonenumber

ngx-material-intl-tel-inputAngular
19.0.0 - 19.2.0>= 19.0.0
18.0.0 - 18.2.1>= 18.0.0
0.0.1 - 17.3.0>= 17.2.0

Installation

$ npm install ngx-material-intl-tel-input --save

Ensure to include provideAnimations() and provideHttpClient() in the providers array of your main.ts file to initialize your application with animations and auto getting country code capabilities. Refer to the Angular Docs provideAnimations and provideHttpClient for detailed instructions.

Additionally, it's essential to incorporate an Angular Material theme by importing the necessary CSS for styling. Please consult the Angular Material Theming guide for instructions on how to set up the theme.

Usage

Import

Include the NgxMaterialIntlTelInputComponent in the imports array of the standalone component where you intend to utilize it.

imports: [NgxMaterialIntlTelInputComponent];

Example

<form [formGroup]="formGroup">
  <ngx-material-intl-tel-input [fieldControl]="control" [required]="true" [autoIpLookup]="false"> </ngx-material-intl-tel-input>
</form>

Options

OptionsTypeDefaultDescription
fieldControlFormControlFormControl('')Form control required to retrieve the value.
fieldControlNamestring''Form control name to assign the control from a FormGroup.
requiredbooleanfalseTelephone field input required.
disabledbooleanfalseTelephone field input disabled.
appearance'fill' \| 'outline'fillMaterial form field appearance.
autoIpLookupbooleantrueSets initial country code based on user's ip.
autoSelectCountrybooleantrueEnables or disables auto selecting a country on initialization.
autoSelectedCountryCountryISO \| string''Sets the country to be auto selected.
numberValidationbooleantrueEnables or disables phone number validation.
enableSearchbooleantrueEnables or disables country search.
includeDialCodebooleanfalseIncludes the dial code in the phone number input.
emojiFlagsbooleanfalseUse standard emoji icons for the country flags.
hidePhoneIconbooleanfalseHides phone icon.
preferredCountries(CountryISO \| string)[][]Shows the specified countries on top of the list.
visibleCountries(CountryISO \| string)[][]Shows only the specified countries.
excludedCountries(CountryISO \| string)[][]Exclude the specified countries from the list.
enablePlaceholderbooleantrueInput placeholder text for every country national number.
iconMakeCallbooleantrueClick on phone icon to trigger call action.
initialValuestring''Sets initial telephone number value
useMaskbooleanfalseUse mask for phone number input.
forceSelectedCountryCodebooleanfalseIf useMask is active it forces the selected country code to be displayed
showMaskPlaceholderbooleanfalseIf useMask is active it shows the placeholder for the mask
outputNumberFormatPhoneNumberFormatPhoneNumberFormat.INTERNATIONALSets the output number format to INTERNATIONAL, E164, or RFC3966 format
textLabelsTextLabels{mainLabel: 'Phone number', codePlaceholder: 'Code', searchPlaceholderLabel: 'Search', noEntriesFoundLabel: 'No countries found', nationalNumberLabel: 'Number', hintLabel: 'Select country and type your phone number', invalidNumberError: 'Number is not valid', requiredError: 'This field is required'}Overrides all component text labels

Events

EventTypeDefaultDescription
currentValuestring''Full phone number value emitted when the value of the input changes.
currentCountryCodestring''Country code value emitted when the value of the input changes.
currentCountryISOstring''Country ISO value emitted when the value of the input changes.

CSS Custom Properties Reference

🎨 Component Styling Variables

Container Styles

  • --mdc-filled-tel-form-outline-width: Outline width (default: 1px)
  • --mdc-filled-tel-form-outline-color: Border color (default: #d8d8d8)
  • --mdc-filled-tel-form-background: Background color (default: #fbfbfb)
  • --mdc-filled-tel-form-container-shape: Border radius (default: 8px)

Focus States

  • --mdc-filled-tel-form-focus-outline-color: Focus border color (default: rgb(32, 159, 252))
  • --mdc-filled-tel-form-focus-background: Focus background (default: #fff)

Hover States

  • --mdc-filled-tel-form-hover-background: Hover background (default: #f5f5f5)
  • --mdc-outline-tel-form-hover-background: Outline variant hover background (default: #f5f5f5)

πŸ“± Input Field Customization

Appearance

  • --mdc-outline-tel-form-background: Outline variant background (default: #fbfbfb)
  • --mdc-tel-form-placeholder-color: Input placeholder color (default: #ccc)
  • --mdc-tel-form-icon-color: Action icon color (default: #909090)

Shape Customization

  • --mdc-outlined-tel-form-container-shape: Outline field border radius (default: Material system variable)
  • --mdc-outlined-text-field-container-shape: Text field border radius (default: Material system variable)

πŸ” Validation & Feedback

  • --mdc-tel-form-hint-color: Hint text color (default: #b2b2b2)
  • --mdc-tel-form-error-color: Error message color (default: Material system error)
  • --mat-sys-error: Material system error fallback (default: #f44336)

πŸ–ŒοΈ Theme Integration

  • --mdc-theme-primary: Primary theme color (default: rgb(32, 159, 252))
  • --mdc-theme-error: Error state color (default: #f44336)
  • --mat-sys-corner-extra-small: Material system small corner radius

Example Configuration

:root {
  /* Container Customization */
  --mdc-filled-tel-form-background: #f8f9fa;
  --mdc-filled-tel-form-container-shape: 6px;

  /* Theme Colors */
  --mdc-theme-primary: #2a7de1;
  --mdc-tel-form-error-color: #dc3545;

  /* Input Styling */
  --mdc-tel-form-placeholder-color: #a0aec0;
}

Contributors

Thanks goes to these wonderful people:

This project follows the all-contributors specification. Contributions of any kind are welcome!

"Buy Me A Coffee"

19.1.0

4 months ago

19.0.0

5 months ago

19.2.1

2 months ago

19.2.0

3 months ago

18.2.1

5 months ago

18.2.0

9 months ago

18.1.1

9 months ago

18.1.0

10 months ago

18.0.1

11 months ago

18.0.0

11 months ago

17.3.0

1 year ago

17.2.2

1 year ago

17.2.1

1 year ago

17.2.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago