@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
@@ -7263,13 +7263,10 @@ 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(pattern => pattern.index === index);
7266
+ patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7267
7267
  // Add pattern's symbol at n position
7268
7268
  if (patternSymbol.length === 1) {
7269
- const last = patternSymbol.pop();
7270
- if (last) {
7271
- valueArray.splice(index, 0, last.symbol);
7272
- }
7269
+ valueArray.splice(index, 0, patternSymbol.pop().symbol);
7273
7270
  }
7274
7271
  }
7275
7272
  return valueArray.join('');
@@ -7340,31 +7337,33 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7340
7337
  var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7341
7338
 
7342
7339
  class WithDisplayFormat extends Component {
7343
- static defaultProps = {
7344
- autoComplete: 'off',
7345
- displayPattern: '',
7346
- type: 'text',
7347
- value: ''
7348
- };
7349
7340
  constructor(props) {
7350
7341
  super(props);
7351
- const unformattedValue = unformatWithPattern$1(props.value, props.displayPattern);
7342
+ const {
7343
+ value,
7344
+ displayPattern
7345
+ } = props;
7346
+ const unformattedValue = unformatWithPattern$1(value, displayPattern);
7352
7347
  this.state = {
7353
- value: formatWithPattern$1(unformattedValue, props.displayPattern),
7348
+ value: formatWithPattern$1(unformattedValue, displayPattern),
7354
7349
  historyNavigator: new HistoryNavigator$1(),
7355
7350
  prevDisplayPattern: props.displayPattern,
7356
7351
  triggerType: null,
7357
7352
  triggerEvent: null
7358
7353
  };
7359
7354
  }
7360
- static getDerivedStateFromProps({
7361
- displayPattern
7362
- }, {
7363
- prevDisplayPattern = displayPattern,
7364
- value,
7365
- historyNavigator
7366
- }) {
7367
- if (prevDisplayPattern !== displayPattern) {
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;
7368
7367
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7369
7368
  historyNavigator.reset();
7370
7369
  return {
@@ -7386,27 +7385,25 @@ class WithDisplayFormat extends Component {
7386
7385
  const {
7387
7386
  displayPattern
7388
7387
  } = this.props;
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) {
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) {
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';
7409
7405
  }
7406
+ return triggerEvent.key;
7410
7407
  };
7411
7408
  resetEvent = () => {
7412
7409
  this.setState({
@@ -7434,6 +7431,7 @@ class WithDisplayFormat extends Component {
7434
7431
  const {
7435
7432
  displayPattern
7436
7433
  } = this.props;
7434
+
7437
7435
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7438
7436
  let newFormattedValue = '';
7439
7437
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7482,6 +7480,7 @@ class WithDisplayFormat extends Component {
7482
7480
  handleOnChange = event => {
7483
7481
  const {
7484
7482
  historyNavigator,
7483
+ triggerEvent,
7485
7484
  triggerType
7486
7485
  } = this.state;
7487
7486
  const {
@@ -7492,7 +7491,9 @@ class WithDisplayFormat extends Component {
7492
7491
  value
7493
7492
  } = event.target;
7494
7493
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7495
- const action = this.getUserAction(unformattedValue);
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);
7496
7497
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7497
7498
  return;
7498
7499
  }
@@ -7502,18 +7503,19 @@ class WithDisplayFormat extends Component {
7502
7503
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7503
7504
  historyNavigator.add(unformattedValue);
7504
7505
  this.handleCursorPositioning(action);
7506
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7505
7507
  this.setState({
7506
7508
  value: newFormattedValue
7507
- }, () => {
7508
- this.resetEvent();
7509
- if (onChange) {
7510
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7511
- onChange(broadcastValue);
7512
- }
7513
- });
7509
+ }, this.resetEvent(), onChange(broadcastValue));
7514
7510
  };
7515
7511
  handleOnBlur = event => {
7516
- this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7512
+ const {
7513
+ displayPattern,
7514
+ onBlur
7515
+ } = this.props;
7516
+ if (onBlur) {
7517
+ onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7518
+ }
7517
7519
  };
7518
7520
  handleOnFocus = event => {
7519
7521
  const {
@@ -7571,36 +7573,103 @@ class WithDisplayFormat extends Component {
7571
7573
  }, 0);
7572
7574
  };
7573
7575
  render() {
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,
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,
7588
7607
  onFocus: this.handleOnFocus,
7589
7608
  onBlur: this.handleOnBlur,
7590
7609
  onPaste: this.handleOnPaste,
7591
7610
  onKeyDown: this.handleOnKeyDown,
7592
7611
  onChange: this.handleOnChange,
7593
7612
  onCut: this.handleOnCut
7594
- });
7613
+ };
7614
+ return this.props.render(renderProps);
7595
7615
  }
7596
7616
  }
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;
7597
7661
 
7598
- const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
7662
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
7599
7663
  ...props,
7600
- render: renderProps => /*#__PURE__*/jsx(Input, {
7664
+ render: renderProps => /*#__PURE__*/jsx("input", {
7601
7665
  ...renderProps
7602
7666
  })
7603
7667
  });
7668
+ InputWithDisplayFormat.propTypes = {
7669
+ displayPattern: PropTypes.string.isRequired,
7670
+ onChange: PropTypes.func.isRequired
7671
+ };
7672
+ var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7604
7673
 
7605
7674
  const InstructionsList = ({
7606
7675
  dos,
@@ -12277,12 +12346,17 @@ Tabs.defaultProps = {
12277
12346
  };
12278
12347
  var Tabs$1 = Tabs;
12279
12348
 
12280
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
12349
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
12281
12350
  ...props,
12282
- render: renderProps => /*#__PURE__*/jsx(TextArea, {
12351
+ render: renderProps => /*#__PURE__*/jsx("textarea", {
12283
12352
  ...renderProps
12284
12353
  })
12285
12354
  });
12355
+ TextareaWithDisplayFormat.propTypes = {
12356
+ displayPattern: PropTypes.string.isRequired,
12357
+ onChange: PropTypes.func.isRequired
12358
+ };
12359
+ var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12286
12360
 
12287
12361
  /* eslint-disable jsx-a11y/no-autofocus */
12288
12362
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15579,5 +15653,5 @@ const translations = {
15579
15653
  'zh-HK': zhHK
15580
15654
  };
15581
15655
 
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 };
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 };
15583
15657
  //# sourceMappingURL=index.esm.js.map