@transferwise/components 46.4.0 → 46.6.0

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.
Files changed (69) hide show
  1. package/build/i18n/th.json +3 -3
  2. package/build/index.esm.js +177 -239
  3. package/build/index.esm.js.map +1 -1
  4. package/build/index.js +178 -240
  5. package/build/index.js.map +1 -1
  6. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
  7. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
  8. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +2 -2
  9. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
  10. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
  11. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
  12. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
  13. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
  14. package/build/types/index.d.ts +3 -0
  15. package/build/types/index.d.ts.map +1 -1
  16. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +7 -11
  17. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
  18. package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
  19. package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
  20. package/build/types/inputs/SelectInput.d.ts +2 -2
  21. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  22. package/build/types/moneyInput/MoneyInput.d.ts +45 -31
  23. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  24. package/build/types/moneyInput/MoneyInput.messages.d.ts +6 -6
  25. package/build/types/moneyInput/MoneyInput.messages.d.ts.map +1 -1
  26. package/build/types/moneyInput/currencyFormatting.d.ts +2 -2
  27. package/build/types/moneyInput/currencyFormatting.d.ts.map +1 -1
  28. package/build/types/moneyInput/index.d.ts +2 -1
  29. package/build/types/moneyInput/index.d.ts.map +1 -1
  30. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +7 -11
  31. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  32. package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
  33. package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
  34. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +55 -83
  35. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  36. package/build/types/withDisplayFormat/index.d.ts +2 -1
  37. package/build/types/withDisplayFormat/index.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
  40. package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
  41. package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
  42. package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
  43. package/src/flowNavigation/FlowNavigation.story.js +1 -1
  44. package/src/i18n/th.json +3 -3
  45. package/src/index.ts +8 -0
  46. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
  47. package/src/inputWithDisplayFormat/index.ts +2 -0
  48. package/src/inputs/SelectInput.tsx +2 -2
  49. package/src/moneyInput/{MoneyInput.rtl.spec.js → MoneyInput.rtl.spec.tsx} +4 -4
  50. package/src/moneyInput/MoneyInput.spec.js +109 -49
  51. package/src/moneyInput/MoneyInput.story.tsx +6 -14
  52. package/src/moneyInput/{MoneyInput.js → MoneyInput.tsx} +189 -173
  53. package/src/moneyInput/{currencyFormatting.spec.js → currencyFormatting.spec.ts} +2 -2
  54. package/src/moneyInput/{currencyFormatting.js → currencyFormatting.ts} +7 -10
  55. package/src/moneyInput/index.ts +7 -0
  56. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
  57. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
  58. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
  59. package/src/textareaWithDisplayFormat/index.ts +2 -0
  60. package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
  61. package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
  62. package/src/withDisplayFormat/index.ts +2 -0
  63. package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
  64. package/src/inputWithDisplayFormat/index.js +0 -1
  65. package/src/moneyInput/index.js +0 -1
  66. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
  67. package/src/textareaWithDisplayFormat/index.js +0 -1
  68. package/src/withDisplayFormat/index.js +0 -1
  69. /package/src/moneyInput/{MoneyInput.messages.js → MoneyInput.messages.ts} +0 -0
@@ -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 {
@@ -7262,10 +7263,13 @@ const formatWithPattern = (value, pattern) => {
7262
7263
  let patternSymbol = [];
7263
7264
  // valueArray.length increments during the cycle cause we are adding new elements.
7264
7265
  for (let index = 0; index < valueArray.length; index += 1) {
7265
- patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7266
+ patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
7266
7267
  // Add pattern's symbol at n position
7267
7268
  if (patternSymbol.length === 1) {
7268
- valueArray.splice(index, 0, patternSymbol.pop().symbol);
7269
+ const last = patternSymbol.pop();
7270
+ if (last) {
7271
+ valueArray.splice(index, 0, last.symbol);
7272
+ }
7269
7273
  }
7270
7274
  }
7271
7275
  return valueArray.join('');
@@ -7311,7 +7315,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
7311
7315
  return groupSize;
7312
7316
  };
7313
7317
 
7314
- const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7318
+ const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7315
7319
  let cursorPosition = selectionStart;
7316
7320
  switch (action) {
7317
7321
  case 'Backspace':
@@ -7333,36 +7337,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7333
7337
  }
7334
7338
  return cursorPosition;
7335
7339
  };
