@invoicebox/ui 0.1.0-alpha.71 → 0.1.0-alpha.72
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/dist/components/form/PhoneInput/constants.js +1 -1
- package/dist/components/form/PhoneInput/index.js +15 -19
- package/dist/components/form/PhoneInput/phoneInputLogic.d.ts +3 -0
- package/dist/components/form/PhoneInput/phoneInputLogic.js +17 -0
- package/dist/components/form/PhoneInput/types.d.ts +1 -0
- package/dist/components/form/PhoneInput/types.js +3 -2
- package/package.json +1 -1
|
@@ -76,47 +76,42 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
76
76
|
onCountryChange(countryCode);
|
|
77
77
|
}
|
|
78
78
|
}, [onCountryChange]);
|
|
79
|
-
var
|
|
79
|
+
var handleInitialValid = (0, _react.useCallback)(function (currentInputValue, countryCode) {
|
|
80
80
|
onChange(currentInputValue);
|
|
81
81
|
setIsHaveInputError(false);
|
|
82
82
|
setCountry(countryCode);
|
|
83
83
|
}, [onChange]);
|
|
84
|
-
var
|
|
84
|
+
var handleInitialUnValid = (0, _react.useCallback)(function (countryCode) {
|
|
85
85
|
onChange('');
|
|
86
86
|
setIsHaveInputError(true);
|
|
87
87
|
setCountry(countryCode);
|
|
88
88
|
}, [onChange]);
|
|
89
|
-
(0, _useValidateInitialValue.useValidateInitialValue)(value, currentCountriesPhoneRules,
|
|
90
|
-
|
|
91
|
-
// хак для того чтобы сдвигать каретку в случае если при вводе "9" надо заменить на "79", каретка не двигается сама и остаётся между "7" и "9" без этой функции
|
|
92
|
-
var moveCaretByValue = (0, _react.useCallback)(function (event) {
|
|
93
|
-
return function (positionCaret) {
|
|
94
|
-
setTimeout(function () {
|
|
95
|
-
event.target.setSelectionRange(positionCaret, positionCaret);
|
|
96
|
-
}, 0);
|
|
97
|
-
};
|
|
98
|
-
}, []);
|
|
99
|
-
var getIsValidValue = (0, _react.useCallback)(function (currentValue) {
|
|
89
|
+
(0, _useValidateInitialValue.useValidateInitialValue)(value, currentCountriesPhoneRules, handleInitialValid, handleInitialUnValid);
|
|
90
|
+
var getNewCountryByInputValue = (0, _react.useCallback)(function (currentValue) {
|
|
100
91
|
var currentCountry = currentCountriesPhoneRules[country];
|
|
101
92
|
var newCountry = Object.entries(currentCountriesPhoneRules).find(function (item) {
|
|
102
|
-
return _phoneInputLogic.phoneInputLogic.getIsHaveStartSequenceInString(currentValue, item[1].startSubsequence) && currentCountry.flag !== item[1].flag
|
|
93
|
+
return _phoneInputLogic.phoneInputLogic.getIsHaveStartSequenceInString(currentValue, item[1].startSubsequence) && currentCountry.flag !== item[1].flag;
|
|
103
94
|
});
|
|
104
|
-
var isNeedChangeCountry =
|
|
95
|
+
var isNeedChangeCountry = _phoneInputLogic.phoneInputLogic.getIsNeedChangeCountry(currentValue, currentCountry, newCountry);
|
|
105
96
|
var isNeedAndCanChangeCountry = isNeedChangeCountry && !!newCountry;
|
|
106
97
|
if (isNeedAndCanChangeCountry) {
|
|
107
98
|
handleChangeCountry(newCountry[0]);
|
|
108
99
|
}
|
|
109
|
-
return
|
|
100
|
+
return isNeedAndCanChangeCountry ? newCountry[1] : currentCountry;
|
|
110
101
|
}, [country, currentCountriesPhoneRules, handleChangeCountry]);
|
|
102
|
+
var getIsValidValue = (0, _react.useCallback)(function (currentValue) {
|
|
103
|
+
var currentCountry = getNewCountryByInputValue(currentValue);
|
|
104
|
+
return _phoneInputLogic.phoneInputLogic.getIsValidPhoneInputByCountry(currentValue, currentCountry);
|
|
105
|
+
}, [getNewCountryByInputValue]);
|
|
111
106
|
var handleInputValueChange = (0, _react.useCallback)(function (currentInputValue, event) {
|
|
112
107
|
var notFormattedValue = _phoneInputLogic.phoneInputLogic.getOnlyNumbersFromString(currentInputValue);
|
|
113
|
-
var moveCaret = event ? moveCaretByValue(event) : undefined;
|
|
108
|
+
var moveCaret = event ? _phoneInputLogic.phoneInputLogic.moveCaretByValue(event) : undefined;
|
|
114
109
|
var intermediateValue = country === _types.RUS_COUNTRY_CODE ? _phoneInputLogic.phoneInputLogic.formatRusPhoneToUnifiedView(notFormattedValue, moveCaret) : notFormattedValue;
|
|
115
110
|
var isValidInputValue = getIsValidValue(intermediateValue);
|
|
116
111
|
setIsHaveInputError(!isValidInputValue);
|
|
117
112
|
onChange(isValidInputValue ? intermediateValue : '');
|
|
118
113
|
setInputValue(intermediateValue);
|
|
119
|
-
}, [country, getIsValidValue,
|
|
114
|
+
}, [country, getIsValidValue, onChange]);
|
|
120
115
|
var handleChange = (0, _react.useCallback)(function (event) {
|
|
121
116
|
handleInputValueChange(event.target.value, event);
|
|
122
117
|
}, [handleInputValueChange]);
|
|
@@ -132,11 +127,12 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
|
|
|
132
127
|
var isValidInputValue = _phoneInputLogic.phoneInputLogic.getIsValidPhoneInputByCountry(inputValue, currentCountry);
|
|
133
128
|
setIsFirstBlur(false);
|
|
134
129
|
setIsHaveInputError(!isValidInputValue);
|
|
130
|
+
onChange(isValidInputValue ? inputValue : '');
|
|
135
131
|
setTimeout(function () {
|
|
136
132
|
var _inputRef$current;
|
|
137
133
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
138
134
|
}, 0);
|
|
139
|
-
}, [currentCountriesPhoneRules, handleChangeCountry, inputValue]);
|
|
135
|
+
}, [currentCountriesPhoneRules, handleChangeCountry, inputValue, onChange]);
|
|
140
136
|
var handlePaste = (0, _react.useCallback)(function (event) {
|
|
141
137
|
event.preventDefault();
|
|
142
138
|
var pasteText = event.clipboardData.getData('Text').trim();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TCountryRule, TCountrySelectOption, TSupportedCountries } from './types';
|
|
2
|
+
import { ChangeEvent } from 'react';
|
|
2
3
|
declare class PhoneInputLogic {
|
|
3
4
|
private getCaretPositionByRusValue;
|
|
4
5
|
getIsValidPhoneInputByCountry(value: string, country: TCountryRule): boolean;
|
|
@@ -22,6 +23,8 @@ declare class PhoneInputLogic {
|
|
|
22
23
|
getIsHaveStartSequenceInString(value: string, subsequence: string): boolean;
|
|
23
24
|
formatRusPhoneToUnifiedView(value: string, moveCaret?: (positionCaret: number) => void): string;
|
|
24
25
|
getOnlyNumbersFromString(value: string): string;
|
|
26
|
+
moveCaretByValue(event: ChangeEvent<HTMLInputElement>): (positionCaret: number) => void;
|
|
27
|
+
getIsNeedChangeCountry(inputValue: string, currentCountry: TCountryRule, newCountry?: [string, TCountryRule]): boolean | "" | undefined;
|
|
25
28
|
}
|
|
26
29
|
export declare const phoneInputLogic: PhoneInputLogic;
|
|
27
30
|
export declare const getIsValidPhone: (value: string, countries?: {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.phoneInputLogic = exports.getIsValidPhone = void 0;
|
|
7
|
+
var _types = require("./types");
|
|
7
8
|
var _constants = require("./constants");
|
|
8
9
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -110,6 +111,22 @@ var PhoneInputLogic = /*#__PURE__*/function () {
|
|
|
110
111
|
var _value$match;
|
|
111
112
|
return ((_value$match = value.match(/\d/g)) === null || _value$match === void 0 ? void 0 : _value$match.join('')) || '';
|
|
112
113
|
}
|
|
114
|
+
|
|
115
|
+
// хак для того чтобы сдвигать каретку в случае если при вводе "9" надо заменить на "79", каретка не двигается сама и остаётся между "7" и "9" без этой функции
|
|
116
|
+
}, {
|
|
117
|
+
key: "moveCaretByValue",
|
|
118
|
+
value: function moveCaretByValue(event) {
|
|
119
|
+
return function (positionCaret) {
|
|
120
|
+
setTimeout(function () {
|
|
121
|
+
event.target.setSelectionRange(positionCaret, positionCaret);
|
|
122
|
+
}, 0);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "getIsNeedChangeCountry",
|
|
127
|
+
value: function getIsNeedChangeCountry(inputValue, currentCountry, newCountry) {
|
|
128
|
+
return newCountry && currentCountry.startSubsequence !== newCountry[1].startSubsequence && inputValue && (newCountry[0] === _types.UNKNOWN_COUNTRY_CODE ? !this.getIsHaveStartSequenceInString(inputValue, currentCountry.startSubsequence) : true);
|
|
129
|
+
}
|
|
113
130
|
}]);
|
|
114
131
|
return PhoneInputLogic;
|
|
115
132
|
}();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TFlagKey } from '../../common/Flag';
|
|
2
2
|
export declare const RUS_COUNTRY_CODE = "RUS";
|
|
3
|
+
export declare const UNKNOWN_COUNTRY_CODE = "UNKNOWN";
|
|
3
4
|
export declare const supportedCountries: readonly ["RUS", "BLR", "AZE", "ARM", "KAZ", "TJK", "UZB", "KGZ", "UNKNOWN"];
|
|
4
5
|
export type TSupportedCountries = (typeof supportedCountries)[number];
|
|
5
6
|
export type TCountryRule = {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.supportedCountries = exports.RUS_COUNTRY_CODE = void 0;
|
|
6
|
+
exports.supportedCountries = exports.UNKNOWN_COUNTRY_CODE = exports.RUS_COUNTRY_CODE = void 0;
|
|
7
7
|
var RUS_COUNTRY_CODE = exports.RUS_COUNTRY_CODE = 'RUS';
|
|
8
|
-
var
|
|
8
|
+
var UNKNOWN_COUNTRY_CODE = exports.UNKNOWN_COUNTRY_CODE = 'UNKNOWN';
|
|
9
|
+
var supportedCountries = exports.supportedCountries = [RUS_COUNTRY_CODE, 'BLR', 'AZE', 'ARM', 'KAZ', 'TJK', 'UZB', 'KGZ', UNKNOWN_COUNTRY_CODE];
|