@transferwise/components 0.0.0-experimental-adcaf57 → 0.0.0-experimental-2118ad7

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 (49) hide show
  1. package/build/index.esm.js +142 -68
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +143 -69
  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 +1 -2
  8. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
  9. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +1 -5
  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 +0 -2
  14. package/build/types/index.d.ts.map +1 -1
  15. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +11 -5
  16. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
  17. package/build/types/inputWithDisplayFormat/index.d.ts +1 -2
  18. package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
  19. package/build/types/inputs/Input.d.ts +6 -8
  20. package/build/types/inputs/Input.d.ts.map +1 -1
  21. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +11 -5
  22. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  23. package/build/types/textareaWithDisplayFormat/index.d.ts +1 -2
  24. package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
  25. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +82 -55
  26. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  27. package/build/types/withDisplayFormat/index.d.ts +1 -2
  28. package/build/types/withDisplayFormat/index.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/common/textFormat/formatWithPattern/{formatWithPattern.ts → formatWithPattern.js} +4 -8
  31. package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.ts → getCursorPositionAfterKeystroke.js} +6 -7
  32. package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.ts → getSymbolsInPatternWithPosition.js} +2 -7
  33. package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.ts → unformatWithPattern.js} +2 -3
  34. package/src/index.ts +0 -2
  35. package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +14 -0
  36. package/src/inputWithDisplayFormat/index.js +1 -0
  37. package/src/inputs/Input.tsx +11 -6
  38. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +14 -0
  39. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +1 -3
  40. package/src/textareaWithDisplayFormat/index.js +1 -0
  41. package/src/withDisplayFormat/WithDisplayFormat.js +312 -0
  42. package/src/withDisplayFormat/index.js +1 -0
  43. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +0 -11
  44. package/src/inputWithDisplayFormat/index.ts +0 -2
  45. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +0 -30
  46. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +0 -11
  47. package/src/textareaWithDisplayFormat/index.ts +0 -2
  48. package/src/withDisplayFormat/WithDisplayFormat.tsx +0 -303
  49. package/src/withDisplayFormat/index.ts +0 -2
package/build/index.js CHANGED
@@ -7297,13 +7297,10 @@ 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(pattern => pattern.index === index);
7300
+ patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7301
7301
  // Add pattern's symbol at n position
7302
7302
  if (patternSymbol.length === 1) {
7303
- const last = patternSymbol.pop();
7304
- if (last) {
7305
- valueArray.splice(index, 0, last.symbol);
7306
- }
7303
+ valueArray.splice(index, 0, patternSymbol.pop().symbol);
7307
7304
  }
7308
7305
  }
7309
7306
  return valueArray.join('');
@@ -7374,31 +7371,33 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7374
7371
  var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7375
7372
 
