Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-international-phone

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-international-phone

International phone component for React

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
162K
increased by15.71%
Maintainers
1
Weekly downloads
 
Created
Source

react-international-phone

🤙 International phone component for react

demo

build-status

Live demo: Storybook

Installation

$ npm install --save react-international-phone
$ yarn add react-international-phone

Usage

import { useState } from 'react';
import { PhoneInput } from 'react-international-phone';

const App = () => {
  const [phone, setPhone] = useState('');

  return (
    <div>
      <PhoneInput initialCountry="ua" phone={phone} onChange={setPhone} />
    </div>
  );
};

Features

  • 😎 Easy to integrate - HTML input under the hood
  • 🔍 Country guessing - Just start typing and component will guess the country
  • 🏳️ Country flag render - Render flags using Twemoji
  • Cursor position handling - Typing in the middle of input value feels naturally
  • Lightweight - no third-party dependencies

PhoneInput component

Properties

PropRequiredTypeDescriptionDefault value
initialCountry+CountryIso2Initial country value (iso2).
initialPhone-stringInitial phone value.""
hideDropdown-booleanHide the dropdown icon. Make country selection not accessible.false
placeholder-stringInput's placeholderundefined
disabled-booleanDisable phone input and country selector.false
prefix-stringPrefix for phone value."+"
defaultMask-stringThis mask will apply on countries that does not have specified mask."............" // 12 chars
hideSpaceAfterDialCode-booleanHide space after country dial codefalse
historySaveDebounceMS-numberSave value to history if there were not any changes in provided milliseconds timeslot.
Undo/redo (ctrl+z/ctrl+shif+z) works only with values that are saved in history
200
disableCountryGuess-booleanDisable country guess on value change.
- onCountryGuess callback would not be called.
false
disableDialCodePrefill-booleanDisable dial code prefill on initialization.
Dial code prefill works only when "empty" phone value have been provided.
false
forceDialCode-booleanAlways display the dial code.
Dial code can't be removed/changed by keyboard events, but it can be changed by pasting another country phone value.
false
disableDialCodeAndPrefix-booleanPhone value will not include passed dialCode and prefix if set to true.
- disableCountryGuess value will be ignored and set to true.
- forceDialCode value will be ignored and set to false.
false
showDisabledDialCodeAndPrefix-booleanShow prefix and dial code between country selector and phone input.
- Works only when disableDialCodeAndPrefix is true
false
inputProps-InputHTMLAttributesDefault input component propsundefined

Events

EventRequiredTypeDescription
onChange-(phone: string) => voidCallback that calls on phone change

Input events like onFocus and onBlur can be passed to the inputProps

Style properties

PropRequiredTypeDescriptionDefault value
style-CSSPropertiesCustom styles for PhoneInput containerundefined
className-stringCustom className for PhoneInput containerundefined
inputStyle-CSSPropertiesCustom styles for input fieldundefined
inputClassName-stringCustom className for input fieldundefined
countrySelectorStyleProps-CountrySelectorStylePropsStyle properties for country selectorundefined
dialCodePreviewStyleProps-DialCodePreviewStylePropsStyle properties for dial code previewundefined

CSS variables

VariableDefault value
--react-international-phone-height36px
--react-international-phone-background-colorwhite
--react-international-phone-text-color#222
--react-international-phone-font-size13px
--react-international-phone-border-radius4px
--react-international-phone-border-colorgainsboro
--react-international-phone-disabled-background-colorwhitesmoke
--react-international-phone-disabled-text-color#666

CountrySelector component

Properties

PropRequiredTypeDescriptionDefault value
selectedCountry-CountryIso2Selected country (iso2)undefined
disabled-booleanIs CountrySelector disabledundefined
hideDropdown-booleanHide dropdown icon and make CountrySelector not clickableundefined

Events

PropRequiredTypeDescriptionDefault value
onSelect-(country: ParsedCountry) => voidCallback that calls on country selectundefined

Style properties (CountrySelectorStyleProps type)

