@transferwise/components 0.0.0-experimental-1f8ed05 → 0.0.0-experimental-d0bd4b4

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/index.esm.js +53 -109
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +54 -110
  4. package/build/index.js.map +1 -1
  5. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
  6. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
  7. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +2 -1
  8. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
  9. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
  10. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
  11. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
  12. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
  13. package/build/types/index.d.ts +2 -0
  14. package/build/types/index.d.ts.map +1 -1
  15. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +5 -11
  16. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
  17. package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
  18. package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
  19. package/build/types/inputs/Input.d.ts +8 -6
  20. package/build/types/inputs/Input.d.ts.map +1 -1
  21. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +5 -11
  22. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  23. package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
  24. package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
  25. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +55 -82
  26. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  27. package/build/types/withDisplayFormat/index.d.ts +2 -1
  28. package/build/types/withDisplayFormat/index.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
  31. package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +7 -6
  32. package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
  33. package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
  34. package/src/index.ts +2 -0
  35. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +11 -0
  36. package/src/inputWithDisplayFormat/index.ts +2 -0
  37. package/src/inputs/Input.tsx +6 -11
  38. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
  39. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
  40. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +11 -0
  41. package/src/textareaWithDisplayFormat/index.ts +2 -0
  42. package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +111 -104
  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('');
@@ -7371,33 +7374,31 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7371
7374
  var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7372
7375
 
7373
7376
  class WithDisplayFormat extends React.Component {
7377
+ static defaultProps = {
7378
+ autoComplete: 'off',
7379
+ displayPattern: '',
7380
+ type: 'text',
7381
+ value: ''
7382
+ };
7374
7383
  constructor(props) {
7375
7384
  super(props);
7376
- const {
7377
- value,
7378
- displayPattern
7379
- } = props;
7380
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7385
+ const unformattedValue = unformatWithPattern$1(props.value, props.displayPattern);
7381
7386
  this.state = {
7382
- value: formatWithPattern$1(unformattedValue, displayPattern),
7387
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7383
7388
  historyNavigator: new HistoryNavigator$1(),
7384
7389
  prevDisplayPattern: props.displayPattern,
7385
7390
  triggerType: null,
7386
7391
  triggerEvent: null
7387
7392
  };
7388
7393
  }
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;
7394
+ static getDerivedStateFromProps({
7395
+ displayPattern
7396
+ }, {
7397
+ prevDisplayPattern = displayPattern,
7398
+ value,
7399
+ historyNavigator
7400
+ }) {
7401
+ if (prevDisplayPattern !== displayPattern) {
7401
7402
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7402
7403
  historyNavigator.reset();
7403
7404
  return {
@@ -7419,25 +7420,27 @@ class WithDisplayFormat extends React.Component {
7419
7420
  const {
7420
7421
  displayPattern
7421
7422
  } = 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) {
7423
+ if (triggerEvent) {
7424
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7425
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7426
+ return triggerType;
7427
+ }
7428
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7429
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7430
+ }
7431
+ // Detect mouse event redo
7432
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7433
+ return 'Delete';
7434
+ }
7435
+ // Android Fix.
7436
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7437
7437
  return 'Backspace';
7438
7438
  }
7439
+ return triggerEvent.key;
7440
+ } else {
7441
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7442
+ return 'Paste';
7439
7443
  }
7440
- return triggerEvent.key;
7441
7444
  };
7442
7445
  resetEvent = () => {
7443
7446
  this.setState({
@@ -7465,7 +7468,6 @@ class WithDisplayFormat extends React.Component {
7465
7468
  const {
7466
7469
  displayPattern
7467
7470
  } = this.props;
7468
-
7469
7471
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7470
7472
  let newFormattedValue = '';
7471
7473
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7514,7 +7516,6 @@ class WithDisplayFormat extends React.Component {
7514
7516
  handleOnChange = event => {
7515
7517
  const {
7516
7518
  historyNavigator,
7517
- triggerEvent,
7518
7519
  triggerType
7519
7520
  } = this.state;
7520
7521
  const {
@@ -7525,9 +7526,7 @@ class WithDisplayFormat extends React.Component {
7525
7526
  value
7526
7527
  } = event.target;
7527
7528
  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);
7529
+ const action = this.getUserAction(unformattedValue);
7531
7530
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7532
7531
  return;
7533
7532
  }
@@ -7537,19 +7536,18 @@ class WithDisplayFormat extends React.Component {
7537
7536
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7538
7537
  historyNavigator.add(unformattedValue);
7539
7538
  this.handleCursorPositioning(action);
7540
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7541
7539
  this.setState({
7542
7540
  value: newFormattedValue
7543
- }, this.resetEvent(), onChange(broadcastValue));
7541
+ }, () => {
7542
+ this.resetEvent();
7543
+ if (onChange) {
7544
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7545
+ onChange(broadcastValue);
7546
+ }
7547
+ });
7544
7548
  };
7545
7549
  handleOnBlur = event => {
7546
- const {
7547
- displayPattern,
7548
- onBlur
7549
- } = this.props;
7550
- if (onBlur) {
7551
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7552
- }
7550
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7553
7551
  };
7554
7552
  handleOnFocus = event => {
7555
7553
  const {
@@ -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 */
@@ -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;