@transferwise/components 46.6.0 → 46.7.0
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/build/index.esm.js +186 -342
- package/build/index.esm.js.map +1 -1
- package/build/index.js +185 -341
- package/build/index.js.map +1 -1
- package/build/main.css +6 -17
- package/build/styles/inputs/Input.css +0 -4
- package/build/styles/inputs/SelectInput.css +6 -1
- package/build/styles/inputs/TextArea.css +0 -4
- package/build/styles/main.css +6 -17
- package/build/styles/select/Select.css +0 -4
- package/build/types/common/locale/index.d.ts +26 -43
- package/build/types/common/locale/index.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts +6 -5
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +22 -27
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/data/countries.d.ts +5 -10
- package/build/types/phoneNumberInput/data/countries.d.ts.map +1 -1
- package/build/types/phoneNumberInput/index.d.ts +1 -1
- package/build/types/phoneNumberInput/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts +8 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +8 -4
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts +2 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/index.d.ts +11 -13
- package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts +6 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +2 -1
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +7 -1
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/common/locale/{index.spec.js → index.spec.ts} +4 -4
- package/src/common/locale/index.ts +96 -0
- package/src/index.ts +1 -0
- package/src/inputs/Input.css +0 -4
- package/src/inputs/SelectInput.css +6 -1
- package/src/inputs/SelectInput.less +8 -1
- package/src/inputs/SelectInput.spec.tsx +26 -0
- package/src/inputs/SelectInput.story.tsx +73 -1
- package/src/inputs/SelectInput.tsx +104 -85
- package/src/inputs/TextArea.css +0 -4
- package/src/main.css +6 -17
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +18 -22
- package/src/phoneNumberInput/PhoneNumberInput.tsx +193 -0
- package/src/phoneNumberInput/data/{countries.js → countries.ts} +9 -1
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +3 -0
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.js → excludeCountries.spec.ts} +1 -1
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.js → excludeCountries.ts} +6 -5
- package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.js → explodeNumberModel.spec.ts} +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +24 -0
- package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.js → findCountryByCode.spec.ts} +0 -1
- package/src/phoneNumberInput/utils/findCountryByCode/index.ts +12 -0
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +12 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +102 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +12 -0
- package/src/phoneNumberInput/utils/{index.js → index.ts} +0 -2
- package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.js → isStringNumeric.spec.ts} +0 -1
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +1 -0
- package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.js → isValidPhoneNumber.spec.ts} +1 -1
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +7 -0
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +4 -0
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +20 -0
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +6 -0
- package/src/select/Select.css +0 -4
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +0 -2
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +0 -1
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +0 -2
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +0 -1
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +0 -3
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +0 -1
- package/build/types/utilities/wrapInFragment.d.ts +0 -3
- package/build/types/utilities/wrapInFragment.d.ts.map +0 -1
- package/src/common/locale/index.js +0 -139
- package/src/phoneNumberInput/PhoneNumberInput.js +0 -210
- package/src/phoneNumberInput/data/countries.spec.js +0 -12
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +0 -4
- package/src/phoneNumberInput/utils/explodeNumberModel/index.js +0 -27
- package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +0 -36
- package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +0 -11
- package/src/phoneNumberInput/utils/findCountryByCode/index.js +0 -10
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +0 -11
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +0 -26
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +0 -67
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +0 -1
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +0 -25
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +0 -66
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +0 -1
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +0 -10
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +0 -2
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +0 -25
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +0 -3
- package/src/utilities/wrapInFragment.tsx +0 -3
- /package/src/phoneNumberInput/{PhoneNumberInput.story.js → PhoneNumberInput.story.tsx} +0 -0
- /package/src/phoneNumberInput/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.js → cleanNumber.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/excludeCountries/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.js → findCountryByPrefix.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/isStringNumeric/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.js → longestMatchingPrefix.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.js → setDefaultPrefix.spec.ts} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.js → index.ts} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{sortArrayByProperty.spec.js → sortArrayByProperty.spec.ts} +0 -0
|
@@ -4,7 +4,7 @@ import { excludeCountries } from './excludeCountries';
|
|
|
4
4
|
|
|
5
5
|
describe('Exclude countries', () => {
|
|
6
6
|
it('should return all the countries of list is empty', () => {
|
|
7
|
-
const remove = [];
|
|
7
|
+
const remove: string[] = [];
|
|
8
8
|
const filteredCountries = excludeCountries(countries, remove);
|
|
9
9
|
expect(filteredCountries).toHaveLength(countries.length);
|
|
10
10
|
});
|
package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.js → excludeCountries.ts}
RENAMED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Country } from '../../data/countries';
|
|
2
|
+
|
|
1
3
|
// Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
|
2
|
-
const filterCountriesByIso3 = (countries, iso3Codes) => {
|
|
4
|
+
const filterCountriesByIso3 = (countries: Country[], iso3Codes: string[]) => {
|
|
3
5
|
const iso3CodesSet = new Set(iso3Codes);
|
|
4
6
|
return countries.filter((country) => !iso3CodesSet.has(country.iso3));
|
|
5
7
|
};
|
|
@@ -7,11 +9,10 @@ const filterCountriesByIso3 = (countries, iso3Codes) => {
|
|
|
7
9
|
/**
|
|
8
10
|
* Removes the countries sepecified in the second param
|
|
9
11
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
12
|
+
* @param countries list of country metadata objects
|
|
13
|
+
* @param disabledCountries list of iso3 country codes to remove from the list
|
|
13
14
|
*/
|
|
14
|
-
export const excludeCountries = (countries, disabledCountries) => {
|
|
15
|
+
export const excludeCountries = (countries: Country[], disabledCountries: string[]) => {
|
|
15
16
|
return disabledCountries.length > 0
|
|
16
17
|
? filterCountriesByIso3(countries, disabledCountries)
|
|
17
18
|
: countries;
|
|
@@ -12,7 +12,7 @@ describe('explodeNumberModel', () => {
|
|
|
12
12
|
|
|
13
13
|
it('should return an exploded number for three digit prefix', () => {
|
|
14
14
|
expect(explodeNumberModel('+3727573135343')).toStrictEqual({
|
|
15
|
-
format:
|
|
15
|
+
format: undefined,
|
|
16
16
|
prefix: '+372',
|
|
17
17
|
suffix: '7573135343',
|
|
18
18
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { findCountryByPrefix } from '../findCountryByPrefix';
|
|
2
|
+
|
|
3
|
+
export interface PhoneNumber {
|
|
4
|
+
prefix: string | null;
|
|
5
|
+
suffix: string;
|
|
6
|
+
format?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param number Phone number in a format like "+447573135343"
|
|
11
|
+
*/
|
|
12
|
+
export const explodeNumberModel = (number: string): PhoneNumber => {
|
|
13
|
+
const country = findCountryByPrefix(number);
|
|
14
|
+
return country
|
|
15
|
+
? {
|
|
16
|
+
prefix: country.phone,
|
|
17
|
+
suffix: number.slice(country.phone.length),
|
|
18
|
+
format: country.phoneFormat,
|
|
19
|
+
}
|
|
20
|
+
: {
|
|
21
|
+
prefix: null,
|
|
22
|
+
suffix: number.slice(1),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -14,7 +14,6 @@ describe('findCountryByCode', () => {
|
|
|
14
14
|
|
|
15
15
|
it('should return null for invalid code', () => {
|
|
16
16
|
expect(findCountryByCode('Wrong')).toBeNull();
|
|
17
|
-
expect(findCountryByCode(null)).toBeNull();
|
|
18
17
|
expect(findCountryByCode('')).toBeNull();
|
|
19
18
|
expect(findCountryByCode(' ')).toBeNull();
|
|
20
19
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import countries from '../../data/countries';
|
|
2
|
+
import { longestMatchingPrefix } from '../longestMatchingPrefix';
|
|
3
|
+
|
|
4
|
+
export const findCountryByCode = (code: string) => {
|
|
5
|
+
if (code.length === 2) {
|
|
6
|
+
const matchingCodes = countries.filter((country) => code.toUpperCase() === country.iso2);
|
|
7
|
+
if (matchingCodes.length > 0) {
|
|
8
|
+
return longestMatchingPrefix(matchingCodes);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import countries from '../../data/countries';
|
|
2
|
+
import { longestMatchingPrefix } from '../longestMatchingPrefix';
|
|
3
|
+
|
|
4
|
+
export const findCountryByPrefix = (number: string) => {
|
|
5
|
+
if (number.length > 1) {
|
|
6
|
+
const matchingCodes = countries.filter((country) => number.startsWith(country.phone));
|
|
7
|
+
if (matchingCodes.length > 0) {
|
|
8
|
+
return longestMatchingPrefix(matchingCodes);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Country } from '../../data/countries';
|
|
2
|
+
|
|
3
|
+
import { groupCountriesByPrefix } from '.';
|
|
4
|
+
|
|
5
|
+
const countries = [
|
|
6
|
+
{
|
|
7
|
+
name: 'Canada',
|
|
8
|
+
iso2: 'CA',
|
|
9
|
+
iso3: 'CAN',
|
|
10
|
+
phone: '+1',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'United States of America',
|
|
14
|
+
iso2: 'US',
|
|
15
|
+
iso3: 'USA',
|
|
16
|
+
phone: '+1',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'United States Minor Outlying Islands',
|
|
20
|
+
iso2: 'UM',
|
|
21
|
+
iso3: 'UMI',
|
|
22
|
+
phone: '+1',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'United Kingdom',
|
|
26
|
+
iso2: 'GB',
|
|
27
|
+
iso3: 'GBR',
|
|
28
|
+
phone: '+44',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'Guernsey',
|
|
32
|
+
iso2: 'GG',
|
|
33
|
+
iso3: 'GGY',
|
|
34
|
+
phone: '+44',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'Guinea',
|
|
38
|
+
iso2: 'GN',
|
|
39
|
+
iso3: 'GIN',
|
|
40
|
+
phone: '+224',
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const groupedCountries = new Map<string, Country[]>([
|
|
45
|
+
[
|
|
46
|
+
'+1',
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
name: 'Canada',
|
|
50
|
+
iso2: 'CA',
|
|
51
|
+
iso3: 'CAN',
|
|
52
|
+
phone: '+1',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'United States of America',
|
|
56
|
+
iso2: 'US',
|
|
57
|
+
iso3: 'USA',
|
|
58
|
+
phone: '+1',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'United States Minor Outlying Islands',
|
|
62
|
+
iso2: 'UM',
|
|
63
|
+
iso3: 'UMI',
|
|
64
|
+
phone: '+1',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
'+44',
|
|
70
|
+
[
|
|
71
|
+
{
|
|
72
|
+
name: 'United Kingdom',
|
|
73
|
+
iso2: 'GB',
|
|
74
|
+
iso3: 'GBR',
|
|
75
|
+
phone: '+44',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'Guernsey',
|
|
79
|
+
iso2: 'GG',
|
|
80
|
+
iso3: 'GGY',
|
|
81
|
+
phone: '+44',
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
'+224',
|
|
87
|
+
[
|
|
88
|
+
{
|
|
89
|
+
name: 'Guinea',
|
|
90
|
+
iso2: 'GN',
|
|
91
|
+
iso3: 'GIN',
|
|
92
|
+
phone: '+224',
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
],
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
describe('groupCountriesByPrefix', () => {
|
|
99
|
+
it('groups countries by prefix', () => {
|
|
100
|
+
expect(groupCountriesByPrefix(countries)).toStrictEqual(groupedCountries);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Country } from '../../data/countries';
|
|
2
|
+
|
|
3
|
+
export const groupCountriesByPrefix = (countries: Country[]) => {
|
|
4
|
+
const countriesByPrefix = new Map<string, Country[]>();
|
|
5
|
+
countries.forEach((country) => {
|
|
6
|
+
countriesByPrefix.set(country.phone, [
|
|
7
|
+
...(countriesByPrefix.get(country.phone) ?? []),
|
|
8
|
+
country,
|
|
9
|
+
]);
|
|
10
|
+
});
|
|
11
|
+
return countriesByPrefix;
|
|
12
|
+
};
|
|
@@ -4,8 +4,6 @@ export { explodeNumberModel } from './explodeNumberModel';
|
|
|
4
4
|
export { longestMatchingPrefix } from './longestMatchingPrefix';
|
|
5
5
|
export { findCountryByPrefix } from './findCountryByPrefix';
|
|
6
6
|
export { findCountryByCode } from './findCountryByCode';
|
|
7
|
-
export { filterOptionsForQuery } from './filterOptionsForQuery';
|
|
8
|
-
export { isOptionAndFitsQuery } from './isOptionAndFitsQuery';
|
|
9
7
|
export { cleanNumber } from './cleanNumber';
|
|
10
8
|
export { isStringNumeric } from './isStringNumeric';
|
|
11
9
|
export { sortArrayByProperty } from './sortArrayByProperty';
|
|
@@ -4,7 +4,6 @@ describe('isStringNumeric', () => {
|
|
|
4
4
|
it('should return true when numeric sting is provided', () => {
|
|
5
5
|
expect(isStringNumeric('+23456')).toBe(true);
|
|
6
6
|
expect(isStringNumeric('23456')).toBe(true);
|
|
7
|
-
expect(isStringNumeric(23456)).toBe(true);
|
|
8
7
|
});
|
|
9
8
|
|
|
10
9
|
it('should return false when string is provided', () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isStringNumeric = (value: string) => /^\+?[\d-\s]+$/.test(value);
|
|
@@ -11,7 +11,7 @@ describe('isValidPhoneNumber', () => {
|
|
|
11
11
|
|
|
12
12
|
it('should return false for invalid numbers', () => {
|
|
13
13
|
expect(isValidPhoneNumber('+441')).toBe(false);
|
|
14
|
-
expect(isValidPhoneNumber(44)).toBe(false);
|
|
14
|
+
expect(isValidPhoneNumber('44')).toBe(false);
|
|
15
15
|
expect(isValidPhoneNumber('44123')).toBe(false);
|
|
16
16
|
});
|
|
17
17
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param phoneNumber
|
|
4
|
+
* @returns True if number that starts with "+" and contains a mix of digits and spaces with at least 4 digits.
|
|
5
|
+
*/
|
|
6
|
+
export const isValidPhoneNumber = (phoneNumber: string) =>
|
|
7
|
+
/^\+[\d-\s]+$/.test(phoneNumber) && (phoneNumber.match(/\d+/g)?.join('').length ?? 0) >= 4;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getCountryFromLocale } from '../../../common/locale';
|
|
2
|
+
import { findCountryByCode } from '../findCountryByCode';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default phone code, the UK one `+44`
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_PHONE_CODE = '+44';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Given a valid locale it returns the correspondent prefix if found or +44 otherwise.
|
|
11
|
+
*
|
|
12
|
+
* @param locale BCP 47 language tag of locale, e.g. `"es-ES"`.
|
|
13
|
+
* @param countryCode Two-letter country code (ISO 3166-1 alpha-2).
|
|
14
|
+
*/
|
|
15
|
+
export const setDefaultPrefix = (locale: string, countryCode?: string) => {
|
|
16
|
+
const country =
|
|
17
|
+
(countryCode != null ? findCountryByCode(countryCode) : null) ??
|
|
18
|
+
findCountryByCode(getCountryFromLocale(locale) ?? locale);
|
|
19
|
+
return country?.phone ?? DEFAULT_PHONE_CODE;
|
|
20
|
+
};
|
package/src/select/Select.css
CHANGED
|
@@ -152,10 +152,6 @@
|
|
|
152
152
|
border-radius: var(--radius-small);
|
|
153
153
|
color: #37517e;
|
|
154
154
|
color: var(--color-content-primary);
|
|
155
|
-
line-height: 1.5;
|
|
156
|
-
line-height: var(--line-height-body);
|
|
157
|
-
font-size: 1rem;
|
|
158
|
-
font-size: var(--font-size-16);
|
|
159
155
|
font-size: 0.875rem;
|
|
160
156
|
font-size: var(--font-size-14);
|
|
161
157
|
line-height: 155%;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/filterOptionsForQuery/index.js"],"names":[],"mappings":"AASO,qEAC0D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js"],"names":[],"mappings":""}
|
package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isOptionAndFitsQuery.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js"],"names":[],"mappings":"AAQO,6CAJI,MAAM,SACN,MAAM,GACJ,OAAO,CAMa;AAE1B,+DAQN"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapInFragment.d.ts","sourceRoot":"","sources":["../../../src/utilities/wrapInFragment.tsx"],"names":[],"mappings":";AAAA,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,+BAE5C"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { Direction } from '..';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default language
|
|
5
|
-
*
|
|
6
|
-
* @type {string}
|
|
7
|
-
*/
|
|
8
|
-
export const DEFAULT_LANG = 'en';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Default locale
|
|
12
|
-
*
|
|
13
|
-
* @type {string}
|
|
14
|
-
*/
|
|
15
|
-
export const DEFAULT_LOCALE = 'en-GB';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Array of languages that are written from the right to the left
|
|
19
|
-
*
|
|
20
|
-
* @type {string[]}
|
|
21
|
-
*/
|
|
22
|
-
export const RTL_LANGUAGES = ['ar', 'he'];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated The source of truth for supported languages lives in Crab.
|
|
26
|
-
* @type {string[]}
|
|
27
|
-
*/
|
|
28
|
-
export const SUPPORTED_LANGUAGES = [
|
|
29
|
-
DEFAULT_LANG,
|
|
30
|
-
'de',
|
|
31
|
-
'es',
|
|
32
|
-
'fr',
|
|
33
|
-
'hu',
|
|
34
|
-
'id',
|
|
35
|
-
'it',
|
|
36
|
-
'ja',
|
|
37
|
-
'pl',
|
|
38
|
-
'pt',
|
|
39
|
-
'ro',
|
|
40
|
-
'ru',
|
|
41
|
-
'th',
|
|
42
|
-
'tr',
|
|
43
|
-
'uk',
|
|
44
|
-
'zh',
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Verifies and adjusts locale (replace `_` with `-`)
|
|
49
|
-
* Returns null if locale is unrecognized by {Intl.Locale}
|
|
50
|
-
*
|
|
51
|
-
* @param {string} locale (`es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
52
|
-
* @returns {string|null}
|
|
53
|
-
*/
|
|
54
|
-
export function adjustLocale(locale) {
|
|
55
|
-
if (!locale || locale.trim().length === 0) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const { baseName } = new Intl.Locale(locale.trim().replace('_', '-'));
|
|
60
|
-
return baseName;
|
|
61
|
-
} catch (error) {
|
|
62
|
-
// eslint-disable-next-line no-console
|
|
63
|
-
console.error(error);
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Provides corresponding lang (iso2) for provided locale
|
|
70
|
-
* if locale is invalid or language is unsupported returns null
|
|
71
|
-
*
|
|
72
|
-
* @deprecated The use of this function almost always breaks language variants
|
|
73
|
-
* e.g. Simplified and Traditional Chinese.
|
|
74
|
-
* There should be no use case for this function.
|
|
75
|
-
* To select the correct translations from a translations object, pass the
|
|
76
|
-
* locale directly into Crab's getLocalisedMessages.
|
|
77
|
-
* @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
78
|
-
* @returns {string|null} two-letter ISO639-1 language
|
|
79
|
-
*/
|
|
80
|
-
export function getLangFromLocale(locale) {
|
|
81
|
-
const adjustedLocale = adjustLocale(locale);
|
|
82
|
-
if (adjustedLocale === null) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
const { language } = new Intl.Locale(adjustedLocale);
|
|
87
|
-
|
|
88
|
-
if (SUPPORTED_LANGUAGES.includes(language)) {
|
|
89
|
-
return language;
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
// eslint-disable-next-line no-console
|
|
94
|
-
console.error(error);
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Provides corresponding country code (iso2) for locales code with explicit region value (`es-ES`, `en-GB`, `ja-JP` etc.)
|
|
101
|
-
* if the value is invalid or missing region it returns null
|
|
102
|
-
*
|
|
103
|
-
* @param {string} locale
|
|
104
|
-
* @returns {string|null}
|
|
105
|
-
*/
|
|
106
|
-
export function getCountryFromLocale(locale) {
|
|
107
|
-
const adjustedLocale = adjustLocale(locale);
|
|
108
|
-
if (adjustedLocale === null) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const { region } = new Intl.Locale(adjustedLocale);
|
|
113
|
-
return region ?? null;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
// eslint-disable-next-line no-console
|
|
116
|
-
console.error(error);
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Provides the layout direction for a given locale.
|
|
123
|
-
* If locale is invalid or language is unsupported returns Direction.LTR
|
|
124
|
-
*
|
|
125
|
-
* @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
126
|
-
* @returns {Direction} The layout direction based on the locale
|
|
127
|
-
*/
|
|
128
|
-
export function getDirectionFromLocale(locale) {
|
|
129
|
-
try {
|
|
130
|
-
const adjustedLocale = adjustLocale(locale);
|
|
131
|
-
const { language } = new Intl.Locale(adjustedLocale);
|
|
132
|
-
|
|
133
|
-
return RTL_LANGUAGES.includes(language) ? Direction.RTL : Direction.LTR;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
// eslint-disable-next-line no-console
|
|
136
|
-
console.error(error);
|
|
137
|
-
return Direction.LTR;
|
|
138
|
-
}
|
|
139
|
-
}
|