@transferwise/components 45.21.2 → 45.21.3
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 +25 -54
- package/build/index.esm.js.map +1 -1
- package/build/index.js +25 -54
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/styles/phoneNumberInput/PhoneNumberInput.css +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/main.css +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.css +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.js +27 -28
- package/src/phoneNumberInput/PhoneNumberInput.less +4 -0
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +64 -72
- package/src/phoneNumberInput/PhoneNumberInput.story.js +1 -3
package/build/index.esm.js
CHANGED
|
@@ -8476,7 +8476,7 @@ class MoneyInput extends Component {
|
|
|
8476
8476
|
this.amountFocused = true;
|
|
8477
8477
|
};
|
|
8478
8478
|
getSelectOptions() {
|
|
8479
|
-
const selectOptions = [...filterOptionsForQuery
|
|
8479
|
+
const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
|
|
8480
8480
|
if (this.props.onCustomAction) {
|
|
8481
8481
|
selectOptions.push({
|
|
8482
8482
|
value: CUSTOM_ACTION,
|
|
@@ -8513,7 +8513,7 @@ class MoneyInput extends Component {
|
|
|
8513
8513
|
if (this.props.onSearchChange) {
|
|
8514
8514
|
this.props.onSearchChange({
|
|
8515
8515
|
searchQuery,
|
|
8516
|
-
filteredOptions: filterOptionsForQuery
|
|
8516
|
+
filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
|
|
8517
8517
|
});
|
|
8518
8518
|
}
|
|
8519
8519
|
};
|
|
@@ -8594,7 +8594,7 @@ class MoneyInput extends Component {
|
|
|
8594
8594
|
});
|
|
8595
8595
|
}
|
|
8596
8596
|
}
|
|
8597
|
-
function filterOptionsForQuery
|
|
8597
|
+
function filterOptionsForQuery(options, query) {
|
|
8598
8598
|
if (!query) {
|
|
8599
8599
|
return options;
|
|
8600
8600
|
}
|
|
@@ -10182,36 +10182,9 @@ const explodeNumberModel = number => {
|
|
|
10182
10182
|
};
|
|
10183
10183
|
};
|
|
10184
10184
|
|
|
10185
|
-
/**
|
|
10186
|
-
* Checks if query is contained into object properties.
|
|
10187
|
-
*
|
|
10188
|
-
* @param {object} option - the select option
|
|
10189
|
-
* @param {string} query - the current search query
|
|
10190
|
-
* @returns {boolean}
|
|
10191
|
-
*/
|
|
10192
|
-
const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
|
|
10193
|
-
const startsWith = (property, query) => {
|
|
10194
|
-
if (isArray(property)) {
|
|
10195
|
-
return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
|
|
10196
|
-
}
|
|
10197
|
-
return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
|
|
10198
|
-
};
|
|
10199
|
-
const normalizeValue = value => value.toLowerCase().replace('+', '');
|
|
10200
|
-
|
|
10201
|
-
/**
|
|
10202
|
-
* Filters a set of options based on search string
|
|
10203
|
-
*
|
|
10204
|
-
* @param options
|
|
10205
|
-
* @param query
|
|
10206
|
-
* @returns {*}
|
|
10207
|
-
*/
|
|
10208
|
-
const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
|
|
10209
|
-
|
|
10210
10185
|
const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
|
|
10211
10186
|
const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
|
|
10212
10187
|
|
|
10213
|
-
const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
|
|
10214
|
-
|
|
10215
10188
|
// Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
|
10216
10189
|
const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
|
|
10217
10190
|
|
|
@@ -10290,17 +10263,15 @@ const PhoneNumberInput = props => {
|
|
|
10290
10263
|
};
|
|
10291
10264
|
const [internalValue, setInternalValue] = useState(getInitialValue());
|
|
10292
10265
|
const [broadcastedValue, setBroadcastedValue] = useState(null);
|
|
10293
|
-
const [searchQuery, setSearchQuery] = useState('');
|
|
10294
|
-
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
10295
|
-
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
10296
|
-
const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
|
|
10297
10266
|
const getSelectOptions = () => {
|
|
10298
|
-
const
|
|
10299
|
-
|
|
10267
|
+
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
10268
|
+
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
10269
|
+
return listSortedByISO3.map(option => {
|
|
10300
10270
|
const {
|
|
10301
10271
|
phone,
|
|
10302
10272
|
iso3,
|
|
10303
|
-
iso2
|
|
10273
|
+
iso2,
|
|
10274
|
+
name
|
|
10304
10275
|
} = option;
|
|
10305
10276
|
let note = '';
|
|
10306
10277
|
if (iso3) {
|
|
@@ -10309,9 +10280,13 @@ const PhoneNumberInput = props => {
|
|
|
10309
10280
|
note = isArray(iso2) ? iso2.join(', ') : iso2;
|
|
10310
10281
|
}
|
|
10311
10282
|
return {
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10283
|
+
type: 'option',
|
|
10284
|
+
value: {
|
|
10285
|
+
value: phone,
|
|
10286
|
+
label: phone,
|
|
10287
|
+
note: note
|
|
10288
|
+
},
|
|
10289
|
+
filterMatchers: [phone, note, name]
|
|
10315
10290
|
};
|
|
10316
10291
|
});
|
|
10317
10292
|
};
|
|
@@ -10319,7 +10294,6 @@ const PhoneNumberInput = props => {
|
|
|
10319
10294
|
const onPrefixChange = ({
|
|
10320
10295
|
value
|
|
10321
10296
|
}) => {
|
|
10322
|
-
setSearchQuery('');
|
|
10323
10297
|
setInternalValue({
|
|
10324
10298
|
prefix: value,
|
|
10325
10299
|
suffix: internalValue.suffix
|
|
@@ -10347,7 +10321,7 @@ const PhoneNumberInput = props => {
|
|
|
10347
10321
|
} = explodeNumberModel(pastedValue);
|
|
10348
10322
|
const selectedPrefix = options.find(({
|
|
10349
10323
|
value
|
|
10350
|
-
}) => value === pastedPrefix);
|
|
10324
|
+
}) => value.value === pastedPrefix);
|
|
10351
10325
|
if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
|
|
10352
10326
|
setInternalValue({
|
|
10353
10327
|
prefix: pastedPrefix,
|
|
@@ -10372,22 +10346,19 @@ const PhoneNumberInput = props => {
|
|
|
10372
10346
|
className: "tw-telephone",
|
|
10373
10347
|
children: [/*#__PURE__*/jsx("div", {
|
|
10374
10348
|
className: "tw-telephone__country-select",
|
|
10375
|
-
children: /*#__PURE__*/jsx(
|
|
10376
|
-
id: id ? `${id}-select` : undefined,
|
|
10377
|
-
options: options,
|
|
10378
|
-
selected: {
|
|
10379
|
-
value: internalValue.prefix,
|
|
10380
|
-
label: internalValue.prefix
|
|
10381
|
-
},
|
|
10349
|
+
children: /*#__PURE__*/jsx(SelectInput, {
|
|
10382
10350
|
placeholder: "Select an option...",
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10351
|
+
items: options,
|
|
10352
|
+
value: options.find(item => item.value.value === internalValue.prefix)?.value,
|
|
10353
|
+
renderValue: (option, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
|
|
10354
|
+
title: option.label,
|
|
10355
|
+
note: withinTrigger ? undefined : option.note
|
|
10356
|
+
}),
|
|
10357
|
+
filterable: true,
|
|
10358
|
+
filterPlaceholder: searchPlaceholder,
|
|
10387
10359
|
disabled: disabled,
|
|
10388
10360
|
size: size,
|
|
10389
10361
|
onChange: onPrefixChange,
|
|
10390
|
-
onSearchChange: newSearch => setSearchQuery(newSearch),
|
|
10391
10362
|
...selectProps
|
|
10392
10363
|
})
|
|
10393
10364
|
}), /*#__PURE__*/jsx("div", {
|