@transferwise/components 0.0.0-experimental-ef158b4 → 0.0.0-experimental-4f82861

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.
package/build/index.js CHANGED
@@ -12244,10 +12244,8 @@ 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
- inputRef = null;
12248
- sizerRef = null;
12249
- constructor(props) {
12250
- super(props);
12247
+ constructor() {
12248
+ super();
12251
12249
  this.state = {
12252
12250
  inputWidth: DEFAULT_INPUT_MIN_WIDTH
12253
12251
  };
@@ -12257,7 +12255,7 @@ class TypeaheadInput extends React.Component {
12257
12255
  autoFocus
12258
12256
  } = this.props;
12259
12257
  if (autoFocus) {
12260
- this.inputRef?.focus();
12258
+ this.inputRef.focus();
12261
12259
  }
12262
12260
  }
12263
12261
  componentDidUpdate(previousProps) {
@@ -12268,19 +12266,19 @@ class TypeaheadInput extends React.Component {
12268
12266
  recalculateWidth = () => {
12269
12267
  requestAnimationFrame(() => {
12270
12268
  this.setState({
12271
- inputWidth: this.sizerRef ? Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10) : DEFAULT_INPUT_MIN_WIDTH
12269
+ inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10)
12272
12270
  });
12273
12271
  });
12274
12272
  };
12275
12273
  renderInput = () => {
12276
12274
  const {
12277
12275
  typeaheadId,
12278
- autoFocus = false,
12276
+ autoFocus,
12279
12277
  multiple,
12280
12278
  name,
12281
- optionsShown = false,
12282
- placeholder = '',
12283
- selected = [],
12279
+ optionsShown,
12280
+ placeholder,
12281
+ selected,
12284
12282
  value,
12285
12283
  onChange,
12286
12284
  onKeyDown,
@@ -12321,18 +12319,18 @@ class TypeaheadInput extends React.Component {
12321
12319
  render() {
12322
12320
  const {
12323
12321
  multiple,
12324
- selected = [],
12322
+ selected,
12325
12323
  value,
12326
- maxHeight = null,
12324
+ maxHeight,
12327
12325
  renderChip
12328
12326
  } = this.props;
12329
12327
  return multiple ? /*#__PURE__*/jsxRuntime.jsxs("div", {
12330
12328
  className: "form-control typeahead__input-container",
12331
- style: {
12332
- maxHeight: maxHeight ?? undefined
12329
+ style: maxHeight && {
12330
+ maxHeight
12333
12331
  },
12334
12332
  onClick: () => {
12335
- this.inputRef?.focus();
12333
+ this.inputRef.focus();
12336
12334
  },
12337
12335
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
12338
12336
  className: "typeahead__input-wrapper",
@@ -12349,6 +12347,30 @@ class TypeaheadInput extends React.Component {
12349
12347
  }) : this.renderInput();
12350
12348
  }
12351
12349
  }
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
+ };
12352
12374
 
12353
12375
  function highlight(value, query) {
12354
12376
  if (value && query) {
@@ -12369,9 +12391,9 @@ function highlight(value, query) {
12369
12391
  const Option = props => {
12370
12392
  const {
12371
12393
  option,
12372
- selected = false,
12373
- onClick = () => {},
12374
- query = ''
12394
+ selected,
12395
+ onClick,
12396
+ query
12375
12397
  } = props;
12376
12398
  const {
12377
12399
  label,
@@ -12401,33 +12423,30 @@ const Option = props => {
12401
12423
  })
12402
12424
  });
12403
12425
  };
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
+ };
12404
12441
  var TypeaheadOption = Option;
12405
12442
 
12406
12443
  /* eslint-disable jsx-a11y/anchor-is-valid */
12407
12444
  /* eslint-disable jsx-a11y/click-events-have-key-events */
12408
12445
  /* eslint-disable jsx-a11y/no-static-element-interactions */
12446
+
12409
12447
  const DEFAULT_MIN_QUERY_LENGTH = 3;
12410
12448
  const SEARCH_DELAY = 200;
12411
12449
  class Typeahead extends React.Component {
12412
- static defaultProps = {
12413
- addon: null,
12414
- allowNew: false,
12415
- autoFillOnBlur: true,
12416
- autoFocus: false,
12417
- chipSeparators: [],
12418
- clearable: true,
12419
- footer: null,
12420
- initialValue: [],
12421
- inputAutoComplete: 'new-password',
12422
- maxHeight: null,
12423
- minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
12424
- multiple: false,
12425
- searchDelay: SEARCH_DELAY,
12426
- showSuggestions: true,
12427
- showNewEntry: true,
12428
- size: exports.Size.MEDIUM,
12429
- validateChip: () => true
12430
- };
12431
12450
  constructor(props) {
12432
12451
  super(props);
12433
12452
  const {
@@ -12444,7 +12463,6 @@ class Typeahead extends React.Component {
12444
12463
  keyboardFocusedOptionIndex: null
12445
12464
  };
12446
12465
  }
12447
- handleSearchDebounced;
12448
12466
  UNSAFE_componentWillReceiveProps(nextProps) {
12449
12467
  if (nextProps.multiple !== this.props.multiple) {
12450
12468
  this.setState(previousState => {
@@ -12458,8 +12476,7 @@ class Typeahead extends React.Component {
12458
12476
  };
12459
12477
  }
12460
12478
  return {
12461
- query: '',
12462
- selected: previousState.selected
12479
+ query: ''
12463
12480
  };
12464
12481
  });
12465
12482
  }
@@ -12468,8 +12485,13 @@ class Typeahead extends React.Component {
12468
12485
  this.handleSearchDebounced.cancel();
12469
12486
  }
12470
12487
  handleOnFocus = () => {
12488
+ const {
12489
+ onFocus
12490
+ } = this.props;
12471
12491
  this.showMenu();
12472
- this.props.onFocus?.();
12492
+ if (onFocus) {
12493
+ this.props.onFocus();
12494
+ }
12473
12495
  };
12474
12496
  onOptionSelected = (event, item) => {
12475
12497
  event.preventDefault();
@@ -12552,7 +12574,7 @@ class Typeahead extends React.Component {
12552
12574
  break;
12553
12575
  case 'Enter':
12554
12576
  event.preventDefault();
12555
- if (keyboardFocusedOptionIndex && options[keyboardFocusedOptionIndex]) {
12577
+ if (options[keyboardFocusedOptionIndex]) {
12556
12578
  this.selectItem(options[keyboardFocusedOptionIndex]);
12557
12579
  } else if (allowNew && query.trim()) {
12558
12580
  this.selectItem({
@@ -12604,6 +12626,13 @@ class Typeahead extends React.Component {
12604
12626
  query
12605
12627
  });
12606
12628
  };
12629
+ stopPropagation = event => {
12630
+ event.stopPropagation();
12631
+ event.preventDefault();
12632
+ if (event.nativeEvent && event.nativeEvent.stopImmediatePropagation) {
12633
+ event.nativeEvent.stopImmediatePropagation();
12634
+ }
12635
+ };
12607
12636
  handleSearch = query => {
12608
12637
  const {
12609
12638
  onSearch
@@ -12688,7 +12717,7 @@ class Typeahead extends React.Component {
12688
12717
  }
12689
12718
  };
12690
12719
  renderChip = (option, idx) => {
12691
- const valid = this.props.validateChip?.(option);
12720
+ const valid = this.props.validateChip(option);
12692
12721
  return /*#__PURE__*/jsxRuntime.jsx(Chip, {
12693
12722
  label: option.label,
12694
12723
  className: classNames__default.default('m-t-1', {
@@ -12766,7 +12795,6 @@ class Typeahead extends React.Component {
12766
12795
  const menu = this.renderMenu({
12767
12796
  footer,
12768
12797
  options,
12769
- id,
12770
12798
  keyboardFocusedOptionIndex,
12771
12799
  query,
12772
12800
  allowNew,
@@ -12785,7 +12813,7 @@ class Typeahead extends React.Component {
12785
12813
  'typeahead--multiple': multiple,
12786
12814
  open: dropdownOpen
12787
12815
  }),
12788
- onClick: stopPropagation$1,
12816
+ onClick: this.stopPropagation,
12789
12817
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
12790
12818
  className: classNames__default.default('form-group', {
12791
12819
  'has-error': hasError,
@@ -12806,7 +12834,6 @@ class Typeahead extends React.Component {
12806
12834
  placeholder,
12807
12835
  selected,
12808
12836
  maxHeight,
12809
- id: id,
12810
12837
  name: name,
12811
12838
  value: query,
12812
12839
  typeaheadId: id,
@@ -12833,6 +12860,72 @@ class Typeahead extends React.Component {
12833
12860
  });
12834
12861
  }
12835
12862
  }
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
+ };
12836
12929
 
12837
12930
  // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12838
12931
  exports.UploadStep = void 0;