@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.
@@ -1,8 +1,15 @@
1
1
  /// <reference types="react" />
2
- import type { TextInput as RNTextInput } from 'react-native';
2
+ import type { CountryCallingCode, ParsedNumber } from 'libphonenumber-js';
3
+ import type { NativeSyntheticEvent, TextInput as RNTextInput, TextInputChangeEventData } from 'react-native';
3
4
  import type { Except } from 'type-fest';
4
5
  import type { InputTextProps } from '../InputText/InputText';
6
+ export interface InputPhoneNumberData extends ParsedNumber {
7
+ countryCode: CountryCallingCode;
8
+ originalNativeEventText: string;
9
+ }
5
10
  export interface InputPhoneProps extends Except<InputTextProps, 'keyboardType' | 'textContentType'> {
11
+ phoneNumberLength?: number;
12
+ onChange?: (event: NativeSyntheticEvent<TextInputChangeEventData>, phoneNumberData?: InputPhoneNumberData) => void;
6
13
  }
7
14
  export declare const InputPhone: import("react").ForwardRefExoticComponent<InputPhoneProps & import("react").RefAttributes<RNTextInput>>;
8
15
  //# sourceMappingURL=InputPhone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InputPhone.d.ts","sourceRoot":"","sources":["../../../../src/forms/InputPhone/InputPhone.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,MAAM,WAAW,eAAgB,SAAQ,MAAM,CAAC,cAAc,EAAE,cAAc,GAAG,iBAAiB,CAAC;CAAG;AAEtG,eAAO,MAAM,UAAU,yGAetB,CAAC"}
1
+ {"version":3,"file":"InputPhone.d.ts","sourceRoot":"","sources":["../../../../src/forms/InputPhone/InputPhone.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAI1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,IAAI,WAAW,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAC7G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAW7D,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,WAAW,EAAE,kBAAkB,CAAC;IAChC,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,eAAgB,SAAQ,MAAM,CAAC,cAAc,EAAE,cAAc,GAAG,iBAAiB,CAAC;IACjG,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,wBAAwB,CAAC,EAAE,eAAe,CAAC,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACpH;AAED,eAAO,MAAM,UAAU,yGA2DtB,CAAC"}
@@ -21,6 +21,7 @@ import { parse } from 'twemoji-parser';
21
21
  import * as WebBrowser from 'expo-web-browser';
22
22
  import DateTimePicker, { DateTimePickerAndroid } from '@react-native-community/datetimepicker';
23
23
  import { FormattedMessage } from 'react-intl';
24
+ import { parseNumber, getCountryCallingCode, isValidNumber } from 'libphonenumber-js';
24
25
  import Svg, { LinearGradient, Stop, Mask, Path, G, Defs, Circle as Circle$1 } from 'react-native-svg';
25
26
  import { Picker as Picker$1 } from '@react-native-picker/picker';
26
27
  import { LinearGradient as LinearGradient$1 } from 'expo-linear-gradient';
@@ -3840,18 +3841,18 @@ function getReturnKeyTypeForNumericInput(returnKeyType) {
3840
3841
  return returnKeyType;
3841
3842
  }
3842
3843
 
3843
- function prefixWithZero(value) {
3844
+ function prefixWithZero$1(value) {
3844
3845
  var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
3845
3846
  return "".concat(value).padStart(maxLength, '0');
3846
3847
  }
3847
3848
  function dayFormatter(day) {
3848
- return prefixWithZero(day);
3849
+ return prefixWithZero$1(day);
3849
3850
  }
3850
3851
  function monthFormatter(month) {
3851
- return prefixWithZero(month);
3852
+ return prefixWithZero$1(month);
3852
3853
  }
3853
3854
  function yearFormatter(year) {
3854
- return prefixWithZero(year, 4);
3855
+ return prefixWithZero$1(year, 4);
3855
3856
  }
3856
3857
 
3857
3858
  function getDayInInterval(value) {
@@ -5119,20 +5120,63 @@ var InputPassword = /*#__PURE__*/forwardRef(function (_ref, ref) {
5119
5120
  }));
5120
5121
  });
5121
5122
 
5122
- var _excluded$c = ["returnKeyType", "autoComplete"];
5123
+ var _excluded$c = ["returnKeyType", "autoComplete", "phoneNumberLength", "value", "onChange"];
5124
+ function isPhoneNumberValid(number) {
5125
+ return isValidNumber(number);
5126
+ }
5127
+ function prefixWithZero(value, phoneNumberLength) {
5128
+ return value.padStart(phoneNumberLength, '0');
5129
+ }
5123
5130
  var InputPhone = /*#__PURE__*/forwardRef(function (_ref, ref) {
5124
5131
  var returnKeyType = _ref.returnKeyType,
5125
5132
  _ref$autoComplete = _ref.autoComplete,
5126
5133
  autoComplete = _ref$autoComplete === void 0 ? 'tel' : _ref$autoComplete,
5134
+ _ref$phoneNumberLengt = _ref.phoneNumberLength,
5135
+ phoneNumberLength = _ref$phoneNumberLengt === void 0 ? 10 : _ref$phoneNumberLengt,
5136
+ value = _ref.value,
5137
+ onChange = _ref.onChange,
5127
5138
  props = _objectWithoutProperties(_ref, _excluded$c);
5139
+ var _useState = useState(value),
5140
+ _useState2 = _slicedToArray(_useState, 2),
5141
+ currentValue = _useState2[0],
5142
+ setCurrentValue = _useState2[1];
5128
5143
  var currentReturnKeyType = returnKeyType ? getReturnKeyTypeForNumericInput(returnKeyType) : undefined;
5129
5144
  return /*#__PURE__*/jsx(InputText, _objectSpread(_objectSpread({
5130
5145
  ref: ref
5131
5146
  }, props), {}, {
5147
+ value: currentValue,
5132
5148
  keyboardType: "phone-pad",
5133
5149
  returnKeyType: currentReturnKeyType,
5134
5150
  autoComplete: autoComplete,
5135
- textContentType: "telephoneNumber"
5151
+ textContentType: "telephoneNumber",
5152
+ onChange: function handleChange(event) {
5153
+ var number = parseNumber(event.nativeEvent.text);
5154
+
5155
+ // When intl phone number is valid :
5156
+ // 1 - We extract intl data
5157
+ // 2 - We recreate the local value to display
5158
+ if (isPhoneNumberValid(number)) {
5159
+ var phone = number.phone;
5160
+ var finalPhoneNumber = prefixWithZero("".concat(phone || ''), phoneNumberLength);
5161
+ var eventWithoutCountryCode = _objectSpread(_objectSpread({}, event), {}, {
5162
+ nativeEvent: _objectSpread(_objectSpread({}, event.nativeEvent), {}, {
5163
+ text: finalPhoneNumber
5164
+ })
5165
+ });
5166
+ setCurrentValue(finalPhoneNumber);
5167
+ if (onChange) {
5168
+ onChange(eventWithoutCountryCode, _objectSpread(_objectSpread({}, number), {}, {
5169
+ countryCode: getCountryCallingCode(number.country),
5170
+ originalNativeEventText: event.nativeEvent.text
5171
+ }));
5172
+ }
5173
+ return;
5174
+ }
5175
+
5176
+ // Value is correctly parsed but might not pass validation
5177
+ setCurrentValue(event.nativeEvent.text);
5178
+ if (onChange) onChange(event);
5179
+ }
5136
5180
  }));
5137
5181
  });
5138
5182