@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.js CHANGED
@@ -8510,7 +8510,7 @@ class MoneyInput extends React.Component {
8510
8510
  this.amountFocused = true;
8511
8511
  };
8512
8512
  getSelectOptions() {
8513
- const selectOptions = [...filterOptionsForQuery$1(this.props.currencies, this.state.searchQuery)];
8513
+ const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
8514
8514
  if (this.props.onCustomAction) {
8515
8515
  selectOptions.push({
8516
8516
  value: CUSTOM_ACTION,
@@ -8547,7 +8547,7 @@ class MoneyInput extends React.Component {
8547
8547
  if (this.props.onSearchChange) {
8548
8548
  this.props.onSearchChange({
8549
8549
  searchQuery,
8550
- filteredOptions: filterOptionsForQuery$1(this.props.currencies, searchQuery)
8550
+ filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8551
8551
  });
8552
8552
  }
8553
8553
  };
@@ -8628,7 +8628,7 @@ class MoneyInput extends React.Component {
8628
8628
  });
8629
8629
  }
8630
8630
  }
8631
- function filterOptionsForQuery$1(options, query) {
8631
+ function filterOptionsForQuery(options, query) {
8632
8632
  if (!query) {
8633
8633
  return options;
8634
8634
  }
@@ -10216,36 +10216,9 @@ const explodeNumberModel = number => {
10216
10216
  };
10217
10217
  };
10218
10218
 
10219
- /**
10220
- * Checks if query is contained into object properties.
10221
- *
10222
- * @param {object} option - the select option
10223
- * @param {string} query - the current search query
10224
- * @returns {boolean}
10225
- */
10226
- const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
10227
- const startsWith = (property, query) => {
10228
- if (neptuneValidation.isArray(property)) {
10229
- return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
10230
- }
10231
- return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
10232
- };
10233
- const normalizeValue = value => value.toLowerCase().replace('+', '');
10234
-
10235
- /**
10236
- * Filters a set of options based on search string
10237
- *
10238
- * @param options
10239
- * @param query
10240
- * @returns {*}
10241
- */
10242
- const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
10243
-
10244
10219
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
10245
10220
  const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
10246
10221
 
10247
- const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
10248
-
10249
10222
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
10250
10223
  const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
10251
10224
 
@@ -10324,17 +10297,15 @@ const PhoneNumberInput = props => {
10324
10297
  };
10325
10298
  const [internalValue, setInternalValue] = React.useState(getInitialValue());
10326
10299
  const [broadcastedValue, setBroadcastedValue] = React.useState(null);
10327
- const [searchQuery, setSearchQuery] = React.useState('');
10328
- const countriesList = excludeCountries(countries$1, disabledCountries);
10329
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10330
- const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
10331
10300
  const getSelectOptions = () => {
10332
- const filteredOptions = filterOptionsForQuery(isStringNumeric(searchQuery) ? listSortedByPhone : listSortedByISO3, searchQuery);
10333
- return filteredOptions.map(option => {
10301
+ const countriesList = excludeCountries(countries$1, disabledCountries);
10302
+ const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10303
+ return listSortedByISO3.map(option => {
10334
10304
  const {
10335
10305
  phone,
10336
10306
  iso3,
10337
- iso2
10307
+ iso2,
10308
+ name
10338
10309
  } = option;
10339
10310
  let note = '';
10340
10311
  if (iso3) {
@@ -10343,9 +10314,13 @@ const PhoneNumberInput = props => {
10343
10314
  note = neptuneValidation.isArray(iso2) ? iso2.join(', ') : iso2;
10344
10315
  }
10345
10316
  return {
10346
- value: phone,
10347
- label: phone,
10348
- note
10317
+ type: 'option',
10318
+ value: {
10319
+ value: phone,
10320
+ label: phone,
10321
+ note: note
10322
+ },
10323
+ filterMatchers: [phone, note, name]
10349
10324
  };
10350
10325
  });
10351
10326
  };
@@ -10353,7 +10328,6 @@ const PhoneNumberInput = props => {
10353
10328
  const onPrefixChange = ({
10354
10329
  value
10355
10330
  }) => {
10356
- setSearchQuery('');
10357
10331
  setInternalValue({
10358
10332
  prefix: value,
10359
10333
  suffix: internalValue.suffix
@@ -10381,7 +10355,7 @@ const PhoneNumberInput = props => {
10381
10355
  } = explodeNumberModel(pastedValue);
10382
10356
  const selectedPrefix = options.find(({
10383
10357
  value
10384
- }) => value === pastedPrefix);
10358
+ }) => value.value === pastedPrefix);
10385
10359
  if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
10386
10360
  setInternalValue({
10387
10361
  prefix: pastedPrefix,
@@ -10406,22 +10380,19 @@ const PhoneNumberInput = props => {
10406
10380
  className: "tw-telephone",
10407
10381
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
10408
10382
  className: "tw-telephone__country-select",
10409
- children: /*#__PURE__*/jsxRuntime.jsx(Select, {
10410
- id: id ? `${id}-select` : undefined,
10411
- options: options,
10412
- selected: {
10413
- value: internalValue.prefix,
10414
- label: internalValue.prefix
10415
- },
10383
+ children: /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
10416
10384
  placeholder: "Select an option...",
10417
- searchPlaceholder: searchPlaceholder,
10418
- dropdownWidth: exports.Size.SMALL,
10419
- searchValue: searchQuery,
10420
- required: required,
10385
+ items: options,
10386
+ value: options.find(item => item.value.value === internalValue.prefix)?.value,
10387
+ renderValue: (option, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
10388
+ title: option.label,
10389
+ note: withinTrigger ? undefined : option.note
10390
+ }),
10391
+ filterable: true,
10392
+ filterPlaceholder: searchPlaceholder,
10421
10393
  disabled: disabled,
10422
10394
  size: size,
10423
10395
  onChange: onPrefixChange,
10424
- onSearchChange: newSearch => setSearchQuery(newSearch),
10425
10396
  ...selectProps
10426
10397
  })
10427
10398
  }), /*#__PURE__*/jsxRuntime.jsx("div", {