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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-phonenr-input

v4.0.2

Published

An automated and intuitive international and national phone input field

Readme

React Phone Number Input

npm version License: MIT

An automated and intuitive international and national phone input field for React with TypeScript support.

Features

  • 🌍 International phone number formatting with country code detection
  • 🎯 Automatic phone number validation using libphonenumber-js
  • 🏳️ Country flags with dropdown selector
  • 📱 Mobile-friendly with optimized UX
  • ⚙️ Flexible configuration - set default country, preferred countries, or filter by regions
  • 🎨 Customizable styling with SCSS support
  • 📦 TypeScript first with full type definitions
  • Accessible with proper ARIA attributes
  • 🔄 Supports both INTERNATIONAL and NATIONAL formats

Installation

npm install react-phonenr-input

or

yarn add react-phonenr-input

Basic Usage

import { useState } from 'react';
import { PhoneInput } from 'react-phonenr-input';
import 'react-phonenr-input/styles.css';

function App() {
  const [phoneNumber, setPhoneNumber] = useState('');

  return (
    <PhoneInput
      onChange={setPhoneNumber}
      placeholder="+1 702 123 4567"
    />
  );
}

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | onChange | (value: PhoneNumber) => void | required | Callback fired when the phone number changes | | defaultCountry | CountryCode | - | Default country code (e.g., 'US', 'GB') | | initialValue | string | - | Initial phone number value with country code | | preferredCountries | CountryCode[] | - | List of countries to show at the top of the dropdown | | regions | Region[] | - | Filter countries by region(s) | | format | 'INTERNATIONAL' \| 'NATIONAL' | 'INTERNATIONAL' | Phone number format | | withCountryMeta | boolean | false | Include country metadata in the returned value | | maxLength | number | 21 | Maximum input length | | disabled | boolean | false | Disable the input | | placeholder | string | - | Placeholder text | | className | string | - | Custom CSS class name | | onFocus | FocusEventHandler | - | Focus event handler | | onBlur | FocusEventHandler | - | Blur event handler |

Additional HTML input attributes are also supported via the spread operator.

Advanced Examples

With Initial Value

<PhoneInput
  onChange={setPhoneNumber}
  initialValue="+491761234112"
/>

With Default Country

<PhoneInput
  onChange={setPhoneNumber}
  defaultCountry="US"
  placeholder="Enter phone number"
/>

With Preferred Countries

<PhoneInput
  onChange={setPhoneNumber}
  preferredCountries={['US', 'GB', 'DE', 'FR']}
/>

Filter by Regions

<PhoneInput
  onChange={setPhoneNumber}
  regions={['europe', 'north-america']}
/>

With Country Metadata

<PhoneInput
  onChange={setPhoneNumber}
  withCountryMeta
/>

When withCountryMeta is enabled, the onChange callback receives an object with the phone number and country information:

{
  phoneNumber: "+491761234112",
  country: {
    name: "Germany",
    iso2: "DE",
    dialCode: "49",
    // ... additional metadata
  }
}

National Format

<PhoneInput
  onChange={setPhoneNumber}
  format="NATIONAL"
  defaultCountry="US"
/>

Types

PhoneNumber

type PhoneNumber = string | {
  phoneNumber: string;
  country: ICountry;
}

Available Regions

type Region =
  | "asia"
  | "europe"
  | "africa"
  | "north-africa"
  | "oceania"
  | "america"
  | "carribean"
  | "south-america"
  | "ex-ussr"
  | "european-union"
  | "middle-east"
  | "central-america"
  | "north-america"

Styling

Import the default styles:

import 'react-phonenr-input/styles.css';

Or create your own custom styles by targeting the component classes. The component uses BEM methodology for CSS class names.

Development

Prerequisites

  • Node.js >= 22
  • Yarn or npm

Setup

# Install dependencies
yarn install

# Start Storybook for development
yarn start

# Run tests
yarn test

# Run linting
yarn lint

# Build the library
yarn build

Scripts

  • yarn start - Start Storybook development server
  • yarn build - Build the library for production
  • yarn test - Run tests with Vitest
  • yarn lint - Run ESLint and Stylelint
  • yarn lint:fix - Fix linting issues automatically
  • yarn check-types - Run TypeScript type checking
  • yarn ci - Run all checks (lint + tests)

Browser Support

This library supports all modern browsers. For older browsers, you may need to include appropriate polyfills.

Dependencies

  • React 19.2.x
  • libphonenumber-js - Phone number parsing and validation
  • react-country-flag - Country flag components

License

MIT © Kai Hotz

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Repository

https://github.com/KaiHotz/React-PhoneNr-Input