@invoicebox/ui 0.1.0-alpha.73 → 0.1.0-alpha.75

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,9 +1,6 @@
1
1
  import { TSupportedCountries } from './types';
2
2
  declare class ExternalPhoneLogic {
3
- getIsValidPhone(value: string, countries?: Array<{
4
- label: string;
5
- value: TSupportedCountries;
6
- }>): boolean;
3
+ getIsValidPhone(value: string, countries?: Array<TSupportedCountries>): boolean;
7
4
  }
8
5
  export declare const phoneLogic: ExternalPhoneLogic;
9
6
  export {};
@@ -20,8 +20,8 @@ var ExternalPhoneLogic = /*#__PURE__*/function () {
20
20
  key: "getIsValidPhone",
21
21
  value: function getIsValidPhone(value, countries) {
22
22
  var notFormattedValue = _phoneInputLogic.phoneInputLogic.getOnlyNumbersFromString(value);
23
- var countrySelectOptions = _phoneInputLogic.phoneInputLogic.getCountriesSelectOptions(countries);
24
- var currentCountriesPhoneRules = _phoneInputLogic.phoneInputLogic.getCountriesPhoneRules(countrySelectOptions);
23
+ var supportedCountries = _phoneInputLogic.phoneInputLogic.getSupportedCountriesByCountryNames(countries);
24
+ var currentCountriesPhoneRules = _phoneInputLogic.phoneInputLogic.getCountriesPhoneRulesByCountryNames(supportedCountries);
25
25
  var country = Object.entries(currentCountriesPhoneRules).find(function (item) {
26
26
  return _phoneInputLogic.phoneInputLogic.getIsHaveStartSequenceInString(notFormattedValue, item[1].startSubsequence);
27
27
  });
@@ -45,7 +45,7 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
45
45
  return _phoneInputLogic.phoneInputLogic.getIsHaveCountriesSelectOptions(countrySelectOptions);
46
46
  }, [countrySelectOptions]);
47
47
  var currentCountriesPhoneRules = (0, _react.useMemo)(function () {
48
- return _phoneInputLogic.phoneInputLogic.getCountriesPhoneRules(countrySelectOptions);
48
+ return _phoneInputLogic.phoneInputLogic.getCountriesPhoneRulesBySelectOptions(countrySelectOptions);
49
49
  }, [countrySelectOptions]);
