@transferwise/components 46.5.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 (48) hide show
  1. package/build/i18n/th.json +3 -3
  2. package/build/index.esm.js +67 -123
  3. package/build/index.esm.js.map +1 -1
  4. package/build/index.js +68 -124
  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 +2 -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/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +7 -11
  21. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  22. package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
  23. package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
  24. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +55 -83
  25. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  26. package/build/types/withDisplayFormat/index.d.ts +2 -1
  27. package/build/types/withDisplayFormat/index.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
  30. package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
  31. package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
  32. package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
  33. package/src/i18n/th.json +3 -3
  34. package/src/index.ts +2 -0
  35. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
  36. package/src/inputWithDisplayFormat/index.ts +2 -0
  37. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
  38. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
  39. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
  40. package/src/textareaWithDisplayFormat/index.ts +2 -0
  41. package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
  42. package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
  43. package/src/withDisplayFormat/index.ts +2 -0
  44. package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
  45. package/src/inputWithDisplayFormat/index.js +0 -1
  46. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
  47. package/src/textareaWithDisplayFormat/index.js +0 -1
  48. package/src/withDisplayFormat/index.js +0 -1
package/build/index.js CHANGED
@@ -7297,10 +7297,13 @@ const formatWithPattern = (value, pattern) => {
7297
7297
  let patternSymbol = [];
7298
7298
  // valueArray.length increments during the cycle cause we are adding new elements.
7299
7299
  for (let index = 0; index < valueArray.length; index += 1) {
7300
- patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7300
+ patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
7301
7301
  // Add pattern's symbol at n position
7302
7302
  if (patternSymbol.length === 1) {
7303
- valueArray.splice(index, 0, patternSymbol.pop().symbol);
7303
+ const last = patternSymbol.pop();
7304
+ if (last) {
7305
+ valueArray.splice(index, 0, last.symbol);
7306
+ }
7304
7307
  }
7305
7308
  }
7306
7309
  return valueArray.join('');
@@ -7346,7 +7349,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
7346
7349
  return groupSize;
7347
7350
  };
7348
7351
 
7349
- const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7352
+ const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7350
7353
  let cursorPosition = selectionStart;
7351
7354
  switch (action) {
7352
7355
  case 'Backspace':
@@ -7368,36 +7371,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7368
7371
  }
7369
7372
  return cursorPosition;
7370
7373
  };
7371
- var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7374
+ var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
7372
7375
 
7373
7376
  class WithDisplayFormat extends React.Component {
7377
+ static defaultProps = {
7378
+ autoComplete: 'off',
7379
+ displayPattern: '',
7380
+ value: ''
7381
+ };
7374
7382
  constructor(props) {
7375
7383
  super(props);
7376
- const {
7377
- value,
7378
- displayPattern
7379
- } = props;
7380
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7384
+ const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
7381
7385
  this.state = {
7382
- value: formatWithPattern$1(unformattedValue, displayPattern),
7386
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7383
7387
  historyNavigator: new HistoryNavigator$1(),
7384
7388
  prevDisplayPattern: props.displayPattern,
7385
- triggerType: null,
7386
- triggerEvent: null
7389
+ triggerType: 'Initial',
7390
+ triggerEvent: null,
7391
+ selectionStart: 0,
7392
+ selectionEnd: 0,
7393
+ pastedLength: 0
7387
7394
  };
7388
7395
  }
7389
- static getDerivedStateFromProps(nextProps, previousState) {
7390
- const {
7391
- displayPattern
7392
- } = nextProps;
7393
- const {
7394
- prevDisplayPattern
7395
- } = previousState;
7396
- if (previousState.prevDisplayPattern !== displayPattern) {
7397
- const {
7398
- value,
7399
- historyNavigator
7400
- } = previousState;
7396
+ static getDerivedStateFromProps({
7397
+ displayPattern
7398
+ }, {
7399
+ prevDisplayPattern = displayPattern,
7400
+ value,
7401
+ historyNavigator
7402
+ }) {
7403
+ if (prevDisplayPattern !== displayPattern) {
7401
7404
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7402
7405
  historyNavigator.reset();
7403
7406
  return {
@@ -7419,29 +7422,31 @@ class WithDisplayFormat extends React.Component {
7419
7422
  const {
7420
7423
  displayPattern
7421
7424
  } = this.props;
7422
- const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7423
- if (triggerType === 'Paste' || triggerType === 'Cut') {
7424
- return triggerType;
7425
- }
7426
- if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7427
- return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7428
- }
7429
- // Detect mouse event redo
7430
- if (triggerEvent.ctrlKey && charCode === 'd') {
7431
- return 'Delete';
7432
- }
7433
-
7434
- // Android Fix.
7435
- if (typeof triggerEvent.key === 'undefined') {
7436
- if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7425
+ if (triggerEvent) {
7426
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7427
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7428
+ return triggerType;
7429
+ }
7430
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7431
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7432
+ }
7433
+ // Detect mouse event redo
7434
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7435
+ return 'Delete';
7436
+ }
7437
+ // Android Fix.
7438
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7437
7439
  return 'Backspace';
7438
7440
  }
7441
+ return triggerEvent.key;
7442
+ } else {
7443
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7444
+ return 'Paste';
7439
7445
  }
7440
- return triggerEvent.key;
7441
7446
  };
7442
7447
  resetEvent = () => {
7443
7448
  this.setState({
7444
- triggerType: null,
7449
+ triggerType: 'Initial',
7445
7450
  triggerEvent: null,
7446
7451
  pastedLength: 0
7447
7452
  });
@@ -7458,14 +7463,13 @@ class WithDisplayFormat extends React.Component {
7458
7463
  const {
7459
7464
  selectionStart,
7460
7465
  selectionEnd
7461
- } = event.target;
7466
+ } = event.currentTarget;
7462
7467
  const {
7463
7468
  historyNavigator
7464
7469
  } = this.state;
7465
7470
  const {
7466
7471
  displayPattern
7467
7472
  } = this.props;
7468
-
7469
7473
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7470
7474
  let newFormattedValue = '';
7471
7475
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7484,8 +7488,8 @@ class WithDisplayFormat extends React.Component {
7484
7488
  this.setState({
7485
7489
  triggerEvent: event,
7486
7490
  triggerType: 'KeyDown',
7487
- selectionStart,
7488
- selectionEnd
7491
+ selectionStart: selectionStart ?? 0,
7492
+ selectionEnd: selectionEnd ?? 0
7489
7493
  });
7490
7494
  }
7491
7495
  };
@@ -7514,7 +7518,6 @@ class WithDisplayFormat extends React.Component {
7514
7518
  handleOnChange = event => {
7515
7519
  const {
7516
7520
  historyNavigator,
7517
- triggerEvent,
7518
7521
  triggerType
7519
7522
  } = this.state;
7520
7523
  const {
@@ -7525,9 +7528,7 @@ class WithDisplayFormat extends React.Component {
7525
7528
  value
7526
7529
  } = event.target;
7527
7530
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7528
- const action = triggerEvent === null ?
7529
- // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7530
- 'Paste' : this.getUserAction(unformattedValue);
7531
+ const action = this.getUserAction(unformattedValue);
7531
7532
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7532
7533
  return;
7533
7534
  }
@@ -7537,19 +7538,18 @@ class WithDisplayFormat extends React.Component {
7537
7538
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7538
7539
  historyNavigator.add(unformattedValue);
7539
7540
  this.handleCursorPositioning(action);
7540
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7541
7541
  this.setState({
7542
7542
  value: newFormattedValue
7543
- }, this.resetEvent(), onChange(broadcastValue));
7543
+ }, () => {
7544
+ this.resetEvent();
7545
+ if (onChange) {
7546
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7547
+ onChange(broadcastValue);
7548
+ }
7549
+ });
7544
7550
  };
7545
7551
  handleOnBlur = event => {
7546
- const {
7547
- displayPattern,
7548
- onBlur
7549
- } = this.props;
7550
- if (onBlur) {
7551
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7552
- }
7552
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7553
7553
  };
7554
7554
  handleOnFocus = event => {
7555
7555
  const {
@@ -7598,7 +7598,7 @@ class WithDisplayFormat extends React.Component {
7598
7598
  const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
7599
7599
  setTimeout(() => {
7600
7600
  if (triggerEvent) {
7601
- triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
7601
+ triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7602
7602
  }
7603
7603
  this.setState({
7604
7604
  selectionStart: cursorPosition,
@@ -7608,7 +7608,6 @@ class WithDisplayFormat extends React.Component {
7608
7608
  };
7609
7609
  render() {
7610
7610
  const {
7611
- type,
7612
7611
  inputMode,
7613
7612
  className,
7614
7613
  id,
@@ -7625,7 +7624,6 @@ class WithDisplayFormat extends React.Component {
7625
7624
  value
7626
7625
  } = this.state;
7627
7626
  const renderProps = {
7628
- type,
7629
7627
  inputMode,
7630
7628
  className,
7631
7629
  id,
@@ -7648,62 +7646,13 @@ class WithDisplayFormat extends React.Component {
7648
7646
  return this.props.render(renderProps);
7649
7647
  }
7650
7648
  }
7651
- WithDisplayFormat.propTypes = {
7652
- /**
7653
- * autocomplete hides our form help so we need to disable it when help text
7654
- * is present. Chrome ignores autocomplete=off, the only way to disable it is
7655
- * to provide an 'invalid' value, for which 'disabled' serves.
7656
- */
7657
- autoComplete: PropTypes__default.default.oneOf(['on', 'off', 'disabled']),
7658
- className: PropTypes__default.default.string,
7659
- disabled: PropTypes__default.default.bool,
7660
- id: PropTypes__default.default.string,
7661
- maxLength: PropTypes__default.default.number,
7662
- minLength: PropTypes__default.default.number,
7663
- name: PropTypes__default.default.string,
7664
- onFocus: PropTypes__default.default.func,
7665
- onBlur: PropTypes__default.default.func,
7666
- onChange: PropTypes__default.default.func.isRequired,
7667
- placeholder: PropTypes__default.default.string,
7668
- readOnly: PropTypes__default.default.bool,
7669
- render: PropTypes__default.default.func.isRequired,
7670
- required: PropTypes__default.default.bool,
7671
- displayPattern: PropTypes__default.default.string,
7672
- type: PropTypes__default.default.string,
7673
- inputMode: PropTypes__default.default.string,
7674
- value: PropTypes__default.default.string
7675
- };
7676
- WithDisplayFormat.defaultProps = {
7677
- autoComplete: 'off',
7678
- className: null,
7679
- disabled: false,
7680
- id: null,
7681
- maxLength: null,
7682
- minLength: null,
7683
- name: null,
7684
- placeholder: null,
7685
- readOnly: false,
7686
- required: false,
7687
- displayPattern: '',
7688
- type: 'text',
7689
- inputMode: null,
7690
- value: '',
7691
- onFocus: null,
7692
- onBlur: null
7693
- };
7694
- var WithDisplayFormat$1 = WithDisplayFormat;
7695
7649
 
7696
- const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
7650
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
7697
7651
  ...props,
7698
- render: renderProps => /*#__PURE__*/jsxRuntime.jsx("input", {
7652
+ render: renderProps => /*#__PURE__*/jsxRuntime.jsx(Input, {
7699
7653
  ...renderProps
7700
7654
  })
7701
7655
  });
7702
- InputWithDisplayFormat.propTypes = {
7703
- displayPattern: PropTypes__default.default.string.isRequired,
7704
- onChange: PropTypes__default.default.func.isRequired
7705
- };
7706
- var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7707
7656
 
7708
7657
  const InstructionsList = ({
7709
7658
  dos,
@@ -12380,17 +12329,12 @@ Tabs.defaultProps = {
12380
12329
  };
12381
12330
  var Tabs$1 = Tabs;
12382
12331
 
12383
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
12332
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
12384
12333
  ...props,
12385
- render: renderProps => /*#__PURE__*/jsxRuntime.jsx("textarea", {
12334
+ render: renderProps => /*#__PURE__*/jsxRuntime.jsx(TextArea, {
12386
12335
  ...renderProps
12387
12336
  })
12388
12337
  });
12389
- TextareaWithDisplayFormat.propTypes = {
12390
- displayPattern: PropTypes__default.default.string.isRequired,
12391
- onChange: PropTypes__default.default.func.isRequired
12392
- };
12393
- var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12394
12338
 
12395
12339
  /* eslint-disable jsx-a11y/no-autofocus */
12396
12340
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15392,16 +15336,16 @@ var th = {
15392
15336
  "neptune.DateInput.year.label": "ปี",
15393
15337
  "neptune.DateInput.year.placeholder": "YYYY",
15394
15338
  "neptune.DateLookup.day": "วัน",
15395
- "neptune.DateLookup.goTo20YearView": "Go to 20 year view",
15339
+ "neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
15396
15340
  "neptune.DateLookup.month": "เดือน",
15397
15341
  "neptune.DateLookup.next": "ถัดไป",
15398
15342
  "neptune.DateLookup.previous": "ก่อนหน้า",
15399
15343
  "neptune.DateLookup.selected": "เลือกแล้ว",
15400
15344
  "neptune.DateLookup.twentyYears": "20 ปี",
15401
15345
  "neptune.DateLookup.year": "ปี",
15402
- "neptune.FlowNavigation.back": "back to previous step",
15346
+ "neptune.FlowNavigation.back": "กลับไปที่ขั้นก่อนหน้า",
15403
15347
  "neptune.Info.ariaLabel": "ข้อมูลเพิ่มเติม",
15404
- "neptune.Link.opensInNewTab": "(opens in new tab)",
15348
+ "neptune.Link.opensInNewTab": "(เปิดในแท็บใหม่)",
15405
15349
  "neptune.MoneyInput.Select.placeholder": "เลือกตัวเลือก...",
15406
15350
  "neptune.Select.searchPlaceholder": "ค้นหา...",
15407
15351
  "neptune.SelectInput.noResultsFound": "ไม่พบผลลัพธ์",
@@ -15727,7 +15671,7 @@ exports.Info = Info;
15727
15671
  exports.InlineAlert = InlineAlert;
15728
15672
  exports.Input = Input;
15729
15673
  exports.InputGroup = InputGroup;
15730
- exports.InputWithDisplayFormat = InputWithDisplayFormat$1;
15674
+ exports.InputWithDisplayFormat = InputWithDisplayFormat;
15731
15675
  exports.InstructionsList = InstructionsList$1;
15732
15676
  exports.LanguageProvider = LanguageProvider;
15733
15677
  exports.Link = Link;
@@ -15775,7 +15719,7 @@ exports.Switch = Switch;
15775
15719
  exports.SwitchOption = SwitchOption;
15776
15720
  exports.Tabs = Tabs$1;
15777
15721
  exports.TextArea = TextArea;
15778
- exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat$1;
15722
+ exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
15779
15723
  exports.Title = Title;
15780
15724
  exports.Tooltip = Tooltip$1;
15781
15725
  exports.Typeahead = Typeahead;