1.0.2 • Published 4 years ago

react-phone-input-textfield-filled v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

React-Phone-Input-TextField-filled

react-phone-input-2 with Material-UI's "filled" variant.

Highly customizable phone input component with auto formatting.

Original look

alt tag

With a Material-UI TextField look:

alt tag

Installation

npm install react-phone-input-textfield-filled --save

Usage

import PhoneInput from "react-phone-input-textfield-filled";
import "react-phone-input-textfield-filled/dist/style.css";

<PhoneInput
  defaultCountry={"us"}
  value={this.state.phone}
  onChange={handleOnChange}
/>;
handleOnChange(value) {
  this.setState({ phone: value })
}

Options

<PhoneInput
  inputExtraProps={{
    name: "phone",
    required: true,
    autoFocus: true
  }}
/>

Contents

Style

Events

Country data object does not return from onKeyDown event

Regions

Regions selected: {'europe'}

<PhoneInput defaultCountry="it" regions={"europe"} />

Regions selected: {'north-america', 'carribean'}

<PhoneInput defaultCountry="ca" regions={["north-america", "carribean"]} />

Custom area codes

<PhoneInput
  onlyCountries={["gr", "fr", "us"]}
  areaCodes={{ gr: ["2694", "2647"], fr: ["369", "463"], us: ["300"] }}
/>

Custom masks

<PhoneInput
  onlyCountries={["fr", "at"]}
  masks={{ fr: "+.. (...) ..-..-..", at: "+.. (....) ...-...." }}
/>

Localization

<PhoneInput
  onlyCountries={['de', 'es']}
  localization={{de: 'Deutschland', es: 'España'}}
/>

<PhoneInput
  onlyCountries={['de', 'es']}
  localization={{'Germany': 'Deutschland', 'Spain': 'España'}}
/>

Predefined translations es, de, ru, fr

import es from "lang/es.json";

<PhoneInput localization={es} />;

Preserve countries order

<PhoneInput
  onlyCountries={["fr", "at"]}
  preserveOrder={["onlyCountries", "preferredCountries"]}
/>

Other props

Guides

Phone without dialCode

handleOnChange(value, data) {
  this.setState({ rawPhone: value.replace(/[^0-9]+/g,'').slice(data.dialCode.length) })
}

Check validity of the phone number

<PhoneInput isValid={v => v === "1"} />

Contributing

Code style changes not allowed

License

GitHub license

Based on react-phone-input-2