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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-phonebox

v2.1.1

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
  • An interactive light and dark theme demo

Try the live demo at https://frkngnc.github.io/react-phonebox/demo.


✨ 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
  • 🏳️ CDN, native emoji, no-flag, or fully custom flag rendering
  • 🔍 Debounced country search with intelligent filtering
  • ⚡ Virtualized country list for low DOM and image overhead
  • ⌨️ Keyboard and screen-reader friendly country picker
  • ✅ Validity feedback via callback
  • 🌗 Light & Dark theme support
  • 🎛️ Classic, minimal, soft, and pill design variants
  • 💡 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"
        variant="soft"
        searchPlaceholder="Ülke ara..."
        flagMode="emoji"
        mobileOnly
      />

      <p>Formatted: {phone || "-"}</p>
      <p>Raw: {rawPhone || "-"}</p>
      <p>Valid: {phone ? (isValid ? "Yes" : "No") : "-"}</p>
    </>
  );
}

⚙️ Advanced Usage (Full Control)

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

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

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

  const formatted = format(value);
  const validation = validate(value, false, country?.iso2);

  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 | Called with the formatted display value | | locale | string | Locale key (en, tr, fr, etc.) | | initialCountry | string | Initial country ISO2 code (TR, US, etc.) | | theme | "dark" | "light" | Theme mode | | variant | "classic" \| "minimal" \| "soft" \| "pill" | Built-in visual treatment | | searchPlaceholder| string | Country search input placeholder | | mobileOnly | boolean | If true, only mobile numbers are considered valid | | onRawChange | (raw: string) => void | Callback for the E.164 phone number | | onValidChange | (valid: boolean) => void | Callback to track if phone number is valid | | countrySelectorLabel | string | Accessible label for the country selector | | noResultsText | string | Empty-state text for country search | | flagMode | "cdn" \| "emoji" \| "none" | Built-in flag rendering strategy | | renderFlag | (country, context) => ReactNode | Overrides built-in flag rendering | | virtualizeThreshold | number | Number of results after which list virtualization starts |

Native input attributes such as name, required, disabled, onBlur, autoComplete, and aria-* are forwarded to the telephone input.

Use flagMode="emoji" for a fully offline flag display, or flagMode="none" when flags are not needed. renderFlag can render a local SVG, icon component, or any other React node.


🧱 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)

Other locales use Intl.DisplayNames when the runtime supports them.


🛆 License

MIT


🔗 Live Demo

Check out the live demo: react-phonebox demo

Developed by frkngnc