@transferwise/components 0.0.0-experimental-4d1e1cf → 0.0.0-experimental-a53ae95
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/README.md +14 -1
- package/build/index.esm.js +147 -49
- package/build/index.esm.js.map +1 -1
- package/build/index.js +147 -49
- package/build/index.js.map +1 -1
- package/build/mocks.esm.js +40 -0
- package/build/mocks.esm.js.map +1 -0
- package/build/mocks.js +43 -0
- package/build/mocks.js.map +1 -0
- package/build/types/index.d.ts +0 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/mocks.d.ts +9 -0
- package/build/types/mocks.d.ts.map +1 -0
- package/build/types/test-utils/window-mock.d.ts.map +1 -1
- package/build/types/typeahead/Typeahead.d.ts +57 -98
- package/build/types/typeahead/Typeahead.d.ts.map +1 -1
- package/build/types/typeahead/index.d.ts +2 -2
- package/build/types/typeahead/index.d.ts.map +1 -1
- package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts +41 -23
- package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts.map +1 -1
- package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts +17 -9
- package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts.map +1 -1
- package/build/types/typeahead/util/highlight.d.ts +1 -2
- package/build/types/typeahead/util/highlight.d.ts.map +1 -1
- package/package.json +23 -10
- package/src/dimmer/Dimmer.spec.js +0 -4
- package/src/index.ts +0 -1
- package/src/mocks.ts +48 -0
- package/src/snackbar/Snackbar.spec.js +0 -4
- package/src/test-utils/window-mock.ts +7 -23
- package/src/typeahead/{Typeahead.tsx → Typeahead.js} +108 -107
- package/src/typeahead/{Typeahead.story.tsx → Typeahead.story.js} +7 -8
- package/src/typeahead/index.js +3 -0
- package/src/typeahead/typeaheadInput/{TypeaheadInput.tsx → TypeaheadInput.js} +51 -43
- package/src/typeahead/typeaheadOption/{TypeaheadOption.tsx → TypeaheadOption.js} +20 -10
- package/src/typeahead/util/{highlight.tsx → highlight.js} +1 -1
- package/src/withNextPortal/withNextPortal.spec.js +0 -4
- package/src/typeahead/index.ts +0 -2
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
|
-
|
|
12248
|
-
|
|
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.
|
|
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: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.
|
|
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
|
|
12276
|
+
autoFocus,
|
|
12279
12277
|
multiple,
|
|
12280
12278
|
name,
|
|
12281
|
-
optionsShown
|
|
12282
|
-
placeholder
|
|
12283
|
-
selected
|
|
12279
|
+
optionsShown,
|
|
12280
|
+
placeholder,
|
|
12281
|
+
selected,
|
|
12284
12282
|
value,
|
|
12285
12283
|
onChange,
|
|
12286
12284
|
onKeyDown,
|
|
@@ -12293,7 +12291,9 @@ class TypeaheadInput extends React.Component {
|
|
|
12293
12291
|
} = this.state;
|
|
12294
12292
|
const hasPlaceholder = !multiple || selected.length === 0;
|
|
12295
12293
|
return /*#__PURE__*/jsxRuntime.jsx(Input, {
|
|
12296
|
-
ref:
|
|
12294
|
+
ref: reference => {
|
|
12295
|
+
this.inputRef = reference;
|
|
12296
|
+
},
|
|
12297
12297
|
className: classNames__default.default(multiple && 'typeahead__input'),
|
|
12298
12298
|
name: name,
|
|
12299
12299
|
id: `input-${typeaheadId}`,
|
|
@@ -12319,18 +12319,18 @@ class TypeaheadInput extends React.Component {
|
|
|
12319
12319
|
render() {
|
|
12320
12320
|
const {
|
|
12321
12321
|
multiple,
|
|
12322
|
-
selected
|
|
12322
|
+
selected,
|
|
12323
12323
|
value,
|
|
12324
|
-
maxHeight
|
|
12324
|
+
maxHeight,
|
|
12325
12325
|
renderChip
|
|
12326
12326
|
} = this.props;
|
|
12327
12327
|
return multiple ? /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
12328
12328
|
className: "form-control typeahead__input-container",
|
|
12329
|
-
style: {
|
|
12330
|
-
maxHeight
|
|
12329
|
+
style: maxHeight && {
|
|
12330
|
+
maxHeight
|
|
12331
12331
|
},
|
|
12332
12332
|
onClick: () => {
|
|
12333
|
-
this.inputRef.
|
|
12333
|
+
this.inputRef.focus();
|
|
12334
12334
|
},
|
|
12335
12335
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
12336
12336
|
className: "typeahead__input-wrapper",
|
|
@@ -12338,13 +12338,39 @@ class TypeaheadInput extends React.Component {
|
|
|
12338
12338
|
className: "typeahead__input-aligner"
|
|
12339
12339
|
})]
|
|
12340
12340
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
12341
|
-
ref:
|
|
12341
|
+
ref: reference => {
|
|
12342
|
+
this.sizerRef = reference;
|
|
12343
|
+
},
|
|
12342
12344
|
className: "sizer form-control typeahead__input",
|
|
12343
12345
|
children: value
|
|
12344
12346
|
})]
|
|
12345
12347
|
}) : this.renderInput();
|
|
12346
12348
|
}
|
|
12347
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
|
+
};
|
|
12348
12374
|
|
|
12349
12375
|
function highlight(value, query) {
|
|
12350
12376
|
if (value && query) {
|
|
@@ -12365,9 +12391,9 @@ function highlight(value, query) {
|
|
|
12365
12391
|
const Option = props => {
|
|
12366
12392
|
const {
|
|
12367
12393
|
option,
|
|
12368
|
-
selected
|
|
12369
|
-
onClick
|
|
12370
|
-
query
|
|
12394
|
+
selected,
|
|
12395
|
+
onClick,
|
|
12396
|
+
query
|
|
12371
12397
|
} = props;
|
|
12372
12398
|
const {
|
|
12373
12399
|
label,
|
|
@@ -12397,32 +12423,30 @@ const Option = props => {
|
|
|
12397
12423
|
})
|
|
12398
12424
|
});
|
|
12399
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
|
+
};
|
|
12441
|
+
var TypeaheadOption = Option;
|
|
12400
12442
|
|
|
12401
12443
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
12402
12444
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
12403
12445
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
12446
|
+
|
|
12404
12447
|
const DEFAULT_MIN_QUERY_LENGTH = 3;
|
|
12405
12448
|
const SEARCH_DELAY = 200;
|
|
12406
12449
|
class Typeahead extends React.Component {
|
|
12407
|
-
static defaultProps = {
|
|
12408
|
-
addon: null,
|
|
12409
|
-
allowNew: false,
|
|
12410
|
-
autoFillOnBlur: true,
|
|
12411
|
-
autoFocus: false,
|
|
12412
|
-
chipSeparators: [],
|
|
12413
|
-
clearable: true,
|
|
12414
|
-
footer: null,
|
|
12415
|
-
initialValue: [],
|
|
12416
|
-
inputAutoComplete: 'new-password',
|
|
12417
|
-
maxHeight: null,
|
|
12418
|
-
minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
|
|
12419
|
-
multiple: false,
|
|
12420
|
-
searchDelay: SEARCH_DELAY,
|
|
12421
|
-
showSuggestions: true,
|
|
12422
|
-
showNewEntry: true,
|
|
12423
|
-
size: exports.Size.MEDIUM,
|
|
12424
|
-
validateChip: () => true
|
|
12425
|
-
};
|
|
12426
12450
|
constructor(props) {
|
|
12427
12451
|
super(props);
|
|
12428
12452
|
const {
|
|
@@ -12439,7 +12463,6 @@ class Typeahead extends React.Component {
|
|
|
12439
12463
|
keyboardFocusedOptionIndex: null
|
|
12440
12464
|
};
|
|
12441
12465
|
}
|
|
12442
|
-
handleSearchDebounced;
|
|
12443
12466
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
12444
12467
|
if (nextProps.multiple !== this.props.multiple) {
|
|
12445
12468
|
this.setState(previousState => {
|
|
@@ -12453,8 +12476,7 @@ class Typeahead extends React.Component {
|
|
|
12453
12476
|
};
|
|
12454
12477
|
}
|
|
12455
12478
|
return {
|
|
12456
|
-
query: ''
|
|
12457
|
-
selected: previousState.selected
|
|
12479
|
+
query: ''
|
|
12458
12480
|
};
|
|
12459
12481
|
});
|
|
12460
12482
|
}
|
|
@@ -12463,8 +12485,13 @@ class Typeahead extends React.Component {
|
|
|
12463
12485
|
this.handleSearchDebounced.cancel();
|
|
12464
12486
|
}
|
|
12465
12487
|
handleOnFocus = () => {
|
|
12488
|
+
const {
|
|
12489
|
+
onFocus
|
|
12490
|
+
} = this.props;
|
|
12466
12491
|
this.showMenu();
|
|
12467
|
-
|
|
12492
|
+
if (onFocus) {
|
|
12493
|
+
this.props.onFocus();
|
|
12494
|
+
}
|
|
12468
12495
|
};
|
|
12469
12496
|
onOptionSelected = (event, item) => {
|
|
12470
12497
|
event.preventDefault();
|
|
@@ -12547,7 +12574,7 @@ class Typeahead extends React.Component {
|
|
|
12547
12574
|
break;
|
|
12548
12575
|
case 'Enter':
|
|
12549
12576
|
event.preventDefault();
|
|
12550
|
-
if (
|
|
12577
|
+
if (options[keyboardFocusedOptionIndex]) {
|
|
12551
12578
|
this.selectItem(options[keyboardFocusedOptionIndex]);
|
|
12552
12579
|
} else if (allowNew && query.trim()) {
|
|
12553
12580
|
this.selectItem({
|
|
@@ -12599,6 +12626,13 @@ class Typeahead extends React.Component {
|
|
|
12599
12626
|
query
|
|
12600
12627
|
});
|
|
12601
12628
|
};
|
|
12629
|
+
stopPropagation = event => {
|
|
12630
|
+
event.stopPropagation();
|
|
12631
|
+
event.preventDefault();
|
|
12632
|
+
if (event.nativeEvent && event.nativeEvent.stopImmediatePropagation) {
|
|
12633
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
12634
|
+
}
|
|
12635
|
+
};
|
|
12602
12636
|
handleSearch = query => {
|
|
12603
12637
|
const {
|
|
12604
12638
|
onSearch
|
|
@@ -12683,7 +12717,7 @@ class Typeahead extends React.Component {
|
|
|
12683
12717
|
}
|
|
12684
12718
|
};
|
|
12685
12719
|
renderChip = (option, idx) => {
|
|
12686
|
-
const valid = this.props.validateChip
|
|
12720
|
+
const valid = this.props.validateChip(option);
|
|
12687
12721
|
return /*#__PURE__*/jsxRuntime.jsx(Chip, {
|
|
12688
12722
|
label: option.label,
|
|
12689
12723
|
className: classNames__default.default('m-t-1', {
|
|
@@ -12718,7 +12752,7 @@ class Typeahead extends React.Component {
|
|
|
12718
12752
|
className: "dropdown-menu",
|
|
12719
12753
|
role: "menu",
|
|
12720
12754
|
"aria-labelledby": "dropdownMenu1",
|
|
12721
|
-
children: [optionsToRender.map((option, idx) => /*#__PURE__*/jsxRuntime.jsx(
|
|
12755
|
+
children: [optionsToRender.map((option, idx) => /*#__PURE__*/jsxRuntime.jsx(TypeaheadOption, {
|
|
12722
12756
|
query: query,
|
|
12723
12757
|
option: option,
|
|
12724
12758
|
selected: keyboardFocusedOptionIndex === idx,
|
|
@@ -12761,7 +12795,6 @@ class Typeahead extends React.Component {
|
|
|
12761
12795
|
const menu = this.renderMenu({
|
|
12762
12796
|
footer,
|
|
12763
12797
|
options,
|
|
12764
|
-
id,
|
|
12765
12798
|
keyboardFocusedOptionIndex,
|
|
12766
12799
|
query,
|
|
12767
12800
|
allowNew,
|
|
@@ -12780,7 +12813,7 @@ class Typeahead extends React.Component {
|
|
|
12780
12813
|
'typeahead--multiple': multiple,
|
|
12781
12814
|
open: dropdownOpen
|
|
12782
12815
|
}),
|
|
12783
|
-
onClick: stopPropagation
|
|
12816
|
+
onClick: this.stopPropagation,
|
|
12784
12817
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
12785
12818
|
className: classNames__default.default('form-group', {
|
|
12786
12819
|
'has-error': hasError,
|
|
@@ -12801,7 +12834,6 @@ class Typeahead extends React.Component {
|
|
|
12801
12834
|
placeholder,
|
|
12802
12835
|
selected,
|
|
12803
12836
|
maxHeight,
|
|
12804
|
-
id: id,
|
|
12805
12837
|
name: name,
|
|
12806
12838
|
value: query,
|
|
12807
12839
|
typeaheadId: id,
|
|
@@ -12828,6 +12860,72 @@ class Typeahead extends React.Component {
|
|
|
12828
12860
|
});
|
|
12829
12861
|
}
|
|
12830
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
|
+
};
|
|
12831
12929
|
|
|
12832
12930
|
// TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
|
|
12833
12931
|
exports.UploadStep = void 0;
|