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-phonebox

v2.0.6

Published

A customizable phone input component with built-in multi-language support.

Readme

React PhoneBox

npm version Docs License: MIT TypeScript

A lightweight, customizable, and i18n-ready phone number input component with country selection, flag icons, validation, and formatting — powered by libphonenumber-js.


📘 Documentation

Official documentation is available at:
🔗 https://frkngnc.github.io/react-phonebox

Includes:

  • Easy & Advanced usage examples
  • Full API reference
  • Customization & styling guides
  • Supported locales & validation behavior

✨ Features

  • 🌍 Locale-based country names (supports en, tr, fr, ar, es, ur, etc.)
  • 📞 Auto-formats and validates numbers using libphonenumber-js
  • 🇺🇳 Flag icons from flagcdn.com
  • 🔍 Debounced country search with intelligent filtering
  • ✅ Validity feedback via callback
  • 🌗 Light & Dark theme support
  • 💡 Built-in RTL support
  • 🔧 Modular hook-based API for advanced use cases
  • 🪶 Lightweight and tree-shakable

🚀 Installation

npm install react-phonebox
# or
yarn add react-phonebox

🔧 Basic Usage (Easy Mode)

import { useState } from "react";
import { PhoneBox } from "react-phonebox";
import "react-phonebox/style.css";

function App() {
  const [phone, setPhone] = useState("");
  const [rawPhone, setRawPhone] = useState("");
  const [isValid, setIsValid] = useState(false);

  return (
    <PhoneBox
      value={phone}
      onChange={setPhone}
      onRawChange={setRawPhone}
      onValidChange={setIsValid}
      locale="tr"
      initialCountry="TR"
      theme="dark"
      searchPlaceholder="Ülke ara..."
      mobileOnly
    />
  );
}

⚙️ Advanced Usage (Full Control)

import { useState } from "react";
import {
  PhoneBoxInput,
  useFormatter,
  useExampleNumber,
  useMobileOnly
} from "react-phonebox";
import "react-phonebox/style.css";

function PhoneInputWithHooks() {
  const [value, setValue] = useState("");
  const [country, setCountry] = useState<any>({
    iso2: "TR",
    dialCode: "+90",
    name: "Turkey"
  });

  const { format } = useFormatter(country?.iso2);
  const { placeholder, example, maxDigits } = useExampleNumber(country?.iso2);
  const { validate } = useMobileOnly();

  const digits = value.replace(/\D/g, "").slice(0, maxDigits ?? 15);
  const formatted = format(digits);
  const raw = (country?.dialCode ?? "") + digits;
  const validation = validate(raw, false);

  return (
      <PhoneBoxInput
        value={formatted}
        onChange={setValue}
        onCountryChange={setCountry}
        initialCountry="TR"
        locale="tr"
        placeholder={placeholder}
        theme="dark"
        searchPlaceholder="Ülke ara..."
      />
  );
}

🔌 Exposed Hooks

| Hook | Description | |----------------------|------------------------------------------------------------| | useFormatter() | Formats input value live using AsYouType | | useExampleNumber() | Returns example number, placeholder, and max digits | | useMobileOnly() | Validates mobile numbers only if mobileOnly: true |


🧪 <PhoneBox /> Props

| Prop | Type | Description | |--------------------|--------------------------------|--------------------------------------------------------------| | value | string | Formatted phone number string | | onChange | (val: string) => void | Input value change handler | | locale | string | Locale key (en, tr, fr, etc.) | | initialCountry | string | Initial country ISO2 code (TR, US, etc.) | | theme | "dark" | "light" | Theme mode | | searchPlaceholder| string | Country search input placeholder | | mobileOnly | boolean | If true, only mobile numbers are considered valid | | onRawChange | (raw: string) => void | Callback for raw (unformatted) phone number | | onValidChange | (valid: boolean) => void | Callback to track if phone number is valid |


🧱 Styling

You must import styles manually:

import "react-phonebox/style.css";

You can override any class via CSS or use CSS variables for customization.


🌐 Languages Supported

Static JSON translations for:

  • English (en)
  • Turkish (tr)
  • Arabic (ar)
  • Urdu (ur)
  • French (fr)
  • Spanish (es)

🛆 License

MIT


🔗 Live Demo

Check out the live demo: react-phonebox demo

Developed with by frkngnc