mui-tel-input 1.0.0 → 1.0.3
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/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>
|
|
2
|
+
<h1>MUI tel input</h1>
|
|
3
3
|
<p>A phone number input designed for the React library <a href="https://mui.com/">MUI</a></p>
|
|
4
4
|
</div>
|
|
5
5
|
<div align="center">
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
[](https://github.com/viclafouch/mui-tel-input/blob/master/LICENSE)
|
|
8
|
+
[](https://www.npmjs.com/package/mui-tel-input)
|
|
9
|
+
[](https://circleci.com/gh/viclafouch/mui-tel-input/tree/master)
|
|
10
|
+
|
|
9
11
|
</div>
|
|
10
12
|
|
|
11
13
|
## Installation
|
|
@@ -66,17 +68,18 @@ const MyComponent = () => {
|
|
|
66
68
|
| Name | Type | Description |
|
|
67
69
|
| --------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
68
70
|
| `value` | `string` | The phone number value (**Required**) |
|
|
69
|
-
| `onChange
|
|
71
|
+
| `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
72
|
| `onlyCountries?` | `array` | [Country codes](#country-code) to be included. | `excludedCountries?` | `array` | [Country codes](#country-code) to be excluded.
|
|
71
73
|
| `preferredCountries?` | `array` | [Country codes](#country-code) to be highlighted to the top of the list of countries.
|
|
72
74
|
| `continents?` | `array` | [Continent codes](#continent-code) to include a list of countries.
|
|
73
75
|
| `forceCallingCode?` | `boolean` | Force the calling code (e.g: `+33`) to be displayed so the value cannot be empty. Default `false`.
|
|
74
76
|
| `focusOnSelectCountry?` | `boolean` | Autofocus the input when the user selects a country in the list. Default `false`.
|
|
75
77
|
| `disableDropdown?` | `boolean` | No country list / The current flag is a `span` instead of a `button`. Default `false`.
|
|
78
|
+
| `disableFormatting?` | `boolean` | Remove format (spaces..) from the input value. Default `false`.
|
|
76
79
|
| `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
80
|
| `MenuProps?` | [Menu API](https://mui.com/api/menu) | Props for the Menu component.
|
|
78
81
|
| `ref?` | `React.Ref<HTMLDivElement>` | A ref pointing to the [Mui TextField component](https://mui.com/components/text-fields/).
|
|
79
|
-
| [TextField Props](#inheritance) | |
|
|
82
|
+
| [TextField Props](#inheritance) | |
|
|
80
83
|
|
|
81
84
|
### Inheritance
|
|
82
85
|
|
|
@@ -91,7 +94,7 @@ This library supports all [officially assigned](https://en.wikipedia.org/wiki/IS
|
|
|
91
94
|
|
|
92
95
|
## Continent code
|
|
93
96
|
|
|
94
|
-
| Code | Continent
|
|
97
|
+
| Code | Continent
|
|
95
98
|
| --------------- | -------------------------------
|
|
96
99
|
| AF | Africa
|
|
97
100
|
| AS | Asia
|
package/dist/mui-tel-input.es.js
CHANGED
|
@@ -265,9 +265,9 @@ const Styled$1 = {
|
|
|
265
265
|
return {
|
|
266
266
|
display: "inline-block",
|
|
267
267
|
backgroundSize: "cover",
|
|
268
|
-
"--
|
|
269
|
-
height: "var(--
|
|
270
|
-
width: "calc(var(--
|
|
268
|
+
"--mui-tel-input-flag-height": "0.8em",
|
|
269
|
+
height: "var(--mui-tel-input-flag-height)",
|
|
270
|
+
width: "calc(var(--mui-tel-input-flag-height)*3/2)"
|
|
271
271
|
};
|
|
272
272
|
}),
|
|
273
273
|
Span: styled("span")(() => {
|
|
@@ -290,6 +290,7 @@ const Flag = (props) => {
|
|
|
290
290
|
const svgFlag = isoCode && isoCode in FLAGS_SVG ? `"${FLAGS_SVG[isoCode]}"` : unknownFlag;
|
|
291
291
|
return /* @__PURE__ */ jsx(Styled$1.Flag, {
|
|
292
292
|
"data-testid": isoCode,
|
|
293
|
+
className: "MuiTelInput-Flag",
|
|
293
294
|
style: {
|
|
294
295
|
backgroundImage: `url(${svgFlag})`
|
|
295
296
|
},
|
|
@@ -309,6 +310,7 @@ const FlagButton = (props) => {
|
|
|
309
310
|
if (disableDropdown) {
|
|
310
311
|
return /* @__PURE__ */ jsx(IconButton, {
|
|
311
312
|
tabIndex: -1,
|
|
313
|
+
className: "MuiTelInput-IconButton",
|
|
312
314
|
role: "",
|
|
313
315
|
disableRipple: true,
|
|
314
316
|
sx: {
|
|
@@ -323,6 +325,7 @@ const FlagButton = (props) => {
|
|
|
323
325
|
return /* @__PURE__ */ jsx(IconButton, {
|
|
324
326
|
...iconButtonProps,
|
|
325
327
|
"aria-label": "Select country",
|
|
328
|
+
className: "MuiTelInput-Flag",
|
|
326
329
|
"aria-haspopup": "listbox",
|
|
327
330
|
"aria-controls": isFlagsMenuOpened ? "select-country" : void 0,
|
|
328
331
|
"aria-expanded": isFlagsMenuOpened ? "true" : "false",
|
|
@@ -10422,15 +10425,19 @@ const FlagMenuItem = (props) => {
|
|
|
10422
10425
|
onClick: handleClick,
|
|
10423
10426
|
role: "option",
|
|
10424
10427
|
"data-testid": `option-${isoCode}`,
|
|
10428
|
+
className: "MuiTelInput-MenuItem",
|
|
10425
10429
|
children: [/* @__PURE__ */ jsx(Styled.ListItemIcon, {
|
|
10430
|
+
className: "MuiTelInput-ListItemIcon-country-code",
|
|
10426
10431
|
children: /* @__PURE__ */ jsx(Flag, {
|
|
10427
10432
|
isoCode
|
|
10428
10433
|
})
|
|
10429
10434
|
}), /* @__PURE__ */ jsx(Styled.ListItemText, {
|
|
10435
|
+
className: "MuiTelInput-ListItemText-country",
|
|
10430
10436
|
children: countryName
|
|
10431
10437
|
}), /* @__PURE__ */ jsxs(Typography, {
|
|
10432
10438
|
variant: "body2",
|
|
10433
10439
|
color: "text.secondary",
|
|
10440
|
+
className: "MuiTelInput-Typography-calling-code",
|
|
10434
10441
|
children: ["+", COUNTRIES[isoCode][0]]
|
|
10435
10442
|
})]
|
|
10436
10443
|
});
|
|
@@ -10818,6 +10825,7 @@ const FlagsMenu = (props) => {
|
|
|
10818
10825
|
anchorEl,
|
|
10819
10826
|
open: Boolean(anchorEl),
|
|
10820
10827
|
id: "select-country",
|
|
10828
|
+
className: "MuiTelInput-Menu",
|
|
10821
10829
|
MenuListProps: {
|
|
10822
10830
|
role: "listbox",
|
|
10823
10831
|
"aria-activedescendant": isoCode ? `country-${isoCode}` : "",
|
|
@@ -16157,12 +16165,15 @@ AsYouType.prototype = Object.create(AsYouType$1.prototype, {});
|
|
|
16157
16165
|
AsYouType.prototype.constructor = AsYouType;
|
|
16158
16166
|
|
|
16159
16167
|
function getInitialState(params) {
|
|
16160
|
-
const { defaultCountry, initialValue } = params;
|
|
16168
|
+
const { defaultCountry, initialValue, disableFormatting } = params;
|
|
16161
16169
|
const fallbackValue = defaultCountry ? `+${COUNTRIES[defaultCountry][0]}` : "";
|
|
16162
16170
|
const asYouType = new AsYouType(defaultCountry);
|
|
16163
16171
|
let inputValue = asYouType.input(initialValue);
|
|
16172
|
+
const phoneNumberValue = asYouType.getNumberValue();
|
|
16164
16173
|
if (defaultCountry && asYouType.getCountry() === void 0) {
|
|
16165
16174
|
inputValue = fallbackValue;
|
|
16175
|
+
} else if (disableFormatting && phoneNumberValue) {
|
|
16176
|
+
inputValue = phoneNumberValue;
|
|
16166
16177
|
}
|
|
16167
16178
|
return {
|
|
16168
16179
|
inputValue: inputValue || fallbackValue,
|
|
@@ -16189,7 +16200,8 @@ function usePhoneDigits({
|
|
|
16189
16200
|
forceCallingCode,
|
|
16190
16201
|
onlyCountries,
|
|
16191
16202
|
excludedCountries,
|
|
16192
|
-
continents
|
|
16203
|
+
continents,
|
|
16204
|
+
disableFormatting
|
|
16193
16205
|
}) {
|
|
16194
16206
|
const asYouTypeRef = React.useRef(new AsYouType(defaultCountry));
|
|
16195
16207
|
const inputRef = React.useRef(null);
|
|
@@ -16197,7 +16209,8 @@ function usePhoneDigits({
|
|
|
16197
16209
|
const [state, setState] = React.useState(() => {
|
|
16198
16210
|
return getInitialState({
|
|
16199
16211
|
initialValue: value,
|
|
16200
|
-
defaultCountry
|
|
16212
|
+
defaultCountry,
|
|
16213
|
+
disableFormatting
|
|
16201
16214
|
});
|
|
16202
16215
|
});
|
|
16203
16216
|
const [previousValue, setPreviousValue] = React.useState(value);
|
|
@@ -16248,6 +16261,13 @@ function usePhoneDigits({
|
|
|
16248
16261
|
isoCode: null,
|
|
16249
16262
|
inputValue: numberValue
|
|
16250
16263
|
});
|
|
16264
|
+
} else if (disableFormatting) {
|
|
16265
|
+
onChange?.(numberValue, buildOnChangeInfo("input"));
|
|
16266
|
+
setPreviousValue(numberValue);
|
|
16267
|
+
setState({
|
|
16268
|
+
isoCode: country || null,
|
|
16269
|
+
inputValue: numberValue
|
|
16270
|
+
});
|
|
16251
16271
|
} else {
|
|
16252
16272
|
onChange?.(formattedValue, buildOnChangeInfo("input"));
|
|
16253
16273
|
setPreviousValue(formattedValue);
|
|
@@ -16275,7 +16295,6 @@ function usePhoneDigits({
|
|
|
16275
16295
|
defaultCountry
|
|
16276
16296
|
});
|
|
16277
16297
|
setPreviousValue(inputValue);
|
|
16278
|
-
asYouTypeRef.current.reset();
|
|
16279
16298
|
asYouTypeRef.current.input(inputValue);
|
|
16280
16299
|
onChange?.(inputValue, buildOnChangeInfo("country"));
|
|
16281
16300
|
setState({
|
|
@@ -16331,6 +16350,7 @@ const MuiTelInput = React.forwardRef((props, propRef) => {
|
|
|
16331
16350
|
continents,
|
|
16332
16351
|
preferredCountries,
|
|
16333
16352
|
MenuProps,
|
|
16353
|
+
className,
|
|
16334
16354
|
...restTextFieldProps
|
|
16335
16355
|
} = props;
|
|
16336
16356
|
const textFieldRef = React.useRef(null);
|
|
@@ -16349,6 +16369,7 @@ const MuiTelInput = React.forwardRef((props, propRef) => {
|
|
|
16349
16369
|
forceCallingCode,
|
|
16350
16370
|
excludedCountries,
|
|
16351
16371
|
onlyCountries,
|
|
16372
|
+
disableFormatting,
|
|
16352
16373
|
continents
|
|
16353
16374
|
});
|
|
16354
16375
|
const handleOpenFlagsMenu = (event) => {
|
|
@@ -16420,6 +16441,7 @@ const MuiTelInput = React.forwardRef((props, propRef) => {
|
|
|
16420
16441
|
ref: handleRef,
|
|
16421
16442
|
onDoubleClick: handleDoubleClick,
|
|
16422
16443
|
inputRef: handleRefInput,
|
|
16444
|
+
className: `MuiTelInput-TextField ${className || ""}`,
|
|
16423
16445
|
onChange: onInputChange,
|
|
16424
16446
|
inputProps: {
|
|
16425
16447
|
onCopy: handleCopy,
|
|
@@ -16456,4 +16478,3 @@ const MuiTelInput = React.forwardRef((props, propRef) => {
|
|
|
16456
16478
|
});
|
|
16457
16479
|
|
|
16458
16480
|
export { AsYouType, MuiTelInput, isValidPhoneNumber };
|
|
16459
|
-
//# sourceMappingURL=mui-tel-input.es.js.map
|