@transferwise/components 46.10.1 → 46.12.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 (41) hide show
  1. package/README.md +14 -1
  2. package/build/i18n/zh-HK.json +2 -2
  3. package/build/index.esm.js +49 -147
  4. package/build/index.esm.js.map +1 -1
  5. package/build/index.js +49 -147
  6. package/build/index.js.map +1 -1
  7. package/build/mocks.esm.js +40 -0
  8. package/build/mocks.esm.js.map +1 -0
  9. package/build/mocks.js +43 -0
  10. package/build/mocks.js.map +1 -0
  11. package/build/types/index.d.ts +1 -0
  12. package/build/types/index.d.ts.map +1 -1
  13. package/build/types/mocks.d.ts +9 -0
  14. package/build/types/mocks.d.ts.map +1 -0
  15. package/build/types/test-utils/window-mock.d.ts.map +1 -1
  16. package/build/types/typeahead/Typeahead.d.ts +95 -57
  17. package/build/types/typeahead/Typeahead.d.ts.map +1 -1
  18. package/build/types/typeahead/index.d.ts +2 -2
  19. package/build/types/typeahead/index.d.ts.map +1 -1
  20. package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts +23 -41
  21. package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts.map +1 -1
  22. package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts +9 -17
  23. package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts.map +1 -1
  24. package/build/types/typeahead/util/highlight.d.ts +2 -1
  25. package/build/types/typeahead/util/highlight.d.ts.map +1 -1
  26. package/package.json +26 -7
  27. package/src/dimmer/Dimmer.spec.js +0 -4
  28. package/src/i18n/zh-HK.json +2 -2
  29. package/src/index.ts +1 -0
  30. package/src/mocks.ts +48 -0
  31. package/src/snackbar/Snackbar.spec.js +0 -4
  32. package/src/test-utils/window-mock.ts +7 -23
  33. package/src/typeahead/{Typeahead.story.js → Typeahead.story.tsx} +8 -7
  34. package/src/typeahead/{Typeahead.js → Typeahead.tsx} +110 -111
  35. package/src/typeahead/index.ts +2 -0
  36. package/src/typeahead/typeaheadInput/TypeaheadInput.spec.js +1 -0
  37. package/src/typeahead/typeaheadInput/{TypeaheadInput.js → TypeaheadInput.tsx} +35 -46
  38. package/src/typeahead/typeaheadOption/{TypeaheadOption.js → TypeaheadOption.tsx} +10 -20
  39. package/src/typeahead/util/{highlight.js → highlight.tsx} +1 -1
  40. package/src/withNextPortal/withNextPortal.spec.js +0 -4
  41. package/src/typeahead/index.js +0 -3
package/build/index.js CHANGED
@@ -12244,8 +12244,10 @@ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDispl
12244
12244
  /* eslint-disable jsx-a11y/no-static-element-interactions */
12245
12245
  const DEFAULT_INPUT_MIN_WIDTH = 10;
12246
12246
  class TypeaheadInput extends React.Component {
12247
- constructor() {
12248
- super();
12247
+ inputRef = /*#__PURE__*/React.createRef();
12248
+ sizerRef = /*#__PURE__*/React.createRef();
12249
+ constructor(props) {
12250
+ super(props);
12249
12251
  this.state = {
12250
12252
  inputWidth: DEFAULT_INPUT_MIN_WIDTH
12251
12253
  };
@@ -12255,7 +12257,7 @@ class TypeaheadInput extends React.Component {
12255
12257
  autoFocus
12256
12258
  } = this.props;
12257
12259
  if (autoFocus) {
12258
- this.inputRef.focus();
12260
+ this.inputRef.current?.focus();
12259
12261
  }
12260
12262
  }
12261
12263
  componentDidUpdate(previousProps) {
@@ -12266,7 +12268,7 @@ class TypeaheadInput extends React.Component {
12266
12268
  recalculateWidth = () => {
12267
12269
  requestAnimationFrame(() => {
12268
12270
  this.setState({
12269
- inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10)
12271
+ inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.current?.scrollWidth ?? 0 + 10)
12270
12272
  });
12271
12273
  });
12272
12274
  };
@@ -12291,9 +12293,7 @@ class TypeaheadInput extends React.Component {
12291
12293
  } = this.state;
12292
12294
  const hasPlaceholder = !multiple || selected.length === 0;
12293
12295
  return /*#__PURE__*/jsxRuntime.jsx(Input, {
12294
- ref: reference => {
12295
- this.inputRef = reference;
12296
- },
12296
+ ref: this.inputRef,
12297
12297
  className: classNames__default.default(multiple && 'typeahead__input'),
12298
12298
  name: name,
12299
12299
  id: `input-${typeaheadId}`,
@@ -12326,11 +12326,11 @@ class TypeaheadInput extends React.Component {
12326
12326
  } = this.props;
12327
12327
  return multiple ? /*#__PURE__*/jsxRuntime.jsxs("div", {
12328
12328
  className: "form-control typeahead__input-container",
12329
- style: maxHeight && {
12329
+ style: {
12330
12330
  maxHeight
12331
12331
  },
12332
12332
  onClick: () => {
12333
- this.inputRef.focus();
12333
+ this.inputRef.current?.focus();
12334
12334
  },
12335
12335
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
12336
12336
  className: "typeahead__input-wrapper",
@@ -12338,39 +12338,13 @@ class TypeaheadInput extends React.Component {
12338
12338
  className: "typeahead__input-aligner"
12339
12339
  })]
12340
12340
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
12341
- ref: reference => {
12342
- this.sizerRef = reference;
12343
- },
12341
+ ref: this.sizerRef,
12344
12342
  className: "sizer form-control typeahead__input",
12345
12343
  children: value
12346
12344
  })]
12347
12345
  }) : this.renderInput();
12348
12346
  }
12349
12347
  }
12350
- TypeaheadInput.propTypes = {
12351
- typeaheadId: PropTypes__default.default.string.isRequired,
12352
- name: PropTypes__default.default.string.isRequired,
12353
- autoFocus: PropTypes__default.default.bool,
12354
- multiple: PropTypes__default.default.bool.isRequired,
12355
- value: PropTypes__default.default.string.isRequired,
12356
- selected: PropTypes__default.default.arrayOf(PropTypes__default.default.object),
12357
- placeholder: PropTypes__default.default.string,
12358
- optionsShown: PropTypes__default.default.bool,
12359
- maxHeight: PropTypes__default.default.number,
12360
- autoComplete: PropTypes__default.default.string.isRequired,
12361
- onChange: PropTypes__default.default.func.isRequired,
12362
- renderChip: PropTypes__default.default.func.isRequired,
12363
- onKeyDown: PropTypes__default.default.func.isRequired,
12364
- onFocus: PropTypes__default.default.func.isRequired,
12365
- onPaste: PropTypes__default.default.func.isRequired
12366
- };
12367
- TypeaheadInput.defaultProps = {
12368
- autoFocus: false,
12369
- maxHeight: null,
12370
- placeholder: '',
12371
- optionsShown: false,
12372
- selected: []
12373
- };
12374
12348
 
