@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/README.md +14 -0
- package/dist/components/Tooltip/Tooltip.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.styles.d.ts +1 -1
- package/dist/true-react-common-ui-kit.js +29 -57
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +28 -56
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/PhoneInput/PhoneInput.stories.tsx +1 -1
- package/src/components/PhoneInput/PhoneInput.tsx +4 -1
- package/src/components/Tooltip/Tooltip.styles.ts +2 -0
- package/src/components/Tooltip/Tooltip.tsx +1 -1
- package/src/constants/phone-info.ts +7 -37
- package/src/helpers/phone.ts +19 -15
package/package.json
CHANGED
|
@@ -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
|
},
|
|
@@ -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
|
-
|
|
11
|
-
fullCodes: ['
|
|
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
|
-
|
|
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
|
{
|
package/src/helpers/phone.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNotEmpty,
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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 => {
|