7336
- var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7340
+ var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
7337
7341
 
7338
7342
  class WithDisplayFormat extends Component {
7343
+ static defaultProps = {
7344
+ autoComplete: 'off',
7345
+ displayPattern: '',
7346
+ value: ''
7347
+ };
7339
7348
  constructor(props) {
7340
7349
  super(props);
7341
- const {
7342
- value,
7343
- displayPattern
7344
- } = props;
7345
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7350
+ const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
7346
7351
  this.state = {
7347
- value: formatWithPattern$1(unformattedValue, displayPattern),
7352
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7348
7353
  historyNavigator: new HistoryNavigator$1(),
7349
7354
  prevDisplayPattern: props.displayPattern,
7350
- triggerType: null,
7351
- triggerEvent: null
7355
+ triggerType: 'Initial',
7356
+ triggerEvent: null,
7357
+ selectionStart: 0,
7358
+ selectionEnd: 0,
7359
+ pastedLength: 0
7352
7360
  };
7353
7361
  }
7354
- static getDerivedStateFromProps(nextProps, previousState) {
7355
- const {
7356
- displayPattern
7357
- } = nextProps;
7358
- const {
7359
- prevDisplayPattern
7360
- } = previousState;
7361
- if (previousState.prevDisplayPattern !== displayPattern) {
7362
- const {
7363
- value,
7364
- historyNavigator
7365
- } = previousState;
7362
+ static getDerivedStateFromProps({
7363
+ displayPattern
7364
+ }, {
7365
+ prevDisplayPattern = displayPattern,
7366
+ value,
7367
+ historyNavigator
7368
+ }) {
7369
+ if (prevDisplayPattern !== displayPattern) {
7366
7370
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7367
7371
  historyNavigator.reset();
7368
7372
  return {
@@ -7384,29 +7388,31 @@ class WithDisplayFormat extends Component {
7384
7388
  const {
7385
7389
  displayPattern
7386
7390
  } = this.props;
7387
- const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7388
- if (triggerType === 'Paste' || triggerType === 'Cut') {
7389
- return triggerType;
7390
- }
7391
- if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7392
- return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7393
- }
7394
- // Detect mouse event redo
7395
- if (triggerEvent.ctrlKey && charCode === 'd') {
7396
- return 'Delete';
7397
- }
7398
-
7399
- // Android Fix.
7400
- if (typeof triggerEvent.key === 'undefined') {
7401
- if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7391
+ if (triggerEvent) {
7392
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7393
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7394
+ return triggerType;
7395
+ }
7396
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7397
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7398
+ }
7399
+ // Detect mouse event redo
7400
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7401
+ return 'Delete';
7402
+ }
7403
+ // Android Fix.
7404
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7402
7405
  return 'Backspace';
7403
7406
  }
7407
+ return triggerEvent.key;
7408
+ } else {
7409
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7410
+ return 'Paste';
7404
7411
  }
7405
- return triggerEvent.key;
7406
7412
  };
7407
7413
  resetEvent = () => {
7408
7414
  this.setState({
7409
- triggerType: null,
7415
+ triggerType: 'Initial',
7410
7416
  triggerEvent: null,
7411
7417
  pastedLength: 0
7412
7418
  });
@@ -7423,14 +7429,13 @@ class WithDisplayFormat extends Component {
7423
7429
  const {
7424
7430
  selectionStart,
7425
7431
  selectionEnd
7426
- } = event.target;
7432
+ } = event.currentTarget;
7427
7433
  const {
7428
7434
  historyNavigator
7429
7435
  } = this.state;
7430
7436
  const {
7431
7437
  displayPattern
7432
7438
  } = this.props;
7433
-
7434
7439
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7435
7440
  let newFormattedValue = '';
7436
7441
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7449,8 +7454,8 @@ class WithDisplayFormat extends Component {
7449
7454
  this.setState({
7450
7455
  triggerEvent: event,
7451
7456
  triggerType: 'KeyDown',
7452
- selectionStart,
7453
- selectionEnd
7457
+ selectionStart: selectionStart ?? 0,
7458
+ selectionEnd: selectionEnd ?? 0
7454
7459
  });
7455
7460
  }
7456
7461
  };
@@ -7479,7 +7484,6 @@ class WithDisplayFormat extends Component {
7479
7484
  handleOnChange = event => {
7480
7485
  const {
7481
7486
  historyNavigator,
7482
- triggerEvent,
7483
7487
  triggerType
7484
7488
  } = this.state;
7485
7489
  const {
@@ -7490,9 +7494,7 @@ class WithDisplayFormat extends Component {
7490
7494
  value
7491
7495
  } = event.target;
7492
7496
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7493
- const action = triggerEvent === null ?
7494
- // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7495
- 'Paste' : this.getUserAction(unformattedValue);
7497
+ const action = this.getUserAction(unformattedValue);
7496
7498
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7497
7499
  return;
7498
7500
  }
@@ -7502,19 +7504,18 @@ class WithDisplayFormat extends Component {
7502
7504
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7503
7505
  historyNavigator.add(unformattedValue);
7504
7506
  this.handleCursorPositioning(action);
7505
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7506
7507
  this.setState({
7507
7508
  value: newFormattedValue
7508
- }, this.resetEvent(), onChange(broadcastValue));
7509
+ }, () => {
7510
+ this.resetEvent();
7511
+ if (onChange) {
7512
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7513
+ onChange(broadcastValue);
7514
+ }
7515
+ });
7509
7516
  };
7510
7517
  handleOnBlur = event => {
7511
- const {
7512
- displayPattern,
7513
- onBlur
7514
- } = this.props;
7515
- if (onBlur) {
7516
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7517
- }
7518
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7518
7519
  };
7519
7520
  handleOnFocus = event => {
7520
7521
  const {
@@ -7563,7 +7564,7 @@ class WithDisplayFormat extends Component {
7563
7564
  const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
7564
7565
  setTimeout(() => {
7565
7566
  if (triggerEvent) {
7566
- triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
7567
+ triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7567
7568
  }
7568
7569
  this.setState({
7569
7570
  selectionStart: cursorPosition,
@@ -7573,7 +7574,6 @@ class WithDisplayFormat extends Component {
7573
7574
  };
7574
7575
  render() {
7575
7576
  const {
7576
- type,
7577
7577
  inputMode,
7578
7578
  className,
7579
7579
  id,
@@ -7590,7 +7590,6 @@ class WithDisplayFormat extends Component {
7590
7590
  value
7591
7591
  } = this.state;
7592
7592
  const renderProps = {
7593
- type,
7594
7593
  inputMode,
7595
7594
  className,
7596
7595
  id,
@@ -7613,62 +7612,13 @@ class WithDisplayFormat extends Component {
7613
7612
  return this.props.render(renderProps);
7614
7613
  }
7615
7614
  }
7616
- WithDisplayFormat.propTypes = {
7617
- /**
7618
- * autocomplete hides our form help so we need to disable it when help text
7619
- * is present. Chrome ignores autocomplete=off, the only way to disable it is
7620
- * to provide an 'invalid' value, for which 'disabled' serves.
7621
- */
7622
- autoComplete: PropTypes.oneOf(['on', 'off', 'disabled']),
7623
- className: PropTypes.string,
7624
- disabled: PropTypes.bool,
7625
- id: PropTypes.string,
7626
- maxLength: PropTypes.number,
7627
- minLength: PropTypes.number,
7628
- name: PropTypes.string,
7629
- onFocus: PropTypes.func,
7630
- onBlur: PropTypes.func,
7631
- onChange: PropTypes.func.isRequired,
7632
- placeholder: PropTypes.string,
7633
- readOnly: PropTypes.bool,
7634
- render: PropTypes.func.isRequired,
7635
- required: PropTypes.bool,
7636
- displayPattern: PropTypes.string,
7637
- type: PropTypes.string,
7638
- inputMode: PropTypes.string,
7639
- value: PropTypes.string
7640
- };
7641
- WithDisplayFormat.defaultProps = {
7642
- autoComplete: 'off',
7643
- className: null,
7644
- disabled: false,
7645
- id: null,
7646
- maxLength: null,
7647
- minLength: null,
7648
- name: null,
7649
- placeholder: null,
7650
- readOnly: false,
7651
- required: false,
7652
- displayPattern: '',
7653
- type: 'text',
7654
- inputMode: null,
7655
- value: '',
7656
- onFocus: null,
7657
- onBlur: null
7658
- };
7659
- var WithDisplayFormat$1 = WithDisplayFormat;
7660
7615
 
7661
- const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
7616
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
7662
7617
  ...props,
7663
- render: renderProps => /*#__PURE__*/jsx("input", {
7618
+ render: renderProps => /*#__PURE__*/jsx(Input, {
7664
7619
  ...renderProps
7665
7620
  })
7666
7621
  });
7667
- InputWithDisplayFormat.propTypes = {
7668
- displayPattern: PropTypes.string.isRequired,
7669
- onChange: PropTypes.func.isRequired
7670
- };
7671
- var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7672
7622
 
7673
7623
  const InstructionsList = ({
7674
7624
  dos,
@@ -7832,20 +7782,17 @@ function getValidLocale(locale) {
7832
7782
  Intl.NumberFormat(noUnderscoreLocale);
7833
7783
  return noUnderscoreLocale;
7834
7784
  } catch {
7835
- return 'en-GB';
7785
+ return DEFAULT_LOCALE;
7836
7786
  }
7837
7787
  }
7838
- function getCurrencyDecimals(currency = '') {
7788
+ function getCurrencyDecimals(currency) {
7839
7789
  const upperCaseCurrency = currency.toUpperCase();
7840
- if (Object.prototype.hasOwnProperty.call(currencyDecimals, upperCaseCurrency)) {
7841
- return currencyDecimals[upperCaseCurrency];
7842
- }
7843
- return DEFAULT_CURRENCY_DECIMALS;
7790
+ return currencyDecimals[upperCaseCurrency] ?? DEFAULT_CURRENCY_DECIMALS;
7844
7791
  }
7845
7792
  function getDecimalSeparator(locale) {
7846
7793
  return isNumberLocaleSupported() ? 1.1.toLocaleString(locale)[1] : '.';
7847
7794
  }
7848
- function parseAmount(number, currency, locale) {
7795
+ function parseAmount(number, currency, locale = DEFAULT_LOCALE) {
7849
7796
  const validLocale = getValidLocale(locale);
7850
7797
  const precision = getCurrencyDecimals(currency);
7851
7798
  const groupSeparator = isNumberLocaleSupported() ? 10000 .toLocaleString(validLocale)[2] : ',';
@@ -7855,53 +7802,67 @@ function parseAmount(number, currency, locale) {
7855
7802
  return Math.abs(parsedAmount);
7856
7803
  }
7857
7804
 
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
7805
  const isNumberOrNull = v => isNumber(v) || isNull(v);
7867
- const formatAmountIfSet = (amount, currency, locale, maxLengthOverride) => {
7806
+ const formatAmountIfSet = ({
7807
+ amount,
7808
+ currency,
7809
+ locale,
7810
+ maxLengthOverride
7811
+ }) => {
7868
7812
  if (maxLengthOverride) {
7869
- return amount || '';
7813
+ return amount != null ? String(amount) : '';
7870
7814
  } else {
7871
7815
  return typeof amount === 'number' ? formatAmount(amount, currency, locale) : '';
7872
7816
  }
7873
7817
  };
7874
- const parseNumber = (amount, currency, locale, maxLengthOverride) => {
7818
+ const parseNumber = ({
7819
+ amount,
7820
+ currency,
7821
+ locale,
7822
+ maxLengthOverride
7823
+ }) => {
7875
7824
  if (!maxLengthOverride) {
7876
7825
  return parseAmount(amount, currency, locale);
7877
7826
  }
7878
7827
  if (maxLengthOverride && amount.length > maxLengthOverride) {
7879
7828
  return 0;
7880
7829
  }
7881
- return +amount;
7830
+ return Number(amount);
7882
7831
  };
7883
7832
  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
7833
  const inputKeyAllowlist = new Set([Key.PERIOD, Key.COMMA]);
7885
7834
  class MoneyInput extends Component {
7835
+ static defaultProps = {
7836
+ size: Size.LARGE,
7837
+ classNames: {},
7838
+ selectProps: {}
7839
+ };
7840
+ amountFocused = false;
7886
7841
  constructor(props) {
7887
7842
  super(props);
7888
- const {
7889
- locale
7890
- } = this.props.intl;
7891
- this.formatMessage = this.props.intl.formatMessage;
7892
7843
  this.state = {
7893
7844
  searchQuery: '',
7894
- formattedAmount: formatAmountIfSet(props.amount, props.selectedCurrency.currency, locale, props.maxLengthOverride),
7895
- locale
7845
+ formattedAmount: formatAmountIfSet({
7846
+ amount: props.amount,
7847
+ currency: props.selectedCurrency.currency,
7848
+ locale: props.intl.locale,
7849
+ maxLengthOverride: props.maxLengthOverride
7850
+ }),
7851
+ locale: props.intl.locale
7896
7852
  };
7897
7853
  }
7898
7854
  UNSAFE_componentWillReceiveProps(nextProps) {
7899
7855
  this.setState({
7900
- locale: nextProps?.intl?.locale
7856
+ locale: nextProps.intl.locale
7901
7857
  });
7902
7858
  if (!this.amountFocused) {
7903
7859
  this.setState({
7904
- formattedAmount: formatAmountIfSet(nextProps.amount, nextProps.selectedCurrency.currency, nextProps?.intl?.locale, nextProps.maxLengthOverride)
7860
+ formattedAmount: formatAmountIfSet({
7861
+ amount: nextProps.amount,
7862
+ currency: nextProps.selectedCurrency.currency,
7863
+ locale: nextProps.intl.locale,
7864
+ maxLengthOverride: nextProps.maxLengthOverride
7865
+ })
7905
7866
  });
7906
7867
  }
7907
7868
  }
@@ -7921,16 +7882,26 @@ class MoneyInput extends Component {
7921
7882
  }
7922
7883
  };
7923
7884
  handlePaste = event => {
7924
- const paste = (event.clipboardData || window.clipboardData).getData('text');
7885
+ const paste = event.clipboardData.getData('text');
7925
7886
  const {
7926
7887
  locale
7927
7888
  } = this.state;
7928
- const parsed = isEmpty(paste) ? null : parseNumber(paste, this.props.selectedCurrency.currency, locale, this.props.maxLengthOverride);
7889
+ const parsed = isEmpty(paste) ? null : parseNumber({
7890
+ amount: paste,
7891
+ currency: this.props.selectedCurrency.currency,
7892
+ locale: locale,
7893
+ maxLengthOverride: this.props.maxLengthOverride
7894
+ });
7929
7895
  if (isNumberOrNull(parsed)) {
7930
7896
  this.setState({
7931
- formattedAmount: formatAmountIfSet(parsed, this.props.selectedCurrency.currency, locale, this.props.maxLengthOverride)
7897
+ formattedAmount: formatAmountIfSet({
7898
+ amount: parsed,
7899
+ currency: this.props.selectedCurrency.currency,
7900
+ locale: locale,
7901
+ maxLengthOverride: this.props.maxLengthOverride
7902
+ })
7932
7903
  });
7933
- this.props.onAmountChange(parsed);
7904
+ this.props.onAmountChange?.(parsed);
7934
7905
  }
7935
7906
  event.preventDefault();
7936
7907
  };
@@ -7941,9 +7912,14 @@ class MoneyInput extends Component {
7941
7912
  this.setState({
7942
7913
  formattedAmount: value
7943
7914
  });
7944
- const parsed = isEmpty(value) ? null : parseNumber(value, this.props.selectedCurrency.currency, this.state.locale, this.props.maxLengthOverride);
7915
+ const parsed = isEmpty(value) ? null : parseNumber({
7916
+ amount: value,
7917
+ currency: this.props.selectedCurrency.currency,
7918
+ locale: this.state.locale,
7919
+ maxLengthOverride: this.props.maxLengthOverride
7920
+ });
7945
7921
  if (isNumberOrNull(parsed)) {
7946
- this.props.onAmountChange(parsed);
7922
+ this.props.onAmountChange?.(parsed);
7947
7923
  }
7948
7924
  };
7949
7925
  onAmountBlur = () => {
@@ -7953,68 +7929,67 @@ class MoneyInput extends Component {
7953
7929
  onAmountFocus = () => {
7954
7930
  this.amountFocused = true;
7955
7931
  };
7956
- mapOption = item => {
7957
- return {
7958
- type: 'option',
7959
- value: item,
7960
- filterMatchers: [item.value, item.label, item.note, item.searchable]
7961
- };
7962
- };
7963
7932
  getSelectOptions() {
7964
- const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
7965
- let formattedOptions = [];
7966
- let groupIndex = null;
7933
+ const selectOptions = filterCurrenciesForQuery(this.props.currencies, this.state.searchQuery);
7934
+ const formattedOptions = [];
7935
+ let currentGroupOptions;
7967
7936
  selectOptions.forEach(item => {
7968
- if (item.header) {
7937
+ if (item.header != null) {
7938
+ currentGroupOptions = [];
7969
7939
  formattedOptions.push({
7970
7940
  type: 'group',
7971
7941
  label: item.header,
7972
- options: []
7942
+ options: currentGroupOptions
7973
7943
  });
7974
- groupIndex = formattedOptions.length - 1;
7975
7944
  } else {
7976
- if (groupIndex === null) {
7977
- formattedOptions.push(this.mapOption(item));
7978
- } else {
7979
- formattedOptions[groupIndex]?.options.push(this.mapOption(item));
7980
- }
7945
+ (currentGroupOptions ?? formattedOptions).push({
7946
+ type: 'option',
7947
+ value: item,
7948
+ filterMatchers: [item.value, item.label, item.note ?? '', item.searchable ?? '']
7949
+ });
7981
7950
  }
7982
7951
  });
7983
7952
  return formattedOptions;
7984
7953
  }
7985
7954
  setAmount() {
7986
7955
  this.setState(previousState => {
7987
- const parsed = parseNumber(previousState.formattedAmount, this.props.selectedCurrency.currency, previousState.locale, this.props.maxLengthOverride);
7956
+ const parsed = parseNumber({
7957
+ amount: previousState.formattedAmount,
7958
+ currency: this.props.selectedCurrency.currency,
7959
+ locale: previousState.locale,
7960
+ maxLengthOverride: this.props.maxLengthOverride
7961
+ });
7988
7962
  if (!isNumberOrNull(parsed)) {
7989
7963
  return {
7990
7964
  formattedAmount: previousState.formattedAmount
7991
7965
  };
7992
7966
  }
7993
7967
  return {
7994
- formattedAmount: formatAmountIfSet(parsed, this.props.selectedCurrency.currency, previousState.locale, this.props.maxLengthOverride)
7968
+ formattedAmount: formatAmountIfSet({
7969
+ amount: parsed,
7970
+ currency: this.props.selectedCurrency.currency,
7971
+ locale: previousState.locale,
7972
+ maxLengthOverride: this.props.maxLengthOverride
7973
+ })
7995
7974
  };
7996
7975
  });
7997
7976
  }
7998
7977
  handleSelectChange = value => {
7999
7978
  this.handleSearchChange('');
8000
- this.props.onCurrencyChange(value);
7979
+ this.props.onCurrencyChange?.(value);
8001
7980
  };
8002
7981
  handleCustomAction = () => {
8003
7982
  this.handleSearchChange('');
8004
- if (this.props.onCustomAction) {
8005
- this.props.onCustomAction();
8006
- }
7983
+ this.props.onCustomAction?.();
8007
7984
  };
8008
7985
  handleSearchChange = searchQuery => {
8009
7986
  this.setState({
8010
7987
  searchQuery
8011
7988
  });
8012
- if (this.props.onSearchChange) {
8013
- this.props.onSearchChange({
8014
- searchQuery,
8015
- filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
8016
- });
8017
- }
7989
+ this.props.onSearchChange?.({
7990
+ searchQuery,
7991
+ filteredOptions: filterCurrenciesForQuery(this.props.currencies, searchQuery)
7992
+ });
8018
7993
  };
8019
7994
  style = className => this.props.classNames[className] || className;
8020
7995
  render() {
@@ -8054,7 +8029,12 @@ class MoneyInput extends Component {
8054
8029
  inputMode: "decimal",
8055
8030
  disabled: disabled,
8056
8031
  maxLength: maxLengthOverride,
8057
- placeholder: formatAmountIfSet(this.props.placeholder, this.props.selectedCurrency.currency, this.state.locale, this.props.maxLengthOverride),
8032
+ placeholder: formatAmountIfSet({
8033
+ amount: this.props.placeholder,
8034
+ currency: this.props.selectedCurrency.currency,
8035
+ locale: this.state.locale,
8036
+ maxLengthOverride: this.props.maxLengthOverride
8037
+ }),
8058
8038
  autoComplete: "off",
8059
8039
  onKeyDown: this.handleKeyDown,
8060
8040
  onChange: this.onAmountChange,
@@ -8099,11 +8079,11 @@ class MoneyInput extends Component {
8099
8079
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events
8100
8080
  jsx("div", {
8101
8081
  role: "button",
8102
- tabIndex: "0",
8082
+ tabIndex: 0,
8103
8083
  onClick: this.handleCustomAction,
8104
8084
  children: this.props.customActionLabel
8105
- }) : null,
8106
- placeholder: this.formatMessage(messages$3.selectPlaceholder),
8085
+ }) : undefined,
8086
+ placeholder: this.props.intl.formatMessage(messages$3.selectPlaceholder),
8107
8087
  filterable: true,
8108
8088
  filterPlaceholder: this.props.searchPlaceholder,
8109
8089
  disabled: disabled,
@@ -8120,25 +8100,25 @@ class MoneyInput extends Component {
8120
8100
  });
8121
8101
  }
8122
8102
  }
8123
- function filterOptionsForQuery(options, query) {
8103
+ function filterCurrenciesForQuery(currencies, query) {
8124
8104
  if (!query) {
8125
- return options;
8105
+ return [...currencies];
8126
8106
  }
8127
- const filteredOptions = removeDuplicateValueOptions(options).filter(option => isCurrencyOptionAndFitsQuery(option, query));
8107
+ const options = currencies.filter(option => option.header == null);
8108
+ const filteredOptions = removeDuplicateValueOptions(options).filter(option => currencyOptionFitsQuery(option, query));
8128
8109
  return sortOptionsLabelsToFirst(filteredOptions, query);
8129
8110
  }
8130
8111
  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);
8112
+ const uniqueValues = new Set();
8113
+ return options.filter(option => {
8114
+ if (!uniqueValues.has(option.value)) {
8115
+ uniqueValues.add(option.value);
8116
+ return true;
8137
8117
  }
8118
+ return false;
8138
8119
  });
8139
- return result;
8140
8120
  }
8141
- function isCurrencyOptionAndFitsQuery(option, query) {
8121
+ function currencyOptionFitsQuery(option, query) {
8142
8122
  if (!option.value) {
8143
8123
  return false;
8144
8124
  }
@@ -8163,43 +8143,6 @@ function sortOptionsLabelsToFirst(options, query) {
8163
8143
  return 0;
8164
8144
  });
8165
8145
  }
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
8146
  var MoneyInput$1 = injectIntl(MoneyInput);
8204
8147
 
8205
8148
  const NavigationOptionList = ({
@@ -12352,17 +12295,12 @@ Tabs.defaultProps = {
12352
12295
  };
12353
12296
  var Tabs$1 = Tabs;
12354
12297
 
12355
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
12298
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
12356
12299
  ...props,
12357
- render: renderProps => /*#__PURE__*/jsx("textarea", {
12300
+ render: renderProps => /*#__PURE__*/jsx(TextArea, {
12358
12301
  ...renderProps
12359
12302
  })
12360
12303
  });
12361
- TextareaWithDisplayFormat.propTypes = {
12362
- displayPattern: PropTypes.string.isRequired,
12363
- onChange: PropTypes.func.isRequired
12364
- };
12365
- var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12366
12304
 
12367
12305
  /* eslint-disable jsx-a11y/no-autofocus */
12368
12306
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15364,16 +15302,16 @@ var th = {
15364
15302
  "neptune.DateInput.year.label": "ปี",
15365
15303
  "neptune.DateInput.year.placeholder": "YYYY",
15366
15304
  "neptune.DateLookup.day": "วัน",
15367
- "neptune.DateLookup.goTo20YearView": "Go to 20 year view",
15305
+ "neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
15368
15306
  "neptune.DateLookup.month": "เดือน",
15369
15307
  "neptune.DateLookup.next": "ถัดไป",
15370
15308
  "neptune.DateLookup.previous": "ก่อนหน้า",
15371
15309
  "neptune.DateLookup.selected": "เลือกแล้ว",
15372
15310
  "neptune.DateLookup.twentyYears": "20 ปี",
15373
15311
  "neptune.DateLookup.year": "ปี",
15374
- "neptune.FlowNavigation.back": "back to previous step",
15312
+ "neptune.FlowNavigation.back": "กลับไปที่ขั้นก่อนหน้า",
15375
15313
  "neptune.Info.ariaLabel": "ข้อมูลเพิ่มเติม",
15376
- "neptune.Link.opensInNewTab": "(opens in new tab)",
15314
+ "neptune.Link.opensInNewTab": "(เปิดในแท็บใหม่)",
15377
15315
  "neptune.MoneyInput.Select.placeholder": "เลือกตัวเลือก...",
15378
15316
  "neptune.Select.searchPlaceholder": "ค้นหา...",
15379
15317
  "neptune.SelectInput.noResultsFound": "ไม่พบผลลัพธ์",
@@ -15659,5 +15597,5 @@ const translations = {
15659
15597
  'zh-HK': zhHK
15660
15598
  };
15661
15599
 
15662
- export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat$1 as InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat$1 as TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15600
+ export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15663
15601
  //# sourceMappingURL=index.esm.js.map