@transferwise/components 0.0.0-experimental-77b2752 → 0.0.0-experimental-c9a3ec4

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
@@ -6767,6 +6767,7 @@ function SelectInputClearButton({
6767
6767
  }
6768
6768
  const noop = () => {};
6769
6769
  function SelectInput({
6770
+ id,
6770
6771
  name,
6771
6772
  multiple,
6772
6773
  placeholder,
@@ -6832,6 +6833,7 @@ function SelectInput({
6832
6833
  // eslint-disable-next-line react/jsx-no-constructed-context-values
6833
6834
  value: {
6834
6835
  ref: mergeRefs__default.default([ref, triggerRef]),
6836
+ id,
6835
6837
  ...mergeProps__default.default({
6836
6838
  onClick: () => {
6837
6839
  setOpen(prev => !prev);
@@ -12234,8 +12236,10 @@ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDispl
12234
12236
  /* eslint-disable jsx-a11y/no-static-element-interactions */
12235
12237
  const DEFAULT_INPUT_MIN_WIDTH = 10;
12236
12238
  class TypeaheadInput extends React.Component {
12237
- constructor() {
12238
- super();
12239
+ inputRef = null;
12240
+ sizerRef = null;
12241
+ constructor(props) {
12242
+ super(props);
12239
12243
  this.state = {
12240
12244
  inputWidth: DEFAULT_INPUT_MIN_WIDTH
12241
12245
  };
@@ -12245,7 +12249,7 @@ class TypeaheadInput extends React.Component {
12245
12249
  autoFocus
12246
12250
  } = this.props;
12247
12251
  if (autoFocus) {
12248
- this.inputRef.focus();
12252
+ this.inputRef?.focus();
12249
12253
  }
12250
12254
  }
12251
12255
  componentDidUpdate(previousProps) {
@@ -12256,19 +12260,19 @@ class TypeaheadInput extends React.Component {
12256
12260
  recalculateWidth = () => {
12257
12261
  requestAnimationFrame(() => {
12258
12262
  this.setState({
12259
- inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10)
12263
+ inputWidth: this.sizerRef ? Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10) : DEFAULT_INPUT_MIN_WIDTH
12260
12264
  });
12261
12265
  });
12262
12266
  };
12263
12267
  renderInput = () => {
12264
12268
  const {
12265
12269
  typeaheadId,
12266
- autoFocus,
12270
+ autoFocus = false,
12267
12271
  multiple,
12268
12272
  name,
12269
- optionsShown,
12270
- placeholder,
12271
- selected,
12273
+ optionsShown = false,
12274
+ placeholder = '',
12275
+ selected = [],
12272
12276
  value,
12273
12277
  onChange,
12274
12278
  onKeyDown,
@@ -12309,18 +12313,18 @@ class TypeaheadInput extends React.Component {
12309
12313
  render() {
12310
12314
  const {
12311
12315
  multiple,
12312
- selected,
12316
+ selected = [],
12313
12317
  value,
12314
- maxHeight,
12318
+ maxHeight = null,
12315
12319
  renderChip
12316
12320
  } = this.props;
12317
12321
  return multiple ? /*#__PURE__*/jsxRuntime.jsxs("div", {
12318
12322
  className: "form-control typeahead__input-container",
12319
- style: maxHeight && {
12320
- maxHeight
12323
+ style: {
12324
+ maxHeight: maxHeight ?? undefined
12321
12325
  },
12322
12326
  onClick: () => {
12323
- this.inputRef.focus();
12327
+ this.inputRef?.focus();
12324
12328
  },
12325
12329
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
12326
12330
  className: "typeahead__input-wrapper",
@@ -12337,30 +12341,6 @@ class TypeaheadInput extends React.Component {
12337
12341
  }) : this.renderInput();
12338
12342
  }
12339
12343
  }
12340
- TypeaheadInput.propTypes = {
12341
- typeaheadId: PropTypes__default.default.string.isRequired,
12342
- name: PropTypes__default.default.string.isRequired,
12343
- autoFocus: PropTypes__default.default.bool,
12344
- multiple: PropTypes__default.default.bool.isRequired,
12345
- value: PropTypes__default.default.string.isRequired,
12346
- selected: PropTypes__default.default.arrayOf(PropTypes__default.default.object),
12347
- placeholder: PropTypes__default.default.string,
12348
- optionsShown: PropTypes__default.default.bool,
12349
- maxHeight: PropTypes__default.default.number,
12350
- autoComplete: PropTypes__default.default.string.isRequired,
12351
- onChange: PropTypes__default.default.func.isRequired,
12352
- renderChip: PropTypes__default.default.func.isRequired,
12353
- onKeyDown: PropTypes__default.default.func.isRequired,
12354
- onFocus: PropTypes__default.default.func.isRequired,
12355
- onPaste: PropTypes__default.default.func.isRequired
12356
- };
12357
- TypeaheadInput.defaultProps = {
12358
- autoFocus: false,
12359
- maxHeight: null,
12360
- placeholder: '',
12361
- optionsShown: false,
12362
- selected: []
12363
- };
12364
12344
 
12365
12345
  function highlight(value, query) {
12366
12346
  if (value && query) {
@@ -12381,9 +12361,9 @@ function highlight(value, query) {
12381
12361
  const Option = props => {
12382
12362
  const {
12383
12363
  option,
12384
- selected,
12385
- onClick,
12386
- query
12364
+ selected = false,
12365
+ onClick = () => {},
12366
+ query = ''
12387
12367
  } = props;
12388
12368
  const {
12389
12369
  label,
@@ -12413,35 +12393,19 @@ const Option = props => {
12413
12393
  })
12414
12394
  });
12415
12395
  };
12416
- Option.propTypes = {
12417
- option: PropTypes__default.default.shape({
12418
- label: PropTypes__default.default.string.isRequired,
12419
- note: PropTypes__default.default.string,
12420
- secondary: PropTypes__default.default.string
12421
- }).isRequired,
12422
- query: PropTypes__default.default.string,
12423
- selected: PropTypes__default.default.bool,
12424
- onClick: PropTypes__default.default.func
12425
- };
12426
- Option.defaultProps = {
12427
- selected: false,
12428
- query: '',
12429
- onClick: () => {}
12430
- };
12431
12396
  var TypeaheadOption = Option;
12432
12397
 
12433
12398
  /* eslint-disable jsx-a11y/anchor-is-valid */
12434
12399
  /* eslint-disable jsx-a11y/click-events-have-key-events */
12435
12400
  /* eslint-disable jsx-a11y/no-static-element-interactions */
12436
-
12437
12401
  const DEFAULT_MIN_QUERY_LENGTH = 3;
12438
12402
  const SEARCH_DELAY = 200;
12439
12403
  class Typeahead extends React.Component {
12440
12404
  constructor(props) {
12441
12405
  super(props);
12442
12406
  const {
12443
- searchDelay,
12444
- initialValue,
12407
+ searchDelay = SEARCH_DELAY,
12408
+ initialValue = [],
12445
12409
  multiple
12446
12410
  } = props;
12447
12411
  this.handleSearchDebounced = debounce__default.default(this.handleSearch, searchDelay);
@@ -12453,6 +12417,7 @@ class Typeahead extends React.Component {
12453
12417
  keyboardFocusedOptionIndex: null
12454
12418
  };
12455
12419
  }
12420
+ handleSearchDebounced;
12456
12421
  UNSAFE_componentWillReceiveProps(nextProps) {
12457
12422
  if (nextProps.multiple !== this.props.multiple) {
12458
12423
  this.setState(previousState => {
@@ -12466,7 +12431,8 @@ class Typeahead extends React.Component {
12466
12431
  };
12467
12432
  }
12468
12433
  return {
12469
- query: ''
12434
+ query: '',
12435
+ selected: previousState.selected
12470
12436
  };
12471
12437
  });
12472
12438
  }
@@ -12475,18 +12441,14 @@ class Typeahead extends React.Component {
12475
12441
  this.handleSearchDebounced.cancel();
12476
12442
  }
12477
12443
  handleOnFocus = () => {
12478
- const {
12479
- onFocus
12480
- } = this.props;
12481
12444
  this.showMenu();
12482
- if (onFocus) {
12483
- this.props.onFocus();
12484
- }
12445
+ this.props.onFocus?.();
12485
12446
  };
12486
12447
  onOptionSelected = (event, item) => {
12487
12448
  event.preventDefault();
12488
12449
  this.selectItem(item);
12489
12450
  };
12451
+ // START HERE
12490
12452
  handleOnChange = event => {
12491
12453
  const {
12492
12454
  optionsShown,
@@ -12514,9 +12476,9 @@ class Typeahead extends React.Component {
12514
12476
  };
12515
12477
  handleOnPaste = event => {
12516
12478
  const {
12517
- allowNew,
12518
- multiple,
12519
- chipSeparators
12479
+ allowNew = false,
12480
+ multiple = false,
12481
+ chipSeparators = []
12520
12482
  } = this.props;
12521
12483
  const {
12522
12484
  selected
@@ -12535,10 +12497,10 @@ class Typeahead extends React.Component {
12535
12497
  };
12536
12498
  handleOnKeyDown = event => {
12537
12499
  const {
12538
- showSuggestions,
12539
- allowNew,
12540
- multiple,
12541
- chipSeparators,
12500
+ showSuggestions = true,
12501
+ allowNew = false,
12502
+ multiple = false,
12503
+ chipSeparators = [],
12542
12504
  options
12543
12505
  } = this.props;
12544
12506
  const {
@@ -12564,7 +12526,7 @@ class Typeahead extends React.Component {
12564
12526
  break;
12565
12527
  case 'Enter':
12566
12528
  event.preventDefault();
12567
- if (options[keyboardFocusedOptionIndex]) {
12529
+ if (keyboardFocusedOptionIndex && options[keyboardFocusedOptionIndex]) {
12568
12530
  this.selectItem(options[keyboardFocusedOptionIndex]);
12569
12531
  } else if (allowNew && query.trim()) {
12570
12532
  this.selectItem({
@@ -12679,7 +12641,7 @@ class Typeahead extends React.Component {
12679
12641
  updateSelectedValue = selected => {
12680
12642
  const {
12681
12643
  onChange,
12682
- validateChip
12644
+ validateChip = () => true
12683
12645
  } = this.props;
12684
12646
  const errorState = selected.some(chip => !validateChip(chip));
12685
12647
  this.setState({
@@ -12707,7 +12669,7 @@ class Typeahead extends React.Component {
12707
12669
  }
12708
12670
  };
12709
12671
  renderChip = (option, idx) => {
12710
- const valid = this.props.validateChip(option);
12672
+ const valid = this.props.validateChip?.(option);
12711
12673
  return /*#__PURE__*/jsxRuntime.jsx(Chip, {
12712
12674
  label: option.label,
12713
12675
  className: classNames__default.default('m-t-1', {
@@ -12757,21 +12719,21 @@ class Typeahead extends React.Component {
12757
12719
  const {
12758
12720
  id,
12759
12721
  placeholder,
12760
- multiple,
12761
- size,
12762
- addon,
12722
+ multiple = false,
12723
+ size = exports.Size.MEDIUM,
12724
+ addon = null,
12763
12725
  name,
12764
- clearable,
12765
- allowNew,
12766
- footer,
12767
- showSuggestions,
12768
- showNewEntry,
12726
+ clearable = true,
12727
+ allowNew = false,
12728
+ footer = null,
12729
+ showSuggestions = true,
12730
+ showNewEntry = true,
12769
12731
  options,
12770
- minQueryLength,
12771
- autoFocus,
12772
- maxHeight,
12773
- alert,
12774
- inputAutoComplete
12732
+ minQueryLength = DEFAULT_MIN_QUERY_LENGTH,
12733
+ autoFocus = false,
12734
+ maxHeight = null,
12735
+ alert = null,
12736
+ inputAutoComplete = 'new-password'
12775
12737
  } = this.props;
12776
12738
  const {
12777
12739
  errorState,
@@ -12785,6 +12747,7 @@ class Typeahead extends React.Component {
12785
12747
  const menu = this.renderMenu({
12786
12748
  footer,
12787
12749
  options,
12750
+ id,
12788
12751
  keyboardFocusedOptionIndex,
12789
12752
  query,
12790
12753
  allowNew,
@@ -12850,72 +12813,6 @@ class Typeahead extends React.Component {
12850
12813
  });
12851
12814
  }
12852
12815
  }
12853
- Typeahead.propTypes = {
12854
- id: PropTypes__default.default.string.isRequired,
12855
- name: PropTypes__default.default.string.isRequired,
12856
- options: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
12857
- label: PropTypes__default.default.string.isRequired,
12858
- note: PropTypes__default.default.string,
12859
- secondary: PropTypes__default.default.string,
12860
- value: PropTypes__default.default.object
12861
- })).isRequired,
12862
- initialValue: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
12863
- label: PropTypes__default.default.string.isRequired,
12864
- note: PropTypes__default.default.string,
12865
- secondary: PropTypes__default.default.string
12866
- })),
12867
- onChange: PropTypes__default.default.func.isRequired,
12868
- allowNew: PropTypes__default.default.bool,
12869
- autoFocus: PropTypes__default.default.bool,
12870
- clearable: PropTypes__default.default.bool,
12871
- multiple: PropTypes__default.default.bool,
12872
- showSuggestions: PropTypes__default.default.bool,
12873
- showNewEntry: PropTypes__default.default.bool,
12874
- searchDelay: PropTypes__default.default.number,
12875
- maxHeight: PropTypes__default.default.number,
12876
- minQueryLength: PropTypes__default.default.number,
12877
- addon: PropTypes__default.default.node,
12878
- placeholder: PropTypes__default.default.string,
12879
- alert: PropTypes__default.default.shape({
12880
- message: PropTypes__default.default.string.isRequired,
12881
- type: PropTypes__default.default.oneOf(['error', 'warning', 'neutral']).isRequired
12882
- }),
12883
- footer: PropTypes__default.default.node,
12884
- validateChip: PropTypes__default.default.func,
12885
- onSearch: PropTypes__default.default.func,
12886
- onBlur: PropTypes__default.default.func,
12887
- onInputChange: PropTypes__default.default.func,
12888
- onFocus: PropTypes__default.default.func,
12889
- chipSeparators: PropTypes__default.default.arrayOf(PropTypes__default.default.string),
12890
- size: PropTypes__default.default.oneOf(['md', 'lg']),
12891
- inputAutoComplete: PropTypes__default.default.string,
12892
- autoFillOnBlur: PropTypes__default.default.bool
12893
- };
12894
- Typeahead.defaultProps = {
12895
- allowNew: false,
12896
- autoFocus: false,
12897
- clearable: true,
12898
- multiple: false,
12899
- maxHeight: null,
12900
- showSuggestions: true,
12901
- showNewEntry: true,
12902
- searchDelay: SEARCH_DELAY,
12903
- minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
12904
- addon: null,
12905
- placeholder: null,
12906
- alert: null,
12907
- footer: null,
12908
- size: exports.Size.MEDIUM,
12909
- chipSeparators: [],
12910
- initialValue: [],
12911
- onSearch: null,
12912
- onBlur: null,
12913
- onInputChange: null,
12914
- onFocus: null,
12915
- validateChip: () => true,
12916
- inputAutoComplete: 'new-password',
12917
- autoFillOnBlur: true
12918
- };
12919
12816
 
12920
12817
  // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12921
12818
  exports.UploadStep = void 0;