@transferwise/components 45.21.1 → 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.
@@ -6637,13 +6637,6 @@ function inferSearchableStrings(value) {
6637
6637
  }
6638
6638
  return [];
6639
6639
  }
6640
- const SelectInputItemCheckPaddingContext = /*#__PURE__*/createContext(false);
6641
- function useSelectInputItemCheckPadding() {
6642
- const checkPadding = useContext(SelectInputItemCheckPaddingContext);
6643
- // Avoid layout shifts during transitions via caching
6644
- const [initialCheckPadding] = useState(checkPadding);
6645
- return initialCheckPadding;
6646
- }
6647
6640
  const SelectInputTriggerButtonPropsContext = /*#__PURE__*/createContext({});
6648
6641
  const SelectInputOptionContentWithinTriggerContext = /*#__PURE__*/createContext(false);
6649
6642
  function dedupeSelectInputOptionItem(item, existingValues) {
@@ -6788,54 +6781,51 @@ function SelectInput({
6788
6781
  children: ({
6789
6782
  disabled: uiDisabled,
6790
6783
  value
6791
- }) => /*#__PURE__*/jsx(SelectInputItemCheckPaddingContext.Provider, {
6792
- value: Boolean(filterable) || value != null,
6793
- children: /*#__PURE__*/jsx(OptionsOverlay, {
6794
- placement: "bottom-start",
6795
- open: open,
6796
- renderTrigger: ({
6797
- ref,
6798
- getInteractionProps
6799
- }) => /*#__PURE__*/jsx(SelectInputTriggerButtonPropsContext.Provider, {
6800
- // eslint-disable-next-line react/jsx-no-constructed-context-values
6801
- value: {
6802
- ref: mergeRefs([ref, triggerRef]),
6803
- ...mergeProps({
6804
- onClick: () => {
6805
- setOpen(prev => !prev);
6806
- }
6807
- }, getInteractionProps())
6808
- },
6809
- children: renderTrigger({
6810
- content: value != null ? /*#__PURE__*/jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
6811
- value: true,
6812
- children: renderValue(value, true)
6813
- }) : placeholder,
6814
- placeholderShown: value == null,
6815
- clear: onClear != null ? () => {
6816
- onClear();
6817
- triggerRef.current?.focus({
6818
- preventScroll: true
6819
- });
6820
- } : undefined,
6821
- disabled: uiDisabled,
6822
- size,
6823
- className
6824
- })
6825
- }),
6826
- initialFocusRef: controllerRef,
6827
- padding: "none",
6828
- onClose: () => {
6829
- setOpen(false);
6784
+ }) => /*#__PURE__*/jsx(OptionsOverlay, {
6785
+ placement: "bottom-start",
6786
+ open: open,
6787
+ renderTrigger: ({
6788
+ ref,
6789
+ getInteractionProps
6790
+ }) => /*#__PURE__*/jsx(SelectInputTriggerButtonPropsContext.Provider, {
6791
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
6792
+ value: {
6793
+ ref: mergeRefs([ref, triggerRef]),
6794
+ ...mergeProps({
6795
+ onClick: () => {
6796
+ setOpen(prev => !prev);
6797
+ }
6798
+ }, getInteractionProps())
6830
6799
  },
6831
- children: /*#__PURE__*/jsx(SelectInputOptions, {
6832
- items: items,
6833
- renderValue: renderValue,
6834
- filterable: filterable,
6835
- filterPlaceholder: filterPlaceholder,
6836
- searchInputRef: searchInputRef,
6837
- listboxRef: listboxRef
6800
+ children: renderTrigger({
6801
+ content: value != null ? /*#__PURE__*/jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
6802
+ value: true,
6803
+ children: renderValue(value, true)
6804
+ }) : placeholder,
6805
+ placeholderShown: value == null,
6806
+ clear: onClear != null ? () => {
6807
+ onClear();
6808
+ triggerRef.current?.focus({
6809
+ preventScroll: true
6810
+ });
6811
+ } : undefined,
6812
+ disabled: uiDisabled,
6813
+ size,
6814
+ className
6838
6815
  })
6816
+ }),
6817
+ initialFocusRef: controllerRef,
6818
+ padding: "none",
6819
+ onClose: () => {
6820
+ setOpen(false);
6821
+ },
6822
+ children: /*#__PURE__*/jsx(SelectInputOptions, {
6823
+ items: items,
6824
+ renderValue: renderValue,
6825
+ filterable: filterable,
6826
+ filterPlaceholder: filterPlaceholder,
6827
+ searchInputRef: searchInputRef,
6828
+ listboxRef: listboxRef
6839
6829
  })
6840
6830
  })
6841
6831
  });
@@ -7025,7 +7015,6 @@ function SelectInputGroupItemView({
7025
7015
  needle
7026
7016
  }) {
7027
7017
  const headerId = useId();
7028
- const checkPadding = useSelectInputItemCheckPadding();
7029
7018
  return (
7030
7019
  /*#__PURE__*/
7031
7020
  // An empty container may be rendered when no options match `needle`
@@ -7034,13 +7023,11 @@ function SelectInputGroupItemView({
7034
7023
  role: "group",
7035
7024
  "aria-labelledby": headerId,
7036
7025
  className: classNames(needle === null && 'np-select-input-group-item--without-needle'),
7037
- children: [needle == null ? /*#__PURE__*/jsxs("header", {
7026
+ children: [needle == null ? /*#__PURE__*/jsx("header", {
7038
7027
  id: headerId,
7039
7028
  role: "presentation",
7040
7029
  className: "np-select-input-group-item-header np-text-title-group",
7041
- children: [checkPadding ? /*#__PURE__*/jsx("span", {
7042
- className: "np-select-input-option-check-placeholder"
7043
- }) : null, item.label]
7030
+ children: item.label
7044
7031
  }) : null, item.options.map((option, index) => /*#__PURE__*/jsx(SelectInputItemView
7045
7032
  // eslint-disable-next-line react/no-array-index-key
7046
7033
  , {
@@ -7056,7 +7043,6 @@ function SelectInputOption({
7056
7043
  disabled,
7057
7044
  children
7058
7045
  }) {
7059
- const checkPadding = useSelectInputItemCheckPadding();
7060
7046
  return /*#__PURE__*/jsx(Listbox.Option, {
7061
7047
  as: "div",
7062
7048
  value: value,
@@ -7068,12 +7054,12 @@ function SelectInputOption({
7068
7054
  children: ({
7069
7055
  selected
7070
7056
  }) => /*#__PURE__*/jsxs(Fragment, {
7071
- children: [checkPadding ? /*#__PURE__*/jsx(Check, {
7072
- size: 16,
7073
- className: classNames('np-select-input-option-check', !selected && 'np-select-input-option-check--not-selected')
7074
- }) : null, /*#__PURE__*/jsx("div", {
7057
+ children: [/*#__PURE__*/jsx("div", {
7075
7058
  className: "np-select-input-option",
7076
7059
  children: children
7060
+ }), /*#__PURE__*/jsx(Check, {
7061
+ size: 16,
7062
+ className: classNames('np-select-input-option-check', !selected && 'np-select-input-option-check--not-selected')
7077
7063
  })]
7078
7064
  })
7079
7065
  });
@@ -8490,7 +8476,7 @@ class MoneyInput extends Component {
8490
8476
  this.amountFocused = true;
8491
8477
  };
8492
8478
  getSelectOptions() {
8493
- const selectOptions = [...filterOptionsForQuery$1(this.props.currencies, this.state.searchQuery)];
8479
+ const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
8494
8480
  if (this.props.onCustomAction) {
8495
8481
  selectOptions.push({
8496
8482
  value: CUSTOM_ACTION,
@@ -8527,7 +8513,7 @@ class MoneyInput extends Component {
8527
8513
  if (this.props.onSearchChange) {
8528
8514
  this.props.onSearchChange({
8529
8515
  searchQuery,
8530
- filteredOptions: filterOptionsForQuery$1(this.props.currencies, searchQuery)
8516
+ filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8531
8517
  });
8532
8518
  }
8533
8519
  };
@@ -8608,7 +8594,7 @@ class MoneyInput extends Component {
8608
8594
  });
8609
8595
  }
8610
8596
  }
8611
- function filterOptionsForQuery$1(options, query) {
8597
+ function filterOptionsForQuery(options, query) {
8612
8598
  if (!query) {
8613
8599
  return options;
8614
8600
  }
@@ -10196,36 +10182,9 @@ const explodeNumberModel = number => {
10196
10182
  };
10197
10183
  };
10198
10184
 
10199
- /**
10200
- * Checks if query is contained into object properties.
10201
- *
10202
- * @param {object} option - the select option
10203
- * @param {string} query - the current search query
10204
- * @returns {boolean}
10205
- */
10206
- const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
10207
- const startsWith = (property, query) => {
10208
- if (isArray(property)) {
10209
- return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
10210
- }
10211
- return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
10212
- };
10213
- const normalizeValue = value => value.toLowerCase().replace('+', '');
10214
-
10215
- /**
10216
- * Filters a set of options based on search string
10217
- *
10218
- * @param options
10219
- * @param query
10220
- * @returns {*}
10221
- */
10222
- const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
10223
-
10224
10185
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
10225
10186
  const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
10226
10187
 
10227
- const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
10228
-
10229
10188
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
10230
10189
  const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
10231
10190
 
@@ -10304,17 +10263,15 @@ const PhoneNumberInput = props => {
10304
10263
  };
10305
10264
  const [internalValue, setInternalValue] = useState(getInitialValue());
10306
10265
  const [broadcastedValue, setBroadcastedValue] = useState(null);
10307
- const [searchQuery, setSearchQuery] = useState('');
10308
- const countriesList = excludeCountries(countries$1, disabledCountries);
10309
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10310
- const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
10311
10266
  const getSelectOptions = () => {
10312
- const filteredOptions = filterOptionsForQuery(isStringNumeric(searchQuery) ? listSortedByPhone : listSortedByISO3, searchQuery);
10313
- return filteredOptions.map(option => {
10267
+ const countriesList = excludeCountries(countries$1, disabledCountries);
10268
+ const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
10269
+ return listSortedByISO3.map(option => {
10314
10270
  const {
10315
10271
  phone,
10316
10272
  iso3,
10317
- iso2
10273
+ iso2,
10274
+ name
10318
10275
  } = option;
10319
10276
  let note = '';
10320
10277
  if (iso3) {
@@ -10323,9 +10280,13 @@ const PhoneNumberInput = props => {
10323
10280
  note = isArray(iso2) ? iso2.join(', ') : iso2;
10324
10281
  }
10325
10282
  return {
10326
- value: phone,
10327
- label: phone,
10328
- note
10283
+ type: 'option',
10284
+ value: {
10285
+ value: phone,
10286
+ label: phone,
10287
+ note: note
10288
+ },
10289
+ filterMatchers: [phone, note, name]
10329
10290
  };
10330
10291
  });
10331
10292
  };
@@ -10333,7 +10294,6 @@ const PhoneNumberInput = props => {
10333
10294
  const onPrefixChange = ({
10334
10295
  value
10335
10296
  }) => {
10336
- setSearchQuery('');
10337
10297
  setInternalValue({
10338
10298
  prefix: value,
10339
10299
  suffix: internalValue.suffix
@@ -10361,7 +10321,7 @@ const PhoneNumberInput = props => {
10361
10321
  } = explodeNumberModel(pastedValue);
10362
10322
  const selectedPrefix = options.find(({
10363
10323
  value
10364
- }) => value === pastedPrefix);
10324
+ }) => value.value === pastedPrefix);
10365
10325
  if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
10366
10326
  setInternalValue({
10367
10327
  prefix: pastedPrefix,
@@ -10386,22 +10346,19 @@ const PhoneNumberInput = props => {
10386
10346
  className: "tw-telephone",
10387
10347
  children: [/*#__PURE__*/jsx("div", {
10388
10348
  className: "tw-telephone__country-select",
10389
- children: /*#__PURE__*/jsx(Select, {
10390
- id: id ? `${id}-select` : undefined,
10391
- options: options,
10392
- selected: {
10393
- value: internalValue.prefix,
10394
- label: internalValue.prefix
10395
- },
10349
+ children: /*#__PURE__*/jsx(SelectInput, {
10396
10350
  placeholder: "Select an option...",
10397
- searchPlaceholder: searchPlaceholder,
10398
- dropdownWidth: Size.SMALL,
10399
- searchValue: searchQuery,
10400
- required: required,
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,
10401
10359
  disabled: disabled,
10402
10360
  size: size,
10403
10361
  onChange: onPrefixChange,
10404
- onSearchChange: newSearch => setSearchQuery(newSearch),
10405
10362
  ...selectProps
10406
10363
  })
10407
10364
  }), /*#__PURE__*/jsx("div", {