@true-engineering/true-react-common-ui-kit 3.45.4 → 3.45.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.45.4",
3
+ "version": "3.45.6",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -26,7 +26,7 @@ export default {
26
26
  const Template: ComponentStory<typeof PhoneInput> = (args) => {
27
27
  const [value, setValue] = useState<IPhoneValue>({
28
28
  dialCode: '7',
29
- phoneNumber: '1234567890',
29
+ phoneNumber: '9134567890',
30
30
  countryCode: 'RU',
31
31
  });
32
32
 
@@ -125,7 +125,10 @@ export const PhoneInput: FC<IPhoneInputProps> = ({
125
125
  if (newPhoneInfo.countryCode !== countryCode) {
126
126
  onChange(
127
127
  {
128
- phoneNumber: '',
128
+ phoneNumber:
129
+ newPhoneInfo.dialCode !== value.dialCode
130
+ ? ''
131
+ : getPhoneObjFromString(phoneWithCode).phoneNumber,
129
132
  dialCode: newPhoneInfo.dialCode,
130
133
  countryCode: newPhoneInfo.countryCode,
131
134
  },
@@ -32,6 +32,8 @@ export const useStyles = createThemedStyles('Tooltip', {
32
32
  letterSpacing: 0.2,
33
33
  },
34
34
 
35
+ custom: {},
36
+
35
37
  info: {},
36
38
 
37
39
  error: {
@@ -8,7 +8,7 @@ import { useStyles, ITooltipStyles } from './Tooltip.styles';
8
8
  export interface ITooltipProps extends ICommonProps<ITooltipStyles> {
9
9
  text: ReactNode;
10
10
  /** @default 'tooltip' */
11
- view?: 'tooltip' | 'hint';
11
+ view?: 'tooltip' | 'hint' | 'custom';
12
12
  /** @default 'info' */
13
13
  type?: 'info' | 'error';
14
14
  }
@@ -5,10 +5,10 @@ export const phoneInfo: IPhoneInfo[] = [
5
5
  countryEn: 'Abkhazia',
6
6
  countryRu: 'Абхазия',
7
7
  countryCode: 'AB',
8
- phoneMask: '999 999-99-99',
8
+ phoneMask: '(999) 999-99-99',
9
9
  dialCode: '7',
10
- areaCodes: ['840', '940'],
11
- fullCodes: ['7840', '7940'],
10
+ dialCodePriority: 1,
11
+ fullCodes: ['7'],
12
12
  },
13
13
  {
14
14
  countryEn: 'Afghanistan',
@@ -794,40 +794,9 @@ export const phoneInfo: IPhoneInfo[] = [
794
794
  countryRu: 'Казахстан',
795
795
  countryCode: 'KZ',
796
796
  dialCode: '7',
797
- phoneMask: '999 999-99-99',
797
+ phoneMask: '(999) 999-99-99',
798
798
  dialCodePriority: 1,
799
- areaCodes: [
800
- '310',
801
- '311',
802
- '312',
803
- '313',
804
- '315',
805
- '318',
806
- '321',
807
- '324',
808
- '325',
809
- '326',
810
- '327',
811
- '336',
812
- '7172',
813
- '73622',
814
- ],
815
- fullCodes: [
816
- '7310',
817
- '7311',
818
- '7312',
819
- '7313',
820
- '7315',
821
- '7318',
822
- '7321',
823
- '7324',
824
- '7325',
825
- '7326',
826
- '7327',
827
- '7336',
828
- '77172',
829
- '773622',
830
- ],
799
+ fullCodes: ['7'],
831
800
  },
832
801
  {
833
802
  countryEn: 'Kenya',
@@ -1417,8 +1386,9 @@ export const phoneInfo: IPhoneInfo[] = [
1417
1386
  countryCode: 'OS',
1418
1387
  countryEn: 'South Ossetia',
1419
1388
  countryRu: 'Южная Осетия',
1420
- phoneMask: '999 999-99-99',
1389
+ phoneMask: '(999) 999-99-99',
1421
1390
  dialCode: '7',
1391
+ dialCodePriority: 1,
1422
1392
  fullCodes: ['7'],
1423
1393
  },
1424
1394
  {
@@ -1,4 +1,4 @@
1
- import { isNotEmpty, isEmpty } from '@true-engineering/true-react-platform-helpers';
1
+ import { isNotEmpty, isStringEmpty } from '@true-engineering/true-react-platform-helpers';
2
2
  import type { IPhoneInfo, IPhoneValue } from '../components';
3
3
  import { phoneInfo } from '../constants';
4
4
 
@@ -46,22 +46,26 @@ export const getFullPhone = (phone?: IPhoneValue): string =>
46
46
  (phone?.dialCode ?? '') + (phone?.phoneNumber ?? '');
47
47
 
48
48
  export const getCountryCodeFromPhone = (phoneWithCode: string): string | undefined => {
49
- // попробуем найти уникальный код страны fullCode (dialCode + arealCode)
50
- let countryCode = phoneInfo.find((info) =>
51
- info.fullCodes.some((code) => phoneWithCode.startsWith(code)),
52
- )?.countryCode;
53
-
54
- if (isEmpty(countryCode) && isNotEmpty(phoneWithCode)) {
55
- // если не нашли уникальный fullCode (dialCode + arealCode),
56
- // то пробуем найти dialCode и выбираем с наименьшим Priority
57
- countryCode = phoneInfo
58
- .filter((info) => phoneWithCode.startsWith(info.dialCode))
59
- .sort(
60
- (infoA, infoB) => (infoA.dialCodePriority ?? 1000) - (infoB.dialCodePriority ?? 1000),
61
- )[0]?.countryCode;
49
+ if (isStringEmpty(phoneWithCode)) {
50
+ return;
62
51
  }
63
52
 
64
- return countryCode;
53
+ // ищем страны, для которых phoneWithCode начинается с fullCode (dialCode + areaCode)
54
+ const matchedCountries = phoneInfo.filter((info) =>
55
+ info.fullCodes.some((fullCode) => phoneWithCode.startsWith(fullCode)),
56
+ );
57
+
58
+ // если нашлась всего одна — ок, выдаём её
59
+ if (matchedCountries.length === 1) {
60
+ return matchedCountries[0].countryCode;
61
+ }
62
+
63
+ // если нашлось несколько, выбираем страну с наименьшим dialCodePriority (0 — самая приоритетная)
64
+ const highestPriorityCountries = phoneInfo
65
+ .filter((info) => phoneWithCode.startsWith(info.dialCode))
66
+ .sort((a, b) => (a.dialCodePriority ?? 1000) - (b.dialCodePriority ?? 1000));
67
+
68
+ return highestPriorityCountries.at(0)?.countryCode;
65
69
  };
66
70
 
67
71
  export const getPhoneObjFromString = (fullPhone: string, countryCode?: string): IPhoneValue => {