@transferwise/components 0.0.0-experimental-d6a1a50 → 0.0.0-experimental-ec79c77

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
@@ -1557,7 +1557,7 @@ class DimmerManager {
1557
1557
  /**
1558
1558
  * Dimmer refs
1559
1559
  */
1560
-
1560
+ dimmers;
1561
1561
  constructor() {
1562
1562
  this.dimmers = [];
1563
1563
  }
@@ -5433,6 +5433,7 @@ var DynamicFieldDefinitionList$1 = DynamicFieldDefinitionList;
5433
5433
  const ESCAPED_OPENING_CHEVRON = '<';
5434
5434
  const ESCAPED_CLOSING_CHEVRON = '>';
5435
5435
  class EmphasisHtmlTransformer {
5436
+ tags;
5436
5437
  constructor(whitelistedTags) {
5437
5438
  this.tags = (whitelistedTags || []).map(tag => {
5438
5439
  return {
@@ -7866,20 +7867,17 @@ function getValidLocale(locale) {
7866
7867
  Intl.NumberFormat(noUnderscoreLocale);
7867
7868
  return noUnderscoreLocale;
7868
7869
  } catch {
7869
- return 'en-GB';
7870
+ return DEFAULT_LOCALE;
7870
7871
  }
7871
7872
  }
7872
- function getCurrencyDecimals(currency = '') {
7873
+ function getCurrencyDecimals(currency) {
7873
7874
  const upperCaseCurrency = currency.toUpperCase();
7874
- if (Object.prototype.hasOwnProperty.call(currencyDecimals, upperCaseCurrency)) {
7875
- return currencyDecimals[upperCaseCurrency];
7876
- }
7877
- return DEFAULT_CURRENCY_DECIMALS;
7875
+ return currencyDecimals[upperCaseCurrency] ?? DEFAULT_CURRENCY_DECIMALS;
7878
7876
  }
7879
7877
  function getDecimalSeparator(locale) {
7880
7878
  return isNumberLocaleSupported() ? 1.1.toLocaleString(locale)[1] : '.';
7881
7879
  }
7882
- function parseAmount(number, currency, locale) {
7880
+ function parseAmount(number, currency, locale = DEFAULT_LOCALE) {
7883
7881
  const validLocale = getValidLocale(locale);
7884
7882
  const precision = getCurrencyDecimals(currency);
7885
7883
  const groupSeparator = isNumberLocaleSupported() ? 10000 .toLocaleString(validLocale)[2] : ',';
@@ -7889,18 +7887,10 @@ function parseAmount(number, currency, locale) {
7889
7887
  return Math.abs(parsedAmount);
7890
7888
  }
7891
7889
 
7892
- const Currency = PropTypes__default.default.shape({
7893
- header: PropTypes__default.default.string,
7894
- value: PropTypes__default.default.string,
7895
- label: PropTypes__default.default.string,
7896
- currency: PropTypes__default.default.string,
7897
- note: PropTypes__default.default.string,
7898
- searchable: PropTypes__default.default.string
7899
- });
7900
7890
  const isNumberOrNull = v => neptuneValidation.isNumber(v) || neptuneValidation.isNull(v);
7901
7891
  const formatAmountIfSet = (amount, currency, locale, maxLengthOverride) => {
7902
7892
  if (maxLengthOverride) {
7903
- return amount || '';
7893
+ return amount != null ? String(amount) : '';
7904
7894
  } else {
7905
7895
  return typeof amount === 'number' ? formatting.formatAmount(amount, currency, locale) : '';
7906
7896
  }
@@ -7912,30 +7902,32 @@ const parseNumber = (amount, currency, locale, maxLengthOverride) => {
7912
7902
  if (maxLengthOverride && amount.length > maxLengthOverride) {
7913
7903
  return 0;
7914
7904
  }
7915
- return +amount;
7905
+ return Number(amount);
7916
7906
  };
7917
7907
  const inputKeyCodeAllowlist = new Set([KeyCodes.BACKSPACE, KeyCodes.DELETE, KeyCodes.COMMA, KeyCodes.PERIOD, KeyCodes.DOWN, KeyCodes.UP, KeyCodes.LEFT, KeyCodes.RIGHT, KeyCodes.ENTER, KeyCodes.ESCAPE, KeyCodes.TAB]);
7918
7908
  const inputKeyAllowlist = new Set([Key.PERIOD, Key.COMMA]);
7919
7909
  class MoneyInput extends React.Component {
7910
+ static defaultProps = {
7911
+ size: exports.Size.LARGE,
7912
+ classNames: {},
7913
+ selectProps: {}
7914
+ };
7915
+ amountFocused = false;
7920
7916
  constructor(props) {
7921
7917
  super(props);
7922
- const {
7923
- locale
7924
- } = this.props.intl;
7925
- this.formatMessage = this.props.intl.formatMessage;
7926
7918
  this.state = {
7927
7919
  searchQuery: '',
7928
- formattedAmount: formatAmountIfSet(props.amount, props.selectedCurrency.currency, locale, props.maxLengthOverride),
7929
- locale
7920
+ formattedAmount: formatAmountIfSet(props.amount, props.selectedCurrency.currency, props.intl.locale, props.maxLengthOverride),
7921
+ locale: props.intl.locale
7930
7922
  };
7931
7923
  }
7932
7924
  UNSAFE_componentWillReceiveProps(nextProps) {
7933
7925
  this.setState({
7934
- locale: nextProps?.intl?.locale
7926
+ locale: nextProps.intl.locale
7935
7927
  });
7936
7928
  if (!this.amountFocused) {
7937
7929
  this.setState({
7938
- formattedAmount: formatAmountIfSet(nextProps.amount, nextProps.selectedCurrency.currency, nextProps?.intl?.locale, nextProps.maxLengthOverride)
7930
+ formattedAmount: formatAmountIfSet(nextProps.amount, nextProps.selectedCurrency.currency, nextProps.intl.locale, nextProps.maxLengthOverride)
7939
7931
  });
7940
7932
  }
7941
7933
  }
@@ -7955,7 +7947,7 @@ class MoneyInput extends React.Component {
7955
7947
  }
7956
7948
  };
7957
7949
  handlePaste = event => {
7958
- const paste = (event.clipboardData || window.clipboardData).getData('text');
7950
+ const paste = event.clipboardData.getData('text');
7959
7951
  const {
7960
7952
  locale
7961
7953
  } = this.state;
@@ -7964,7 +7956,7 @@ class MoneyInput extends React.Component {
7964
7956
  this.setState({
7965
7957
  formattedAmount: formatAmountIfSet(parsed, this.props.selectedCurrency.currency, locale, this.props.maxLengthOverride)
7966
7958
  });
7967
- this.props.onAmountChange(parsed);
7959
+ this.props.onAmountChange?.(parsed);
7968
7960
  }
7969
7961
  event.preventDefault();
7970
7962
  };
@@ -7977,7 +7969,7 @@ class MoneyInput extends React.Component {
7977
7969
  });
7978
7970
  const parsed = neptuneValidation.isEmpty(value) ? null : parseNumber(value, this.props.selectedCurrency.currency, this.state.locale, this.props.maxLengthOverride);
7979
7971
  if (isNumberOrNull(parsed)) {
7980
- this.props.onAmountChange(parsed);
7972
+ this.props.onAmountChange?.(parsed);
7981
7973
  }
7982
7974
  };
7983
7975
  onAmountBlur = () => {
@@ -7987,31 +7979,24 @@ class MoneyInput extends React.Component {
7987
7979
  onAmountFocus = () => {
7988
7980
  this.amountFocused = true;
7989
7981
  };
7990
- mapOption = item => {
7991
- return {
7992
- type: 'option',
7993
- value: item,
7994
- filterMatchers: [item.value, item.label, item.note, item.searchable]
7995
- };
7996
- };
7997
7982
  getSelectOptions() {
7998
- const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
7999
- let formattedOptions = [];
8000
- let groupIndex = null;
7983
+ const selectOptions = filterCurrenciesForQuery(this.props.currencies, this.state.searchQuery);
7984
+ const formattedOptions = [];
7985
+ let currentGroupOptions;
8001
7986
  selectOptions.forEach(item => {
8002
- if (item.header) {
7987
+ if (item.header != null) {
7988
+ currentGroupOptions = [];
8003
7989
  formattedOptions.push({
8004
7990
  type: 'group',
8005
7991
  label: item.header,
8006
- options: []
7992
+ options: currentGroupOptions
8007
7993
  });
8008
- groupIndex = formattedOptions.length - 1;
8009
7994
  } else {
8010
- if (groupIndex === null) {
8011
- formattedOptions.push(this.mapOption(item));
8012
- } else {
8013
- formattedOptions[groupIndex]?.options.push(this.mapOption(item));
8014
- }
7995
+ (currentGroupOptions ?? formattedOptions).push({
7996
+ type: 'option',
7997
+ value: item,
7998
+ filterMatchers: [item.value, item.label, item.note ?? '', item.searchable ?? '']
7999
+ });
8015
8000
  }
8016
8001
  });
8017
8002
  return formattedOptions;
@@ -8031,24 +8016,20 @@ class MoneyInput extends React.Component {
8031
8016
  }
8032
8017
  handleSelectChange = value => {
8033
8018
  this.handleSearchChange('');
8034
- this.props.onCurrencyChange(value);
8019
+ this.props.onCurrencyChange?.(value);
8035
8020
  };
8036
8021
  handleCustomAction = () => {
8037
8022
  this.handleSearchChange('');
8038
- if (this.props.onCustomAction) {
8039
- this.props.onCustomAction();
8040
- }
8023
+ this.props.onCustomAction?.();
8041
8024
  };
8042
8025
  handleSearchChange = searchQuery => {
8043
8026
  this.setState({
8044
8027
  searchQuery
8045
8028
  });
8046
- if (this.props.onSearchChange) {
8047
- this.props.onSearchChange({
8048
- searchQuery,
8049
- filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8050
- });
8051
- }
8029
+ this.props.onSearchChange?.({
8030
+ searchQuery,
8031
+ filteredOptions: filterCurrenciesForQuery(this.props.currencies, searchQuery)
8032
+ });
8052
8033
  };
8053
8034
  style = className => this.props.classNames[className] || className;
8054
8035
  render() {
@@ -8133,11 +8114,11 @@ class MoneyInput extends React.Component {
8133
8114
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events
8134
8115
  jsxRuntime.jsx("div", {
8135
8116
  role: "button",
8136
- tabIndex: "0",
8117
+ tabIndex: 0,
8137
8118
  onClick: this.handleCustomAction,
8138
8119
  children: this.props.customActionLabel
8139
- }) : null,
8140
- placeholder: this.formatMessage(messages$3.selectPlaceholder),
8120
+ }) : undefined,
8121
+ placeholder: this.props.intl.formatMessage(messages$3.selectPlaceholder),
8141
8122
  filterable: true,
8142
8123
  filterPlaceholder: this.props.searchPlaceholder,
8143
8124
  disabled: disabled,
@@ -8154,25 +8135,25 @@ class MoneyInput extends React.Component {
8154
8135
  });
8155
8136
  }
8156
8137
  }
8157
- function filterOptionsForQuery(options, query) {
8138
+ function filterCurrenciesForQuery(currencies, query) {
8158
8139
  if (!query) {
8159
- return options;
8140
+ return [...currencies];
8160
8141
  }
8161
- const filteredOptions = removeDuplicateValueOptions(options).filter(option => isCurrencyOptionAndFitsQuery(option, query));
8142
+ const options = currencies.filter(option => option.header == null);
8143
+ const filteredOptions = removeDuplicateValueOptions(options).filter(option => currencyOptionFitsQuery(option, query));
8162
8144
  return sortOptionsLabelsToFirst(filteredOptions, query);
8163
8145
  }
8164
8146
  function removeDuplicateValueOptions(options) {
8165
- const result = [];
8166
- const resultValues = [];
8167
- options.forEach(option => {
8168
- if (option.value && !resultValues.includes(option.value)) {
8169
- result.push(option);
8170
- resultValues.push(option.value);
8147
+ const uniqueValues = new Set();
8148
+ return options.filter(option => {
8149
+ if (!uniqueValues.has(option.value)) {
8150
+ uniqueValues.add(option.value);
8151
+ return true;
8171
8152
  }
8153
+ return false;
8172
8154
  });
8173
- return result;
8174
8155
  }
8175
- function isCurrencyOptionAndFitsQuery(option, query) {
8156
+ function currencyOptionFitsQuery(option, query) {
8176
8157
  if (!option.value) {
8177
8158
  return false;
8178
8159
  }
@@ -8197,43 +8178,6 @@ function sortOptionsLabelsToFirst(options, query) {
8197
8178
  return 0;
8198
8179
  });
8199
8180
  }
8200
- MoneyInput.propTypes = {
8201
- id: PropTypes__default.default.string,
8202
- currencies: PropTypes__default.default.arrayOf(Currency).isRequired,
8203
- selectedCurrency: Currency.isRequired,
8204
- onCurrencyChange: PropTypes__default.default.func,
8205
- placeholder: PropTypes__default.default.number,
8206
- amount: PropTypes__default.default.number,
8207
- size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
8208
- onAmountChange: PropTypes__default.default.func,
8209
- addon: PropTypes__default.default.node,
8210
- searchPlaceholder: PropTypes__default.default.string,
8211
- /**
8212
- * Allows the consumer to react to searching, while the search itself is handled internally. Called with `{ searchQuery: string, filteredOptions: Currency[] }`
8213
- */
8214
- onSearchChange: PropTypes__default.default.func,
8215
- customActionLabel: PropTypes__default.default.node,
8216
- onCustomAction: PropTypes__default.default.func,
8217
- classNames: PropTypes__default.default.objectOf(PropTypes__default.default.string),
8218
- selectProps: PropTypes__default.default.object,
8219
- maxLengthOverride: PropTypes__default.default.number
8220
- };
8221
- MoneyInput.defaultProps = {
8222
- id: null,
8223
- size: exports.Size.LARGE,
8224
- addon: null,
8225
- searchPlaceholder: '',
8226
- onSearchChange: undefined,
8227
- onCurrencyChange: null,
8228
- placeholder: null,
8229
- amount: null,
8230
- onAmountChange: null,
8231
- customActionLabel: '',
8232
- onCustomAction: null,
8233
- classNames: {},
8234
- selectProps: {},
8235
- maxLengthOverride: null
8236
- };
8237
8181
  var MoneyInput$1 = reactIntl.injectIntl(MoneyInput);
8238
8182
 
8239
8183
  const NavigationOptionList = ({