12375
12349
  function highlight(value, query) {
12376
12350
  if (value && query) {
@@ -12391,9 +12365,9 @@ function highlight(value, query) {
12391
12365
  const Option = props => {
12392
12366
  const {
12393
12367
  option,
12394
- selected,
12395
- onClick,
12396
- query
12368
+ selected = false,
12369
+ onClick = () => {},
12370
+ query = ''
12397
12371
  } = props;
12398
12372
  const {
12399
12373
  label,
@@ -12423,46 +12397,48 @@ const Option = props => {
12423
12397
  })
12424
12398
  });
12425
12399
  };
12426
- Option.propTypes = {
12427
- option: PropTypes__default.default.shape({
12428
- label: PropTypes__default.default.string.isRequired,
12429
- note: PropTypes__default.default.string,
12430
- secondary: PropTypes__default.default.string
12431
- }).isRequired,
12432
- query: PropTypes__default.default.string,
12433
- selected: PropTypes__default.default.bool,
12434
- onClick: PropTypes__default.default.func
12435
- };
12436
- Option.defaultProps = {
12437
- selected: false,
12438
- query: '',
12439
- onClick: () => {}
12440
- };
12441
- var TypeaheadOption = Option;
12442
12400
 
12443
12401
  /* eslint-disable jsx-a11y/anchor-is-valid */
12444
12402
  /* eslint-disable jsx-a11y/click-events-have-key-events */
12445
12403
  /* eslint-disable jsx-a11y/no-static-element-interactions */
12446
-
12447
12404
  const DEFAULT_MIN_QUERY_LENGTH = 3;
12448
12405
  const SEARCH_DELAY = 200;
12449
12406
  class Typeahead extends React.Component {
12407
+ static defaultProps = {
12408
+ allowNew: false,
12409
+ autoFillOnBlur: true,
12410
+ autoFocus: false,
12411
+ chipSeparators: [],
12412
+ clearable: true,
12413
+ initialValue: [],
12414
+ inputAutoComplete: 'new-password',
12415
+ minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
12416
+ multiple: false,
12417
+ searchDelay: SEARCH_DELAY,
12418
+ showSuggestions: true,
12419
+ showNewEntry: true,
12420
+ size: exports.Size.MEDIUM,
12421
+ validateChip: () => true
12422
+ };
12450
12423
  constructor(props) {
12451
12424
  super(props);
12452
12425
  const {
12453
12426
  searchDelay,
12454
12427
  initialValue,
12455
12428
  multiple
12456
- } = props;
12429
+ } = this.props;
12457
12430
  this.handleSearchDebounced = debounce__default.default(this.handleSearch, searchDelay);
12458
12431
  const initialQuery = !multiple && initialValue.length > 0 ? initialValue[0].label : '';
12459
12432
  this.state = {
12460
12433
  selected: initialValue,
12461
12434
  errorState: false,
12462
12435
  query: initialQuery,
12463
- keyboardFocusedOptionIndex: null
12436
+ keyboardFocusedOptionIndex: null,
12437
+ optionsShown: false,
12438
+ isFocused: false
12464
12439
  };
12465
12440
  }
12441
+ handleSearchDebounced;
12466
12442
  UNSAFE_componentWillReceiveProps(nextProps) {
12467
12443
  if (nextProps.multiple !== this.props.multiple) {
12468
12444
  this.setState(previousState => {
@@ -12476,6 +12452,7 @@ class Typeahead extends React.Component {
12476
12452
  };
12477
12453
  }
12478
12454
  return {
12455
+ selected: previousState.selected,
12479
12456
  query: ''
12480
12457
  };
12481
12458
  });
@@ -12485,13 +12462,8 @@ class Typeahead extends React.Component {
12485
12462
  this.handleSearchDebounced.cancel();
12486
12463
  }
12487
12464
  handleOnFocus = () => {
12488
- const {
12489
- onFocus
12490
- } = this.props;
12491
12465
  this.showMenu();
12492
- if (onFocus) {
12493
- this.props.onFocus();
12494
- }
12466
+ this.props.onFocus?.();
12495
12467
  };
12496
12468
  onOptionSelected = (event, item) => {
12497
12469
  event.preventDefault();
@@ -12574,7 +12546,7 @@ class Typeahead extends React.Component {
12574
12546
  break;
12575
12547
  case 'Enter':
12576
12548
  event.preventDefault();
12577
- if (options[keyboardFocusedOptionIndex]) {
12549
+ if (keyboardFocusedOptionIndex != null && options[keyboardFocusedOptionIndex]) {
12578
12550
  this.selectItem(options[keyboardFocusedOptionIndex]);
12579
12551
  } else if (allowNew && query.trim()) {
12580
12552
  this.selectItem({
@@ -12626,13 +12598,6 @@ class Typeahead extends React.Component {
12626
12598
  query
12627
12599
  });
12628
12600
  };
12629
- stopPropagation = event => {
12630
- event.stopPropagation();
12631
- event.preventDefault();
12632
- if (event.nativeEvent && event.nativeEvent.stopImmediatePropagation) {
12633
- event.nativeEvent.stopImmediatePropagation();
12634
- }
12635
- };
12636
12601
  handleSearch = query => {
12637
12602
  const {
12638
12603
  onSearch
@@ -12717,7 +12682,7 @@ class Typeahead extends React.Component {
12717
12682
  }
12718
12683
  };
12719
12684
  renderChip = (option, idx) => {
12720
- const valid = this.props.validateChip(option);
12685
+ const valid = this.props.validateChip?.(option);
12721
12686
  return /*#__PURE__*/jsxRuntime.jsx(Chip, {
12722
12687
  label: option.label,
12723
12688
  className: classNames__default.default('m-t-1', {
@@ -12752,7 +12717,7 @@ class Typeahead extends React.Component {
12752
12717
  className: "dropdown-menu",
12753
12718
  role: "menu",
12754
12719
  "aria-labelledby": "dropdownMenu1",
12755
- children: [optionsToRender.map((option, idx) => /*#__PURE__*/jsxRuntime.jsx(TypeaheadOption, {
12720
+ children: [optionsToRender.map((option, idx) => /*#__PURE__*/jsxRuntime.jsx(Option, {
12756
12721
  query: query,
12757
12722
  option: option,
12758
12723
  selected: keyboardFocusedOptionIndex === idx,
@@ -12795,16 +12760,18 @@ class Typeahead extends React.Component {
12795
12760
  const menu = this.renderMenu({
12796
12761
  footer,
12797
12762
  options,
12763
+ id,
12798
12764
  keyboardFocusedOptionIndex,
12799
12765
  query,
12800
12766
  allowNew,
12801
12767
  showNewEntry,
12802
12768
  dropdownOpen
12803
12769
  });
12804
- const hasError = errorState || alert && alert.type === exports.Sentiment.ERROR;
12805
- const displayAlert = !errorState && alert || alert && alert.type === exports.Sentiment.ERROR;
12806
- const hasWarning = displayAlert && alert.type === exports.Sentiment.WARNING;
12807
- const hasInfo = displayAlert && alert.type === exports.Sentiment.NEUTRAL;
12770
+ const alertType = alert?.type ?? exports.Sentiment.NEUTRAL;
12771
+ const hasError = errorState || alert && alertType === exports.Sentiment.ERROR;
12772
+ const displayAlert = !errorState && alert || alert && alertType === exports.Sentiment.ERROR;
12773
+ const hasWarning = displayAlert && alertType === exports.Sentiment.WARNING;
12774
+ const hasInfo = displayAlert && alertType === exports.Sentiment.NEUTRAL;
12808
12775
  return /*#__PURE__*/jsxRuntime.jsx("div", {
12809
12776
  id: id,
12810
12777
  className: classNames__default.default('typeahead', `typeahead-${size}`, {
@@ -12813,7 +12780,7 @@ class Typeahead extends React.Component {
12813
12780
  'typeahead--multiple': multiple,
12814
12781
  open: dropdownOpen
12815
12782
  }),
12816
- onClick: this.stopPropagation,
12783
+ onClick: stopPropagation$1,
12817
12784
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
12818
12785
  className: classNames__default.default('form-group', {
12819
12786
  'has-error': hasError,
@@ -12834,6 +12801,7 @@ class Typeahead extends React.Component {
12834
12801
  placeholder,
12835
12802
  selected,
12836
12803
  maxHeight,
12804
+ id: id,
12837
12805
  name: name,
12838
12806
  value: query,
12839
12807
  typeaheadId: id,
@@ -12860,72 +12828,6 @@ class Typeahead extends React.Component {
12860
12828
  });
12861
12829
  }
12862
12830
  }
12863
- Typeahead.propTypes = {
12864
- id: PropTypes__default.default.string.isRequired,
12865
- name: PropTypes__default.default.string.isRequired,
12866
- options: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
12867
- label: PropTypes__default.default.string.isRequired,
12868
- note: PropTypes__default.default.string,
12869
- secondary: PropTypes__default.default.string,
12870
- value: PropTypes__default.default.object
12871
- })).isRequired,
12872
- initialValue: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
12873
- label: PropTypes__default.default.string.isRequired,
12874
- note: PropTypes__default.default.string,
12875
- secondary: PropTypes__default.default.string
12876
- })),
12877
- onChange: PropTypes__default.default.func.isRequired,
12878
- allowNew: PropTypes__default.default.bool,
12879
- autoFocus: PropTypes__default.default.bool,
12880
- clearable: PropTypes__default.default.bool,
12881
- multiple: PropTypes__default.default.bool,
12882
- showSuggestions: PropTypes__default.default.bool,
12883
- showNewEntry: PropTypes__default.default.bool,
12884
- searchDelay: PropTypes__default.default.number,
12885
- maxHeight: PropTypes__default.default.number,
12886
- minQueryLength: PropTypes__default.default.number,
12887
- addon: PropTypes__default.default.node,
12888
- placeholder: PropTypes__default.default.string,
12889
- alert: PropTypes__default.default.shape({
12890
- message: PropTypes__default.default.string.isRequired,
12891
- type: PropTypes__default.default.oneOf(['error', 'warning', 'neutral']).isRequired
12892
- }),
12893
- footer: PropTypes__default.default.node,
12894
- validateChip: PropTypes__default.default.func,
12895
- onSearch: PropTypes__default.default.func,
12896
- onBlur: PropTypes__default.default.func,
12897
- onInputChange: PropTypes__default.default.func,
12898
- onFocus: PropTypes__default.default.func,
12899
- chipSeparators: PropTypes__default.default.arrayOf(PropTypes__default.default.string),
12900
- size: PropTypes__default.default.oneOf(['md', 'lg']),
12901
- inputAutoComplete: PropTypes__default.default.string,
12902
- autoFillOnBlur: PropTypes__default.default.bool
12903
- };
12904
- Typeahead.defaultProps = {
12905
- allowNew: false,
12906
- autoFocus: false,
12907
- clearable: true,
12908
- multiple: false,
12909
- maxHeight: null,
12910
- showSuggestions: true,
12911
- showNewEntry: true,
12912
- searchDelay: SEARCH_DELAY,
12913
- minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
12914
- addon: null,
12915
- placeholder: null,
12916
- alert: null,
12917
- footer: null,
12918
- size: exports.Size.MEDIUM,
12919
- chipSeparators: [],
12920
- initialValue: [],
12921
- onSearch: null,
12922
- onBlur: null,
12923
- onInputChange: null,
12924
- onFocus: null,
12925
- validateChip: () => true,
12926
- inputAutoComplete: 'new-password',
12927
- autoFillOnBlur: true
12928
- };
12929
12831
 
12930
12832
  // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12931
12833
  exports.UploadStep = void 0;
@@ -15474,10 +15376,10 @@ var zhHK = {
15474
15376
  "neptune.ClearButton.ariaLabel": "清除",
15475
15377
  "neptune.CloseButton.ariaLabel": "關閉",
15476
15378
  "neptune.DateInput.day.label": "日",
15477
- "neptune.DateInput.day.placeholder": "",
15379
+ "neptune.DateInput.day.placeholder": "DD",
15478
15380
  "neptune.DateInput.month.label": "月",
15479
15381
  "neptune.DateInput.year.label": "年",
15480
- "neptune.DateInput.year.placeholder": "",
15382
+ "neptune.DateInput.year.placeholder": "YYYY",
15481
15383
  "neptune.DateLookup.day": "日",
15482
15384
  "neptune.DateLookup.goTo20YearView": "切換至20年視圖",
15483
15385
  "neptune.DateLookup.month": "月",