PropRequiredTypeDescriptionDefault value
style-CSSPropertiesCustom styles for CountrySelector containerundefined
className-stringCustom className for CountrySelector containerundefined
buttonStyle-CSSPropertiesCustom styles for CountrySelector buttonundefined
buttonClassName-stringCustom className for CountrySelector buttonundefined
flagStyle-dropdownStylePropsCustom styles for CountrySelector flagundefined
flagClassName-stringCustom className for CountrySelector flagundefined
dropdownArrowStyle-dropdownStylePropsCustom styles for CountrySelector dropdown arrowundefined
dropdownArrowClassName-stringCustom className for CountrySelector dropdown arrowundefined
dropdownStyleProps-CountrySelectorDropdownStylePropsStyle properties for CountrySelector dropdownundefined

CSS variables

VariableDefault value
--react-international-phone-country-selector-background-color--react-international-phone-background-color
--react-international-phone-country-selector-background-color-hoverwhitesmoke
--react-international-phone-disabled-country-selector-background-color--react-international-phone-disabled-background-color
--react-international-phone-country-selector-border-color13px
--react-international-phone-country-selector-arrow-size4px
--react-international-phone-country-selector-arrow-color#777
--react-international-phone-disabled-country-selector-arrow-color#999

CountrySelectorDropdown component

Properties

PropRequiredTypeDescriptionDefault value
show+booleanShow dropdown
dialCodePrefix-stringPrefix for country code"+"
selectedCountry-CountryIso2Selected option country code (iso2)undefined

Events

PropRequiredTypeDescriptionDefault value
onSelect-(country: ParsedCountry) => voidCallback that calls on option selectundefined
onClickOutside-() => voidCallback that calls on outside clickundefined
onEscapePress-() => voidCallback that calls on escape keyboard key pressundefined

Style properties (CountrySelectorDropdownStyleProps type)

PropRequiredTypeDescriptionDefault value
style-CSSPropertiesCustom styles for CountrySelectorDropdown containerundefined
className-stringCustom className for CountrySelectorDropdown containerundefined
listItemStyle-CSSPropertiesCustom styles for CountrySelectorDropdown list-item containerundefined
listItemClassName-stringCustom className for CountrySelectorDropdown list-item containerundefined
listItemFlagStyle-CSSPropertiesCustom styles for CountrySelectorDropdown list-item flagundefined
listItemFlagClassName-stringCustom className for CountrySelectorDropdown list-item flagundefined
listItemCountryNameStyle-CSSPropertiesCustom styles for CountrySelectorDropdown list-item country nameundefined
listItemCountryNameClassName-stringCustom className for CountrySelectorDropdown list-item country nameundefined
listItemDialCodeStyle-CSSPropertiesCustom styles for CountrySelectorDropdown list-item country dial codeundefined
listItemDialCodeClassName-stringCustom className for CountrySelectorDropdown list-item country dial codeundefined

CSS variables

VariableDefault value
--react-international-phone-dropdown-item-font-size14px
--react-international-phone-dropdown-item-text-color--react-international-phone-text-color
--react-international-phone-dropdown-item-background-color--react-international-phone-background-color
--react-international-phone-dropdown-item-dial-code-colorgray
--react-international-phone-selected-dropdown-item-text-color--react-international-phone-text-color
--react-international-phone-selected-dropdown-item-background-colorwhitesmoke
--react-international-phone-selected-dropdown-item-dial-code-color-react-international-phone-dropdown-item-dial-code-color
--react-international-phone-dropdown-shadow2px 2px 16px rgb(0 0 0 / 25%)

DialCodePreview component

Properties

PropRequiredTypeDescriptionDefault value
dialCode+stringCountry dial code (iso2)
prefix+stringDial code prefix
disabled-booleanIs component disabledundefined

Style properties (DialCodePreviewStyleProps type)

PropRequiredTypeDescriptionDefault value
style-CSSPropertiesCustom styles for DialCodePreview containerundefined
className-stringCustom className for DialCodePreview containerundefined

CSS variables

VariableDefault value
--react-international-phone-dial-code-preview-background-color--react-international-phone-background-color
--react-international-phone-dial-code-preview-border-color--react-international-phone-border-color
--react-international-phone-dial-code-preview-text-color--react-international-phone-text-color
--react-international-phone-dial-code-preview-font-size--react-international-phone-font-size
--react-international-phone-dial-code-preview-disabled-background-color--react-international-phone-disabled-background-color
--react-international-phone-dial-code-preview-disabled-text-color--react-international-phone-disabled-text-color

Keywords

FAQs

Package last updated on 30 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc