vpn
@atimermann/vue-phone-number-input
npm i @atimermann/vue-phone-number-input
vpn

@atimermann/vue-phone-number-input

A phone number input made with Vue JS (format & valid phone number)

by Mazel

1.7.0 (see all)License:MITTypeScript:Built-In
npm i @atimermann/vue-phone-number-input
Readme

vue-phone-number-input

license vue 2 npm npm Codacy grade

npm

A beautiful text field to format phone numbers made with VueJS

vue-phone-number-input

Demo

Enjoy

Installation

Using yarn

yarn add vue-phone-number-input

Using npm

npm i --save vue-phone-number-input

Usage

ES6 Modules / CommonJS

import VuePhoneNumberInput from 'vue-phone-number-input';
import 'vue-phone-number-input/dist/vue-phone-number-input.css';

Vue.component('vue-phone-number-input', VuePhoneNumberInput);
<VuePhoneNumberInput v-model="yourValue" />

UMD

<VuePhoneNumberInput v-model="yourValue" />

<script src="https://unpkg.com/vue" charset="utf-8"></script>
<script src="./dist/vue-phone-number-input.umd.min.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="./dist/vue-phone-number-input.css">

<script type="text/javascript">
  Vue.component('vue-phone-number-input', window.VuePhoneNumberInput.default);
</script>

Features List

  • You can set preferred-countries, ignored-countries or have only-countries
  • Validator State: input becomes green (you can modify this color with valid-color option) when the phone number is valid (can be disabled by no-validator-state attr)
  • Multi options to getting country code : By default the component get the country code via the browser (disable it with no-use-browser-locale) or you can use fetch-country to get the country code via https://ip2c.org/s (network needed) - you can use default-country-code option instead to set one
  • Phone number formatting while typing
  • You can search your country in list (open countries list & type your country name)
  • Keyboard accessibility (Arrow down, Arrow up: Countries list navigation - Escape: Close countries list)
  • Phone number example for each country in placeholder/label
  • Auto focus phone number input after selecting country
  • You can disable the flags - no-flags props
  • Set your translations

All options of VueInputUi are available

  • Differents size of input (sm or lg) size="sm|lg"
  • Disabled option (disabled prop)
  • Dark UI option (dark prop)
  • Active a clear button by the prop clearable (cf: VueInputUi options)
  • Active a loader progress bar by the prop loader (cf: VueInputUi options)
  • And others

Props API

PropsTypeRequiredDefault
v-modelString/Inttrue-
idStringfalseVuePhoneNumberInput
colorString HEXnodogderblue
valid-colorString HEXnoyellowgreen
error-colorString HEXnoorangered
sizeString `smlg`no
default-country-code (1)Stringnonull
preferred-countries (2)Array<string>nonull
ignored-countriesArray<string>nonull
only-countriesArray<string>nonull
no-validator-stateBooleannofalse
no-flagsBooleannofalse
disabledBooleannofalse
darkBooleannofalse
dark-colorString (hex)no#424242
requiredBooleannofalse
errorBooleannofalse
clearableBooleannofalse
loader (3)Booleannofalse
translations (4)Objectnonull
countries-height (5)Numberno30
no-use-browser-locale (6)Booleannofalse
fetch-country (7)Booleannofalse
no-country-selector (8)Booleannofalse
border-radiusNumberno4
show-code-on-listBooleannofalse
no-exampleBooleannofalse

(1) Ex : default-country-code="FR"

(2) Ex : preferred-countries="['FR', 'BE', 'DE']" This countries will be at the top of the list

(3) Loader progress bar has the input color (color props)

(4) translations comes to replace default texts - Ex :

translations="{
  countrySelectorLabel: 'Code pays',
  countrySelectorError: 'Choisir un pays',
  phoneNumberLabel: 'Numéro de téléphone',
  example: 'Exemple :'
}"

(5) height in px of the rows included in the dropdown. Ex: countries-height: 40

(6) By default the component get country code via browser - No network needed but not work on SSR with NuxtJS (disable it with no-use-browser-locale)

(7) Fetch country code via https://ip2c.org/s - Network needed - (Do not use it with default-country-code options)

(8) The country selector is not shown, you can validate your phone number with the country code set

Events API

EventReturn
phone-number-focused- (emit when phone number input is focused)
phone-number-blur- (emit when phone number input is blur)
inputAsYouType value (emit when new value is enter on phone number input && when a country is choosed)
updateAll values (cf values in table on demo) (emit when new value is enter on phone number input && when a country is choosed)

Keyboard accessibility

PropsAction
ArrowDownNavigation down in countries list
ArrowUpNavigation up in countries list
EscapeClose countries list
All letters charactersSearching country name in countries list (should be open)

Named slots

SlotAction
arrowOverride the default arrow character for toggling the list of countries

Contribution

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Lints and fixes files

npm run lint

License

This project is licensed under MIT License

Downloads/wk

15

GitHub Stars

544

LAST COMMIT

1yr ago

MAINTAINERS

1

CONTRIBUTORS

6

OPEN ISSUES

39

OPEN PRs

17
VersionTagPublished
1.7.0
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate