mui-tel-input 1.0.2 → 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>Mui-tel-input</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
- [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/viclafouch/mui-tel-input/blob/master/LICENSE)
8
-
6
+
7
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/viclafouch/mui-tel-input/blob/master/LICENSE)
8
+ [![npm](https://img.shields.io/npm/v/mui-tel-input)](https://www.npmjs.com/package/mui-tel-input)
9
+ [![CircleCI](https://circleci.com/gh/viclafouch/mui-tel-input/tree/master.svg?style=svg)](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` | `(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.
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
@@ -16165,12 +16165,15 @@ AsYouType.prototype = Object.create(AsYouType$1.prototype, {});
16165
16165
  AsYouType.prototype.constructor = AsYouType;
16166
16166
 
16167
16167
  function getInitialState(params) {
16168
- const { defaultCountry, initialValue } = params;
16168
+ const { defaultCountry, initialValue, disableFormatting } = params;
16169
16169
  const fallbackValue = defaultCountry ? `+${COUNTRIES[defaultCountry][0]}` : "";
16170
16170
  const asYouType = new AsYouType(defaultCountry);
16171
16171
  let inputValue = asYouType.input(initialValue);
16172
+ const phoneNumberValue = asYouType.getNumberValue();
16172
16173
  if (defaultCountry && asYouType.getCountry() === void 0) {
16173
16174
  inputValue = fallbackValue;
16175
+ } else if (disableFormatting && phoneNumberValue) {
16176
+ inputValue = phoneNumberValue;
16174
16177
  }
16175
16178
  return {
16176
16179
  inputValue: inputValue || fallbackValue,
@@ -16197,7 +16200,8 @@ function usePhoneDigits({
16197
16200
  forceCallingCode,
16198
16201
  onlyCountries,
16199
16202
  excludedCountries,
16200
- continents
16203
+ continents,
16204
+ disableFormatting
16201
16205
  }) {
16202
16206
  const asYouTypeRef = React.useRef(new AsYouType(defaultCountry));
16203
16207
  const inputRef = React.useRef(null);
@@ -16205,7 +16209,8 @@ function usePhoneDigits({
16205
16209
  const [state, setState] = React.useState(() => {
16206
16210
  return getInitialState({
16207
16211
  initialValue: value,
16208
- defaultCountry
16212
+ defaultCountry,
16213
+ disableFormatting
16209
16214
  });
16210
16215
  });
16211
16216
  const [previousValue, setPreviousValue] = React.useState(value);
@@ -16256,6 +16261,13 @@ function usePhoneDigits({
16256
16261
  isoCode: null,
16257
16262
  inputValue: numberValue
16258
16263
  });
16264
+ } else if (disableFormatting) {
16265
+ onChange?.(numberValue, buildOnChangeInfo("input"));
16266
+ setPreviousValue(numberValue);
16267
+ setState({
16268
+ isoCode: country || null,
16269
+ inputValue: numberValue
16270
+ });
16259
16271
  } else {
16260
16272
  onChange?.(formattedValue, buildOnChangeInfo("input"));
16261
16273
  setPreviousValue(formattedValue);
@@ -16283,7 +16295,6 @@ function usePhoneDigits({
16283
16295
  defaultCountry
16284
16296
  });
16285
16297
  setPreviousValue(inputValue);
16286
- asYouTypeRef.current.reset();
16287
16298
  asYouTypeRef.current.input(inputValue);
16288
16299
  onChange?.(inputValue, buildOnChangeInfo("country"));
16289
16300
  setState({
@@ -16358,6 +16369,7 @@ const MuiTelInput = React.forwardRef((props, propRef) => {
16358
16369
  forceCallingCode,
16359
16370
  excludedCountries,
16360
16371
  onlyCountries,
16372
+ disableFormatting,
16361
16373
  continents
16362
16374
  });
16363
16375
  const handleOpenFlagsMenu = (event) => {
@@ -16466,4 +16478,3 @@ const MuiTelInput = React.forwardRef((props, propRef) => {
16466
16478
  });
16467
16479
 
16468
16480
  export { AsYouType, MuiTelInput, isValidPhoneNumber };
16469
- //# sourceMappingURL=mui-tel-input.es.js.map