@transferwise/components 0.0.0-experimental-02eda23 → 0.0.0-experimental-32cf8db
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 +135 -81
- package/build/index.esm.js.map +1 -1
- package/build/index.js +136 -81
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/dateLookup/DateLookup.css +1 -1
- package/build/styles/inputs/SelectInput.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/types/common/polymorphicWithOverrides/PolymorphicWithOverrides.d.ts +10 -0
- package/build/types/common/polymorphicWithOverrides/PolymorphicWithOverrides.d.ts.map +1 -0
- package/build/types/inputs/SelectInput.d.ts +13 -2
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/common/polymorphicWithOverrides/PolymorphicWithOverrides.tsx +16 -0
- package/src/dateLookup/DateLookup.css +1 -1
- package/src/dateLookup/DateLookup.less +4 -4
- package/src/dateLookup/dateHeader/DateHeader.js +1 -1
- package/src/inputs/SelectInput.css +1 -1
- package/src/inputs/SelectInput.less +2 -2
- package/src/inputs/SelectInput.story.tsx +45 -4
- package/src/inputs/SelectInput.tsx +153 -96
- package/src/inputs/_Popover.less +1 -1
- package/src/main.css +1 -1
package/build/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var mergeRefs = require('react-merge-refs');
|
|
|
17
17
|
var neptuneValidation = require('@transferwise/neptune-validation');
|
|
18
18
|
var reactPopper = require('react-popper');
|
|
19
19
|
var react$1 = require('@headlessui/react');
|
|
20
|
+
var mergeProps = require('merge-props');
|
|
20
21
|
var shim = require('use-sync-external-store/shim');
|
|
21
22
|
var react = require('@floating-ui/react');
|
|
22
23
|
var overlays = require('@react-aria/overlays');
|
|
@@ -54,6 +55,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
54
55
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
55
56
|
var throttle__default = /*#__PURE__*/_interopDefault(throttle);
|
|
56
57
|
var mergeRefs__default = /*#__PURE__*/_interopDefault(mergeRefs);
|
|
58
|
+
var mergeProps__default = /*#__PURE__*/_interopDefault(mergeProps);
|
|
57
59
|
var clamp__default = /*#__PURE__*/_interopDefault(clamp$2);
|
|
58
60
|
var debounce__default = /*#__PURE__*/_interopDefault(debounce);
|
|
59
61
|
var requiredIf__default = /*#__PURE__*/_interopDefault(requiredIf);
|
|
@@ -3464,9 +3466,7 @@ const DateHeader = ({
|
|
|
3464
3466
|
className: `tw-date-lookup-header-current ${buttonClasses}`,
|
|
3465
3467
|
"aria-label": intl.formatMessage(messages$4.goTo20YearView),
|
|
3466
3468
|
onClick: onLabelClick,
|
|
3467
|
-
children:
|
|
3468
|
-
children: label
|
|
3469
|
-
})
|
|
3469
|
+
children: label
|
|
3470
3470
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
3471
3471
|
className: "pull-right-single-direction",
|
|
3472
3472
|
children: /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
@@ -6364,6 +6364,20 @@ function useScreenSize(size) {
|
|
|
6364
6364
|
return useMedia(`(min-width: ${size}px)`);
|
|
6365
6365
|
}
|
|
6366
6366
|
|
|
6367
|
+
const PolymorphicWithOverrides = /*#__PURE__*/React.forwardRef(function PolymorphicWithOverrides({
|
|
6368
|
+
__overrides: {
|
|
6369
|
+
as: Element,
|
|
6370
|
+
...restOverrides
|
|
6371
|
+
},
|
|
6372
|
+
...restProps
|
|
6373
|
+
}, ref) {
|
|
6374
|
+
return /*#__PURE__*/jsxRuntime.jsx(Element, {
|
|
6375
|
+
ref: ref,
|
|
6376
|
+
...restProps,
|
|
6377
|
+
...restOverrides
|
|
6378
|
+
});
|
|
6379
|
+
});
|
|
6380
|
+
|
|
6367
6381
|
function wrapInFragment(value) {
|
|
6368
6382
|
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
6369
6383
|
children: value
|
|
@@ -6610,7 +6624,8 @@ function inferSearchableStrings(value) {
|
|
|
6610
6624
|
return [];
|
|
6611
6625
|
}
|
|
6612
6626
|
const SelectInputHasValueContext = /*#__PURE__*/React.createContext(false);
|
|
6613
|
-
const
|
|
6627
|
+
const SelectInputTriggerButtonPropsContext = /*#__PURE__*/React.createContext({});
|
|
6628
|
+
const SelectInputOptionContentWithinTriggerContext = /*#__PURE__*/React.createContext(false);
|
|
6614
6629
|
function dedupeSelectInputOptionItem(item, existingValues) {
|
|
6615
6630
|
if (existingValues.has(item.value)) {
|
|
6616
6631
|
return {
|
|
@@ -6640,14 +6655,68 @@ function dedupeSelectInputItems(items) {
|
|
|
6640
6655
|
return item;
|
|
6641
6656
|
});
|
|
6642
6657
|
}
|
|
6658
|
+
const defaultRenderTrigger = ({
|
|
6659
|
+
content,
|
|
6660
|
+
placeholderShown,
|
|
6661
|
+
clear,
|
|
6662
|
+
disabled,
|
|
6663
|
+
className
|
|
6664
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(InputGroup, {
|
|
6665
|
+
addonEnd: {
|
|
6666
|
+
content: /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
6667
|
+
className: classNames__default.default('np-select-input-addon-container', disabled && 'disabled'),
|
|
6668
|
+
children: [clear != null && !placeholderShown ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
6669
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(SelectInputClearButton, {
|
|
6670
|
+
onClick: event => {
|
|
6671
|
+
event.preventDefault();
|
|
6672
|
+
clear();
|
|
6673
|
+
}
|
|
6674
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
6675
|
+
className: "np-select-input-addon-separator"
|
|
6676
|
+
})]
|
|
6677
|
+
}) : null, /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
6678
|
+
className: "np-select-input-addon",
|
|
6679
|
+
children: /*#__PURE__*/jsxRuntime.jsx(icons.ChevronDown, {
|
|
6680
|
+
size: 16
|
|
6681
|
+
})
|
|
6682
|
+
})]
|
|
6683
|
+
}),
|
|
6684
|
+
padding: 'sm'
|
|
6685
|
+
},
|
|
6686
|
+
disabled: disabled,
|
|
6687
|
+
className: className,
|
|
6688
|
+
children: /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButton, {
|
|
6689
|
+
as: ButtonInput,
|
|
6690
|
+
children: placeholderShown ? /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
6691
|
+
className: "np-select-input-placeholder",
|
|
6692
|
+
children: [" ", content]
|
|
6693
|
+
}) : content
|
|
6694
|
+
})
|
|
6695
|
+
});
|
|
6696
|
+
function SelectInputClearButton({
|
|
6697
|
+
className,
|
|
6698
|
+
onClick
|
|
6699
|
+
}) {
|
|
6700
|
+
const intl = reactIntl.useIntl();
|
|
6701
|
+
return /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
6702
|
+
type: "button",
|
|
6703
|
+
"aria-label": intl.formatMessage(messages$5.ariaLabel),
|
|
6704
|
+
className: classNames__default.default(className, 'np-select-input-addon np-select-input-addon--interactive'),
|
|
6705
|
+
onClick: onClick,
|
|
6706
|
+
children: /*#__PURE__*/jsxRuntime.jsx(icons.Cross, {
|
|
6707
|
+
size: 16
|
|
6708
|
+
})
|
|
6709
|
+
});
|
|
6710
|
+
}
|
|
6643
6711
|
function SelectInput({
|
|
6644
6712
|
name,
|
|
6645
6713
|
placeholder,
|
|
6646
6714
|
items,
|
|
6647
6715
|
defaultValue,
|
|
6648
6716
|
value: controlledValue,
|
|
6649
|
-
renderValue = wrapInFragment,
|
|
6650
6717
|
compareValues,
|
|
6718
|
+
renderValue = wrapInFragment,
|
|
6719
|
+
renderTrigger = defaultRenderTrigger,
|
|
6651
6720
|
filterable,
|
|
6652
6721
|
filterPlaceholder,
|
|
6653
6722
|
disabled,
|
|
@@ -6655,7 +6724,6 @@ function SelectInput({
|
|
|
6655
6724
|
onChange,
|
|
6656
6725
|
onClear
|
|
6657
6726
|
}) {
|
|
6658
|
-
const intl = reactIntl.useIntl();
|
|
6659
6727
|
const [open, setOpen] = React.useState(false);
|
|
6660
6728
|
const triggerRef = React.useRef(null);
|
|
6661
6729
|
const screenSm = useScreenSize(exports.Breakpoint.SMALL);
|
|
@@ -6681,87 +6749,75 @@ function SelectInput({
|
|
|
6681
6749
|
value
|
|
6682
6750
|
}) => /*#__PURE__*/jsxRuntime.jsx(SelectInputHasValueContext.Provider, {
|
|
6683
6751
|
value: value != null,
|
|
6684
|
-
children: /*#__PURE__*/jsxRuntime.jsx(
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
disabled: uiDisabled,
|
|
6693
|
-
className: "np-select-input-addon np-select-input-addon--interactive",
|
|
6694
|
-
onClick: event => {
|
|
6695
|
-
event.preventDefault();
|
|
6696
|
-
onClear();
|
|
6697
|
-
triggerRef.current?.focus({
|
|
6698
|
-
preventScroll: true
|
|
6699
|
-
});
|
|
6700
|
-
},
|
|
6701
|
-
children: /*#__PURE__*/jsxRuntime.jsx(icons.Cross, {
|
|
6702
|
-
size: 16
|
|
6703
|
-
})
|
|
6704
|
-
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
6705
|
-
className: "np-select-input-addon-separator"
|
|
6706
|
-
})]
|
|
6707
|
-
}) : null, /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
6708
|
-
className: "np-select-input-addon",
|
|
6709
|
-
children: /*#__PURE__*/jsxRuntime.jsx(icons.ChevronDown, {
|
|
6710
|
-
size: 16
|
|
6711
|
-
})
|
|
6712
|
-
})]
|
|
6713
|
-
}),
|
|
6714
|
-
padding: 'sm'
|
|
6715
|
-
},
|
|
6716
|
-
className: className,
|
|
6717
|
-
children: /*#__PURE__*/jsxRuntime.jsx(OptionsOverlay, {
|
|
6718
|
-
open: open,
|
|
6719
|
-
renderTrigger: ({
|
|
6720
|
-
ref,
|
|
6721
|
-
getInteractionProps
|
|
6722
|
-
}) => /*#__PURE__*/jsxRuntime.jsx(react$1.Listbox.Button, {
|
|
6752
|
+
children: /*#__PURE__*/jsxRuntime.jsx(OptionsOverlay, {
|
|
6753
|
+
open: open,
|
|
6754
|
+
renderTrigger: ({
|
|
6755
|
+
ref,
|
|
6756
|
+
getInteractionProps
|
|
6757
|
+
}) => /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButtonPropsContext.Provider, {
|
|
6758
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
6759
|
+
value: {
|
|
6723
6760
|
ref: mergeRefs__default.default([ref, triggerRef]),
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
},
|
|
6729
|
-
|
|
6761
|
+
...mergeProps__default.default({
|
|
6762
|
+
onClick: () => {
|
|
6763
|
+
setOpen(prev => !prev);
|
|
6764
|
+
}
|
|
6765
|
+
}, getInteractionProps())
|
|
6766
|
+
},
|
|
6767
|
+
children: renderTrigger({
|
|
6768
|
+
content: value != null ? /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
|
|
6730
6769
|
value: true,
|
|
6731
6770
|
children: renderValue(value, true)
|
|
6732
|
-
}) :
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
|
|
6743
|
-
items: items,
|
|
6744
|
-
renderValue: renderValue,
|
|
6745
|
-
filterable: filterable,
|
|
6746
|
-
filterPlaceholder: filterPlaceholder,
|
|
6747
|
-
searchInputRef: searchInputRef,
|
|
6748
|
-
listboxRef: listboxRef
|
|
6771
|
+
}) : placeholder,
|
|
6772
|
+
placeholderShown: value == null,
|
|
6773
|
+
clear: onClear != null ? () => {
|
|
6774
|
+
onClear();
|
|
6775
|
+
triggerRef.current?.focus({
|
|
6776
|
+
preventScroll: true
|
|
6777
|
+
});
|
|
6778
|
+
} : undefined,
|
|
6779
|
+
disabled: uiDisabled,
|
|
6780
|
+
className: classNames__default.default(className, 'np-text-body-large')
|
|
6749
6781
|
})
|
|
6782
|
+
}),
|
|
6783
|
+
initialFocusRef: controllerRef,
|
|
6784
|
+
padding: "none",
|
|
6785
|
+
onClose: () => {
|
|
6786
|
+
setOpen(false);
|
|
6787
|
+
},
|
|
6788
|
+
children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
|
|
6789
|
+
items: items,
|
|
6790
|
+
renderValue: renderValue,
|
|
6791
|
+
filterable: filterable,
|
|
6792
|
+
filterPlaceholder: filterPlaceholder,
|
|
6793
|
+
searchInputRef: searchInputRef,
|
|
6794
|
+
listboxRef: listboxRef
|
|
6750
6795
|
})
|
|
6751
6796
|
})
|
|
6752
6797
|
})
|
|
6753
6798
|
});
|
|
6754
6799
|
}
|
|
6755
|
-
|
|
6756
|
-
|
|
6800
|
+
function SelectInputTriggerButton({
|
|
6801
|
+
as = 'button',
|
|
6757
6802
|
...restProps
|
|
6758
|
-
}
|
|
6759
|
-
|
|
6803
|
+
}) {
|
|
6804
|
+
const {
|
|
6805
|
+
ref,
|
|
6806
|
+
onClick,
|
|
6807
|
+
...interactionProps
|
|
6808
|
+
} = React.useContext(SelectInputTriggerButtonPropsContext);
|
|
6809
|
+
return /*#__PURE__*/jsxRuntime.jsx(react$1.Listbox.Button, {
|
|
6760
6810
|
ref: ref,
|
|
6761
|
-
|
|
6762
|
-
|
|
6811
|
+
as: PolymorphicWithOverrides,
|
|
6812
|
+
__overrides: {
|
|
6813
|
+
as,
|
|
6814
|
+
...interactionProps
|
|
6815
|
+
},
|
|
6816
|
+
...mergeProps__default.default({
|
|
6817
|
+
onClick
|
|
6818
|
+
}, restProps)
|
|
6763
6819
|
});
|
|
6764
|
-
}
|
|
6820
|
+
}
|
|
6765
6821
|
const SelectInputOptionsContainer = /*#__PURE__*/React.forwardRef(function SelectInputOptionsContainer({
|
|
6766
6822
|
'aria-orientation': ariaOrientation,
|
|
6767
6823
|
'aria-activedescendant': ariaActiveDescendant,
|
|
@@ -6890,8 +6946,7 @@ function SelectInputItemView({
|
|
|
6890
6946
|
{
|
|
6891
6947
|
if (needle == null) {
|
|
6892
6948
|
return /*#__PURE__*/jsxRuntime.jsx("hr", {
|
|
6893
|
-
className: "np-select-input-separator-item"
|
|
6894
|
-
"aria-hidden": true
|
|
6949
|
+
className: "np-select-input-separator-item"
|
|
6895
6950
|
});
|
|
6896
6951
|
}
|
|
6897
6952
|
break;
|
|
@@ -6966,16 +7021,16 @@ function SelectInputOptionContent({
|
|
|
6966
7021
|
description,
|
|
6967
7022
|
icon
|
|
6968
7023
|
}) {
|
|
6969
|
-
const
|
|
7024
|
+
const withinTrigger = React.useContext(SelectInputOptionContentWithinTriggerContext);
|
|
6970
7025
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
6971
7026
|
className: "np-select-input-option-content-container np-text-body-large",
|
|
6972
7027
|
children: [icon ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
6973
|
-
className: classNames__default.default('np-select-input-option-content-icon', !
|
|
7028
|
+
className: classNames__default.default('np-select-input-option-content-icon', !withinTrigger && 'np-select-input-option-content-icon--not-within-trigger'),
|
|
6974
7029
|
children: icon
|
|
6975
7030
|
}) : null, /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
6976
7031
|
className: "np-select-input-option-content-text",
|
|
6977
7032
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
6978
|
-
className: classNames__default.default('np-select-input-option-content-text-line-1',
|
|
7033
|
+
className: classNames__default.default('np-select-input-option-content-text-line-1', withinTrigger && 'np-select-input-option-content-text-within-trigger'),
|
|
6979
7034
|
children: [/*#__PURE__*/jsxRuntime.jsx("h4", {
|
|
6980
7035
|
className: "d-inline np-text-body-large",
|
|
6981
7036
|
children: title
|
|
@@ -6984,7 +7039,7 @@ function SelectInputOptionContent({
|
|
|
6984
7039
|
children: note
|
|
6985
7040
|
}) : null]
|
|
6986
7041
|
}), description ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
6987
|
-
className: classNames__default.default('np-select-input-option-content-text-secondary np-text-body-default',
|
|
7042
|
+
className: classNames__default.default('np-select-input-option-content-text-secondary np-text-body-default', withinTrigger && 'np-select-input-option-content-text-within-trigger'),
|
|
6988
7043
|
children: description
|
|
6989
7044
|
}) : null]
|
|
6990
7045
|
})]
|