@transferwise/components 0.0.0-experimental-cf10171 → 0.0.0-experimental-ae2a4e7
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 +10 -17
- package/build/index.esm.js.map +1 -1
- package/build/index.js +10 -17
- package/build/index.js.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +2 -2
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.tsx +16 -9
- package/src/phoneNumberInput/utils/explodeNumberModel/explodeNumberModel.spec.ts +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +5 -5
|
@@ -21,7 +21,7 @@ export interface PhoneNumberInputProps {
|
|
|
21
21
|
searchPlaceholder?: string;
|
|
22
22
|
size?: SizeSmall | SizeMedium | SizeLarge;
|
|
23
23
|
placeholder?: string;
|
|
24
|
-
selectProps?: Partial<SelectInputProps<string>>;
|
|
24
|
+
selectProps?: Partial<SelectInputProps<string | null>>;
|
|
25
25
|
/** List of iso3 codes of countries to remove from the list */
|
|
26
26
|
disabledCountries?: string[];
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneNumberInput.d.ts","sourceRoot":"","sources":["../../../src/phoneNumberInput/PhoneNumberInput.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAQ,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAyC,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAgBhG,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MA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d,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,OAAO,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;IACvD,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAKD,QAAA,MAAM,gBAAgB,4JAcnB,qBAAqB,gCAuIvB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/explodeNumberModel/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/phoneNumberInput/utils/explodeNumberModel/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,WAAY,MAAM,KAAG,WAanD,CAAC"}
|
package/package.json
CHANGED
|
@@ -173,7 +173,7 @@ describe('Given a telephone number component', () => {
|
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
it('should empty the select', () => {
|
|
176
|
-
expect(select.props().value).
|
|
176
|
+
expect(select.props().value).toBeNull();
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
it('should put the whole value in the input without the plus', () => {
|
|
@@ -39,7 +39,7 @@ export interface PhoneNumberInputProps {
|
|
|
39
39
|
searchPlaceholder?: string;
|
|
40
40
|
size?: SizeSmall | SizeMedium | SizeLarge;
|
|
41
41
|
placeholder?: string;
|
|
42
|
-
selectProps?: Partial<SelectInputProps<string>>;
|
|
42
|
+
selectProps?: Partial<SelectInputProps<string | null>>;
|
|
43
43
|
/** List of iso3 codes of countries to remove from the list */
|
|
44
44
|
disabledCountries?: string[];
|
|
45
45
|
}
|
|
@@ -71,7 +71,7 @@ const PhoneNumberInput = ({
|
|
|
71
71
|
return {
|
|
72
72
|
prefix: setDefaultPrefix(locale, countryCode),
|
|
73
73
|
suffix: '',
|
|
74
|
-
format:
|
|
74
|
+
format: undefined,
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -103,10 +103,14 @@ const PhoneNumberInput = ({
|
|
|
103
103
|
/(\s|-)+/g,
|
|
104
104
|
'',
|
|
105
105
|
);
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
106
|
+
const pastedNumber = explodeNumberModel(pastedValue);
|
|
107
|
+
|
|
108
|
+
if (
|
|
109
|
+
pastedNumber.prefix != null &&
|
|
110
|
+
countriesByPrefix.has(pastedNumber.prefix) &&
|
|
111
|
+
ALLOWED_PHONE_CHARS.test(pastedNumber.suffix)
|
|
112
|
+
) {
|
|
113
|
+
setInternalValue(pastedNumber);
|
|
110
114
|
}
|
|
111
115
|
};
|
|
112
116
|
|
|
@@ -115,8 +119,8 @@ const PhoneNumberInput = ({
|
|
|
115
119
|
return setBroadcastedValue(internalValue);
|
|
116
120
|
}
|
|
117
121
|
|
|
118
|
-
const internalPhoneNumber = internalValue.prefix
|
|
119
|
-
const broadcastedPhoneNumber = broadcastedValue.prefix
|
|
122
|
+
const internalPhoneNumber = `${internalValue.prefix ?? ''}${internalValue.suffix}`;
|
|
123
|
+
const broadcastedPhoneNumber = `${broadcastedValue.prefix ?? ''}${broadcastedValue.suffix}`;
|
|
120
124
|
|
|
121
125
|
if (internalPhoneNumber === broadcastedPhoneNumber) {
|
|
122
126
|
return;
|
|
@@ -126,7 +130,10 @@ const PhoneNumberInput = ({
|
|
|
126
130
|
? cleanNumber(internalPhoneNumber)
|
|
127
131
|
: null;
|
|
128
132
|
|
|
129
|
-
onChange(
|
|
133
|
+
onChange(
|
|
134
|
+
newValue,
|
|
135
|
+
internalValue.prefix ?? '', // TODO: Allow `null` in public API
|
|
136
|
+
);
|
|
130
137
|
setBroadcastedValue(internalValue);
|
|
131
138
|
}, [onChange, broadcastedValue, internalValue]);
|
|
132
139
|
|
|
@@ -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
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { findCountryByPrefix } from '../findCountryByPrefix';
|
|
2
2
|
|
|
3
3
|
export interface PhoneNumber {
|
|
4
|
-
prefix: string;
|
|
4
|
+
prefix: string | null;
|
|
5
5
|
suffix: string;
|
|
6
|
-
format: string;
|
|
6
|
+
format: string | undefined;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -15,11 +15,11 @@ export const explodeNumberModel = (number: string): PhoneNumber => {
|
|
|
15
15
|
? {
|
|
16
16
|
prefix: country.phone,
|
|
17
17
|
suffix: number.slice(country.phone.length),
|
|
18
|
-
format: country.phoneFormat
|
|
18
|
+
format: country.phoneFormat,
|
|
19
19
|
}
|
|
20
20
|
: {
|
|
21
|
-
prefix:
|
|
21
|
+
prefix: null,
|
|
22
22
|
suffix: number.slice(1),
|
|
23
|
-
format:
|
|
23
|
+
format: undefined,
|
|
24
24
|
};
|
|
25
25
|
};
|