@transferwise/components 0.0.0-experimental-210ef2c → 0.0.0-experimental-6d7ebae
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 +33 -56
- package/build/index.esm.js.map +1 -1
- package/build/index.js +33 -56
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/inputs/SelectInput.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/styles/phoneNumberInput/PhoneNumberInput.css +1 -1
- package/build/types/inputs/SelectInput.d.ts +2 -1
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/inputs/SelectInput.css +1 -1
- package/src/inputs/SelectInput.less +4 -0
- package/src/inputs/SelectInput.spec.tsx +40 -0
- package/src/inputs/SelectInput.story.tsx +18 -0
- package/src/inputs/SelectInput.tsx +14 -3
- package/src/main.css +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.css +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.js +27 -28
- package/src/phoneNumberInput/PhoneNumberInput.less +4 -0
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +64 -72
- package/src/phoneNumberInput/PhoneNumberInput.story.js +1 -3
package/build/index.js
CHANGED
|
@@ -6783,6 +6783,7 @@ function SelectInput({
|
|
|
6783
6783
|
value: controlledValue,
|
|
6784
6784
|
compareValues,
|
|
6785
6785
|
renderValue = wrapInFragment,
|
|
6786
|
+
renderFooter,
|
|
6786
6787
|
renderTrigger = defaultRenderTrigger,
|
|
6787
6788
|
filterable,
|
|
6788
6789
|
filterPlaceholder,
|
|
@@ -6856,6 +6857,7 @@ function SelectInput({
|
|
|
6856
6857
|
children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
|
|
6857
6858
|
items: items,
|
|
6858
6859
|
renderValue: renderValue,
|
|
6860
|
+
renderFooter: renderFooter,
|
|
6859
6861
|
filterable: filterable,
|
|
6860
6862
|
filterPlaceholder: filterPlaceholder,
|
|
6861
6863
|
searchInputRef: searchInputRef,
|
|
@@ -6921,6 +6923,7 @@ const SelectInputOptionsContainer = /*#__PURE__*/React.forwardRef(function Selec
|
|
|
6921
6923
|
function SelectInputOptions({
|
|
6922
6924
|
items,
|
|
6923
6925
|
renderValue = wrapInFragment,
|
|
6926
|
+
renderFooter,
|
|
6924
6927
|
filterable = false,
|
|
6925
6928
|
filterPlaceholder,
|
|
6926
6929
|
searchInputRef,
|
|
@@ -6978,7 +6981,7 @@ function SelectInputOptions({
|
|
|
6978
6981
|
setQuery(event.currentTarget.value);
|
|
6979
6982
|
}
|
|
6980
6983
|
})
|
|
6981
|
-
}) : null, /*#__PURE__*/jsxRuntime.jsxs("
|
|
6984
|
+
}) : null, /*#__PURE__*/jsxRuntime.jsxs("section", {
|
|
6982
6985
|
ref: listboxContainerRef,
|
|
6983
6986
|
className: classNames__default.default('np-select-input-listbox-container', items.some(item => item.type === 'group') && 'np-select-input-listbox-container--has-group'),
|
|
6984
6987
|
children: [empty ? /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
@@ -7002,7 +7005,10 @@ function SelectInputOptions({
|
|
|
7002
7005
|
renderValue: renderValue,
|
|
7003
7006
|
needle: needle
|
|
7004
7007
|
}, index))
|
|
7005
|
-
})
|
|
7008
|
+
}), renderFooter != null ? /*#__PURE__*/jsxRuntime.jsx("footer", {
|
|
7009
|
+
className: "np-select-input-footer",
|
|
7010
|
+
children: renderFooter(needle)
|
|
7011
|
+
}) : null]
|
|
7006
7012
|
})]
|
|
7007
7013
|
});
|
|
7008
7014
|
}
|
|
@@ -8510,7 +8516,7 @@ class MoneyInput extends React.Component {
|
|
|
8510
8516
|
this.amountFocused = true;
|
|
8511
8517
|
};
|
|
8512
8518
|
getSelectOptions() {
|
|
8513
|
-
const selectOptions = [...filterOptionsForQuery
|
|
8519
|
+
const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
|
|
8514
8520
|
if (this.props.onCustomAction) {
|
|
8515
8521
|
selectOptions.push({
|
|
8516
8522
|
value: CUSTOM_ACTION,
|
|
@@ -8547,7 +8553,7 @@ class MoneyInput extends React.Component {
|
|
|
8547
8553
|
if (this.props.onSearchChange) {
|
|
8548
8554
|
this.props.onSearchChange({
|
|
8549
8555
|
searchQuery,
|
|
8550
|
-
filteredOptions: filterOptionsForQuery
|
|
8556
|
+
filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
|
|
8551
8557
|
});
|
|
8552
8558
|
}
|
|
8553
8559
|
};
|
|
@@ -8628,7 +8634,7 @@ class MoneyInput extends React.Component {
|
|
|
8628
8634
|
});
|
|
8629
8635
|
}
|
|
8630
8636
|
}
|
|
8631
|
-
function filterOptionsForQuery
|
|
8637
|
+
function filterOptionsForQuery(options, query) {
|
|
8632
8638
|
if (!query) {
|
|
8633
8639
|
return options;
|
|
8634
8640
|
}
|
|
@@ -10216,36 +10222,9 @@ const explodeNumberModel = number => {
|
|
|
10216
10222
|
};
|
|
10217
10223
|
};
|
|
10218
10224
|
|
|
10219
|
-
/**
|
|
10220
|
-
* Checks if query is contained into object properties.
|
|
10221
|
-
*
|
|
10222
|
-
* @param {object} option - the select option
|
|
10223
|
-
* @param {string} query - the current search query
|
|
10224
|
-
* @returns {boolean}
|
|
10225
|
-
*/
|
|
10226
|
-
const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
|
|
10227
|
-
const startsWith = (property, query) => {
|
|
10228
|
-
if (neptuneValidation.isArray(property)) {
|
|
10229
|
-
return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
|
|
10230
|
-
}
|
|
10231
|
-
return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
|
|
10232
|
-
};
|
|
10233
|
-
const normalizeValue = value => value.toLowerCase().replace('+', '');
|
|
10234
|
-
|
|
10235
|
-
/**
|
|
10236
|
-
* Filters a set of options based on search string
|
|
10237
|
-
*
|
|
10238
|
-
* @param options
|
|
10239
|
-
* @param query
|
|
10240
|
-
* @returns {*}
|
|
10241
|
-
*/
|
|
10242
|
-
const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
|
|
10243
|
-
|
|
10244
10225
|
const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
|
|
10245
10226
|
const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
|
|
10246
10227
|
|
|
10247
|
-
const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
|
|
10248
|
-
|
|
10249
10228
|
// Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
|
10250
10229
|
const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
|
|
10251
10230
|
|
|
@@ -10324,17 +10303,15 @@ const PhoneNumberInput = props => {
|
|
|
10324
10303
|
};
|
|
10325
10304
|
const [internalValue, setInternalValue] = React.useState(getInitialValue());
|
|
10326
10305
|
const [broadcastedValue, setBroadcastedValue] = React.useState(null);
|
|
10327
|
-
const [searchQuery, setSearchQuery] = React.useState('');
|
|
10328
|
-
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
10329
|
-
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
10330
|
-
const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
|
|
10331
10306
|
const getSelectOptions = () => {
|
|
10332
|
-
const
|
|
10333
|
-
|
|
10307
|
+
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
10308
|
+
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
10309
|
+
return listSortedByISO3.map(option => {
|
|
10334
10310
|
const {
|
|
10335
10311
|
phone,
|
|
10336
10312
|
iso3,
|
|
10337
|
-
iso2
|
|
10313
|
+
iso2,
|
|
10314
|
+
name
|
|
10338
10315
|
} = option;
|
|
10339
10316
|
let note = '';
|
|
10340
10317
|
if (iso3) {
|
|
@@ -10343,9 +10320,13 @@ const PhoneNumberInput = props => {
|
|
|
10343
10320
|
note = neptuneValidation.isArray(iso2) ? iso2.join(', ') : iso2;
|
|
10344
10321
|
}
|
|
10345
10322
|
return {
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10323
|
+
type: 'option',
|
|
10324
|
+
value: {
|
|
10325
|
+
value: phone,
|
|
10326
|
+
label: phone,
|
|
10327
|
+
note: note
|
|
10328
|
+
},
|
|
10329
|
+
filterMatchers: [phone, note, name]
|
|
10349
10330
|
};
|
|
10350
10331
|
});
|
|
10351
10332
|
};
|
|
@@ -10353,7 +10334,6 @@ const PhoneNumberInput = props => {
|
|
|
10353
10334
|
const onPrefixChange = ({
|
|
10354
10335
|
value
|
|
10355
10336
|
}) => {
|
|
10356
|
-
setSearchQuery('');
|
|
10357
10337
|
setInternalValue({
|
|
10358
10338
|
prefix: value,
|
|
10359
10339
|
suffix: internalValue.suffix
|
|
@@ -10381,7 +10361,7 @@ const PhoneNumberInput = props => {
|
|
|
10381
10361
|
} = explodeNumberModel(pastedValue);
|
|
10382
10362
|
const selectedPrefix = options.find(({
|
|
10383
10363
|
value
|
|
10384
|
-
}) => value === pastedPrefix);
|
|
10364
|
+
}) => value.value === pastedPrefix);
|
|
10385
10365
|
if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
|
|
10386
10366
|
setInternalValue({
|
|
10387
10367
|
prefix: pastedPrefix,
|
|
@@ -10406,22 +10386,19 @@ const PhoneNumberInput = props => {
|
|
|
10406
10386
|
className: "tw-telephone",
|
|
10407
10387
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
10408
10388
|
className: "tw-telephone__country-select",
|
|
10409
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
|
10410
|
-
id: id ? `${id}-select` : undefined,
|
|
10411
|
-
options: options,
|
|
10412
|
-
selected: {
|
|
10413
|
-
value: internalValue.prefix,
|
|
10414
|
-
label: internalValue.prefix
|
|
10415
|
-
},
|
|
10389
|
+
children: /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
|
|
10416
10390
|
placeholder: "Select an option...",
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
|
|
10420
|
-
|
|
10391
|
+
items: options,
|
|
10392
|
+
value: options.find(item => item.value.value === internalValue.prefix)?.value,
|
|
10393
|
+
renderValue: (option, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
|
|
10394
|
+
title: option.label,
|
|
10395
|
+
note: withinTrigger ? undefined : option.note
|
|
10396
|
+
}),
|
|
10397
|
+
filterable: true,
|
|
10398
|
+
filterPlaceholder: searchPlaceholder,
|
|
10421
10399
|
disabled: disabled,
|
|
10422
10400
|
size: size,
|
|
10423
10401
|
onChange: onPrefixChange,
|
|
10424
|
-
onSearchChange: newSearch => setSearchQuery(newSearch),
|
|
10425
10402
|
...selectProps
|
|
10426
10403
|
})
|
|
10427
10404
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|