@transferwise/components 0.0.0-experimental-210ef2c → 0.0.0-experimental-6d7ebae

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.
@@ -6749,6 +6749,7 @@ function SelectInput({
6749
6749
  value: controlledValue,
6750
6750
  compareValues,
6751
6751
  renderValue = wrapInFragment,
6752
+ renderFooter,
6752
6753
  renderTrigger = defaultRenderTrigger,
6753
6754
  filterable,
6754
6755
  filterPlaceholder,
@@ -6822,6 +6823,7 @@ function SelectInput({
6822
6823
  children: /*#__PURE__*/jsx(SelectInputOptions, {
6823
6824
  items: items,
6824
6825
  renderValue: renderValue,
6826
+ renderFooter: renderFooter,
6825
6827
  filterable: filterable,
6826
6828
  filterPlaceholder: filterPlaceholder,
6827
6829
  searchInputRef: searchInputRef,
@@ -6887,6 +6889,7 @@ const SelectInputOptionsContainer = /*#__PURE__*/forwardRef(function SelectInput
6887
6889
  function SelectInputOptions({
6888
6890
  items,
6889
6891
  renderValue = wrapInFragment,
6892
+ renderFooter,
6890
6893
  filterable = false,
6891
6894
  filterPlaceholder,
6892
6895
  searchInputRef,
@@ -6944,7 +6947,7 @@ function SelectInputOptions({
6944
6947
  setQuery(event.currentTarget.value);
6945
6948
  }
6946
6949
  })
6947
- }) : null, /*#__PURE__*/jsxs("div", {
6950
+ }) : null, /*#__PURE__*/jsxs("section", {
6948
6951
  ref: listboxContainerRef,
6949
6952
  className: classNames('np-select-input-listbox-container', items.some(item => item.type === 'group') && 'np-select-input-listbox-container--has-group'),
6950
6953
  children: [empty ? /*#__PURE__*/jsxs("div", {
@@ -6968,7 +6971,10 @@ function SelectInputOptions({
6968
6971
  renderValue: renderValue,
6969
6972
  needle: needle
6970
6973
  }, index))
6971
- })]
6974
+ }), renderFooter != null ? /*#__PURE__*/jsx("footer", {
6975
+ className: "np-select-input-footer",
6976
+ children: renderFooter(needle)
6977
+ }) : null]
6972
6978
  })]
6973
6979
  });
6974
6980
  }
@@ -8476,7 +8482,7 @@ class MoneyInput extends Component {
8476
8482
  this.amountFocused = true;
8477
8483
  };
8478
8484
  getSelectOptions() {
8479
- const selectOptions = [...filterOptionsForQuery$1(this.props.currencies, this.state.searchQuery)];
8485
+ const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
8480
8486
  if (this.props.onCustomAction) {
8481
8487
  selectOptions.push({
8482
8488
  value: CUSTOM_ACTION,
@@ -8513,7 +8519,7 @@ class MoneyInput extends Component {
8513
8519
  if (this.props.onSearchChange) {
8514
8520
  this.props.onSearchChange({
8515
8521
  searchQuery,
8516
- filteredOptions: filterOptionsForQuery$1(this.props.currencies, searchQuery)
8522
+ filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8517
8523
  });
8518
8524
  }
8519
8525
  };
@@ -8594,7 +8600,7 @@ class MoneyInput extends Component {
8594
8600
  });
8595
8601
  }
8596
8602
  }
8597
- function filterOptionsForQuery$1(options, query) {
8603
+ function filterOptionsForQuery(options, query) {
8598
8604
  if (!query) {
8599
8605
  return options;
8600
8606
  }
@@ -10182,36 +10188,9 @@ const explodeNumberModel = number => {
10182
10188
  };
10183
10189
  };
10184
10190
 
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
10191
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
10211
10192
  const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
10212
10193
 
10213
- const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
10214
-
10215
10194
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
10216
10195
  const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
10217
10196
 
@@ -10290,17 +10269,15 @@ const PhoneNumberInput = props => {
10290
10269
  };
10291
10270
  const [internalValue, setInternalValue] = useState(getInitialValue());
10292
10271
  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
10272
  const getSelectOptions = () => {
10298
- const filteredOptions = filterOptionsForQuery(isStringNumeric(searchQuery) ? listSortedByPhone : listSortedByISO3, searchQuery);
10299
- return filteredOptions.map(option => {
10273
+ const countriesList = excludeCountries(countries$1, disabledCountries);
10274
+ const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10275
+ return listSortedByISO3.map(option => {
10300
10276
  const {
10301
10277
  phone,
10302
10278
  iso3,
10303
- iso2
10279
+ iso2,
10280
+ name
10304
10281
  } = option;
10305
10282
  let note = '';
10306
10283
  if (iso3) {
@@ -10309,9 +10286,13 @@ const PhoneNumberInput = props => {
10309
10286
  note = isArray(iso2) ? iso2.join(', ') : iso2;
10310
10287
  }
10311
10288
  return {
10312
- value: phone,
10313
- label: phone,
10314
- note
10289
+ type: 'option',
10290
+ value: {
10291
+ value: phone,
10292
+ label: phone,
10293
+ note: note
10294
+ },
10295
+ filterMatchers: [phone, note, name]
10315
10296
  };
10316
10297
  });
10317
10298
  };
@@ -10319,7 +10300,6 @@ const PhoneNumberInput = props => {
10319
10300
  const onPrefixChange = ({
10320
10301
  value
10321
10302
  }) => {
10322
- setSearchQuery('');
10323
10303
  setInternalValue({
10324
10304
  prefix: value,
10325
10305
  suffix: internalValue.suffix
@@ -10347,7 +10327,7 @@ const PhoneNumberInput = props => {
10347
10327
  } = explodeNumberModel(pastedValue);
10348
10328
  const selectedPrefix = options.find(({
10349
10329
  value
10350
- }) => value === pastedPrefix);
10330
+ }) => value.value === pastedPrefix);
10351
10331
  if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
10352
10332
  setInternalValue({
10353
10333
  prefix: pastedPrefix,
@@ -10372,22 +10352,19 @@ const PhoneNumberInput = props => {
10372
10352
  className: "tw-telephone",
10373
10353
  children: [/*#__PURE__*/jsx("div", {
10374
10354
  className: "tw-telephone__country-select",
10375
- children: /*#__PURE__*/jsx(Select, {
10376
- id: id ? `${id}-select` : undefined,
10377
- options: options,
10378
- selected: {
10379
- value: internalValue.prefix,
10380
- label: internalValue.prefix
10381
- },
10355
+ children: /*#__PURE__*/jsx(SelectInput, {
10382
10356
  placeholder: "Select an option...",
10383
- searchPlaceholder: searchPlaceholder,
10384
- dropdownWidth: Size.SMALL,
10385
- searchValue: searchQuery,
10386
- required: required,
10357
+ items: options,
10358
+ value: options.find(item => item.value.value === internalValue.prefix)?.value,
10359
+ renderValue: (option, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
10360
+ title: option.label,
10361
+ note: withinTrigger ? undefined : option.note
10362
+ }),
10363
+ filterable: true,
10364
+ filterPlaceholder: searchPlaceholder,
10387
10365
  disabled: disabled,
10388
10366
  size: size,
10389
10367
  onChange: onPrefixChange,
10390
- onSearchChange: newSearch => setSearchQuery(newSearch),
10391
10368
  ...selectProps
10392
10369
  })
10393
10370
  }), /*#__PURE__*/jsx("div", {