All Projects → benaubin → react-headless-phone-input

benaubin / react-headless-phone-input

Licence: MIT license
Headless phone number input component for React. Because phone numbers are hard.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to react-headless-phone-input

Vue Phone Number Input
A phone number input made with Vue JS (format & valid phone number)
Stars: ✭ 407 (+1528%)
Mutual labels:  input, phone-number
intl-tel-input-rails
intl-tel-input for the Rails asset pipeline
Stars: ✭ 35 (+40%)
Mutual labels:  input, phone-number
Intl Tel Input
A JavaScript plugin for entering and validating international telephone numbers
Stars: ✭ 5,963 (+23752%)
Mutual labels:  input, phone-number
ember-phone-input
An Ember.js component to handle international phone numbers
Stars: ✭ 22 (-12%)
Mutual labels:  input, phone-number
international-telephone-input
Integration to Magento 2 a jQuery plugin for entering and validating international telephone numbers.
Stars: ✭ 26 (+4%)
Mutual labels:  input, phone-number
ra-input-markdown
A markdown editor for react-admin
Stars: ✭ 22 (-12%)
Mutual labels:  input
PhoneNumberKit
Android Kotlin library to parse and format international phone numbers. Country code picker.
Stars: ✭ 124 (+396%)
Mutual labels:  phone-number
getcontact
Find info about user by phone number using GetContact API
Stars: ✭ 228 (+812%)
Mutual labels:  phone-number
react-ratings-declarative
A customizable rating component for selecting x widgets or visualizing x widgets
Stars: ✭ 41 (+64%)
Mutual labels:  input
rci
🔢 better code inputs for react/web
Stars: ✭ 805 (+3120%)
Mutual labels:  input
kindaVim.theapp
Ultimate Vim Mode for macOS
Stars: ✭ 372 (+1388%)
Mutual labels:  input
MaiSense
Touch Sensor Emulation for SDEY - 💦 Touchlaundry Disco
Stars: ✭ 110 (+340%)
Mutual labels:  input
tag-picker
Better tags input interaction with JavaScript.
Stars: ✭ 27 (+8%)
Mutual labels:  input
vue-pincode-input
Great pincode input component
Stars: ✭ 128 (+412%)
Mutual labels:  input
muxnect
Send input to just about any interactive command-line tool through a local web server
Stars: ✭ 23 (-8%)
Mutual labels:  input
react-file-input-previews-base64
This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.
Stars: ✭ 15 (-40%)
Mutual labels:  input
clrprint
Print colorful output in the terminal, idle, cmd, and Windows PowerShell using the same functions.
Stars: ✭ 22 (-12%)
Mutual labels:  input
numberbox-card
Replace input_number sliders with plus and minus buttons
Stars: ✭ 61 (+144%)
Mutual labels:  input
Reborn
ReborN SMS BOMBER | SpeedX & 4NAT
Stars: ✭ 126 (+404%)
Mutual labels:  phone-number
magento2-sign-in-with-phone-number
This extension allow your customers to login to your Magento store using their phone number.
Stars: ✭ 42 (+68%)
Mutual labels:  phone-number

React Headless Phone Input

A headless phone number input component built for usability.

Phone numbers are hard. Users expect to be able to enter phone numbers in the format they're used to. Here's the problem: most people are used to national - or even local phone number formats. If you offload phone number validation to your backend (or an API), resolving the ambiguity becomes difficult or even impossible.

This component helps you build a UI that gracefully guides your users towards unambiguous phone number formats. And you get the result in standard e164 format: ready for use with any telephony service.

Other libraries are generally heavy (phone number rulesets can be big - 99.1% of this library's footprint is due to libphonenumber-js), force you to use their UI, and can't handle copy & paste or edit-in-place. react-headless-phone-input is designed for usability-first, and lets you bring your own input components. In fact, your existing input fields will almost certainly work with no modifications. Plus, it supports optional lazy-loading with progressive enhancement powered by React Suspense.

Built with React Hooks.

Demo

Install

Install both react-headless-input and libphonenumber-js:

npm i --save react-headless-phone-input libphonenumber-js

or

yarn add react-headless-phone-input libphonenumber-js

Features

  • 100% headless: Bring your own UI. You can use almost any input component you already have
  • Lets users copy & paste phone numbers of any format
  • Typescript support
  • Built-in lazy-loading with progressive enhancement (clocks in at 40KB without lazy-loading)
  • Detects the associated country, enabling international phone input.
  • Lets users copy & paste phone numbers of any format
  • Acts like a normal input: Doesn’t glitch if a user edits in-place or deletes template characters
  • Validates number plausibility
  • External state is standard e164 format

Example

This library is headless: you bring your own UI, but it's almost as easy as using regular inputs.

Here's an example using tiny-flag-react to show the flag associated with the number's country:

import TinyFlagReact from "tiny-flag-react";
import PhoneFormatter from "react-headless-phone-input";
// import PhoneFormatter from "react-headless-phone-input/lazy"; RECOMMENDED

const [e164, setE164] = useState("");

<PhoneFormatter defaultCountry="US" value={e164} onChange={setE164}>
  {({ country, impossible, onBlur, onInputChange, inputValue }) => {
    return (
      <>
        <div style={{ display: "flex", alignItems: "center" }}>
          <span
            style={{
              fontSize: "24px",
            }}>
            {country ? (
              <TinyFlagReact
                country={country}
                alt={country + " flag"}
                fallbackImageURL={`https://cdn.jsdelivr.net/npm/[email protected]/img/SVG/${country}.svg`}
              />
            ) : (
              <></>
            )}
          </span>
          <input
            type="tel"
            value={inputValue}
            onBlur={onBlur}
            onChange={(e) => onInputChange(e.target.value)}
          />
        </div>
        {impossible && (
          <div style={{ color: "red" }}>Impossible phone number</div>
        )}
      </>
    );
  }}
</PhoneFormatter>;

Demo

Performance

Due to this library's dependence on libphonenumber-js, it clocks in at 38.7KB minified + gzipped. To improve your user's experience, react-headless-phone-component supports lazy loading with React Suspense with progressive auto-enachement. If your bundler supports dynamic imports and are using a compatible version of React, just swap react-headless-phone-input for react-headless-phone-input/lazy.

Your UI will render and can be used immediately. Once react-headless-phone-input loads, the component will be automatically upgraded. No other changes are required.

import PhoneFormatter from "react-headless-phone-input/lazy";

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].