@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.esm.js +51 -154
- package/build/index.esm.js.map +1 -1
- package/build/index.js +51 -154
- package/build/index.js.map +1 -1
- package/build/types/inputs/SelectInput.d.ts +2 -1
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/typeahead/Typeahead.d.ts +77 -57
- package/build/types/typeahead/Typeahead.d.ts.map +1 -1
- package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts +28 -41
- package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts.map +1 -1
- package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts +9 -17
- package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts.map +1 -1
- package/package.json +4 -1
- package/src/inputs/SelectInput.spec.tsx +7 -0
- package/src/inputs/SelectInput.story.tsx +221 -315
- package/src/inputs/SelectInput.tsx +4 -0
- package/src/typeahead/{Typeahead.story.js → Typeahead.story.tsx} +8 -7
- package/src/typeahead/{Typeahead.js → Typeahead.tsx} +101 -114
- package/src/typeahead/typeaheadInput/{TypeaheadInput.js → TypeaheadInput.tsx} +45 -42
- package/src/typeahead/typeaheadOption/{TypeaheadOption.js → TypeaheadOption.tsx} +10 -20
package/build/index.esm.js
CHANGED
|
@@ -6733,6 +6733,7 @@ function SelectInputClearButton({
|
|
|
6733
6733
|
}
|
|
6734
6734
|
const noop = () => {};
|
|
6735
6735
|
function SelectInput({
|
|
6736
|
+
id,
|
|
6736
6737
|
name,
|
|
6737
6738
|
multiple,
|
|
6738
6739
|
placeholder,
|
|
@@ -6798,6 +6799,7 @@ function SelectInput({
|
|
|
6798
6799
|
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
6799
6800
|
value: {
|
|
6800
6801
|
ref: mergeRefs([ref, triggerRef]),
|
|
6802
|
+
id,
|
|
6801
6803
|
...mergeProps({
|
|
6802
6804
|
onClick: () => {
|
|
6803
6805
|
setOpen(prev => !prev);
|
|
@@ -12200,8 +12202,10 @@ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
|
|
|
12200
12202
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
12201
12203
|
const DEFAULT_INPUT_MIN_WIDTH = 10;
|
|
12202
12204
|
class TypeaheadInput extends Component {
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
+
inputRef = null;
|
|
12206
|
+
sizerRef = null;
|
|
12207
|
+
constructor(props) {
|
|
12208
|
+
super(props);
|
|
12205
12209
|
this.state = {
|
|
12206
12210
|
inputWidth: DEFAULT_INPUT_MIN_WIDTH
|
|
12207
12211
|
};
|
|
@@ -12211,7 +12215,7 @@ class TypeaheadInput extends Component {
|
|
|
12211
12215
|
autoFocus
|
|
12212
12216
|
} = this.props;
|
|
12213
12217
|
if (autoFocus) {
|
|
12214
|
-
this.inputRef
|
|
12218
|
+
this.inputRef?.focus();
|
|
12215
12219
|
}
|
|
12216
12220
|
}
|
|
12217
12221
|
componentDidUpdate(previousProps) {
|
|
@@ -12222,19 +12226,19 @@ class TypeaheadInput extends Component {
|
|
|
12222
12226
|
recalculateWidth = () => {
|
|
12223
12227
|
requestAnimationFrame(() => {
|
|
12224
12228
|
this.setState({
|
|
12225
|
-
inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10)
|
|
12229
|
+
inputWidth: this.sizerRef ? Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10) : DEFAULT_INPUT_MIN_WIDTH
|
|
12226
12230
|
});
|
|
12227
12231
|
});
|
|
12228
12232
|
};
|
|
12229
12233
|
renderInput = () => {
|
|
12230
12234
|
const {
|
|
12231
12235
|
typeaheadId,
|
|
12232
|
-
autoFocus,
|
|
12236
|
+
autoFocus = false,
|
|
12233
12237
|
multiple,
|
|
12234
12238
|
name,
|
|
12235
|
-
optionsShown,
|
|
12236
|
-
placeholder,
|
|
12237
|
-
selected,
|
|
12239
|
+
optionsShown = false,
|
|
12240
|
+
placeholder = '',
|
|
12241
|
+
selected = [],
|
|
12238
12242
|
value,
|
|
12239
12243
|
onChange,
|
|
12240
12244
|
onKeyDown,
|
|
@@ -12275,18 +12279,18 @@ class TypeaheadInput extends Component {
|
|
|
12275
12279
|
render() {
|
|
12276
12280
|
const {
|
|
12277
12281
|
multiple,
|
|
12278
|
-
selected,
|
|
12282
|
+
selected = [],
|
|
12279
12283
|
value,
|
|
12280
|
-
maxHeight,
|
|
12284
|
+
maxHeight = null,
|
|
12281
12285
|
renderChip
|
|
12282
12286
|
} = this.props;
|
|
12283
12287
|
return multiple ? /*#__PURE__*/jsxs("div", {
|
|
12284
12288
|
className: "form-control typeahead__input-container",
|
|
12285
|
-
style:
|
|
12286
|
-
maxHeight
|
|
12289
|
+
style: {
|
|
12290
|
+
maxHeight: maxHeight ?? undefined
|
|
12287
12291
|
},
|
|
12288
12292
|
onClick: () => {
|
|
12289
|
-
this.inputRef
|
|
12293
|
+
this.inputRef?.focus();
|
|
12290
12294
|
},
|
|
12291
12295
|
children: [/*#__PURE__*/jsxs("div", {
|
|
12292
12296
|
className: "typeahead__input-wrapper",
|
|
@@ -12303,30 +12307,6 @@ class TypeaheadInput extends Component {
|
|
|
12303
12307
|
}) : this.renderInput();
|
|
12304
12308
|
}
|
|
12305
12309
|
}
|
|
12306
|
-
TypeaheadInput.propTypes = {
|
|
12307
|
-
typeaheadId: PropTypes.string.isRequired,
|
|
12308
|
-
name: PropTypes.string.isRequired,
|
|
12309
|
-
autoFocus: PropTypes.bool,
|
|
12310
|
-
multiple: PropTypes.bool.isRequired,
|
|
12311
|
-
value: PropTypes.string.isRequired,
|
|
12312
|
-
selected: PropTypes.arrayOf(PropTypes.object),
|
|
12313
|
-
placeholder: PropTypes.string,
|
|
12314
|
-
optionsShown: PropTypes.bool,
|
|
12315
|
-
maxHeight: PropTypes.number,
|
|
12316
|
-
autoComplete: PropTypes.string.isRequired,
|
|
12317
|
-
onChange: PropTypes.func.isRequired,
|
|
12318
|
-
renderChip: PropTypes.func.isRequired,
|
|
12319
|
-
onKeyDown: PropTypes.func.isRequired,
|
|
12320
|
-
onFocus: PropTypes.func.isRequired,
|
|
12321
|
-
onPaste: PropTypes.func.isRequired
|
|
12322
|
-
};
|
|
12323
|
-
TypeaheadInput.defaultProps = {
|
|
12324
|
-
autoFocus: false,
|
|
12325
|
-
maxHeight: null,
|
|
12326
|
-
placeholder: '',
|
|
12327
|
-
optionsShown: false,
|
|
12328
|
-
selected: []
|
|
12329
|
-
};
|
|
12330
12310
|
|
|
12331
12311
|
function highlight(value, query) {
|
|
12332
12312
|
if (value && query) {
|
|
@@ -12347,9 +12327,9 @@ function highlight(value, query) {
|
|
|
12347
12327
|
const Option = props => {
|
|
12348
12328
|
const {
|
|
12349
12329
|
option,
|
|
12350
|
-
selected,
|
|
12351
|
-
onClick,
|
|
12352
|
-
query
|
|
12330
|
+
selected = false,
|
|
12331
|
+
onClick = () => {},
|
|
12332
|
+
query = ''
|
|
12353
12333
|
} = props;
|
|
12354
12334
|
const {
|
|
12355
12335
|
label,
|
|
@@ -12379,35 +12359,19 @@ const Option = props => {
|
|
|
12379
12359
|
})
|
|
12380
12360
|
});
|
|
12381
12361
|
};
|
|
12382
|
-
Option.propTypes = {
|
|
12383
|
-
option: PropTypes.shape({
|
|
12384
|
-
label: PropTypes.string.isRequired,
|
|
12385
|
-
note: PropTypes.string,
|
|
12386
|
-
secondary: PropTypes.string
|
|
12387
|
-
}).isRequired,
|
|
12388
|
-
query: PropTypes.string,
|
|
12389
|
-
selected: PropTypes.bool,
|
|
12390
|
-
onClick: PropTypes.func
|
|
12391
|
-
};
|
|
12392
|
-
Option.defaultProps = {
|
|
12393
|
-
selected: false,
|
|
12394
|
-
query: '',
|
|
12395
|
-
onClick: () => {}
|
|
12396
|
-
};
|
|
12397
12362
|
var TypeaheadOption = Option;
|
|
12398
12363
|
|
|
12399
12364
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
12400
12365
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
12401
12366
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
12402
|
-
|
|
12403
12367
|
const DEFAULT_MIN_QUERY_LENGTH = 3;
|
|
12404
12368
|
const SEARCH_DELAY = 200;
|
|
12405
12369
|
class Typeahead extends Component {
|
|
12406
12370
|
constructor(props) {
|
|
12407
12371
|
super(props);
|
|
12408
12372
|
const {
|
|
12409
|
-
searchDelay,
|
|
12410
|
-
initialValue,
|
|
12373
|
+
searchDelay = SEARCH_DELAY,
|
|
12374
|
+
initialValue = [],
|
|
12411
12375
|
multiple
|
|
12412
12376
|
} = props;
|
|
12413
12377
|
this.handleSearchDebounced = debounce(this.handleSearch, searchDelay);
|
|
@@ -12419,6 +12383,7 @@ class Typeahead extends Component {
|
|
|
12419
12383
|
keyboardFocusedOptionIndex: null
|
|
12420
12384
|
};
|
|
12421
12385
|
}
|
|
12386
|
+
handleSearchDebounced;
|
|
12422
12387
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
12423
12388
|
if (nextProps.multiple !== this.props.multiple) {
|
|
12424
12389
|
this.setState(previousState => {
|
|
@@ -12432,7 +12397,8 @@ class Typeahead extends Component {
|
|
|
12432
12397
|
};
|
|
12433
12398
|
}
|
|
12434
12399
|
return {
|
|
12435
|
-
query: ''
|
|
12400
|
+
query: '',
|
|
12401
|
+
selected: previousState.selected
|
|
12436
12402
|
};
|
|
12437
12403
|
});
|
|
12438
12404
|
}
|
|
@@ -12441,18 +12407,14 @@ class Typeahead extends Component {
|
|
|
12441
12407
|
this.handleSearchDebounced.cancel();
|
|
12442
12408
|
}
|
|
12443
12409
|
handleOnFocus = () => {
|
|
12444
|
-
const {
|
|
12445
|
-
onFocus
|
|
12446
|
-
} = this.props;
|
|
12447
12410
|
this.showMenu();
|
|
12448
|
-
|
|
12449
|
-
this.props.onFocus();
|
|
12450
|
-
}
|
|
12411
|
+
this.props.onFocus?.();
|
|
12451
12412
|
};
|
|
12452
12413
|
onOptionSelected = (event, item) => {
|
|
12453
12414
|
event.preventDefault();
|
|
12454
12415
|
this.selectItem(item);
|
|
12455
12416
|
};
|
|
12417
|
+
// START HERE
|
|
12456
12418
|
handleOnChange = event => {
|
|
12457
12419
|
const {
|
|
12458
12420
|
optionsShown,
|
|
@@ -12480,9 +12442,9 @@ class Typeahead extends Component {
|
|
|
12480
12442
|
};
|
|
12481
12443
|
handleOnPaste = event => {
|
|
12482
12444
|
const {
|
|
12483
|
-
allowNew,
|
|
12484
|
-
multiple,
|
|
12485
|
-
chipSeparators
|
|
12445
|
+
allowNew = false,
|
|
12446
|
+
multiple = false,
|
|
12447
|
+
chipSeparators = []
|
|
12486
12448
|
} = this.props;
|
|
12487
12449
|
const {
|
|
12488
12450
|
selected
|
|
@@ -12501,10 +12463,10 @@ class Typeahead extends Component {
|
|
|
12501
12463
|
};
|
|
12502
12464
|
handleOnKeyDown = event => {
|
|
12503
12465
|
const {
|
|
12504
|
-
showSuggestions,
|
|
12505
|
-
allowNew,
|
|
12506
|
-
multiple,
|
|
12507
|
-
chipSeparators,
|
|
12466
|
+
showSuggestions = true,
|
|
12467
|
+
allowNew = false,
|
|
12468
|
+
multiple = false,
|
|
12469
|
+
chipSeparators = [],
|
|
12508
12470
|
options
|
|
12509
12471
|
} = this.props;
|
|
12510
12472
|
const {
|
|
@@ -12530,7 +12492,7 @@ class Typeahead extends Component {
|
|
|
12530
12492
|
break;
|
|
12531
12493
|
case 'Enter':
|
|
12532
12494
|
event.preventDefault();
|
|
12533
|
-
if (options[keyboardFocusedOptionIndex]) {
|
|
12495
|
+
if (keyboardFocusedOptionIndex && options[keyboardFocusedOptionIndex]) {
|
|
12534
12496
|
this.selectItem(options[keyboardFocusedOptionIndex]);
|
|
12535
12497
|
} else if (allowNew && query.trim()) {
|
|
12536
12498
|
this.selectItem({
|
|
@@ -12645,7 +12607,7 @@ class Typeahead extends Component {
|
|
|
12645
12607
|
updateSelectedValue = selected => {
|
|
12646
12608
|
const {
|
|
12647
12609
|
onChange,
|
|
12648
|
-
validateChip
|
|
12610
|
+
validateChip = () => true
|
|
12649
12611
|
} = this.props;
|
|
12650
12612
|
const errorState = selected.some(chip => !validateChip(chip));
|
|
12651
12613
|
this.setState({
|
|
@@ -12673,7 +12635,7 @@ class Typeahead extends Component {
|
|
|
12673
12635
|
}
|
|
12674
12636
|
};
|
|
12675
12637
|
renderChip = (option, idx) => {
|
|
12676
|
-
const valid = this.props.validateChip(option);
|
|
12638
|
+
const valid = this.props.validateChip?.(option);
|
|
12677
12639
|
return /*#__PURE__*/jsx(Chip, {
|
|
12678
12640
|
label: option.label,
|
|
12679
12641
|
className: classNames('m-t-1', {
|
|
@@ -12723,21 +12685,21 @@ class Typeahead extends Component {
|
|
|
12723
12685
|
const {
|
|
12724
12686
|
id,
|
|
12725
12687
|
placeholder,
|
|
12726
|
-
multiple,
|
|
12727
|
-
size,
|
|
12728
|
-
addon,
|
|
12688
|
+
multiple = false,
|
|
12689
|
+
size = Size.MEDIUM,
|
|
12690
|
+
addon = null,
|
|
12729
12691
|
name,
|
|
12730
|
-
clearable,
|
|
12731
|
-
allowNew,
|
|
12732
|
-
footer,
|
|
12733
|
-
showSuggestions,
|
|
12734
|
-
showNewEntry,
|
|
12692
|
+
clearable = true,
|
|
12693
|
+
allowNew = false,
|
|
12694
|
+
footer = null,
|
|
12695
|
+
showSuggestions = true,
|
|
12696
|
+
showNewEntry = true,
|
|
12735
12697
|
options,
|
|
12736
|
-
minQueryLength,
|
|
12737
|
-
autoFocus,
|
|
12738
|
-
maxHeight,
|
|
12739
|
-
alert,
|
|
12740
|
-
inputAutoComplete
|
|
12698
|
+
minQueryLength = DEFAULT_MIN_QUERY_LENGTH,
|
|
12699
|
+
autoFocus = false,
|
|
12700
|
+
maxHeight = null,
|
|
12701
|
+
alert = null,
|
|
12702
|
+
inputAutoComplete = 'new-password'
|
|
12741
12703
|
} = this.props;
|
|
12742
12704
|
const {
|
|
12743
12705
|
errorState,
|
|
@@ -12751,6 +12713,7 @@ class Typeahead extends Component {
|
|
|
12751
12713
|
const menu = this.renderMenu({
|
|
12752
12714
|
footer,
|
|
12753
12715
|
options,
|
|
12716
|
+
id,
|
|
12754
12717
|
keyboardFocusedOptionIndex,
|
|
12755
12718
|
query,
|
|
12756
12719
|
allowNew,
|
|
@@ -12816,72 +12779,6 @@ class Typeahead extends Component {
|
|
|
12816
12779
|
});
|
|
12817
12780
|
}
|
|
12818
12781
|
}
|
|
12819
|
-
Typeahead.propTypes = {
|
|
12820
|
-
id: PropTypes.string.isRequired,
|
|
12821
|
-
name: PropTypes.string.isRequired,
|
|
12822
|
-
options: PropTypes.arrayOf(PropTypes.shape({
|
|
12823
|
-
label: PropTypes.string.isRequired,
|
|
12824
|
-
note: PropTypes.string,
|
|
12825
|
-
secondary: PropTypes.string,
|
|
12826
|
-
value: PropTypes.object
|
|
12827
|
-
})).isRequired,
|
|
12828
|
-
initialValue: PropTypes.arrayOf(PropTypes.shape({
|
|
12829
|
-
label: PropTypes.string.isRequired,
|
|
12830
|
-
note: PropTypes.string,
|
|
12831
|
-
secondary: PropTypes.string
|
|
12832
|
-
})),
|
|
12833
|
-
onChange: PropTypes.func.isRequired,
|
|
12834
|
-
allowNew: PropTypes.bool,
|
|
12835
|
-
autoFocus: PropTypes.bool,
|
|
12836
|
-
clearable: PropTypes.bool,
|
|
12837
|
-
multiple: PropTypes.bool,
|
|
12838
|
-
showSuggestions: PropTypes.bool,
|
|
12839
|
-
showNewEntry: PropTypes.bool,
|
|
12840
|
-
searchDelay: PropTypes.number,
|
|
12841
|
-
maxHeight: PropTypes.number,
|
|
12842
|
-
minQueryLength: PropTypes.number,
|
|
12843
|
-
addon: PropTypes.node,
|
|
12844
|
-
placeholder: PropTypes.string,
|
|
12845
|
-
alert: PropTypes.shape({
|
|
12846
|
-
message: PropTypes.string.isRequired,
|
|
12847
|
-
type: PropTypes.oneOf(['error', 'warning', 'neutral']).isRequired
|
|
12848
|
-
}),
|
|
12849
|
-
footer: PropTypes.node,
|
|
12850
|
-
validateChip: PropTypes.func,
|
|
12851
|
-
onSearch: PropTypes.func,
|
|
12852
|
-
onBlur: PropTypes.func,
|
|
12853
|
-
onInputChange: PropTypes.func,
|
|
12854
|
-
onFocus: PropTypes.func,
|
|
12855
|
-
chipSeparators: PropTypes.arrayOf(PropTypes.string),
|
|
12856
|
-
size: PropTypes.oneOf(['md', 'lg']),
|
|
12857
|
-
inputAutoComplete: PropTypes.string,
|
|
12858
|
-
autoFillOnBlur: PropTypes.bool
|
|
12859
|
-
};
|
|
12860
|
-
Typeahead.defaultProps = {
|
|
12861
|
-
allowNew: false,
|
|
12862
|
-
autoFocus: false,
|
|
12863
|
-
clearable: true,
|
|
12864
|
-
multiple: false,
|
|
12865
|
-
maxHeight: null,
|
|
12866
|
-
showSuggestions: true,
|
|
12867
|
-
showNewEntry: true,
|
|
12868
|
-
searchDelay: SEARCH_DELAY,
|
|
12869
|
-
minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
|
|
12870
|
-
addon: null,
|
|
12871
|
-
placeholder: null,
|
|
12872
|
-
alert: null,
|
|
12873
|
-
footer: null,
|
|
12874
|
-
size: Size.MEDIUM,
|
|
12875
|
-
chipSeparators: [],
|
|
12876
|
-
initialValue: [],
|
|
12877
|
-
onSearch: null,
|
|
12878
|
-
onBlur: null,
|
|
12879
|
-
onInputChange: null,
|
|
12880
|
-
onFocus: null,
|
|
12881
|
-
validateChip: () => true,
|
|
12882
|
-
inputAutoComplete: 'new-password',
|
|
12883
|
-
autoFillOnBlur: true
|
|
12884
|
-
};
|
|
12885
12782
|
|
|
12886
12783
|
// TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
|
|
12887
12784
|
var UploadStep;
|