npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

base-vue-phone-input

v0.1.13

Published

customizable vue3 phone input

Downloads

413

Readme

Base vue phone input

Basic phone input deeply customizable with slots

Installation

using npm

  npm install basic-vue-phone-input

Examples

Demo with shadcn/vue

Usage

<script setup lang="ts">
import { ref } from 'vue'
import PhoneInput from './index'

const tel = ref('')
const res = ref()
</script>

<template>
    <PhoneInput
        v-model="tel"// for phone number
        @update="res = $event"// for phone number object />
    {{ res }}
    {{ tel }}
</template>

But this input is meant to be customized

Features

  • You can set preferred-countries, ignored-countries or have only-countries
  • 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
  • Fully cusstomizable with slots

Props API

| Prop name | Description | Type | Values | Default | | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------ | --------- | | modelValue | @model Country calling code + telephone number in international format | string | - | undefined | | countryCode | @model Country code selected - Ex: "FR" | CountryCode | - | undefined | | placeholder | Placeholder of the input | string | - | undefined | | label | label of the input | string | - | undefined | | preferredCountries | List of country codes to place first in the select list - Ex: ['FR', 'BE', 'GE'] | Array | - | undefined | | ignoredCountries | List of country codes to be removed from the select list - Ex: ['FR', 'BE', 'GE'] | Array | - | undefined | | onlyCountries | List of country codes to only have the countries selected in the select list - Ex: ['FR', 'BE', 'GE'] | Array | - | undefined | | translations | Locale strings of the component | Partial | - | undefined | | noUseBrowserLocale | By default the component use the browser locale to set the default country code if not country code is provided | boolean | - | | | fetchCountry | The component will make a request (https://ipwho.is) to get the location of the user and use it to set the default country code | boolean | - | | | customCountriesList | Replace country names | Record | - | undefined | | autoFormat | Disabled auto-format when phone is valid @default true | boolean | - | true | | noFormattingAsYouType | Disabled auto-format as you type @default false | boolean | - | false | | countryLocale | locale of country list - Ex: "fr-FR" @default {string} browser locale | string | - | undefined | | excludeSelectors | Exclude selectors to close country selector list - usefull when you using custom flag | Array | - | undefined |

Events API

| Event | Return | | --- | --- | | input | AsYouType value (emit when new value is enter on phone number input && when a country is choosed) | | update | All values (Result type) |

Keyboard accessibility

| Props | Action | | --------- | --------------------------------- | | ArrowDown | Navigation down in countries list | | ArrowUp | Navigation up in countries list | | Escape | Close countries list |

Named slots

| Name | Description | Bindings | | -------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | selector | Change the country selector component | input-value String - current selected country code - Ex: "FR" updateInputValue - action for changing country code by passing country code countries - array of all countries | | input | Change the input component | input-value String - phone number value updateInputValue - action for updating phone value placeholder - placeholder |

Translations

Labels & placeholders

<PhoneInput
  :translations="{
    phoneInput: {
      placeholder: 'Phone number',
      example: 'Example:',
    },
  }"
/>

Country list

Two ways to translate the country list:

First solution - set country locale

<PhoneInput country-locale='fr-FR' />

Second solution - custom list

<PhoneInput
  :custom-countries-list="{
    FR: 'France',
    BE: 'Belgique',
    DE: 'Allemagne',
    US: 'Etats-Unis',
  }"
/>

Types

Results emitted by @update or @data event

export type Results = {
  isValid: boolean
  isPossible?: boolean
  countryCode?: CountryCode
  countryCallingCode?: CountryCallingCode
  nationalNumber?: NationalNumber
  type?: NumberType
  formatInternational?: string
  formatNational?: string
  uri?: string
  e164?: string
  rfc3966?: string
}

Country type

export interface Country {
    iso2: CountryCode
    dialCode: CountryCallingCode
    name: string
}