@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.esm.js +139 -46
- package/build/index.esm.js.map +1 -1
- package/build/index.js +139 -46
- package/build/index.js.map +1 -1
- package/build/main.css +2 -1
- package/build/styles/main.css +2 -1
- package/build/styles/modal/Modal.css +2 -1
- package/build/types/typeahead/Typeahead.d.ts +57 -98
- package/build/types/typeahead/Typeahead.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/package.json +1 -4
- package/src/main.css +2 -1
- package/src/modal/Modal.css +2 -1
- package/src/modal/Modal.less +1 -1
- package/src/modal/Modal.story.tsx +53 -21
- package/src/typeahead/{Typeahead.tsx → Typeahead.js} +106 -105
- package/src/typeahead/{Typeahead.story.tsx → Typeahead.story.js} +7 -8
- package/src/typeahead/typeaheadInput/{TypeaheadInput.tsx → TypeaheadInput.js} +42 -43
- package/src/typeahead/typeaheadOption/{TypeaheadOption.tsx → TypeaheadOption.js} +20 -10
package/build/index.esm.js
CHANGED
|
@@ -12210,10 +12210,8 @@ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
|
|
|
12210
12210
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
12211
12211
|
const DEFAULT_INPUT_MIN_WIDTH = 10;
|
|
12212
12212
|
class TypeaheadInput extends Component {
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
constructor(props) {
|
|
12216
|
-
super(props);
|
|
12213
|
+
constructor() {
|
|
12214
|
+
super();
|
|
12217
12215
|
this.state = {
|
|
12218
12216
|
inputWidth: DEFAULT_INPUT_MIN_WIDTH
|
|
12219
12217
|
};
|
|
@@ -12223,7 +12221,7 @@ class TypeaheadInput extends Component {
|
|
|
12223
12221
|
autoFocus
|
|
12224
12222
|
} = this.props;
|
|
12225
12223
|
if (autoFocus) {
|
|
12226
|
-
this.inputRef
|
|
12224
|
+
this.inputRef.focus();
|
|
12227
12225
|
}
|
|
12228
12226
|
}
|
|
12229
12227
|
componentDidUpdate(previousProps) {
|
|
@@ -12234,19 +12232,19 @@ class TypeaheadInput extends Component {
|
|
|
12234
12232
|
recalculateWidth = () => {
|
|
12235
12233
|
requestAnimationFrame(() => {
|
|
12236
12234
|
this.setState({
|
|
12237
|
-
inputWidth:
|
|
12235
|
+
inputWidth: Math.max(DEFAULT_INPUT_MIN_WIDTH, this.sizerRef.scrollWidth + 10)
|
|
12238
12236
|
});
|
|
12239
12237
|
});
|
|
12240
12238
|
};
|
|
12241
12239
|
renderInput = () => {
|
|
12242
12240
|
const {
|
|
12243
12241
|
typeaheadId,
|
|
12244
|
-
autoFocus
|
|
12242
|
+
autoFocus,
|
|
12245
12243
|
multiple,
|
|
12246
12244
|
name,
|
|
12247
|
-
optionsShown
|
|
12248
|
-
placeholder
|
|
12249
|
-
selected
|
|
12245
|
+
optionsShown,
|
|
12246
|
+
placeholder,
|
|
12247
|
+
selected,
|
|
12250
12248
|
value,
|
|
12251
12249
|
onChange,
|
|
12252
12250
|
onKeyDown,
|
|
@@ -12287,18 +12285,18 @@ class TypeaheadInput extends Component {
|
|
|
12287
12285
|
render() {
|
|
12288
12286
|
const {
|
|
12289
12287
|
multiple,
|
|
12290
|
-
selected
|
|
12288
|
+
selected,
|
|
12291
12289
|
value,
|
|
12292
|
-
maxHeight
|
|
12290
|
+
maxHeight,
|
|
12293
12291
|
renderChip
|
|
12294
12292
|
} = this.props;
|
|
12295
12293
|
return multiple ? /*#__PURE__*/jsxs("div", {
|
|
12296
12294
|
className: "form-control typeahead__input-container",
|
|
12297
|
-
style: {
|
|
12298
|
-
maxHeight
|
|
12295
|
+
style: maxHeight && {
|
|
12296
|
+
maxHeight
|
|
12299
12297
|
},
|
|
12300
12298
|
onClick: () => {
|
|
12301
|
-
this.inputRef
|
|
12299
|
+
this.inputRef.focus();
|
|
12302
12300
|
},
|
|
12303
12301
|
children: [/*#__PURE__*/jsxs("div", {
|
|
12304
12302
|
className: "typeahead__input-wrapper",
|
|
@@ -12315,6 +12313,30 @@ class TypeaheadInput extends Component {
|
|
|
12315
12313
|
}) : this.renderInput();
|
|
12316
12314
|
}
|
|
12317
12315
|
}
|
|
12316
|
+
TypeaheadInput.propTypes = {
|
|
12317
|
+
typeaheadId: PropTypes.string.isRequired,
|
|
12318
|
+
name: PropTypes.string.isRequired,
|
|
12319
|
+
autoFocus: PropTypes.bool,
|
|
12320
|
+
multiple: PropTypes.bool.isRequired,
|
|
12321
|
+
value: PropTypes.string.isRequired,
|
|
12322
|
+
selected: PropTypes.arrayOf(PropTypes.object),
|
|
12323
|
+
placeholder: PropTypes.string,
|
|
12324
|
+
optionsShown: PropTypes.bool,
|
|
12325
|
+
maxHeight: PropTypes.number,
|
|
12326
|
+
autoComplete: PropTypes.string.isRequired,
|
|
12327
|
+
onChange: PropTypes.func.isRequired,
|
|
12328
|
+
renderChip: PropTypes.func.isRequired,
|
|
12329
|
+
onKeyDown: PropTypes.func.isRequired,
|
|
12330
|
+
onFocus: PropTypes.func.isRequired,
|
|
12331
|
+
onPaste: PropTypes.func.isRequired
|
|
12332
|
+
};
|
|
12333
|
+
TypeaheadInput.defaultProps = {
|
|
12334
|
+
autoFocus: false,
|
|
12335
|
+
maxHeight: null,
|
|
12336
|
+
placeholder: '',
|
|
12337
|
+
optionsShown: false,
|
|
12338
|
+
selected: []
|
|
12339
|
+
};
|
|
12318
12340
|
|
|
12319
12341
|
function highlight(value, query) {
|
|
12320
12342
|
if (value && query) {
|
|
@@ -12335,9 +12357,9 @@ function highlight(value, query) {
|
|
|
12335
12357
|
const Option = props => {
|
|
12336
12358
|
const {
|
|
12337
12359
|
option,
|
|
12338
|
-
selected
|
|
12339
|
-
onClick
|
|
12340
|
-
query
|
|
12360
|
+
selected,
|
|
12361
|
+
onClick,
|
|
12362
|
+
query
|
|
12341
12363
|
} = props;
|
|
12342
12364
|
const {
|
|
12343
12365
|
label,
|
|
@@ -12367,33 +12389,30 @@ const Option = props => {
|
|
|
12367
12389
|
})
|
|
12368
12390
|
});
|
|
12369
12391
|
};
|
|
12392
|
+
Option.propTypes = {
|
|
12393
|
+
option: PropTypes.shape({
|
|
12394
|
+
label: PropTypes.string.isRequired,
|
|
12395
|
+
note: PropTypes.string,
|
|
12396
|
+
secondary: PropTypes.string
|
|
12397
|
+
}).isRequired,
|
|
12398
|
+
query: PropTypes.string,
|
|
12399
|
+
selected: PropTypes.bool,
|
|
12400
|
+
onClick: PropTypes.func
|
|
12401
|
+
};
|
|
12402
|
+
Option.defaultProps = {
|
|
12403
|
+
selected: false,
|
|
12404
|
+
query: '',
|
|
12405
|
+
onClick: () => {}
|
|
12406
|
+
};
|
|
12370
12407
|
var TypeaheadOption = Option;
|
|
12371
12408
|
|
|
12372
12409
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
12373
12410
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
12374
12411
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
12412
|
+
|
|
12375
12413
|
const DEFAULT_MIN_QUERY_LENGTH = 3;
|
|
12376
12414
|
const SEARCH_DELAY = 200;
|
|
12377
12415
|
class Typeahead extends Component {
|
|
12378
|
-
static defaultProps = {
|
|
12379
|
-
addon: null,
|
|
12380
|
-
allowNew: false,
|
|
12381
|
-
autoFillOnBlur: true,
|
|
12382
|
-
autoFocus: false,
|
|
12383
|
-
chipSeparators: [],
|
|
12384
|
-
clearable: true,
|
|
12385
|
-
footer: null,
|
|
12386
|
-
initialValue: [],
|
|
12387
|
-
inputAutoComplete: 'new-password',
|
|
12388
|
-
maxHeight: null,
|
|
12389
|
-
minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
|
|
12390
|
-
multiple: false,
|
|
12391
|
-
searchDelay: SEARCH_DELAY,
|
|
12392
|
-
showSuggestions: true,
|
|
12393
|
-
showNewEntry: true,
|
|
12394
|
-
size: Size.MEDIUM,
|
|
12395
|
-
validateChip: () => true
|
|
12396
|
-
};
|
|
12397
12416
|
constructor(props) {
|
|
12398
12417
|
super(props);
|
|
12399
12418
|
const {
|
|
@@ -12410,7 +12429,6 @@ class Typeahead extends Component {
|
|
|
12410
12429
|
keyboardFocusedOptionIndex: null
|
|
12411
12430
|
};
|
|
12412
12431
|
}
|
|
12413
|
-
handleSearchDebounced;
|
|
12414
12432
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
12415
12433
|
if (nextProps.multiple !== this.props.multiple) {
|
|
12416
12434
|
this.setState(previousState => {
|
|
@@ -12424,8 +12442,7 @@ class Typeahead extends Component {
|
|
|
12424
12442
|
};
|
|
12425
12443
|
}
|
|
12426
12444
|
return {
|
|
12427
|
-
query: ''
|
|
12428
|
-
selected: previousState.selected
|
|
12445
|
+
query: ''
|
|
12429
12446
|
};
|
|
12430
12447
|
});
|
|
12431
12448
|
}
|
|
@@ -12434,8 +12451,13 @@ class Typeahead extends Component {
|
|
|
12434
12451
|
this.handleSearchDebounced.cancel();
|
|
12435
12452
|
}
|
|
12436
12453
|
handleOnFocus = () => {
|
|
12454
|
+
const {
|
|
12455
|
+
onFocus
|
|
12456
|
+
} = this.props;
|
|
12437
12457
|
this.showMenu();
|
|
12438
|
-
|
|
12458
|
+
if (onFocus) {
|
|
12459
|
+
this.props.onFocus();
|
|
12460
|
+
}
|
|
12439
12461
|
};
|
|
12440
12462
|
onOptionSelected = (event, item) => {
|
|
12441
12463
|
event.preventDefault();
|
|
@@ -12518,7 +12540,7 @@ class Typeahead extends Component {
|
|
|
12518
12540
|
break;
|
|
12519
12541
|
case 'Enter':
|
|
12520
12542
|
event.preventDefault();
|
|
12521
|
-
if (
|
|
12543
|
+
if (options[keyboardFocusedOptionIndex]) {
|
|
12522
12544
|
this.selectItem(options[keyboardFocusedOptionIndex]);
|
|
12523
12545
|
} else if (allowNew && query.trim()) {
|
|
12524
12546
|
this.selectItem({
|
|
@@ -12570,6 +12592,13 @@ class Typeahead extends Component {
|
|
|
12570
12592
|
query
|
|
12571
12593
|
});
|
|
12572
12594
|
};
|
|
12595
|
+
stopPropagation = event => {
|
|
12596
|
+
event.stopPropagation();
|
|
12597
|
+
event.preventDefault();
|
|
12598
|
+
if (event.nativeEvent && event.nativeEvent.stopImmediatePropagation) {
|
|
12599
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
12600
|
+
}
|
|
12601
|
+
};
|
|
12573
12602
|
handleSearch = query => {
|
|
12574
12603
|
const {
|
|
12575
12604
|
onSearch
|
|
@@ -12654,7 +12683,7 @@ class Typeahead extends Component {
|
|
|
12654
12683
|
}
|
|
12655
12684
|
};
|
|
12656
12685
|
renderChip = (option, idx) => {
|
|
12657
|
-
const valid = this.props.validateChip
|
|
12686
|
+
const valid = this.props.validateChip(option);
|
|
12658
12687
|
return /*#__PURE__*/jsx(Chip, {
|
|
12659
12688
|
label: option.label,
|
|
12660
12689
|
className: classNames('m-t-1', {
|
|
@@ -12732,7 +12761,6 @@ class Typeahead extends Component {
|
|
|
12732
12761
|
const menu = this.renderMenu({
|
|
12733
12762
|
footer,
|
|
12734
12763
|
options,
|
|
12735
|
-
id,
|
|
12736
12764
|
keyboardFocusedOptionIndex,
|
|
12737
12765
|
query,
|
|
12738
12766
|
allowNew,
|
|
@@ -12751,7 +12779,7 @@ class Typeahead extends Component {
|
|
|
12751
12779
|
'typeahead--multiple': multiple,
|
|
12752
12780
|
open: dropdownOpen
|
|
12753
12781
|
}),
|
|
12754
|
-
onClick: stopPropagation
|
|
12782
|
+
onClick: this.stopPropagation,
|
|
12755
12783
|
children: /*#__PURE__*/jsxs("div", {
|
|
12756
12784
|
className: classNames('form-group', {
|
|
12757
12785
|
'has-error': hasError,
|
|
@@ -12772,7 +12800,6 @@ class Typeahead extends Component {
|
|
|
12772
12800
|
placeholder,
|
|
12773
12801
|
selected,
|
|
12774
12802
|
maxHeight,
|
|
12775
|
-
id: id,
|
|
12776
12803
|
name: name,
|
|
12777
12804
|
value: query,
|
|
12778
12805
|
typeaheadId: id,
|
|
@@ -12799,6 +12826,72 @@ class Typeahead extends Component {
|
|
|
12799
12826
|
});
|
|
12800
12827
|
}
|
|
12801
12828
|
}
|
|
12829
|
+
Typeahead.propTypes = {
|
|
12830
|
+
id: PropTypes.string.isRequired,
|
|
12831
|
+
name: PropTypes.string.isRequired,
|
|
12832
|
+
options: PropTypes.arrayOf(PropTypes.shape({
|
|
12833
|
+
label: PropTypes.string.isRequired,
|
|
12834
|
+
note: PropTypes.string,
|
|
12835
|
+
secondary: PropTypes.string,
|
|
12836
|
+
value: PropTypes.object
|
|
12837
|
+
})).isRequired,
|
|
12838
|
+
initialValue: PropTypes.arrayOf(PropTypes.shape({
|
|
12839
|
+
label: PropTypes.string.isRequired,
|
|
12840
|
+
note: PropTypes.string,
|
|
12841
|
+
secondary: PropTypes.string
|
|
12842
|
+
})),
|
|
12843
|
+
onChange: PropTypes.func.isRequired,
|
|
12844
|
+
allowNew: PropTypes.bool,
|
|
12845
|
+
autoFocus: PropTypes.bool,
|
|
12846
|
+
clearable: PropTypes.bool,
|
|
12847
|
+
multiple: PropTypes.bool,
|
|
12848
|
+
showSuggestions: PropTypes.bool,
|
|
12849
|
+
showNewEntry: PropTypes.bool,
|
|
12850
|
+
searchDelay: PropTypes.number,
|
|
12851
|
+
maxHeight: PropTypes.number,
|
|
12852
|
+
minQueryLength: PropTypes.number,
|
|
12853
|
+
addon: PropTypes.node,
|
|
12854
|
+
placeholder: PropTypes.string,
|
|
12855
|
+
alert: PropTypes.shape({
|
|
12856
|
+
message: PropTypes.string.isRequired,
|
|
12857
|
+
type: PropTypes.oneOf(['error', 'warning', 'neutral']).isRequired
|
|
12858
|
+
}),
|
|
12859
|
+
footer: PropTypes.node,
|
|
12860
|
+
validateChip: PropTypes.func,
|
|
12861
|
+
onSearch: PropTypes.func,
|
|
12862
|
+
onBlur: PropTypes.func,
|
|
12863
|
+
onInputChange: PropTypes.func,
|
|
12864
|
+
onFocus: PropTypes.func,
|
|
12865
|
+
chipSeparators: PropTypes.arrayOf(PropTypes.string),
|
|
12866
|
+
size: PropTypes.oneOf(['md', 'lg']),
|
|
12867
|
+
inputAutoComplete: PropTypes.string,
|
|
12868
|
+
autoFillOnBlur: PropTypes.bool
|
|
12869
|
+
};
|
|
12870
|
+
Typeahead.defaultProps = {
|
|
12871
|
+
allowNew: false,
|
|
12872
|
+
autoFocus: false,
|
|
12873
|
+
clearable: true,
|
|
12874
|
+
multiple: false,
|
|
12875
|
+
maxHeight: null,
|
|
12876
|
+
showSuggestions: true,
|
|
12877
|
+
showNewEntry: true,
|
|
12878
|
+
searchDelay: SEARCH_DELAY,
|
|
12879
|
+
minQueryLength: DEFAULT_MIN_QUERY_LENGTH,
|
|
12880
|
+
addon: null,
|
|
12881
|
+
placeholder: null,
|
|
12882
|
+
alert: null,
|
|
12883
|
+
footer: null,
|
|
12884
|
+
size: Size.MEDIUM,
|
|
12885
|
+
chipSeparators: [],
|
|
12886
|
+
initialValue: [],
|
|
12887
|
+
onSearch: null,
|
|
12888
|
+
onBlur: null,
|
|
12889
|
+
onInputChange: null,
|
|
12890
|
+
onFocus: null,
|
|
12891
|
+
validateChip: () => true,
|
|
12892
|
+
inputAutoComplete: 'new-password',
|
|
12893
|
+
autoFillOnBlur: true
|
|
12894
|
+
};
|
|
12802
12895
|
|
|
12803
12896
|
// TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
|
|
12804
12897
|
var UploadStep;
|