50
50
  var _useInputFocus = (0, _useInputFocus2.useInputFocus)({
51
51
  onFocus: onFocus,
@@ -3,10 +3,7 @@ import { ChangeEvent } from 'react';
3
3
  declare class PhoneInputLogic {
4
4
  private getCaretPositionByRusValue;
5
5
  getIsValidPhoneInputByCountry(value: string, country: TCountryRule): boolean;
6
- getIsValidPhone(value: string, countries?: Array<{
7
- label: string;
8
- value: TSupportedCountries;
9
- }>): boolean;
6
+ getSupportedCountriesByCountryNames(countries?: Array<TSupportedCountries>): ("RUS" | "BLR" | "KAZ" | "AZE" | "ARM" | "KGZ" | "TJK" | "UZB" | "UNKNOWN")[] | undefined;
10
7
  getCountriesSelectOptions(countries?: Array<{
11
8
  label: string;
12
9
  value: TSupportedCountries;
@@ -16,8 +13,11 @@ declare class PhoneInputLogic {
16
13
  label: string;
17
14
  value: TSupportedCountries;
18
15
  }[] | undefined;
19
- getIsHaveCountriesSelectOptions(countrySelectOptions?: Array<TCountrySelectOption>): boolean;
20
- getCountriesPhoneRules(countrySelectOptions?: Array<TCountrySelectOption>): {
16
+ getIsHaveCountriesSelectOptions(countrySelectOptions?: Array<TCountrySelectOption | TSupportedCountries>): boolean;
17
+ getCountriesPhoneRulesBySelectOptions(countrySelectOptions?: Array<TCountrySelectOption>): {
18
+ [k: string]: TCountryRule;
19
+ };
20
+ getCountriesPhoneRulesByCountryNames(countrySelectOptions?: Array<TSupportedCountries>): {
21
21
  [k: string]: TCountryRule;
22
22
  };
23
23
  getIsHaveStartSequenceInString(value: string, subsequence: string): boolean;
@@ -41,15 +41,11 @@ var PhoneInputLogic = /*#__PURE__*/function () {
41
41
  return !!value.match(country.regexp);
42
42
  }
43
43
  }, {
44
- key: "getIsValidPhone",
45
- value: function getIsValidPhone(value, countries) {
46
- var notFormattedValue = this.getOnlyNumbersFromString(value);
47
- var countrySelectOptions = this.getCountriesSelectOptions(countries);
48
- var currentCountriesPhoneRules = this.getCountriesPhoneRules(countrySelectOptions);
49
- var country = Object.entries(currentCountriesPhoneRules).find(function (item) {
50
- return phoneInputLogic.getIsHaveStartSequenceInString(notFormattedValue, item[1].startSubsequence);
44
+ key: "getSupportedCountriesByCountryNames",
45
+ value: function getSupportedCountriesByCountryNames(countries) {
46
+ return countries === null || countries === void 0 ? void 0 : countries.filter(function (country) {
47
+ return _constants.allCountriesPhoneRules[country];
51
48
  });
52
- return this.getIsValidPhoneInputByCountry(notFormattedValue, country ? country[1] : _constants.allCountriesPhoneRules.RUS);
53
49
  }
54
50
  }, {
55
51
  key: "getCountriesSelectOptions",
@@ -71,8 +67,8 @@ var PhoneInputLogic = /*#__PURE__*/function () {
71
67
  return !!(countrySelectOptions !== null && countrySelectOptions !== void 0 && countrySelectOptions.length);
72
68
  }
73
69
  }, {
74
- key: "getCountriesPhoneRules",
75
- value: function getCountriesPhoneRules(countrySelectOptions) {
70
+ key: "getCountriesPhoneRulesBySelectOptions",
71
+ value: function getCountriesPhoneRulesBySelectOptions(countrySelectOptions) {
76
72
  return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(_constants.allCountriesPhoneRules).filter(function (ruleItem) {
77
73
  return countrySelectOptions === null || countrySelectOptions === void 0 ? void 0 : countrySelectOptions.find(function (countrySelectOption) {
78
74
  return countrySelectOption.value === ruleItem[0];
@@ -81,6 +77,17 @@ var PhoneInputLogic = /*#__PURE__*/function () {
81
77
  RUS: _constants.allCountriesPhoneRules.RUS
82
78
  };
83
79
  }
80
+ }, {
81
+ key: "getCountriesPhoneRulesByCountryNames",
82
+ value: function getCountriesPhoneRulesByCountryNames(countrySelectOptions) {
83
+ return this.getIsHaveCountriesSelectOptions(countrySelectOptions) ? Object.fromEntries(Object.entries(_constants.allCountriesPhoneRules).filter(function (ruleItem) {
84
+ return countrySelectOptions === null || countrySelectOptions === void 0 ? void 0 : countrySelectOptions.find(function (countrySelectOption) {
85
+ return countrySelectOption === ruleItem[0];
86
+ });
87
+ })) : {
88
+ RUS: _constants.allCountriesPhoneRules.RUS
89
+ };
90
+ }
84
91
  }, {
85
92
  key: "getIsHaveStartSequenceInString",
86
93
  value: function getIsHaveStartSequenceInString(value, subsequence) {
package/dist/index.d.ts CHANGED
@@ -30,6 +30,7 @@ export type { TProps as TCountrySelectProps } from './components/form/CountrySel
30
30
  export { PhoneInput } from './components/form/PhoneInput';
31
31
  export type { TProps as TPhoneInputProps } from './components/form/PhoneInput';
32
32
  export { phoneLogic } from './components/form/PhoneInput/externalPhoneLogic';
33
+ export type { TSupportedCountries as TSupportedCountriesPhoneInput } from './components/form/PhoneInput/types';
33
34
  export { PaletteProvider } from './palette';
34
35
  export type { TAbstractPalette } from './palette';
35
36
  export { useOutsideClick } from './hooks/useOutsideClick';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invoicebox/ui",
3
- "version": "0.1.0-alpha.73",
3
+ "version": "0.1.0-alpha.75",
4
4
  "description": "Invoicebox UI",
5
5
  "license": "Apache License 2.0",
6
6
  "scripts": {