@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.
@@ -1523,7 +1523,7 @@ class DimmerManager {
1523
1523
  /**
1524
1524
  * Dimmer refs
1525
1525
  */
1526
-
1526
+ dimmers;
1527
1527
  constructor() {
1528
1528
  this.dimmers = [];
1529
1529
  }
@@ -5399,6 +5399,7 @@ var DynamicFieldDefinitionList$1 = DynamicFieldDefinitionList;
5399
5399
  const ESCAPED_OPENING_CHEVRON = '<';
5400
5400
  const ESCAPED_CLOSING_CHEVRON = '>';
5401
5401
  class EmphasisHtmlTransformer {
5402
+ tags;
5402
5403
  constructor(whitelistedTags) {
5403
5404
  this.tags = (whitelistedTags || []).map(tag => {
5404
5405
  return {
@@ -7832,20 +7833,17 @@ function getValidLocale(locale) {
7832
7833
  Intl.NumberFormat(noUnderscoreLocale);
7833
7834
  return noUnderscoreLocale;
7834
7835
  } catch {
7835
- return 'en-GB';
7836
+ return DEFAULT_LOCALE;
7836
7837
  }
7837
7838
  }
7838
- function getCurrencyDecimals(currency = '') {
7839
+ function getCurrencyDecimals(currency) {
7839
7840
  const upperCaseCurrency = currency.toUpperCase();
7840
- if (Object.prototype.hasOwnProperty.call(currencyDecimals, upperCaseCurrency)) {
7841
- return currencyDecimals[upperCaseCurrency];
7842
- }
7843
- return DEFAULT_CURRENCY_DECIMALS;
7841
+ return currencyDecimals[upperCaseCurrency] ?? DEFAULT_CURRENCY_DECIMALS;
7844
7842
  }
7845
7843
  function getDecimalSeparator(locale) {
7846
7844
  return isNumberLocaleSupported() ? 1.1.toLocaleString(locale)[1] : '.';
7847
7845
  }
7848
- function parseAmount(number, currency, locale) {
7846
+ function parseAmount(number, currency, locale = DEFAULT_LOCALE) {
7849
7847
  const validLocale = getValidLocale(locale);
7850
7848
  const precision = getCurrencyDecimals(currency);
7851
7849
  const groupSeparator = isNumberLocaleSupported() ? 10000 .toLocaleString(validLocale)[2] : ',';
@@ -7855,18 +7853,10 @@ function parseAmount(number, currency, locale) {
7855
7853
  return Math.abs(parsedAmount);
7856
7854
  }
7857
7855
 
7858
- const Currency = PropTypes.shape({
7859
- header: PropTypes.string,
7860
- value: PropTypes.string,
7861
- label: PropTypes.string,
7862
- currency: PropTypes.string,
7863
- note: PropTypes.string,
7864
- searchable: PropTypes.string
7865
- });
7866
7856
  const isNumberOrNull = v => isNumber(v) || isNull(v);
7867
7857
  const formatAmountIfSet = (amount, currency, locale, maxLengthOverride) => {
7868
7858
  if (maxLengthOverride) {
7869
- return amount || '';
7859
+ return amount != null ? String(amount) : '';
7870
7860
  } else {
7871
7861
  return typeof amount === 'number' ? formatAmount(amount, currency, locale) : '';
7872
7862
  }
@@ -7878,30 +7868,32 @@ const parseNumber = (amount, currency, locale, maxLengthOverride) => {
7878
7868
  if (maxLengthOverride && amount.length > maxLengthOverride) {
7879
7869
  return 0;
7880
7870
  }
7881
- return +amount;
7871
+ return Number(amount);
7882
7872
  };
7883
7873
  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]);
7884
7874
  const inputKeyAllowlist = new Set([Key.PERIOD, Key.COMMA]);
7885
7875
  class MoneyInput extends Component {
7876
+ static defaultProps = {
7877
+ size: Size.LARGE,
7878
+ classNames: {},
7879
+ selectProps: {}
7880
+ };
7881
+ amountFocused = false;
7886
7882
  constructor(props) {
7887
7883
  super(props);
7888
- const {
7889
- locale
7890
- } = this.props.intl;
7891
- this.formatMessage = this.props.intl.formatMessage;
7892
7884
  this.state = {
7893
7885
  searchQuery: '',
7894
- formattedAmount: formatAmountIfSet(props.amount, props.selectedCurrency.currency, locale, props.maxLengthOverride),
7895
- locale
7886
+ formattedAmount: formatAmountIfSet(props.amount, props.selectedCurrency.currency, props.intl.locale, props.maxLengthOverride),
7887
+ locale: props.intl.locale
7896
7888
  };
7897
7889
  }
7898
7890
  UNSAFE_componentWillReceiveProps(nextProps) {
7899
7891
  this.setState({
7900
- locale: nextProps?.intl?.locale
7892
+ locale: nextProps.intl.locale
7901
7893
  });
7902
7894
  if (!this.amountFocused) {
7903
7895
  this.setState({
7904
- formattedAmount: formatAmountIfSet(nextProps.amount, nextProps.selectedCurrency.currency, nextProps?.intl?.locale, nextProps.maxLengthOverride)
7896
+ formattedAmount: formatAmountIfSet(nextProps.amount, nextProps.selectedCurrency.currency, nextProps.intl.locale, nextProps.maxLengthOverride)
7905
7897
  });
7906
7898
  }
7907
7899
  }
@@ -7921,7 +7913,7 @@ class MoneyInput extends Component {
7921
7913
  }
7922
7914
  };
7923
7915
  handlePaste = event => {
7924
- const paste = (event.clipboardData || window.clipboardData).getData('text');
7916
+ const paste = event.clipboardData.getData('text');
7925
7917
  const {
7926
7918
  locale
7927
7919
  } = this.state;
@@ -7930,7 +7922,7 @@ class MoneyInput extends Component {
7930
7922
  this.setState({
7931
7923
  formattedAmount: formatAmountIfSet(parsed, this.props.selectedCurrency.currency, locale, this.props.maxLengthOverride)
7932
7924
  });
7933
- this.props.onAmountChange(parsed);
7925
+ this.props.onAmountChange?.(parsed);
7934
7926
  }
7935
7927
  event.preventDefault();
7936
7928
  };
@@ -7943,7 +7935,7 @@ class MoneyInput extends Component {
7943
7935
  });
7944
7936
  const parsed = isEmpty(value) ? null : parseNumber(value, this.props.selectedCurrency.currency, this.state.locale, this.props.maxLengthOverride);
7945
7937
  if (isNumberOrNull(parsed)) {
7946
- this.props.onAmountChange(parsed);
7938
+ this.props.onAmountChange?.(parsed);
7947
7939
  }
7948
7940
  };
7949
7941
  onAmountBlur = () => {
@@ -7953,31 +7945,24 @@ class MoneyInput extends Component {
7953
7945
  onAmountFocus = () => {
7954
7946
  this.amountFocused = true;
7955
7947
  };
7956
- mapOption = item => {
7957
- return {
7958
- type: 'option',
7959
- value: item,
7960
- filterMatchers: [item.value, item.label, item.note, item.searchable]
7961
- };
7962
- };
7963
7948
  getSelectOptions() {
7964
- const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
7965
- let formattedOptions = [];
7966
- let groupIndex = null;
7949
+ const selectOptions = filterCurrenciesForQuery(this.props.currencies, this.state.searchQuery);
7950
+ const formattedOptions = [];
7951
+ let currentGroupOptions;
7967
7952
  selectOptions.forEach(item => {
7968
- if (item.header) {
7953
+ if (item.header != null) {
7954
+ currentGroupOptions = [];
7969
7955
  formattedOptions.push({
7970
7956
  type: 'group',
7971
7957
  label: item.header,
7972
- options: []
7958
+ options: currentGroupOptions
7973
7959
  });
7974
- groupIndex = formattedOptions.length - 1;
7975
7960
  } else {
7976
- if (groupIndex === null) {
7977
- formattedOptions.push(this.mapOption(item));
7978
- } else {
7979
- formattedOptions[groupIndex]?.options.push(this.mapOption(item));
7980
- }
7961
+ (currentGroupOptions ?? formattedOptions).push({
7962
+ type: 'option',
7963
+ value: item,
7964
+ filterMatchers: [item.value, item.label, item.note ?? '', item.searchable ?? '']
7965
+ });
7981
7966
  }
7982
7967
  });
7983
7968
  return formattedOptions;
@@ -7997,24 +7982,20 @@ class MoneyInput extends Component {
7997
7982
  }
7998
7983
  handleSelectChange = value => {
7999
7984
  this.handleSearchChange('');
8000
- this.props.onCurrencyChange(value);
7985
+ this.props.onCurrencyChange?.(value);
8001
7986
  };
8002
7987
  handleCustomAction = () => {
8003
7988
  this.handleSearchChange('');
8004
- if (this.props.onCustomAction) {
8005
- this.props.onCustomAction();
8006
- }
7989
+ this.props.onCustomAction?.();
8007
7990
  };
8008
7991
  handleSearchChange = searchQuery => {
8009
7992
  this.setState({
8010
7993
  searchQuery
8011
7994
  });
8012
- if (this.props.onSearchChange) {
8013
- this.props.onSearchChange({
8014
- searchQuery,
8015
- filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8016
- });
8017
- }
7995
+ this.props.onSearchChange?.({
7996
+ searchQuery,
7997
+ filteredOptions: filterCurrenciesForQuery(this.props.currencies, searchQuery)
7998
+ });
8018
7999
  };
8019
8000
  style = className => this.props.classNames[className] || className;
8020
8001
  render() {
@@ -8099,11 +8080,11 @@ class MoneyInput extends Component {
8099
8080
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events
8100
8081
  jsx("div", {
8101
8082
  role: "button",
8102
- tabIndex: "0",
8083
+ tabIndex: 0,
8103
8084
  onClick: this.handleCustomAction,
8104
8085
  children: this.props.customActionLabel
8105
- }) : null,
8106
- placeholder: this.formatMessage(messages$3.selectPlaceholder),
8086
+ }) : undefined,
8087
+ placeholder: this.props.intl.formatMessage(messages$3.selectPlaceholder),
8107
8088
  filterable: true,
8108
8089
  filterPlaceholder: this.props.searchPlaceholder,
8109
8090
  disabled: disabled,
@@ -8120,25 +8101,25 @@ class MoneyInput extends Component {
8120
8101
  });
8121
8102
  }
8122
8103
  }
8123
- function filterOptionsForQuery(options, query) {
8104
+ function filterCurrenciesForQuery(currencies, query) {
8124
8105
  if (!query) {
8125
- return options;
8106
+ return [...currencies];
8126
8107
  }
8127
- const filteredOptions = removeDuplicateValueOptions(options).filter(option => isCurrencyOptionAndFitsQuery(option, query));
8108
+ const options = currencies.filter(option => option.header == null);
8109
+ const filteredOptions = removeDuplicateValueOptions(options).filter(option => currencyOptionFitsQuery(option, query));
8128
8110
  return sortOptionsLabelsToFirst(filteredOptions, query);
8129
8111
  }
8130
8112
  function removeDuplicateValueOptions(options) {
8131
- const result = [];
8132
- const resultValues = [];
8133
- options.forEach(option => {
8134
- if (option.value && !resultValues.includes(option.value)) {
8135
- result.push(option);
8136
- resultValues.push(option.value);
8113
+ const uniqueValues = new Set();
8114
+ return options.filter(option => {
8115
+ if (!uniqueValues.has(option.value)) {
8116
+ uniqueValues.add(option.value);
8117
+ return true;
8137
8118
  }
8119
+ return false;
8138
8120
  });
8139
- return result;
8140
8121
  }
8141
- function isCurrencyOptionAndFitsQuery(option, query) {
8122
+ function currencyOptionFitsQuery(option, query) {
8142
8123
  if (!option.value) {
8143
8124
  return false;
8144
8125
  }
@@ -8163,43 +8144,6 @@ function sortOptionsLabelsToFirst(options, query) {
8163
8144
  return 0;
8164
8145
  });
8165
8146
  }
8166
- MoneyInput.propTypes = {
8167
- id: PropTypes.string,
8168
- currencies: PropTypes.arrayOf(Currency).isRequired,
8169
- selectedCurrency: Currency.isRequired,
8170
- onCurrencyChange: PropTypes.func,
8171
- placeholder: PropTypes.number,
8172
- amount: PropTypes.number,
8173
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
8174
- onAmountChange: PropTypes.func,
8175
- addon: PropTypes.node,
8176
- searchPlaceholder: PropTypes.string,
8177
- /**
8178
- * Allows the consumer to react to searching, while the search itself is handled internally. Called with `{ searchQuery: string, filteredOptions: Currency[] }`
8179
- */
8180
- onSearchChange: PropTypes.func,
8181
- customActionLabel: PropTypes.node,
8182
- onCustomAction: PropTypes.func,
8183
- classNames: PropTypes.objectOf(PropTypes.string),
8184
- selectProps: PropTypes.object,
8185
- maxLengthOverride: PropTypes.number
8186
- };
8187
- MoneyInput.defaultProps = {
8188
- id: null,
8189
- size: Size.LARGE,
8190
- addon: null,
8191
- searchPlaceholder: '',
8192
- onSearchChange: undefined,
8193
- onCurrencyChange: null,
8194
- placeholder: null,
8195
- amount: null,
8196
- onAmountChange: null,
8197
- customActionLabel: '',
8198
- onCustomAction: null,
8199
- classNames: {},
8200
- selectProps: {},
8201
- maxLengthOverride: null
8202
- };
8203
8147
  var MoneyInput$1 = injectIntl(MoneyInput);
8204
8148
 
8205
8149
  const NavigationOptionList = ({