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

react-phone-input-pro

v1.0.11

Published

Phone number input component for react to format phone numbers according to selected countries in real time.

Downloads

168

Readme

react-phone-input-pro

Phone number input component for react to format phone numbers according to selected country in real time.

Features

  • Easy to use - just import and use.
  • Lightweight - No third-party dependencies.
  • Search bar - You can anable or disable search bar from countries options list.
  • You have option to include or exclude dial code from number.
  • You can create your own formats

Installation

Run this command in your terminal

npm install react-phone-input-pro

| Props | Description | | --- | --- | | initialFormat: Boolean | When using this component in editable forms. this function automatically guess the the dial code and formats the number| | prefix: Boolean| user will get dial code pre defined When this is true or undefined | | className: String | To add a css class in this component | | includeDialingCode: Boolean | If you don't want to include dial code in number then make this false | | placeholder: String | To change placeholder | | onchange: Function() | This function returns current unformatted value. Which you can use to setState of value. | | onlyCountries: Array | To filter country options. e.g.: ["USA", "IND"] | | fixLength: Boolean | To limit input length | | disabled: Boolean | To make input and selector disable| | fullIsoCode: Boolean | Sets 3 letter ISO Code e.g. "IND", "USA"| | searchOption: Boolean | To add or remove search bar| | getCountryCode: Function() | To get selected country code | | flags: Boolean | To get country code instead of flag | | error: [errorStatus:boolean, errorMessage:string] | To show error message |

Usage

import PhoneInput from 'react-phone-input-pro';
const [number, setNumber] = useState();
const [err, setErr] = useState(false);
//for typescript
const [number, setNumber] = useState<string | number>();
 const [err, setErr] = useState(false);

Example: Inside React-hook-form

<Controller
  control={control}
  name={"phone"}
  render={({ field: { onChange, value } }) => (
    <PhoneInput
      value={value}
      prefix
      onchange={(n: string) => {
        onChange(n);
      }}
    />
  )}
/>

Normal use

<PhoneInput
  initialFormat={true} 
  value={number}
  prefix={true}
  onchange={(n) => setNumber(n)}
  fullIsoCode={true}
/> 

Untitled

Create your own format

<PhoneInput 
   value={number}
   initialFormat={true} 
   prefix={true}
   placeholder={"Phone number..."}
   fixLength={true}
   format={"+100 #,##-(###)/##,##"}
   fullIsoCode={true}
   searchOption={true}
   onchange={(n)=> setPhone(n)} 
 />

Screen Recording 2023-05-27 at 9 14 55 PM

Error handling

<PhoneInput
  value={number}
  initialFormat={true}
  prefix={false}
  placeholder={"Phone number..."}
  error={[err, "Invalid Number"]}
  fullIsoCode={true} 
  searchOption={true}
  onchange={(value: string)=> {
    setNumber(value)
    setErr(false);
  }}
/> 

Screen Recording 2023-05-06 at 8 35 22 PM

Based on react-number-formatter