mui-tel-input 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.types.d.ts +29 -0
- package/dist/mui-tel-input.es.js +16459 -0
- package/dist/mui-tel-input.es.js.map +1 -0
- package/dist/mui-tel-input.umd.js +4 -0
- package/dist/mui-tel-input.umd.js.map +1 -0
- package/dist/shared/constants/continents.d.ts +7 -0
- package/dist/shared/constants/countries.d.ts +4 -0
- package/dist/shared/constants/flags.d.ts +6 -0
- package/dist/shared/constants/lang.d.ts +2 -0
- package/dist/shared/helpers/array.d.ts +2 -0
- package/dist/shared/helpers/country.d.ts +16 -0
- package/dist/shared/helpers/dom.d.ts +1 -0
- package/dist/shared/helpers/intl.d.ts +1 -0
- package/dist/shared/helpers/log.d.ts +1 -0
- package/dist/shared/helpers/object.d.ts +2 -0
- package/dist/shared/helpers/ref.d.ts +2 -0
- package/dist/shared/hooks/useMissmatchProps.d.ts +2 -0
- package/dist/shared/hooks/usePhoneDigits.d.ts +31 -0
- package/dist/vite-env.d.ts +1 -0
- package/package.json +109 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Victor de la Fouchardière
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>Mui-tel-input</h1>
|
|
3
|
+
<p>A phone number input designed for the React library <a href="https://mui.com/">MUI</a></p>
|
|
4
|
+
</div>
|
|
5
|
+
<div align="center">
|
|
6
|
+
|
|
7
|
+
[](https://github.com/viclafouch/mui-tel-input/blob/master/LICENSE)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
// with npm
|
|
15
|
+
npm install mui-tel-input
|
|
16
|
+
|
|
17
|
+
// with yarn
|
|
18
|
+
yarn add mui-tel-input
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import React from 'react'
|
|
25
|
+
import { MuiTelInput } from 'mui-tel-input'
|
|
26
|
+
|
|
27
|
+
const MyComponent = () => {
|
|
28
|
+
const [value, setValue] = React.useState('')
|
|
29
|
+
|
|
30
|
+
const handleChange = (newValue) => {
|
|
31
|
+
setValue(newValue)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return <MuiTelInput value={value} onChange={handleChange} />
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Phone number validation
|
|
39
|
+
|
|
40
|
+
```jsx
|
|
41
|
+
import React from 'react'
|
|
42
|
+
import Box from '@mui/material/Box'
|
|
43
|
+
import Typography from '@mui/material/Typography'
|
|
44
|
+
import { MuiTelInput, isValidPhoneNumber } from 'mui-tel-input'
|
|
45
|
+
|
|
46
|
+
const MyComponent = () => {
|
|
47
|
+
const [value, setValue] = React.useState('')
|
|
48
|
+
const [isValid, setIsValid] = React.useState(false)
|
|
49
|
+
|
|
50
|
+
const handleChange = (newValue) => {
|
|
51
|
+
setIsValid(isValidPhoneNumber(newValue))
|
|
52
|
+
setValue(newValue)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Box>
|
|
57
|
+
<Typography>This is valid ? {isValid ? 'yes' : 'no'}</Typography>
|
|
58
|
+
<MuiTelInput value={value} onChange={handleChange} />
|
|
59
|
+
</Box>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Options
|
|
65
|
+
|
|
66
|
+
| Name | Type | Description |
|
|
67
|
+
| --------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `value` | `string` | The phone number value (**Required**) |
|
|
69
|
+
| `onChange` | `(value, info) => void` | Gets called once the user updates the input or selects a new country. | `defaultCountry?` | `string` | [Country code](#country-code) to be displayed on mount.
|
|
70
|
+
| `onlyCountries?` | `array` | [Country codes](#country-code) to be included. | `excludedCountries?` | `array` | [Country codes](#country-code) to be excluded.
|
|
71
|
+
| `preferredCountries?` | `array` | [Country codes](#country-code) to be highlighted to the top of the list of countries.
|
|
72
|
+
| `continents?` | `array` | [Continent codes](#continent-code) to include a list of countries.
|
|
73
|
+
| `forceCallingCode?` | `boolean` | Force the calling code (e.g: `+33`) to be displayed so the value cannot be empty. Default `false`.
|
|
74
|
+
| `focusOnSelectCountry?` | `boolean` | Autofocus the input when the user selects a country in the list. Default `false`.
|
|
75
|
+
| `disableDropdown?` | `boolean` | No country list / The current flag is a `span` instead of a `button`. Default `false`.
|
|
76
|
+
| `langOfCountryName?` | `string` | An Intl locale to translate countries (see [Intl locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)). Default `en`.
|
|
77
|
+
| `MenuProps?` | [Menu API](https://mui.com/api/menu) | Props for the Menu component.
|
|
78
|
+
| `ref?` | `React.Ref<HTMLDivElement>` | A ref pointing to the [Mui TextField component](https://mui.com/components/text-fields/).
|
|
79
|
+
| [TextField Props](#inheritance) | |
|
|
80
|
+
|
|
81
|
+
### Inheritance
|
|
82
|
+
|
|
83
|
+
While not explicitly documented above, the props of the [TextField](https://mui.com/api/text-field) component are also available on MuiTelInput.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Country code
|
|
87
|
+
|
|
88
|
+
A "country code" is a [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (like `US`).
|
|
89
|
+
|
|
90
|
+
This library supports all [officially assigned](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) ISO alpha-2 country codes, plus a few extra ones like: `AC` ([Ascension Island](https://en.wikipedia.org/wiki/Ascension_Island)), `TA` ([Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha)), `XK` ([Kosovo](https://en.wikipedia.org/wiki/Kosovo)).
|
|
91
|
+
|
|
92
|
+
## Continent code
|
|
93
|
+
|
|
94
|
+
| Code | Continent
|
|
95
|
+
| --------------- | -------------------------------
|
|
96
|
+
| AF | Africa
|
|
97
|
+
| AS | Asia
|
|
98
|
+
| EU | Europe
|
|
99
|
+
| NA | North America
|
|
100
|
+
| OC | Oceania
|
|
101
|
+
| SA | South America
|
|
102
|
+
| OC | Oceania
|
|
103
|
+
|
|
104
|
+
## TypeScript
|
|
105
|
+
|
|
106
|
+
This library comes with TypeScript "typings". If you happen to find any bugs in those, create an issue.
|
|
107
|
+
|
|
108
|
+
### 🐛 Bugs
|
|
109
|
+
|
|
110
|
+
Please file an issue for bugs, missing documentation, or unexpected behavior.
|
|
111
|
+
|
|
112
|
+
### 💡 Feature Requests
|
|
113
|
+
|
|
114
|
+
Please file an issue to suggest new features. Vote on feature requests by adding
|
|
115
|
+
a 👍. This helps maintainers prioritize what to work on.
|
|
116
|
+
|
|
117
|
+
## LICENSE
|
|
118
|
+
|
|
119
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { MuiTelInputContinent, MuiTelInputCountry, MuiTelInputInfo, MuiTelInputProps, MuiTelInputReason } from './index.types';
|
|
3
|
+
export { isValidPhoneNumber, AsYouType } from 'libphonenumber-js';
|
|
4
|
+
export type { MuiTelInputProps, MuiTelInputReason, MuiTelInputInfo, MuiTelInputCountry, MuiTelInputContinent };
|
|
5
|
+
declare const MuiTelInput: React.ForwardRefExoticComponent<Pick<MuiTelInputProps, "onChange" | "classes" | "className" | "style" | "children" | "color" | "disabled" | "error" | "fullWidth" | "focused" | "hiddenLabel" | "margin" | "required" | "size" | "sx" | "variant" | "label" | "slot" | "title" | "key" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "InputProps" | "autoComplete" | "autoFocus" | "FormHelperTextProps" | "helperText" | "InputLabelProps" | "inputProps" | "inputRef" | "name" | "rows" | "maxRows" | "minRows" | "SelectProps" | "value" | "disableDropdown" | "excludedCountries" | "onlyCountries" | "preferredCountries" | "defaultCountry" | "forceCallingCode" | "focusOnSelectCountry" | "langOfCountryName" | "disableFormatting" | "continents" | "MenuProps"> & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
export { MuiTelInput };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MenuProps } from '@mui/material/Menu';
|
|
2
|
+
import type { TextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
import type { MuiTelInputContinent } from './shared/constants/continents';
|
|
4
|
+
import type { MuiTelInputCountry } from './shared/constants/countries';
|
|
5
|
+
declare type BaseTextFieldProps = Omit<TextFieldProps, 'onChange' | 'select' | 'type' | 'multiline' | 'defaultValue'>;
|
|
6
|
+
export type { MuiTelInputContinent, MuiTelInputCountry };
|
|
7
|
+
export declare type MuiTelInputReason = 'country' | 'input';
|
|
8
|
+
export interface MuiTelInputInfo {
|
|
9
|
+
countryCode: MuiTelInputCountry | null;
|
|
10
|
+
countryCallingCode: string | null;
|
|
11
|
+
nationalNumber: string | null;
|
|
12
|
+
numberValue: string | null;
|
|
13
|
+
reason: MuiTelInputReason;
|
|
14
|
+
}
|
|
15
|
+
export interface MuiTelInputProps extends BaseTextFieldProps {
|
|
16
|
+
excludedCountries?: MuiTelInputCountry[];
|
|
17
|
+
onlyCountries?: MuiTelInputCountry[];
|
|
18
|
+
preferredCountries?: MuiTelInputCountry[];
|
|
19
|
+
defaultCountry?: MuiTelInputCountry;
|
|
20
|
+
forceCallingCode?: boolean;
|
|
21
|
+
focusOnSelectCountry?: boolean;
|
|
22
|
+
disableDropdown?: boolean;
|
|
23
|
+
langOfCountryName?: string;
|
|
24
|
+
disableFormatting?: boolean;
|
|
25
|
+
continents?: MuiTelInputContinent[];
|
|
26
|
+
onChange?: (value: string, info: MuiTelInputInfo) => void;
|
|
27
|
+
value: string;
|
|
28
|
+
MenuProps?: Partial<MenuProps>;
|
|
29
|
+
}
|