@ornikar/kitt-universal 9.40.0 → 9.41.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.
@@ -15,6 +15,7 @@ const twemojiParser = require('twemoji-parser');
15
15
  const WebBrowser = require('expo-web-browser');
16
16
  const DateTimePicker = require('@react-native-community/datetimepicker');
17
17
  const reactIntl = require('react-intl');
18
+ const libphonenumberJs = require('libphonenumber-js');
18
19
  const Svg = require('react-native-svg');
19
20
  const picker$1 = require('@react-native-picker/picker');
20
21
  const expoLinearGradient = require('expo-linear-gradient');
@@ -3791,17 +3792,17 @@ function getReturnKeyTypeForNumericInput(returnKeyType) {
3791
3792
  return returnKeyType;
3792
3793
  }
3793
3794
 
3794
- function prefixWithZero(value, maxLength = 2) {
3795
+ function prefixWithZero$1(value, maxLength = 2) {
3795
3796
  return `${value}`.padStart(maxLength, '0');
3796
3797
  }
3797
3798
  function dayFormatter(day) {
3798
- return prefixWithZero(day);
3799
+ return prefixWithZero$1(day);
3799
3800
  }
3800
3801
  function monthFormatter(month) {
3801
- return prefixWithZero(month);
3802
+ return prefixWithZero$1(month);
3802
3803
  }
3803
3804
  function yearFormatter(year) {
3804
- return prefixWithZero(year, 4);
3805
+ return prefixWithZero$1(year, 4);
3805
3806
  }
3806
3807
 
3807
3808
  function getDayInInterval(value) {
@@ -5068,19 +5069,63 @@ const InputPassword = /*#__PURE__*/React.forwardRef(({
5068
5069
  });
5069
5070
  });
5070
5071
 
5072
+ function isPhoneNumberValid(number) {
5073
+ return libphonenumberJs.isValidNumber(number);
5074
+ }
5075
+ function prefixWithZero(value, phoneNumberLength) {
5076
+ return value.padStart(phoneNumberLength, '0');
5077
+ }
5071
5078
  const InputPhone = /*#__PURE__*/React.forwardRef(({
5072
5079
  returnKeyType,
5073
5080
  autoComplete = 'tel',
5081
+ phoneNumberLength = 10,
5082
+ value,
5083
+ onChange,
5074
5084
  ...props
5075
5085
  }, ref) => {
5086
+ const [currentValue, setCurrentValue] = React.useState(value);
5076
5087
  const currentReturnKeyType = returnKeyType ? getReturnKeyTypeForNumericInput(returnKeyType) : undefined;
5077
5088
  return /*#__PURE__*/jsxRuntime.jsx(InputText, {
5078
5089
  ref: ref,
5079
5090
  ...props,
5091
+ value: currentValue,
5080
5092
  keyboardType: "phone-pad",
5081
5093
  returnKeyType: currentReturnKeyType,
5082
5094
  autoComplete: autoComplete,
5083
- textContentType: "telephoneNumber"
5095
+ textContentType: "telephoneNumber",
5096
+ onChange: event => {
5097
+ const number = libphonenumberJs.parseNumber(event.nativeEvent.text);
5098
+
5099
+ // When intl phone number is valid :
5100
+ // 1 - We extract intl data
5101
+ // 2 - We recreate the local value to display
5102
+ if (isPhoneNumberValid(number)) {
5103
+ const {
5104
+ phone
5105
+ } = number;
5106
+ const finalPhoneNumber = prefixWithZero(`${phone || ''}`, phoneNumberLength);
5107
+ const eventWithoutCountryCode = {
5108
+ ...event,
5109
+ nativeEvent: {
5110
+ ...event.nativeEvent,
5111
+ text: finalPhoneNumber
5112
+ }
5113
+ };
5114
+ setCurrentValue(finalPhoneNumber);
5115
+ if (onChange) {
5116
+ onChange(eventWithoutCountryCode, {
5117
+ ...number,
5118
+ countryCode: libphonenumberJs.getCountryCallingCode(number.country),
5119
+ originalNativeEventText: event.nativeEvent.text
5120
+ });
5121
+ }
5122
+ return;
5123
+ }
5124
+
5125
+ // Value is correctly parsed but might not pass validation
5126
+ setCurrentValue(event.nativeEvent.text);
5127
+ if (onChange) onChange(event);
5128
+ }
5084
5129
  });
5085
5130
  });
5086
5131