@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.esm.js
CHANGED
|
@@ -16,6 +16,7 @@ import mergeRefs from 'react-merge-refs';
|
|
|
16
16
|
import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } from '@transferwise/neptune-validation';
|
|
17
17
|
import { usePopper } from 'react-popper';
|
|
18
18
|
import { Transition, Listbox } from '@headlessui/react';
|
|
19
|
+
import mergeProps from 'merge-props';
|
|
19
20
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
20
21
|
import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, offset, flip, shift, size, autoUpdate } from '@floating-ui/react';
|
|
21
22
|
import { usePreventScroll } from '@react-aria/overlays';
|
|
@@ -3431,9 +3432,7 @@ const DateHeader = ({
|
|
|
3431
3432
|
className: `tw-date-lookup-header-current ${buttonClasses}`,
|
|
3432
3433
|
"aria-label": intl.formatMessage(messages$4.goTo20YearView),
|
|
3433
3434
|
onClick: onLabelClick,
|
|
3434
|
-
children:
|
|
3435
|
-
children: label
|
|
3436
|
-
})
|
|
3435
|
+
children: label
|
|
3437
3436
|
}), /*#__PURE__*/jsx("div", {
|
|
3438
3437
|
className: "pull-right-single-direction",
|
|
3439
3438
|
children: /*#__PURE__*/jsx("button", {
|
|
@@ -6331,6 +6330,20 @@ function useScreenSize(size) {
|
|
|
6331
6330
|
return useMedia(`(min-width: ${size}px)`);
|
|
6332
6331
|
}
|
|
6333
6332
|
|
|
6333
|
+
const PolymorphicWithOverrides = /*#__PURE__*/forwardRef(function PolymorphicWithOverrides({
|
|
6334
|
+
__overrides: {
|
|
6335
|
+
as: Element,
|
|
6336
|
+
...restOverrides
|
|
6337
|
+
},
|
|
6338
|
+
...restProps
|
|
6339
|
+
}, ref) {
|
|
6340
|
+
return /*#__PURE__*/jsx(Element, {
|
|
6341
|
+
ref: ref,
|
|
6342
|
+
...restProps,
|
|
6343
|
+
...restOverrides
|
|
6344
|
+
});
|
|
6345
|
+
});
|
|
6346
|
+
|
|
6334
6347
|
function wrapInFragment(value) {
|
|
6335
6348
|
return /*#__PURE__*/jsx(Fragment, {
|
|
6336
6349
|
children: value
|
|
@@ -6577,7 +6590,8 @@ function inferSearchableStrings(value) {
|
|
|
6577
6590
|
return [];
|
|
6578
6591
|
}
|
|
6579
6592
|
const SelectInputHasValueContext = /*#__PURE__*/createContext(false);
|
|
6580
|
-
const
|
|
6593
|
+
const SelectInputTriggerButtonPropsContext = /*#__PURE__*/createContext({});
|
|
6594
|
+
const SelectInputOptionContentWithinTriggerContext = /*#__PURE__*/createContext(false);
|
|
6581
6595
|
function dedupeSelectInputOptionItem(item, existingValues) {
|
|
6582
6596
|
if (existingValues.has(item.value)) {
|
|
6583
6597
|
return {
|
|
@@ -6607,14 +6621,68 @@ function dedupeSelectInputItems(items) {
|
|
|
6607
6621
|
return item;
|
|
6608
6622
|
});
|
|
6609
6623
|
}
|
|
6624
|
+
const defaultRenderTrigger = ({
|
|
6625
|
+
content,
|
|
6626
|
+
placeholderShown,
|
|
6627
|
+
clear,
|
|
6628
|
+
disabled,
|
|
6629
|
+
className
|
|
6630
|
+
}) => /*#__PURE__*/jsx(InputGroup, {
|
|
6631
|
+
addonEnd: {
|
|
6632
|
+
content: /*#__PURE__*/jsxs("span", {
|
|
6633
|
+
className: classNames('np-select-input-addon-container', disabled && 'disabled'),
|
|
6634
|
+
children: [clear != null && !placeholderShown ? /*#__PURE__*/jsxs(Fragment, {
|
|
6635
|
+
children: [/*#__PURE__*/jsx(SelectInputClearButton, {
|
|
6636
|
+
onClick: event => {
|
|
6637
|
+
event.preventDefault();
|
|
6638
|
+
clear();
|
|
6639
|
+
}
|
|
6640
|
+
}), /*#__PURE__*/jsx("span", {
|
|
6641
|
+
className: "np-select-input-addon-separator"
|
|
6642
|
+
})]
|
|
6643
|
+
}) : null, /*#__PURE__*/jsx("span", {
|
|
6644
|
+
className: "np-select-input-addon",
|
|
6645
|
+
children: /*#__PURE__*/jsx(ChevronDown, {
|
|
6646
|
+
size: 16
|
|
6647
|
+
})
|
|
6648
|
+
})]
|
|
6649
|
+
}),
|
|
6650
|
+
padding: 'sm'
|
|
6651
|
+
},
|
|
6652
|
+
disabled: disabled,
|
|
6653
|
+
className: className,
|
|
6654
|
+
children: /*#__PURE__*/jsx(SelectInputTriggerButton, {
|
|
6655
|
+
as: ButtonInput,
|
|
6656
|
+
children: placeholderShown ? /*#__PURE__*/jsxs("span", {
|
|
6657
|
+
className: "np-select-input-placeholder",
|
|
6658
|
+
children: [" ", content]
|
|
6659
|
+
}) : content
|
|
6660
|
+
})
|
|
6661
|
+
});
|
|
6662
|
+
function SelectInputClearButton({
|
|
6663
|
+
className,
|
|
6664
|
+
onClick
|
|
6665
|
+
}) {
|
|
6666
|
+
const intl = useIntl();
|
|
6667
|
+
return /*#__PURE__*/jsx("button", {
|
|
6668
|
+
type: "button",
|
|
6669
|
+
"aria-label": intl.formatMessage(messages$5.ariaLabel),
|
|
6670
|
+
className: classNames(className, 'np-select-input-addon np-select-input-addon--interactive'),
|
|
6671
|
+
onClick: onClick,
|
|
6672
|
+
children: /*#__PURE__*/jsx(Cross, {
|
|
6673
|
+
size: 16
|
|
6674
|
+
})
|
|
6675
|
+
});
|
|
6676
|
+
}
|
|
6610
6677
|
function SelectInput({
|
|
6611
6678
|
name,
|
|
6612
6679
|
placeholder,
|
|
6613
6680
|
items,
|
|
6614
6681
|
defaultValue,
|
|
6615
6682
|
value: controlledValue,
|
|
6616
|
-
renderValue = wrapInFragment,
|
|
6617
6683
|
compareValues,
|
|
6684
|
+
renderValue = wrapInFragment,
|
|
6685
|
+
renderTrigger = defaultRenderTrigger,
|
|
6618
6686
|
filterable,
|
|
6619
6687
|
filterPlaceholder,
|
|
6620
6688
|
disabled,
|
|
@@ -6622,7 +6690,6 @@ function SelectInput({
|
|
|
6622
6690
|
onChange,
|
|
6623
6691
|
onClear
|
|
6624
6692
|
}) {
|
|
6625
|
-
const intl = useIntl();
|
|
6626
6693
|
const [open, setOpen] = useState(false);
|
|
6627
6694
|
const triggerRef = useRef(null);
|
|
6628
6695
|
const screenSm = useScreenSize(Breakpoint.SMALL);
|
|
@@ -6648,87 +6715,75 @@ function SelectInput({
|
|
|
6648
6715
|
value
|
|
6649
6716
|
}) => /*#__PURE__*/jsx(SelectInputHasValueContext.Provider, {
|
|
6650
6717
|
value: value != null,
|
|
6651
|
-
children: /*#__PURE__*/jsx(
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
disabled: uiDisabled,
|
|
6660
|
-
className: "np-select-input-addon np-select-input-addon--interactive",
|
|
6661
|
-
onClick: event => {
|
|
6662
|
-
event.preventDefault();
|
|
6663
|
-
onClear();
|
|
6664
|
-
triggerRef.current?.focus({
|
|
6665
|
-
preventScroll: true
|
|
6666
|
-
});
|
|
6667
|
-
},
|
|
6668
|
-
children: /*#__PURE__*/jsx(Cross, {
|
|
6669
|
-
size: 16
|
|
6670
|
-
})
|
|
6671
|
-
}), /*#__PURE__*/jsx("span", {
|
|
6672
|
-
className: "np-select-input-addon-separator"
|
|
6673
|
-
})]
|
|
6674
|
-
}) : null, /*#__PURE__*/jsx("span", {
|
|
6675
|
-
className: "np-select-input-addon",
|
|
6676
|
-
children: /*#__PURE__*/jsx(ChevronDown, {
|
|
6677
|
-
size: 16
|
|
6678
|
-
})
|
|
6679
|
-
})]
|
|
6680
|
-
}),
|
|
6681
|
-
padding: 'sm'
|
|
6682
|
-
},
|
|
6683
|
-
className: className,
|
|
6684
|
-
children: /*#__PURE__*/jsx(OptionsOverlay, {
|
|
6685
|
-
open: open,
|
|
6686
|
-
renderTrigger: ({
|
|
6687
|
-
ref,
|
|
6688
|
-
getInteractionProps
|
|
6689
|
-
}) => /*#__PURE__*/jsx(Listbox.Button, {
|
|
6718
|
+
children: /*#__PURE__*/jsx(OptionsOverlay, {
|
|
6719
|
+
open: open,
|
|
6720
|
+
renderTrigger: ({
|
|
6721
|
+
ref,
|
|
6722
|
+
getInteractionProps
|
|
6723
|
+
}) => /*#__PURE__*/jsx(SelectInputTriggerButtonPropsContext.Provider, {
|
|
6724
|
+
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
6725
|
+
value: {
|
|
6690
6726
|
ref: mergeRefs([ref, triggerRef]),
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
},
|
|
6696
|
-
|
|
6727
|
+
...mergeProps({
|
|
6728
|
+
onClick: () => {
|
|
6729
|
+
setOpen(prev => !prev);
|
|
6730
|
+
}
|
|
6731
|
+
}, getInteractionProps())
|
|
6732
|
+
},
|
|
6733
|
+
children: renderTrigger({
|
|
6734
|
+
content: value != null ? /*#__PURE__*/jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
|
|
6697
6735
|
value: true,
|
|
6698
6736
|
children: renderValue(value, true)
|
|
6699
|
-
}) :
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
children: /*#__PURE__*/jsx(SelectInputOptions, {
|
|
6710
|
-
items: items,
|
|
6711
|
-
renderValue: renderValue,
|
|
6712
|
-
filterable: filterable,
|
|
6713
|
-
filterPlaceholder: filterPlaceholder,
|
|
6714
|
-
searchInputRef: searchInputRef,
|
|
6715
|
-
listboxRef: listboxRef
|
|
6737
|
+
}) : placeholder,
|
|
6738
|
+
placeholderShown: value == null,
|
|
6739
|
+
clear: onClear != null ? () => {
|
|
6740
|
+
onClear();
|
|
6741
|
+
triggerRef.current?.focus({
|
|
6742
|
+
preventScroll: true
|
|
6743
|
+
});
|
|
6744
|
+
} : undefined,
|
|
6745
|
+
disabled: uiDisabled,
|
|
6746
|
+
className: classNames(className, 'np-text-body-large')
|
|
6716
6747
|
})
|
|
6748
|
+
}),
|
|
6749
|
+
initialFocusRef: controllerRef,
|
|
6750
|
+
padding: "none",
|
|
6751
|
+
onClose: () => {
|
|
6752
|
+
setOpen(false);
|
|
6753
|
+
},
|
|
6754
|
+
children: /*#__PURE__*/jsx(SelectInputOptions, {
|
|
6755
|
+
items: items,
|
|
6756
|
+
renderValue: renderValue,
|
|
6757
|
+
filterable: filterable,
|
|
6758
|
+
filterPlaceholder: filterPlaceholder,
|
|
6759
|
+
searchInputRef: searchInputRef,
|
|
6760
|
+
listboxRef: listboxRef
|
|
6717
6761
|
})
|
|
6718
6762
|
})
|
|
6719
6763
|
})
|
|
6720
6764
|
});
|
|
6721
6765
|
}
|
|
6722
|
-
|
|
6723
|
-
|
|
6766
|
+
function SelectInputTriggerButton({
|
|
6767
|
+
as = 'button',
|
|
6724
6768
|
...restProps
|
|
6725
|
-
}
|
|
6726
|
-
|
|
6769
|
+
}) {
|
|
6770
|
+
const {
|
|
6771
|
+
ref,
|
|
6772
|
+
onClick,
|
|
6773
|
+
...interactionProps
|
|
6774
|
+
} = useContext(SelectInputTriggerButtonPropsContext);
|
|
6775
|
+
return /*#__PURE__*/jsx(Listbox.Button, {
|
|
6727
6776
|
ref: ref,
|
|
6728
|
-
|
|
6729
|
-
|
|
6777
|
+
as: PolymorphicWithOverrides,
|
|
6778
|
+
__overrides: {
|
|
6779
|
+
as,
|
|
6780
|
+
...interactionProps
|
|
6781
|
+
},
|
|
6782
|
+
...mergeProps({
|
|
6783
|
+
onClick
|
|
6784
|
+
}, restProps)
|
|
6730
6785
|
});
|
|
6731
|
-
}
|
|
6786
|
+
}
|
|
6732
6787
|
const SelectInputOptionsContainer = /*#__PURE__*/forwardRef(function SelectInputOptionsContainer({
|
|
6733
6788
|
'aria-orientation': ariaOrientation,
|
|
6734
6789
|
'aria-activedescendant': ariaActiveDescendant,
|
|
@@ -6857,8 +6912,7 @@ function SelectInputItemView({
|
|
|
6857
6912
|
{
|
|
6858
6913
|
if (needle == null) {
|
|
6859
6914
|
return /*#__PURE__*/jsx("hr", {
|
|
6860
|
-
className: "np-select-input-separator-item"
|
|
6861
|
-
"aria-hidden": true
|
|
6915
|
+
className: "np-select-input-separator-item"
|
|
6862
6916
|
});
|
|
6863
6917
|
}
|
|
6864
6918
|
break;
|
|
@@ -6933,16 +6987,16 @@ function SelectInputOptionContent({
|
|
|
6933
6987
|
description,
|
|
6934
6988
|
icon
|
|
6935
6989
|
}) {
|
|
6936
|
-
const
|
|
6990
|
+
const withinTrigger = useContext(SelectInputOptionContentWithinTriggerContext);
|
|
6937
6991
|
return /*#__PURE__*/jsxs("div", {
|
|
6938
6992
|
className: "np-select-input-option-content-container np-text-body-large",
|
|
6939
6993
|
children: [icon ? /*#__PURE__*/jsx("div", {
|
|
6940
|
-
className: classNames('np-select-input-option-content-icon', !
|
|
6994
|
+
className: classNames('np-select-input-option-content-icon', !withinTrigger && 'np-select-input-option-content-icon--not-within-trigger'),
|
|
6941
6995
|
children: icon
|
|
6942
6996
|
}) : null, /*#__PURE__*/jsxs("div", {
|
|
6943
6997
|
className: "np-select-input-option-content-text",
|
|
6944
6998
|
children: [/*#__PURE__*/jsxs("div", {
|
|
6945
|
-
className: classNames('np-select-input-option-content-text-line-1',
|
|
6999
|
+
className: classNames('np-select-input-option-content-text-line-1', withinTrigger && 'np-select-input-option-content-text-within-trigger'),
|
|
6946
7000
|
children: [/*#__PURE__*/jsx("h4", {
|
|
6947
7001
|
className: "d-inline np-text-body-large",
|
|
6948
7002
|
children: title
|
|
@@ -6951,7 +7005,7 @@ function SelectInputOptionContent({
|
|
|
6951
7005
|
children: note
|
|
6952
7006
|
}) : null]
|
|
6953
7007
|
}), description ? /*#__PURE__*/jsx("div", {
|
|
6954
|
-
className: classNames('np-select-input-option-content-text-secondary np-text-body-default',
|
|
7008
|
+
className: classNames('np-select-input-option-content-text-secondary np-text-body-default', withinTrigger && 'np-select-input-option-content-text-within-trigger'),
|
|
6955
7009
|
children: description
|
|
6956
7010
|
}) : null]
|
|
6957
7011
|
})]
|