7376
7373
  class WithDisplayFormat extends React.Component {
7377
- static defaultProps = {
7378
- autoComplete: 'off',
7379
- displayPattern: '',
7380
- type: 'text',
7381
- value: ''
7382
- };
7383
7374
  constructor(props) {
7384
7375
  super(props);
7385
- const unformattedValue = unformatWithPattern$1(props.value, props.displayPattern);
7376
+ const {
7377
+ value,
7378
+ displayPattern
7379
+ } = props;
7380
+ const unformattedValue = unformatWithPattern$1(value, displayPattern);
7386
7381
  this.state = {
7387
- value: formatWithPattern$1(unformattedValue, props.displayPattern),
7382
+ value: formatWithPattern$1(unformattedValue, displayPattern),
7388
7383
  historyNavigator: new HistoryNavigator$1(),
7389
7384
  prevDisplayPattern: props.displayPattern,
7390
7385
  triggerType: null,
7391
7386
  triggerEvent: null
7392
7387
  };
7393
7388
  }
7394
- static getDerivedStateFromProps({
7395
- displayPattern
7396
- }, {
7397
- prevDisplayPattern = displayPattern,
7398
- value,
7399
- historyNavigator
7400
- }) {
7401
- if (prevDisplayPattern !== displayPattern) {
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;
7402
7401
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7403
7402
  historyNavigator.reset();
7404
7403
  return {
@@ -7420,27 +7419,25 @@ class WithDisplayFormat extends React.Component {
7420
7419
  const {
7421
7420
  displayPattern
7422
7421
  } = this.props;
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) {
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) {
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';
7443
7439
  }
7440
+ return triggerEvent.key;
7444
7441
  };
7445
7442
  resetEvent = () => {
7446
7443
  this.setState({
@@ -7468,6 +7465,7 @@ class WithDisplayFormat extends React.Component {
7468
7465
  const {
7469
7466
  displayPattern
7470
7467
  } = this.props;
7468
+
7471
7469
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7472
7470
  let newFormattedValue = '';
7473
7471
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7516,6 +7514,7 @@ class WithDisplayFormat extends React.Component {
7516
7514
  handleOnChange = event => {
7517
7515
  const {
7518
7516
  historyNavigator,
7517
+ triggerEvent,
7519
7518
  triggerType
7520
7519
  } = this.state;
7521
7520
  const {
@@ -7526,7 +7525,9 @@ class WithDisplayFormat extends React.Component {
7526
7525
  value
7527
7526
  } = event.target;
7528
7527
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7529
- const action = this.getUserAction(unformattedValue);
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);
7530
7531
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7531
7532
  return;
7532
7533
  }
@@ -7536,18 +7537,19 @@ class WithDisplayFormat extends React.Component {
7536
7537
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7537
7538
  historyNavigator.add(unformattedValue);
7538
7539
  this.handleCursorPositioning(action);
7540
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7539
7541
  this.setState({
7540
7542
  value: newFormattedValue
7541
- }, () => {
7542
- this.resetEvent();
7543
- if (onChange) {
7544
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7545
- onChange(broadcastValue);
7546
- }
7547
- });
7543
+ }, this.resetEvent(), onChange(broadcastValue));
7548
7544
  };
7549
7545
  handleOnBlur = event => {
7550
- this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7546
+ const {
7547
+ displayPattern,
7548
+ onBlur
7549
+ } = this.props;
7550
+ if (onBlur) {
7551
+ onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7552
+ }
7551
7553
  };
7552
7554
  handleOnFocus = event => {
7553
7555
  const {
@@ -7605,36 +7607,103 @@ class WithDisplayFormat extends React.Component {
7605
7607
  }, 0);
7606
7608
  };
7607
7609
  render() {
7608
- return this.props.render({
7609
- value: this.state.value,
7610
- type: this.props.type,
7611
- inputMode: this.props.inputMode,
7612
- className: this.props.className,
7613
- id: this.props.id,
7614
- name: this.props.name,
7615
- placeholder: this.props.placeholder,
7616
- readOnly: this.props.readOnly,
7617
- required: this.props.required,
7618
- minLength: this.props.minLength,
7619
- maxLength: this.props.maxLength,
7620
- disabled: this.props.disabled,
7621
- autoComplete: this.props.autoComplete,
7610
+ const {
7611
+ type,
7612
+ inputMode,
7613
+ className,
7614
+ id,
7615
+ name,
7616
+ placeholder,
7617
+ readOnly,
7618
+ required,
7619
+ minLength,
7620
+ maxLength,
7621
+ disabled,
7622
+ autoComplete
7623
+ } = this.props;
7624
+ const {
7625
+ value
7626
+ } = this.state;
7627
+ const renderProps = {
7628
+ type,
7629
+ inputMode,
7630
+ className,
7631
+ id,
7632
+ name,
7633
+ placeholder,
7634
+ readOnly,
7635
+ required,
7636
+ minLength,
7637
+ maxLength,
7638
+ disabled,
7639
+ autoComplete,
7640
+ value,
7622
7641
  onFocus: this.handleOnFocus,
7623
7642
  onBlur: this.handleOnBlur,
7624
7643
  onPaste: this.handleOnPaste,
7625
7644
  onKeyDown: this.handleOnKeyDown,
7626
7645
  onChange: this.handleOnChange,
7627
7646
  onCut: this.handleOnCut
7628
- });
7647
+ };
7648
+ return this.props.render(renderProps);
7629
7649
  }
7630
7650
  }
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;
7631
7695
 
7632
- const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
7696
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
7633
7697
  ...props,
7634
- render: renderProps => /*#__PURE__*/jsxRuntime.jsx(Input, {
7698
+ render: renderProps => /*#__PURE__*/jsxRuntime.jsx("input", {
7635
7699
  ...renderProps
7636
7700
  })
7637
7701
  });
7702
+ InputWithDisplayFormat.propTypes = {
7703
+ displayPattern: PropTypes__default.default.string.isRequired,
7704
+ onChange: PropTypes__default.default.func.isRequired
7705
+ };
7706
+ var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7638
7707
 
7639
7708
  const InstructionsList = ({
7640
7709
  dos,
@@ -12311,12 +12380,17 @@ Tabs.defaultProps = {
12311
12380
  };
12312
12381
  var Tabs$1 = Tabs;
12313
12382
 
12314
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
12383
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
12315
12384
  ...props,
12316
- render: renderProps => /*#__PURE__*/jsxRuntime.jsx(TextArea, {
12385
+ render: renderProps => /*#__PURE__*/jsxRuntime.jsx("textarea", {
12317
12386
  ...renderProps
12318
12387
  })
12319
12388
  });
12389
+ TextareaWithDisplayFormat.propTypes = {
12390
+ displayPattern: PropTypes__default.default.string.isRequired,
12391
+ onChange: PropTypes__default.default.func.isRequired
12392
+ };
12393
+ var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12320
12394
 
12321
12395
  /* eslint-disable jsx-a11y/no-autofocus */
12322
12396
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15653,7 +15727,7 @@ exports.Info = Info;
15653
15727
  exports.InlineAlert = InlineAlert;
15654
15728
  exports.Input = Input;
15655
15729
  exports.InputGroup = InputGroup;
15656
- exports.InputWithDisplayFormat = InputWithDisplayFormat;
15730
+ exports.InputWithDisplayFormat = InputWithDisplayFormat$1;
15657
15731
  exports.InstructionsList = InstructionsList$1;
15658
15732
  exports.LanguageProvider = LanguageProvider;
15659
15733
  exports.Link = Link;
@@ -15701,7 +15775,7 @@ exports.Switch = Switch;
15701
15775
  exports.SwitchOption = SwitchOption;
15702
15776
  exports.Tabs = Tabs$1;
15703
15777
  exports.TextArea = TextArea;
15704
- exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
15778
+ exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat$1;
15705
15779
  exports.Title = Title;
15706
15780
  exports.Tooltip = Tooltip$1;
15707
15781
  exports.Typeahead = Typeahead;