react-phone-input-material-ui
Version:
A material-ui react component to format phone numbers. Based on react-phone-input-2
83 lines (58 loc) • 2.29 kB
Markdown
with auto formatting. Based on the wonderful [react-phone-input-2](https://github.com/bl00mber/react-phone-input-2) package.
Supports material-ui v4 and v5.


```shell-script
npm install react-phone-input-material-ui --save
or
yarn add react-phone-input-material-ui
```
Mandatory props: `value` and `onChange` for controlling field; `component`, ideally `TextField`
```jsx
import React from 'react';
import ReactPhoneInput from 'react-phone-input-material-ui';
import { TextField, withStyles } from '@material-ui/core';
const styles = theme => ({
field: {
margin: '10px 0',
},
countryList: {
...theme.typography.body1,
},
});
function PhoneField(props) {
const { value, defaultCountry, onChange, classes } = props;
return (
<React.Fragment>
{/* Simple usage */}
<ReactPhoneInput
value={value}
onChange={onChange} // passed function receives the phone value
component={TextField}
/>
{/* Configure more */}
<ReactPhoneInput
value={value}
defaultCountry={defaultCountry || 'gb'}
onChange={onChange}
inputClass={classes.field}
dropdownClass={classes.countryList}
component={TextField}
/>
</React.Fragment>
);
}
export default withStyles(styles)(PhoneField);
```
**Forked from [react-phone-input-2](https://github.com/bl00mber/react-phone-input-2). All the features of [react-phone-input-2](https://github.com/bl00mber/react-phone-input-2) are available. I will be update this library frequently to upto date with origin library**
Code style changes not allowed
[](https://github.com/bl00mber/react-phone-input-2/blob/master/LICENSE)
Based on [react-phone-input](https://github.com/razagill/react-phone-input)
Make sure you donated for lib maintenance [](https://www.paypal.me/bloomber/20)
Highly customizable phone input component