@trackunit/react-form-components 0.0.179 → 0.0.180

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/index.cjs.js CHANGED
@@ -14525,9 +14525,10 @@ const PhoneInput = React.forwardRef((_a, ref) => {
14525
14525
  const { getPhoneNumber } = usePhoneInput();
14526
14526
  const countryCodePlaceholderValue = !readOnly ? countryCodePlaceholder || DEFAULT_COUNTRY_CODE : "";
14527
14527
  const safePhoneNumber = getPhoneNumberWithPlus(value || "");
14528
- const number = parsePhoneNumber(safePhoneNumber);
14528
+ const number = parsePhoneNumber(safePhoneNumber, { defaultCountry: "DK" });
14529
+ const valueHasOnlyCountryCode = (number === null || number === void 0 ? void 0 : number.isPossible) === undefined && typeof value === "string" && value[0] === "+" && value.length < 5;
14529
14530
  const [phone, setPhone] = React.useState((_b = number === null || number === void 0 ? void 0 : number.nationalNumber.toString()) !== null && _b !== void 0 ? _b : "");
14530
- const [code, setCode] = React.useState((_c = number === null || number === void 0 ? void 0 : number.countryCallingCode.toString()) !== null && _c !== void 0 ? _c : "");
14531
+ const [code, setCode] = React.useState(valueHasOnlyCountryCode ? value.replace("+", "") : (_c = number === null || number === void 0 ? void 0 : number.countryCallingCode.toString()) !== null && _c !== void 0 ? _c : "");
14531
14532
  const codeRef = React.useRef(code); // synchronus reliable source of truth (country code is calling onblur just after onchange, useState is too slow for this)
14532
14533
  const phoneRef = React.useRef(phone); // synchronus reliable source of truth
14533
14534
  const onChangeHandler = React__default["default"].useCallback(({ newPhone, newCode }) => {
package/index.esm.js CHANGED
@@ -14499,9 +14499,10 @@ const PhoneInput = forwardRef((_a, ref) => {
14499
14499
  const { getPhoneNumber } = usePhoneInput();
14500
14500
  const countryCodePlaceholderValue = !readOnly ? countryCodePlaceholder || DEFAULT_COUNTRY_CODE : "";
14501
14501
  const safePhoneNumber = getPhoneNumberWithPlus(value || "");
14502
- const number = parsePhoneNumber(safePhoneNumber);
14502
+ const number = parsePhoneNumber(safePhoneNumber, { defaultCountry: "DK" });
14503
+ const valueHasOnlyCountryCode = (number === null || number === void 0 ? void 0 : number.isPossible) === undefined && typeof value === "string" && value[0] === "+" && value.length < 5;
14503
14504
  const [phone, setPhone] = useState((_b = number === null || number === void 0 ? void 0 : number.nationalNumber.toString()) !== null && _b !== void 0 ? _b : "");
14504
- const [code, setCode] = useState((_c = number === null || number === void 0 ? void 0 : number.countryCallingCode.toString()) !== null && _c !== void 0 ? _c : "");
14505
+ const [code, setCode] = useState(valueHasOnlyCountryCode ? value.replace("+", "") : (_c = number === null || number === void 0 ? void 0 : number.countryCallingCode.toString()) !== null && _c !== void 0 ? _c : "");
14505
14506
  const codeRef = useRef(code); // synchronus reliable source of truth (country code is calling onblur just after onchange, useState is too slow for this)
14506
14507
  const phoneRef = useRef(phone); // synchronus reliable source of truth
14507
14508
  const onChangeHandler = React__default.useCallback(({ newPhone, newCode }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.179",
3
+ "version": "0.0.180",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {