@transferwise/components 45.21.1 → 45.21.3
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 +74 -117
- package/build/index.esm.js.map +1 -1
- package/build/index.js +74 -117
- 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.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 +1 -13
- package/src/inputs/SelectInput.tsx +61 -80
- 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
|
@@ -6671,13 +6671,6 @@ function inferSearchableStrings(value) {
|
|
|
6671
6671
|
}
|
|
6672
6672
|
return [];
|
|
6673
6673
|
}
|
|
6674
|
-
const SelectInputItemCheckPaddingContext = /*#__PURE__*/React.createContext(false);
|
|
6675
|
-
function useSelectInputItemCheckPadding() {
|
|
6676
|
-
const checkPadding = React.useContext(SelectInputItemCheckPaddingContext);
|
|
6677
|
-
// Avoid layout shifts during transitions via caching
|
|
6678
|
-
const [initialCheckPadding] = React.useState(checkPadding);
|
|
6679
|
-
return initialCheckPadding;
|
|
6680
|
-
}
|
|
6681
6674
|
const SelectInputTriggerButtonPropsContext = /*#__PURE__*/React.createContext({});
|
|
6682
6675
|
const SelectInputOptionContentWithinTriggerContext = /*#__PURE__*/React.createContext(false);
|
|
6683
6676
|
function dedupeSelectInputOptionItem(item, existingValues) {
|
|
@@ -6822,54 +6815,51 @@ function SelectInput({
|
|
|
6822
6815
|
children: ({
|
|
6823
6816
|
disabled: uiDisabled,
|
|
6824
6817
|
value
|
|
6825
|
-
}) => /*#__PURE__*/jsxRuntime.jsx(
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
}
|
|
6841
|
-
}, getInteractionProps())
|
|
6842
|
-
},
|
|
6843
|
-
children: renderTrigger({
|
|
6844
|
-
content: value != null ? /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
|
|
6845
|
-
value: true,
|
|
6846
|
-
children: renderValue(value, true)
|
|
6847
|
-
}) : placeholder,
|
|
6848
|
-
placeholderShown: value == null,
|
|
6849
|
-
clear: onClear != null ? () => {
|
|
6850
|
-
onClear();
|
|
6851
|
-
triggerRef.current?.focus({
|
|
6852
|
-
preventScroll: true
|
|
6853
|
-
});
|
|
6854
|
-
} : undefined,
|
|
6855
|
-
disabled: uiDisabled,
|
|
6856
|
-
size,
|
|
6857
|
-
className
|
|
6858
|
-
})
|
|
6859
|
-
}),
|
|
6860
|
-
initialFocusRef: controllerRef,
|
|
6861
|
-
padding: "none",
|
|
6862
|
-
onClose: () => {
|
|
6863
|
-
setOpen(false);
|
|
6818
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(OptionsOverlay, {
|
|
6819
|
+
placement: "bottom-start",
|
|
6820
|
+
open: open,
|
|
6821
|
+
renderTrigger: ({
|
|
6822
|
+
ref,
|
|
6823
|
+
getInteractionProps
|
|
6824
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButtonPropsContext.Provider, {
|
|
6825
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
6826
|
+
value: {
|
|
6827
|
+
ref: mergeRefs__default.default([ref, triggerRef]),
|
|
6828
|
+
...mergeProps__default.default({
|
|
6829
|
+
onClick: () => {
|
|
6830
|
+
setOpen(prev => !prev);
|
|
6831
|
+
}
|
|
6832
|
+
}, getInteractionProps())
|
|
6864
6833
|
},
|
|
6865
|
-
children:
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6834
|
+
children: renderTrigger({
|
|
6835
|
+
content: value != null ? /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
|
|
6836
|
+
value: true,
|
|
6837
|
+
children: renderValue(value, true)
|
|
6838
|
+
}) : placeholder,
|
|
6839
|
+
placeholderShown: value == null,
|
|
6840
|
+
clear: onClear != null ? () => {
|
|
6841
|
+
onClear();
|
|
6842
|
+
triggerRef.current?.focus({
|
|
6843
|
+
preventScroll: true
|
|
6844
|
+
});
|
|
6845
|
+
} : undefined,
|
|
6846
|
+
disabled: uiDisabled,
|
|
6847
|
+
size,
|
|
6848
|
+
className
|
|
6872
6849
|
})
|
|
6850
|
+
}),
|
|
6851
|
+
initialFocusRef: controllerRef,
|
|
6852
|
+
padding: "none",
|
|
6853
|
+
onClose: () => {
|
|
6854
|
+
setOpen(false);
|
|
6855
|
+
},
|
|
6856
|
+
children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
|
|
6857
|
+
items: items,
|
|
6858
|
+
renderValue: renderValue,
|
|
6859
|
+
filterable: filterable,
|
|
6860
|
+
filterPlaceholder: filterPlaceholder,
|
|
6861
|
+
searchInputRef: searchInputRef,
|
|
6862
|
+
listboxRef: listboxRef
|
|
6873
6863
|
})
|
|
6874
6864
|
})
|
|
6875
6865
|
});
|
|
@@ -7059,7 +7049,6 @@ function SelectInputGroupItemView({
|
|
|
7059
7049
|
needle
|
|
7060
7050
|
}) {
|
|
7061
7051
|
const headerId = reactId.useId();
|
|
7062
|
-
const checkPadding = useSelectInputItemCheckPadding();
|
|
7063
7052
|
return (
|
|
7064
7053
|
/*#__PURE__*/
|
|
7065
7054
|
// An empty container may be rendered when no options match `needle`
|
|
@@ -7068,13 +7057,11 @@ function SelectInputGroupItemView({
|
|
|
7068
7057
|
role: "group",
|
|
7069
7058
|
"aria-labelledby": headerId,
|
|
7070
7059
|
className: classNames__default.default(needle === null && 'np-select-input-group-item--without-needle'),
|
|
7071
|
-
children: [needle == null ? /*#__PURE__*/jsxRuntime.
|
|
7060
|
+
children: [needle == null ? /*#__PURE__*/jsxRuntime.jsx("header", {
|
|
7072
7061
|
id: headerId,
|
|
7073
7062
|
role: "presentation",
|
|
7074
7063
|
className: "np-select-input-group-item-header np-text-title-group",
|
|
7075
|
-
children:
|
|
7076
|
-
className: "np-select-input-option-check-placeholder"
|
|
7077
|
-
}) : null, item.label]
|
|
7064
|
+
children: item.label
|
|
7078
7065
|
}) : null, item.options.map((option, index) => /*#__PURE__*/jsxRuntime.jsx(SelectInputItemView
|
|
7079
7066
|
// eslint-disable-next-line react/no-array-index-key
|
|
7080
7067
|
, {
|
|
@@ -7090,7 +7077,6 @@ function SelectInputOption({
|
|
|
7090
7077
|
disabled,
|
|
7091
7078
|
children
|
|
7092
7079
|
}) {
|
|
7093
|
-
const checkPadding = useSelectInputItemCheckPadding();
|
|
7094
7080
|
return /*#__PURE__*/jsxRuntime.jsx(react$1.Listbox.Option, {
|
|
7095
7081
|
as: "div",
|
|
7096
7082
|
value: value,
|
|
@@ -7102,12 +7088,12 @@ function SelectInputOption({
|
|
|
7102
7088
|
children: ({
|
|
7103
7089
|
selected
|
|
7104
7090
|
}) => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
7105
|
-
children: [
|
|
7106
|
-
size: 16,
|
|
7107
|
-
className: classNames__default.default('np-select-input-option-check', !selected && 'np-select-input-option-check--not-selected')
|
|
7108
|
-
}) : null, /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
7091
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
7109
7092
|
className: "np-select-input-option",
|
|
7110
7093
|
children: children
|
|
7094
|
+
}), /*#__PURE__*/jsxRuntime.jsx(icons.Check, {
|
|
7095
|
+
size: 16,
|
|
7096
|
+
className: classNames__default.default('np-select-input-option-check', !selected && 'np-select-input-option-check--not-selected')
|
|
7111
7097
|
})]
|
|
7112
7098
|
})
|
|
7113
7099
|
});
|
|
@@ -8524,7 +8510,7 @@ class MoneyInput extends React.Component {
|
|
|
8524
8510
|
this.amountFocused = true;
|
|
8525
8511
|
};
|
|
8526
8512
|
getSelectOptions() {
|
|
8527
|
-
const selectOptions = [...filterOptionsForQuery
|
|
8513
|
+
const selectOptions = [...filterOptionsForQuery(this.props.currencies, this.state.searchQuery)];
|
|
8528
8514
|
if (this.props.onCustomAction) {
|
|
8529
8515
|
selectOptions.push({
|
|
8530
8516
|
value: CUSTOM_ACTION,
|
|
@@ -8561,7 +8547,7 @@ class MoneyInput extends React.Component {
|
|
|
8561
8547
|
if (this.props.onSearchChange) {
|
|
8562
8548
|
this.props.onSearchChange({
|
|
8563
8549
|
searchQuery,
|
|
8564
|
-
filteredOptions: filterOptionsForQuery
|
|
8550
|
+
filteredOptions: filterOptionsForQuery(this.props.currencies, searchQuery)
|
|
8565
8551
|
});
|
|
8566
8552
|
}
|
|
8567
8553
|
};
|
|
@@ -8642,7 +8628,7 @@ class MoneyInput extends React.Component {
|
|
|
8642
8628
|
});
|
|
8643
8629
|
}
|
|
8644
8630
|
}
|
|
8645
|
-
function filterOptionsForQuery
|
|
8631
|
+
function filterOptionsForQuery(options, query) {
|
|
8646
8632
|
if (!query) {
|
|
8647
8633
|
return options;
|
|
8648
8634
|
}
|
|
@@ -10230,36 +10216,9 @@ const explodeNumberModel = number => {
|
|
|
10230
10216
|
};
|
|
10231
10217
|
};
|
|
10232
10218
|
|
|
10233
|
-
/**
|
|
10234
|
-
* Checks if query is contained into object properties.
|
|
10235
|
-
*
|
|
10236
|
-
* @param {object} option - the select option
|
|
10237
|
-
* @param {string} query - the current search query
|
|
10238
|
-
* @returns {boolean}
|
|
10239
|
-
*/
|
|
10240
|
-
const isOptionAndFitsQuery = (option, query) => startsWith(option.iso3, query) || startsWith(option.iso2, query) || startsWith(option.name, query) || startsWith(option.phone, query);
|
|
10241
|
-
const startsWith = (property, query) => {
|
|
10242
|
-
if (neptuneValidation.isArray(property)) {
|
|
10243
|
-
return property.filter(proper => normalizeValue(proper).indexOf(normalizeValue(query)) === 0).length > 0;
|
|
10244
|
-
}
|
|
10245
|
-
return normalizeValue(property).indexOf(normalizeValue(query)) === 0;
|
|
10246
|
-
};
|
|
10247
|
-
const normalizeValue = value => value.toLowerCase().replace('+', '');
|
|
10248
|
-
|
|
10249
|
-
/**
|
|
10250
|
-
* Filters a set of options based on search string
|
|
10251
|
-
*
|
|
10252
|
-
* @param options
|
|
10253
|
-
* @param query
|
|
10254
|
-
* @returns {*}
|
|
10255
|
-
*/
|
|
10256
|
-
const filterOptionsForQuery = (options, query) => options.filter(option => isOptionAndFitsQuery(option, query));
|
|
10257
|
-
|
|
10258
10219
|
const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
|
|
10259
10220
|
const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
|
|
10260
10221
|
|
|
10261
|
-
const isStringNumeric = value => /^\+?[\d-\s]+$/.test(value);
|
|
10262
|
-
|
|
10263
10222
|
// Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
|
10264
10223
|
const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
|
|
10265
10224
|
|
|
@@ -10338,17 +10297,15 @@ const PhoneNumberInput = props => {
|
|
|
10338
10297
|
};
|
|
10339
10298
|
const [internalValue, setInternalValue] = React.useState(getInitialValue());
|
|
10340
10299
|
const [broadcastedValue, setBroadcastedValue] = React.useState(null);
|
|
10341
|
-
const [searchQuery, setSearchQuery] = React.useState('');
|
|
10342
|
-
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
10343
|
-
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
10344
|
-
const listSortedByPhone = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'phone'));
|
|
10345
10300
|
const getSelectOptions = () => {
|
|
10346
|
-
const
|
|
10347
|
-
|
|
10301
|
+
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
10302
|
+
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
10303
|
+
return listSortedByISO3.map(option => {
|
|
10348
10304
|
const {
|
|
10349
10305
|
phone,
|
|
10350
10306
|
iso3,
|
|
10351
|
-
iso2
|
|
10307
|
+
iso2,
|
|
10308
|
+
name
|
|
10352
10309
|
} = option;
|
|
10353
10310
|
let note = '';
|
|
10354
10311
|
if (iso3) {
|
|
@@ -10357,9 +10314,13 @@ const PhoneNumberInput = props => {
|
|
|
10357
10314
|
note = neptuneValidation.isArray(iso2) ? iso2.join(', ') : iso2;
|
|
10358
10315
|
}
|
|
10359
10316
|
return {
|
|
10360
|
-
|
|
10361
|
-
|
|
10362
|
-
|
|
10317
|
+
type: 'option',
|
|
10318
|
+
value: {
|
|
10319
|
+
value: phone,
|
|
10320
|
+
label: phone,
|
|
10321
|
+
note: note
|
|
10322
|
+
},
|
|
10323
|
+
filterMatchers: [phone, note, name]
|
|
10363
10324
|
};
|
|
10364
10325
|
});
|
|
10365
10326
|
};
|
|
@@ -10367,7 +10328,6 @@ const PhoneNumberInput = props => {
|
|
|
10367
10328
|
const onPrefixChange = ({
|
|
10368
10329
|
value
|
|
10369
10330
|
}) => {
|
|
10370
|
-
setSearchQuery('');
|
|
10371
10331
|
setInternalValue({
|
|
10372
10332
|
prefix: value,
|
|
10373
10333
|
suffix: internalValue.suffix
|
|
@@ -10395,7 +10355,7 @@ const PhoneNumberInput = props => {
|
|
|
10395
10355
|
} = explodeNumberModel(pastedValue);
|
|
10396
10356
|
const selectedPrefix = options.find(({
|
|
10397
10357
|
value
|
|
10398
|
-
}) => value === pastedPrefix);
|
|
10358
|
+
}) => value.value === pastedPrefix);
|
|
10399
10359
|
if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
|
|
10400
10360
|
setInternalValue({
|
|
10401
10361
|
prefix: pastedPrefix,
|
|
@@ -10420,22 +10380,19 @@ const PhoneNumberInput = props => {
|
|
|
10420
10380
|
className: "tw-telephone",
|
|
10421
10381
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
10422
10382
|
className: "tw-telephone__country-select",
|
|
10423
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
|
10424
|
-
id: id ? `${id}-select` : undefined,
|
|
10425
|
-
options: options,
|
|
10426
|
-
selected: {
|
|
10427
|
-
value: internalValue.prefix,
|
|
10428
|
-
label: internalValue.prefix
|
|
10429
|
-
},
|
|
10383
|
+
children: /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
|
|
10430
10384
|
placeholder: "Select an option...",
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10385
|
+
items: options,
|
|
10386
|
+
value: options.find(item => item.value.value === internalValue.prefix)?.value,
|
|
10387
|
+
renderValue: (option, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
|
|
10388
|
+
title: option.label,
|
|
10389
|
+
note: withinTrigger ? undefined : option.note
|
|
10390
|
+
}),
|
|
10391
|
+
filterable: true,
|
|
10392
|
+
filterPlaceholder: searchPlaceholder,
|
|
10435
10393
|
disabled: disabled,
|
|
10436
10394
|
size: size,
|
|
10437
10395
|
onChange: onPrefixChange,
|
|
10438
|
-
onSearchChange: newSearch => setSearchQuery(newSearch),
|
|
10439
10396
|
...selectProps
|
|
10440
10397
|
})
|
|
10441
10398
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|