@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.
package/build/index.js CHANGED
@@ -8449,7 +8449,7 @@ class MoneyInput extends React.Component {
8449
8449
  this.amountFocused = true;
8450
8450
  };
8451
8451
  getSelectOptions() {
8452
- const selectOptions = [...filterOptionsForQuery$1(this.props.currencies, this.state.searchQuery)];
8452
+ const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
8453
8453
  if (this.props.onCustomAction) {
8454
8454
  selectOptions.push({
8455
8455
  value: CUSTOM_ACTION,
@@ -8486,7 +8486,7 @@ class MoneyInput extends React.Component {
8486
8486
  if (this.props.onSearchChange) {
8487
8487
  this.props.onSearchChange({
8488
8488
  searchQuery,
8489
- filteredOptions: filterOptionsForQuery$1(this.props.currencies, searchQuery)
8489
+ filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8490
8490
  });
8491
8491
  }
8492
8492
  };
@@ -8567,7 +8567,7 @@ class MoneyInput extends React.Component {
8567
8567
  });
8568
8568
  }
8569
8569
  }
8570
- function filterOptionsForQuery$1(options, query) {
8570
+ function filterOptionsForQuery(options, query) {
8571
8571
  if (!query) {
8572
8572
  return options;
8573
8573
  }
@@ -10155,36 +10155,9 @@ const explodeNumberModel = number => {
10155
10155
  };
10156
10156
  };
10157
10157
 
10158
- /**
10159
- * Checks if query is contained into object properties.
10160
- *
10161
- * @param {object} option - the select option
10162
- * @param {string} query - the current search query
10163
- * @returns {boolean}
10164
- */
10165
- const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
10166
- const startsWith = (property, query) => {
10167
- if (neptuneValidation.isArray(property)) {
10168
- return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
10169
- }
10170
- return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
10171
- };
10172
- const normalizeValue = value => value.toLowerCase().replace('+', '');
10173
-
10174
- /**
10175
- * Filters a set of options based on search string
10176
- *
10177
- * @param options
10178
- * @param query
10179
- * @returns {*}
10180
- */
10181
- const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
10182
-
10183
10158
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
10184
10159
  const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
10185
10160
 
10186
- const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
10187
-
10188
10161
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
10189
10162
  const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
10190
10163
 
@@ -10263,13 +10236,10 @@ const PhoneNumberInput = props => {
10263
10236
  };
10264
10237
  const [internalValue, setInternalValue] = React.useState(getInitialValue());
10265
10238
  const [broadcastedValue, setBroadcastedValue] = React.useState(null);
10266
- const [searchQuery, setSearchQuery] = React.useState('');
10267
- const countriesList = excludeCountries(countries$1, disabledCountries);
10268
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10269
- const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
10270
10239
  const getSelectOptions = () => {
10271
- const filteredOptions = filterOptionsForQuery(isStringNumeric(searchQuery) ? listSortedByPhone : listSortedByISO3, searchQuery);
10272
- return filteredOptions.map(option => {
10240
+ const countriesList = excludeCountries(countries$1, disabledCountries);
10241
+ const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10242
+ return listSortedByISO3.map(option => {
10273
10243
  const {
10274
10244
  phone,
10275
10245
  iso3,
@@ -10282,9 +10252,13 @@ const PhoneNumberInput = props => {
10282
10252
  note = neptuneValidation.isArray(iso2) ? iso2.join(', ') : iso2;
10283
10253
  }
10284
10254
  return {
10285
- value: phone,
10286
- label: phone,
10287
- note
10255
+ type: 'option',
10256
+ value: {
10257
+ value: phone,
10258
+ label: phone,
10259
+ note: note
10260
+ },
10261
+ filterMatchers: [phone, note]
10288
10262
  };
10289
10263
  });
10290
10264
  };
@@ -10292,7 +10266,6 @@ const PhoneNumberInput = props => {
10292
10266
  const onPrefixChange = ({
10293
10267
  value
10294
10268
  }) => {
10295
- setSearchQuery('');
10296
10269
  setInternalValue({
10297
10270
  prefix: value,
10298
10271
  suffix: internalValue.suffix
@@ -10320,7 +10293,7 @@ const PhoneNumberInput = props => {
10320
10293
  } = explodeNumberModel(pastedValue);
10321
10294
  const selectedPrefix = options.find(({
10322
10295
  value
10323
- }) => value === pastedPrefix);
10296
+ }) => value.value === pastedPrefix);
10324
10297
  if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
10325
10298
  setInternalValue({
10326
10299
  prefix: pastedPrefix,
@@ -10345,22 +10318,22 @@ const PhoneNumberInput = props => {
10345
10318
  className: "tw-telephone",
10346
10319
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
10347
10320
  className: "tw-telephone__country-select",
10348
- children: /*#__PURE__*/jsxRuntime.jsx(Select, {
10349
- id: id ? `${id}-select` : undefined,
10350
- options: options,
10351
- selected: {
10321
+ children: /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
10322
+ placeholder: "Select an option...",
10323
+ items: options,
10324
+ value: {
10352
10325
  value: internalValue.prefix,
10353
10326
  label: internalValue.prefix
10354
10327
  },
10355
- placeholder: "Select an option...",
10356
- searchPlaceholder: searchPlaceholder,
10357
- dropdownWidth: exports.Size.SMALL,
10358
- searchValue: searchQuery,
10359
- required: required,
10328
+ renderValue: (option, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
10329
+ title: option.label,
10330
+ note: withinTrigger ? undefined : option.note
10331
+ }),
10332
+ filterable: true,
10333
+ filterPlaceholder: searchPlaceholder,
10360
10334
  disabled: disabled,
10361
10335
  size: size,
10362
10336
  onChange: onPrefixChange,
10363
- onSearchChange: newSearch => setSearchQuery(newSearch),
10364
10337
  ...selectProps
10365
10338
  })
10366
10339
  }), /*#__PURE__*/jsxRuntime.jsx("div", {