@transferwise/components 0.0.0-experimental-eb6ccd6 → 0.0.0-experimental-a81440a

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.
@@ -8415,7 +8415,7 @@ class MoneyInput extends Component {
8415
8415
  this.amountFocused = true;
8416
8416
  };
8417
8417
  getSelectOptions() {
8418
- const selectOptions = [...filterOptionsForQuery$1(this.props.currencies, this.state.searchQuery)];
8418
+ const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
8419
8419
  if (this.props.onCustomAction) {
8420
8420
  selectOptions.push({
8421
8421
  value: CUSTOM_ACTION,
@@ -8452,7 +8452,7 @@ class MoneyInput extends Component {
8452
8452
  if (this.props.onSearchChange) {
8453
8453
  this.props.onSearchChange({
8454
8454
  searchQuery,
8455
- filteredOptions: filterOptionsForQuery$1(this.props.currencies, searchQuery)
8455
+ filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8456
8456
  });
8457
8457
  }
8458
8458
  };
@@ -8533,7 +8533,7 @@ class MoneyInput extends Component {
8533
8533
  });
8534
8534
  }
8535
8535
  }
8536
- function filterOptionsForQuery$1(options, query) {
8536
+ function filterOptionsForQuery(options, query) {
8537
8537
  if (!query) {
8538
8538
  return options;
8539
8539
  }
@@ -10121,36 +10121,9 @@ const explodeNumberModel = number => {
10121
10121
  };
10122
10122
  };
10123
10123
 
10124
- /**
10125
- * Checks if query is contained into object properties.
10126
- *
10127
- * @param {object} option - the select option
10128
- * @param {string} query - the current search query
10129
- * @returns {boolean}
10130
- */
10131
- const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
10132
- const startsWith = (property, query) => {
10133
- if (isArray(property)) {
10134
- return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
10135
- }
10136
- return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
10137
- };
10138
- const normalizeValue = value => value.toLowerCase().replace('+', '');
10139
-
10140
- /**
10141
- * Filters a set of options based on search string
10142
- *
10143
- * @param options
10144
- * @param query
10145
- * @returns {*}
10146
- */
10147
- const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
10148
-
10149
10124
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
10150
10125
  const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
10151
10126
 
10152
- const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
10153
-
10154
10127
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
10155
10128
  const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
10156
10129
 
@@ -10229,13 +10202,10 @@ const PhoneNumberInput = props => {
10229
10202
  };
10230
10203
  const [internalValue, setInternalValue] = useState(getInitialValue());
10231
10204
  const [broadcastedValue, setBroadcastedValue] = useState(null);
10232
- const [searchQuery, setSearchQuery] = useState('');
10233
- const countriesList = excludeCountries(countries$1, disabledCountries);
10234
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10235
- const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
10236
10205
  const getSelectOptions = () => {
10237
- const filteredOptions = filterOptionsForQuery(isStringNumeric(searchQuery) ? listSortedByPhone : listSortedByISO3, searchQuery);
10238
- return filteredOptions.map(option => {
10206
+ const countriesList = excludeCountries(countries$1, disabledCountries);
10207
+ const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10208
+ return listSortedByISO3.map(option => {
10239
10209
  const {
10240
10210
  phone,
10241
10211
  iso3,
@@ -10248,9 +10218,13 @@ const PhoneNumberInput = props => {
10248
10218
  note = isArray(iso2) ? iso2.join(', ') : iso2;
10249
10219
  }
10250
10220
  return {
10251
- value: phone,
10252
- label: phone,
10253
- note
10221
+ type: 'option',
10222
+ value: {
10223
+ value: phone,
10224
+ label: phone,
10225
+ note: note
10226
+ },
10227
+ filterMatchers: [phone, note]
10254
10228
  };
10255
10229
  });
10256
10230
  };
@@ -10258,7 +10232,6 @@ const PhoneNumberInput = props => {
10258
10232
  const onPrefixChange = ({
10259
10233
  value
10260
10234
  }) => {
10261
- setSearchQuery('');
10262
10235
  setInternalValue({
10263
10236
  prefix: value,
10264
10237
  suffix: internalValue.suffix
@@ -10286,7 +10259,7 @@ const PhoneNumberInput = props => {
10286
10259
  } = explodeNumberModel(pastedValue);
10287
10260
  const selectedPrefix = options.find(({
10288
10261
  value
10289
- }) => value === pastedPrefix);
10262
+ }) => value.value === pastedPrefix);
10290
10263
  if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
10291
10264
  setInternalValue({
10292
10265
  prefix: pastedPrefix,
@@ -10311,22 +10284,22 @@ const PhoneNumberInput = props => {
10311
10284
  className: "tw-telephone",
10312
10285
  children: [/*#__PURE__*/jsx("div", {
10313
10286
  className: "tw-telephone__country-select",
10314
- children: /*#__PURE__*/jsx(Select, {
10315
- id: id ? `${id}-select` : undefined,
10316
- options: options,
10317
- selected: {
10287
+ children: /*#__PURE__*/jsx(SelectInput, {
10288
+ placeholder: "Select an option...",
10289
+ items: options,
10290
+ value: {
10318
10291
  value: internalValue.prefix,
10319
10292
  label: internalValue.prefix
10320
10293
  },
10321
- placeholder: "Select an option...",
10322
- searchPlaceholder: searchPlaceholder,
10323
- dropdownWidth: Size.SMALL,
10324
- searchValue: searchQuery,
10325
- required: required,
10294
+ renderValue: (option, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
10295
+ title: option.label,
10296
+ note: withinTrigger ? undefined : option.note
10297
+ }),
10298
+ filterable: true,
10299
+ filterPlaceholder: searchPlaceholder,
10326
10300
  disabled: disabled,
10327
10301
  size: size,
10328
10302
  onChange: onPrefixChange,
10329
- onSearchChange: newSearch => setSearchQuery(newSearch),
10330
10303
  ...selectProps
10331
10304
  })
10332
10305
  }), /*#__PURE__*/jsx("div", {