Gathering detailed insights and metrics for mui-phone-input
Gathering detailed insights and metrics for mui-phone-input
Gathering detailed insights and metrics for mui-phone-input
Gathering detailed insights and metrics for mui-phone-input
Advanced, highly customizable phone input component for Material UI.
npm install mui-phone-input
Typescript
Module System
Node Version
NPM Version
73.6
Supply Chain
97.6
Quality
85.9
Maintenance
100
Vulnerability
100
License
TypeScript (99.57%)
JavaScript (0.43%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
11,625
Last Day
107
Last Week
596
Last Month
1,897
Last Year
11,532
10 Stars
129 Commits
1 Forks
1 Watching
1 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
0.1.5
Package Id
mui-phone-input@0.1.5
Unpacked Size
64.64 kB
Size
11.35 kB
File Count
36
NPM Version
10.8.2
Node Version
20.18.2
Publised On
03 Feb 2025
Cumulative downloads
Total Downloads
Last day
143.2%
107
Compared to previous day
Last week
70.8%
596
Compared to previous week
Last month
2.8%
1,897
Compared to previous month
Last year
12,300%
11,532
Compared to previous year
1
1
Advanced phone input component for Material UI that leverages the react-phone-hooks supporting all countries. The package is compatible with @material-ui/core, @mui/material, @mui/base and @mui/joy distributions. It provides built-in support for area codes and strict validation.
The value of the component is an object containing the parts of the phone number. This format of value gives a wide range of opportunities for handling the data in your desired way.
1{ 2 countryCode: 1, 3 areaCode: "702", 4 phoneNumber: "1234567", 5 isoCode: "us", 6 valid: function valid(strict) 7}
The validation is checked by the valid
function of the value object that returns a boolean value. An example with the react-hook-form is shown below:
1import {useMemo, useState} from "react"; 2import {useForm} from "react-hook-form"; 3import PhoneInput from "mui-phone-input"; 4import {checkValidity, parsePhoneNumber} from "react-phone-hooks"; 5 6const Demo = () => { 7 const {register, handleSubmit} = useForm(); 8 const [value, setValue] = useState({}); 9 10 const phoneProps = register("phone", { 11 validate: (value: any) => checkValidity(parsePhoneNumber(value)), 12 }) 13 14 const onChange = async (value: any) => { 15 await phoneProps.onChange({target: {value, name: phoneProps.name}}); 16 setValue(value); 17 } 18 19 const error = useMemo(() => value.valid && !value.valid(), [value]); 20 21 return ( 22 <form onSubmit={handleSubmit(console.log)}> 23 <PhoneInput 24 enableSearch 25 error={error} 26 {...phoneProps} 27 variant="filled" 28 onChange={onChange} 29 searchVariant="standard" 30 /> 31 <button type="submit">Submit</button> 32 </form> 33 ) 34} 35 36export default Demo;
The valid
function primarily checks if a phone number has a length appropriate for its specified country. In addition, a more comprehensive validation can be performed, including verifying the dial and area codes' accuracy for the selected country. To activate the strict validation, pass true
as the first argument to the valid
function.
The package provides a built-in localization feature that allows you to change the language of the component. The locale
function returns the language object that can be passed to the createTheme
function of Material UI.
1import {createTheme, ThemeProvider} from "@mui/material/styles"; 2import PhoneInput, {locale} from "mui-phone-input"; 3 4const theme = createTheme({}, locale("frFR")); 5 6<ThemeProvider theme={theme}> 7 <PhoneInput/> 8</ThemeProvider>
NOTE: If you use localization in the documented way, you should replace the language object with the locale
function, specifying the desired language code.
Apart from the phone-specific properties described below, all Input and TextField properties supported by the used Material distribution can be applied to the phone input component.
Property | Description | Type |
---|---|---|
value | An object containing a parsed phone number or the raw number. | object / string |
country | Country code to be selected by default. By default, it will show the flag of the user's country. | string |
distinct | Show the distinct list of country codes not listing all area codes. | boolean |
enableArrow | Shows an arrow next to the country flag. Default value is false . | boolean |
enableSearch | Enables search in the country selection dropdown menu. Default value is false . | boolean |
searchVariant | Accepts an Input variant, and values depend on the chosen Material distribution. | TextFieldVariants |
searchNotFound | The value is shown if enableSearch is true and the query does not match any country. Default value is No country found . | string |
searchPlaceholder | The value is shown if enableSearch is true . Default value is Search country . | string |
disableDropdown | Disables the manual country selection through the dropdown menu. | boolean |
disableParentheses | Disables parentheses from the input masks. Default enabled. | boolean |
onlyCountries | Country codes to be included in the list. E.g. onlyCountries={['us', 'ca', 'uk']} . | string[] |
excludeCountries | Country codes to be excluded from the list of countries. E.g. excludeCountries={['us', 'ca', 'uk']} . | string[] |
preferredCountries | Country codes to be at the top of the list. E.g. preferredCountries={['us', 'ca', 'uk']} . | string[] |
onChange | The only difference from the default onChange is that value comes first. | function(value, event) |
onMount | The callback is triggered once the component gets mounted. | function(value) |
Any contribution is welcome. Don't hesitate to open an issue or discussion if you have questions about your project's usage and integration. For ideas or suggestions, please open a pull request. Your name will shine on our contributors' list. Be proud of what you build!
Copyright (C) 2023 Artyom Vancyan. MIT
No vulnerabilities found.
No security vulnerabilities found.
mui-tel-input
A phone number input designed for the React library MUI built with libphonenumber-js
mui-phone-number
A material-ui v5+ react component to format phone numbers. Based on react-phone-input-2
react-mui-phone-input
React component to format phone number, based on MUI.
os-mui-phone-input
Mui phone input with country code and country flag.