@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.
@@ -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: /*#__PURE__*/jsx("h4", {
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 SelectInputOptionContentCompactContext = /*#__PURE__*/createContext(false);
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(InputGroup, {
6652
- addonEnd: {
6653
- content: /*#__PURE__*/jsxs("span", {
6654
- className: classNames('np-select-input-addon-container', uiDisabled && 'disabled'),
6655
- children: [onClear != null && value != null ? /*#__PURE__*/jsxs(Fragment, {
6656
- children: [/*#__PURE__*/jsx("button", {
6657
- type: "button",
6658
- "aria-label": intl.formatMessage(messages$5.ariaLabel),
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
- as: SelectInputButton,
6692
- overrides: getInteractionProps(),
6693
- onClick: () => {
6694
- setOpen(prev => !prev);
6695
- },
6696
- children: value != null ? /*#__PURE__*/jsx(SelectInputOptionContentCompactContext.Provider, {
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
- }) : /*#__PURE__*/jsx("span", {
6700
- className: "np-select-input-placeholder",
6701
- children: placeholder
6702
- })
6703
- }),
6704
- initialFocusRef: controllerRef,
6705
- padding: "none",
6706
- onClose: () => {
6707
- setOpen(false);
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
- const SelectInputButton = /*#__PURE__*/forwardRef(function SelectInputButton({
6723
- overrides,
6766
+ function SelectInputTriggerButton({
6767
+ as = 'button',
6724
6768
  ...restProps
6725
- }, ref) {
6726
- return /*#__PURE__*/jsx(ButtonInput, {
6769
+ }) {
6770
+ const {
6771
+ ref,
6772
+ onClick,
6773
+ ...interactionProps
6774
+ } = useContext(SelectInputTriggerButtonPropsContext);
6775
+ return /*#__PURE__*/jsx(Listbox.Button, {
6727
6776
  ref: ref,
6728
- ...restProps,
6729
- ...overrides
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 compact = useContext(SelectInputOptionContentCompactContext);
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', !compact && 'np-select-input-option-content-icon--not-compact'),
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', compact && 'np-select-input-option-content-text-compact'),
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', compact && 'np-select-input-option-content-text-compact'),
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
  })]