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

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 +68 -142
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +69 -143
  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 +30 -0
  40. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +11 -0
  41. package/src/textareaWithDisplayFormat/index.ts +2 -0
  42. package/src/withDisplayFormat/WithDisplayFormat.tsx +303 -0
  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/WithDisplayFormat.js +0 -312
  49. package/src/withDisplayFormat/index.js +0 -1
@@ -7263,10 +7263,13 @@ const formatWithPattern = (value, pattern) => {
7263
7263
  let patternSymbol = [];
7264
7264
  // valueArray.length increments during the cycle cause we are adding new elements.
7265
7265
  for (let index = 0; index < valueArray.length; index += 1) {
7266
- patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7266
+ patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
7267
7267
  // Add pattern's symbol at n position
7268
7268
  if (patternSymbol.length === 1) {
7269
- valueArray.splice(index, 0, patternSymbol.pop().symbol);
7269
+ const last = patternSymbol.pop();
7270
+ if (last) {
7271
+ valueArray.splice(index, 0, last.symbol);
7272
+ }
7270
7273
  }
7271
7274
  }
7272
7275
  return valueArray.join('');
@@ -7337,33 +7340,31 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7337
7340
  var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7338
7341
 
7339
7342
  class WithDisplayFormat extends Component {
7343
+ static defaultProps = {
7344
+ autoComplete: 'off',
7345
+ displayPattern: '',
7346
+ type: 'text',
7347
+ value: ''
7348
+ };
7340
7349
  constructor(props) {
7341
7350
  super(props);
7342
- const {
7343
- value,
7344
- displayPattern
7345
- } = props;
7346
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7351
+ const unformattedValue = unformatWithPattern$1(props.value, props.displayPattern);
7347
7352
  this.state = {
7348
- value: formatWithPattern$1(unformattedValue, displayPattern),
7353
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7349
7354
  historyNavigator: new HistoryNavigator$1(),
7350
7355
  prevDisplayPattern: props.displayPattern,
7351
7356
  triggerType: null,
7352
7357
  triggerEvent: null
7353
7358
  };
7354
7359
  }
7355
- static getDerivedStateFromProps(nextProps, previousState) {
7356
- const {
7357
- displayPattern
7358
- } = nextProps;
7359
- const {
7360
- prevDisplayPattern
7361
- } = previousState;
7362
- if (previousState.prevDisplayPattern !== displayPattern) {
7363
- const {
7364
- value,
7365
- historyNavigator
7366
- } = previousState;
7360
+ static getDerivedStateFromProps({
7361
+ displayPattern
7362
+ }, {
7363
+ prevDisplayPattern = displayPattern,
7364
+ value,
7365
+ historyNavigator
7366
+ }) {
7367
+ if (prevDisplayPattern !== displayPattern) {
7367
7368
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7368
7369
  historyNavigator.reset();
7369
7370
  return {
@@ -7385,25 +7386,27 @@ class WithDisplayFormat extends Component {
7385
7386
  const {
7386
7387
  displayPattern
7387
7388
  } = this.props;
7388
- const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7389
- if (triggerType === 'Paste' || triggerType === 'Cut') {
7390
- return triggerType;
7391
- }
7392
- if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7393
- return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7394
- }
7395
- // Detect mouse event redo
7396
- if (triggerEvent.ctrlKey && charCode === 'd') {
7397
- return 'Delete';
7398
- }
7399
-
7400
- // Android Fix.
7401
- if (typeof triggerEvent.key === 'undefined') {
7402
- if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7389
+ if (triggerEvent) {
7390
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7391
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7392
+ return triggerType;
7393
+ }
7394
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7395
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7396
+ }
7397
+ // Detect mouse event redo
7398
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7399
+ return 'Delete';
7400
+ }
7401
+ // Android Fix.
7402
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7403
7403
  return 'Backspace';
7404
7404
  }
7405
+ return triggerEvent.key;
7406
+ } else {
7407
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7408
+ return 'Paste';
7405
7409
  }
7406
- return triggerEvent.key;
7407
7410
  };
7408
7411
  resetEvent = () => {
7409
7412
  this.setState({
@@ -7431,7 +7434,6 @@ class WithDisplayFormat extends Component {
7431
7434
  const {
7432
7435
  displayPattern
7433
7436
  } = this.props;
7434
-
7435
7437
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7436
7438
  let newFormattedValue = '';
7437
7439
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7480,7 +7482,6 @@ class WithDisplayFormat extends Component {
7480
7482
  handleOnChange = event => {
7481
7483
  const {
7482
7484
  historyNavigator,
7483
- triggerEvent,
7484
7485
  triggerType
7485
7486
  } = this.state;
7486
7487
  const {
@@ -7491,9 +7492,7 @@ class WithDisplayFormat extends Component {
7491
7492
  value
7492
7493
  } = event.target;
7493
7494
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7494
- const action = triggerEvent === null ?
7495
- // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7496
- 'Paste' : this.getUserAction(unformattedValue);
7495
+ const action = this.getUserAction(unformattedValue);
7497
7496
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7498
7497
  return;
7499
7498
  }
@@ -7503,19 +7502,18 @@ class WithDisplayFormat extends Component {
7503
7502
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7504
7503
  historyNavigator.add(unformattedValue);
7505
7504
  this.handleCursorPositioning(action);
7506
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7507
7505
  this.setState({
7508
7506
  value: newFormattedValue
7509
- }, this.resetEvent(), onChange(broadcastValue));
7507
+ }, () => {
7508
+ this.resetEvent();
7509
+ if (onChange) {
7510
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7511
+ onChange(broadcastValue);
7512
+ }
7513
+ });
7510
7514
  };
7511
7515
  handleOnBlur = event => {
7512
- const {
7513
- displayPattern,
7514
- onBlur
7515
- } = this.props;
7516
- if (onBlur) {
7517
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7518
- }
7516
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7519
7517
  };
7520
7518
  handleOnFocus = event => {
7521
7519
  const {
@@ -7573,103 +7571,36 @@ class WithDisplayFormat extends Component {
7573
7571
  }, 0);
7574
7572
  };
7575
7573
  render() {
7576
- const {
7577
- type,
7578
- inputMode,
7579
- className,
7580
- id,
7581
- name,
7582
- placeholder,
7583
- readOnly,
7584
- required,
7585
- minLength,
7586
- maxLength,
7587
- disabled,
7588
- autoComplete
7589
- } = this.props;
7590
- const {
7591
- value
7592
- } = this.state;
7593
- const renderProps = {
7594
- type,
7595
- inputMode,
7596
- className,
7597
- id,
7598
- name,
7599
- placeholder,
7600
- readOnly,
7601
- required,
7602
- minLength,
7603
- maxLength,
7604
- disabled,
7605
- autoComplete,
7606
- value,
7574
+ return this.props.render({
7575
+ value: this.state.value,
7576
+ type: this.props.type,
7577
+ inputMode: this.props.inputMode,
7578
+ className: this.props.className,
7579
+ id: this.props.id,
7580
+ name: this.props.name,
7581
+ placeholder: this.props.placeholder,
7582
+ readOnly: this.props.readOnly,
7583
+ required: this.props.required,
7584
+ minLength: this.props.minLength,
7585
+ maxLength: this.props.maxLength,
7586
+ disabled: this.props.disabled,
7587
+ autoComplete: this.props.autoComplete,
7607
7588
  onFocus: this.handleOnFocus,
7608
7589
  onBlur: this.handleOnBlur,
7609
7590
  onPaste: this.handleOnPaste,
7610
7591
  onKeyDown: this.handleOnKeyDown,
7611
7592
  onChange: this.handleOnChange,
7612
7593
  onCut: this.handleOnCut
7613
- };
7614
- return this.props.render(renderProps);
7594
+ });
7615
7595
  }
7616
7596
  }
7617
- WithDisplayFormat.propTypes = {
7618
- /**
7619
- * autocomplete hides our form help so we need to disable it when help text
7620
- * is present. Chrome ignores autocomplete=off, the only way to disable it is
7621
- * to provide an 'invalid' value, for which 'disabled' serves.
7622
- */
7623
- autoComplete: PropTypes.oneOf(['on', 'off', 'disabled']),
7624
- className: PropTypes.string,
7625
- disabled: PropTypes.bool,
7626
- id: PropTypes.string,
7627
- maxLength: PropTypes.number,
7628
- minLength: PropTypes.number,
7629
- name: PropTypes.string,
7630
- onFocus: PropTypes.func,
7631
- onBlur: PropTypes.func,
7632
- onChange: PropTypes.func.isRequired,
7633
- placeholder: PropTypes.string,
7634
- readOnly: PropTypes.bool,
7635
- render: PropTypes.func.isRequired,
7636
- required: PropTypes.bool,
7637
- displayPattern: PropTypes.string,
7638
- type: PropTypes.string,
7639
- inputMode: PropTypes.string,
7640
- value: PropTypes.string
7641
- };
7642
- WithDisplayFormat.defaultProps = {
7643
- autoComplete: 'off',
7644
- className: null,
7645
- disabled: false,
7646
- id: null,
7647
- maxLength: null,
7648
- minLength: null,
7649
- name: null,
7650
- placeholder: null,
7651
- readOnly: false,
7652
- required: false,
7653
- displayPattern: '',
7654
- type: 'text',
7655
- inputMode: null,
7656
- value: '',
7657
- onFocus: null,
7658
- onBlur: null
7659
- };
7660
- var WithDisplayFormat$1 = WithDisplayFormat;
7661
7597
 
7662
- const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
7598
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
7663
7599
  ...props,
7664
- render: renderProps => /*#__PURE__*/jsx("input", {
7600
+ render: renderProps => /*#__PURE__*/jsx(Input, {
7665
7601
  ...renderProps
7666
7602
  })
7667
7603
  });
7668
- InputWithDisplayFormat.propTypes = {
7669
- displayPattern: PropTypes.string.isRequired,
7670
- onChange: PropTypes.func.isRequired
7671
- };
7672
- var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7673
7604
 
7674
7605
  const InstructionsList = ({
7675
7606
  dos,
@@ -12346,17 +12277,12 @@ Tabs.defaultProps = {
12346
12277
  };
12347
12278
  var Tabs$1 = Tabs;
12348
12279
 
12349
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
12280
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
12350
12281
  ...props,
12351
- render: renderProps => /*#__PURE__*/jsx("textarea", {
12282
+ render: renderProps => /*#__PURE__*/jsx(TextArea, {
12352
12283
  ...renderProps
12353
12284
  })
12354
12285
  });
12355
- TextareaWithDisplayFormat.propTypes = {
12356
- displayPattern: PropTypes.string.isRequired,
12357
- onChange: PropTypes.func.isRequired
12358
- };
12359
- var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12360
12286
 
12361
12287
  /* eslint-disable jsx-a11y/no-autofocus */
12362
12288
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15653,5 +15579,5 @@ const translations = {
15653
15579
  'zh-HK': zhHK
15654
15580
  };
15655
15581
 
15656
- 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 };
15582
+ 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 };
15657
15583
  //# sourceMappingURL=index.esm.js.map