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

@hyperse/hero-tel-input

v1.0.1

Published

A hero-ui tel input component

Readme

@hyperse/hero-tel-input

A modern, accessible, and feature-rich international telephone input component built with React and HeroUI. Perfect for forms that require phone number input with country selection.

✨ Features

  • 🌍 International Support: Supports all countries with their respective calling codes
  • 🎨 HeroUI Integration: Built on top of HeroUI for consistent design and theming
  • 📱 Smart Formatting: Automatic phone number formatting based on country
  • 🔍 Country Search: Easy country selection with search functionality
  • 🚀 TypeScript: Full TypeScript support with comprehensive type definitions
  • Accessible: WCAG compliant with proper ARIA attributes
  • 🎯 Form Integration: Works seamlessly with React Hook Form and other form libraries
  • 🔧 Customizable: Extensive customization options for flags, styling, and behavior
  • 📦 Lightweight: Minimal bundle size with tree-shaking support

📦 Installation

npm install @hyperse/hero-tel-input
# or
yarn add @hyperse/hero-tel-input
# or
pnpm add @hyperse/hero-tel-input

🚀 Quick Start

import { HeroTelInput } from '@hyperse/hero-tel-input';

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

  return (
    <HeroTelInput
      value={phoneNumber}
      onChange={(value, info) => {
        setPhoneNumber(value);
        console.log('Phone info:', info);
      }}
      defaultCountry="US"
      placeholder="Enter phone number"
    />
  );
}

📖 Basic Usage

Simple Implementation

import { HeroTelInput } from '@hyperse/hero-tel-input';

function PhoneInput() {
  return (
    <HeroTelInput
      label="Phone Number"
      placeholder="Enter your phone number"
      defaultCountry="CN"
      onChange={(value, info) => {
        console.log('Value:', value);
        console.log('Country:', info.countryCode);
        console.log('Calling Code:', info.countryCallingCode);
      }}
    />
  );
}

With React Hook Form

import { Controller, useForm } from 'react-hook-form';
import { HeroTelInput, matchIsValidTel } from '@hyperse/hero-tel-input';

function PhoneForm() {
  const { control, handleSubmit } = useForm();

  const onSubmit = (data) => {
    console.log('Form data:', data);
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <Controller
        name="phoneNumber"
        control={control}
        rules={{
          validate: (value) => matchIsValidTel(value) || 'Invalid phone number',
        }}
        render={({ field, fieldState }) => (
          <HeroTelInput
            {...field}
            label="Phone Number"
            defaultCountry="US"
            isInvalid={fieldState.invalid}
            errorMessage={fieldState.error?.message}
          />
        )}
      />
      <button type="submit">Submit</button>
    </form>
  );
}

🎛️ API Reference

Props

| Prop | Type | Default | Description | | ---------------------- | ------------------------------------------------- | ------- | ---------------------------------------- | | value | string | '' | The phone number value | | defaultCountry | HeroTelInputCountry | - | Default country to select | | forceCallingCode | boolean | false | Force the calling code to be included | | onlyCountries | HeroTelInputCountry[] | - | Only allow these countries | | excludedCountries | HeroTelInputCountry[] | - | Exclude these countries | | preferredCountries | HeroTelInputCountry[] | - | Show these countries at the top | | continents | HeroTelInputContinent[] | - | Only allow countries in these continents | | langOfCountryName | string | - | Language for country names | | disableFormatting | boolean | false | Disable phone number formatting | | disableDropdown | boolean | false | Disable country dropdown | | focusOnSelectCountry | boolean | - | Focus input after country selection | | onChange | (value: string, info: HeroTelInputInfo) => void | - | Callback when value changes | | onBlur | (event, info: HeroTelInputInfo) => void | - | Callback when input loses focus | | unknownFlagElement | React.ReactNode | - | Element for unknown flags |

HeroTelInputInfo

interface HeroTelInputInfo {
  countryCode: HeroTelInputCountry | null; // ISO country code (e.g., 'CN')
  countryCallingCode: string | null; // Calling code (e.g., '86')
  nationalNumber: string | null; // National number part
  numberType: NumberType | null; // Number type (e.g., 'MOBILE')
  numberValue: string | null; // E.164 formatted value
  reason: 'country' | 'input' | 'blur'; // Change reason
}

🎨 Advanced Examples

Custom Country Filtering

<HeroTelInput
  onlyCountries={['US', 'CA', 'MX']}
  preferredCountries={['US']}
  defaultCountry="US"
  label="North American Phone"
/>

Force Calling Code

<HeroTelInput
  forceCallingCode
  defaultCountry="CN"
  label="Chinese Phone (with +86)"
/>

Custom Styling

<HeroTelInput
  defaultCountry="FR"
  classNames={{
    base: 'custom-dropdown-base',
    trigger: 'custom-trigger',
    content: 'custom-content',
  }}
/>

Form Validation

import { matchIsValidTel } from '@hyperse/hero-tel-input';

const validatePhone = (value: string) => {
  if (!value) return 'Phone number is required';
  if (!matchIsValidTel(value)) return 'Invalid phone number';
  return true;
};

🌍 Supported Countries

The component supports all countries with their respective calling codes. You can:

  • Filter by specific countries using onlyCountries
  • Exclude countries using excludedCountries
  • Set preferred countries using preferredCountries
  • Filter by continents using continents

Available Continents

  • 'AF' - Africa
  • 'AS' - Asia
  • 'EU' - Europe
  • 'NA' - North America
  • 'OC' - Oceania
  • 'SA' - South America

Examples

Check out the examples in the examples/ directory:

  • example-nextjs/ - Next.js integration example
  • website/ - Documentation website

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.