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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mui-react-phone-input

v0.0.10

Published

MUI and React component for entering and validating international telephone numbers

Downloads

41

Readme

React Material Telephone Input

This is a fork of mukeshsoni's mui-react-phone-input plugin built on Material UI components v0.15.4

Getting Started

Using npm

npm install mui-react-phone-input

Using yarn

yarn add mui-react-phone-input

Use in code thus


import React from 'react'
import { render } from 'react-dom'
import ReactTelInput from 'mui-react-phone-input';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import injectTapEventPlugin from 'react-tap-event-plugin';

injectTapEventPlugin();

const changeHandler = (target, formattedNumber, selectedCountry, rawValue) => {
  console.log(`${formattedNumber} - ${rawValue}`, 'Formatted value and raw value')
}
const Demo = () =>(<div>
<MuiThemeProvider>
<div>
<RTI
  flagsImagePath="./images/flags.png"
  name="phone"
  onChange={changeHandler}
  floatingLabelText="phone"
  floatingLabelStyle={{ color: '#01579b' }}
  flagDropDownEnabled
  value={''}
/>
</div>
  </div>)
render(<Demo />, document.querySelector('#demo'))

Features

  • Automatically format the number as the user types
  • Navigate the country dropdown by typing a country's name, or using up/down keys
  • Selecting a country from the dropdown will update the dial code in the input
  • Typing a different dial code will automatically update the displayed flag
  • Country names in the dropdown also include localised versions in brackets
  • Dropdown appears above or below the input depending on available space/scroll position

Prerequisites

Requires following as peerDependencies

  • material-ui
  • react
  • react-dom
  • react-tap-event-plugin

Development

Clone the repository

git clone https://github.com/copartit/mui-react-phone-input

Run npm install

npm install

Or yarn

yarn install

Run the demo files

yarn run start

Run clean

yarn run clean

Build the files

yarn run build

Running the tests

yarn test

Linting

yarn run lint

Built With

  • React - Facebook's rendering library
  • material-ui - React based presentational components using Google's material design principles

Contributing

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

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

Acknowledgments

  • Hat tip to mukeshsoni, for creating the original plugin in react

Component props

The component accepts other props to customize it -

value and initialValue

Both the props have the same purpose - for setting the initial value of the input programatically.

initialValue

See value above.

autoFormat

true by default. Setting it to false will turn off all auto formatting.

defaultCountry

The component selects the country code of a country by default. You can change it by passing the iso2 name of a country. E.g. for United States, set defaultCountry to 'us'.

onlyCountries

If you don't want all countries to be shown in the dropdown list, you can pass an array of country iso2 names to be shown in the dropdown list.

preferredCountries

Preferred countries show up in the top of the list. This prop also accepts an array of country iso2 names.

E.g.

<ReactTelephoneInput
  preferredCountries={['in', 'us', 'uk']}
  />

classNames

You can send in style classes to be applied to the top container div of the component.

onChange

Function, called whenever there is a change of value in the input box.

onEnterKeyPress

Function, called when user presses the 'enter' key when the input box is in focus.

onBlur

Function, called when the focus goes away from the input box.

onFocus

Function, called when the input box gets the focus.

disabled

Boolean value. When set to true, the input box is disabled and clicking on flag dropdown does nothing.

flagDropDownEnabled

Boolean value. False by default. To toggle the flag display functionality