@transferwise/components 45.28.1 → 46.0.1

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.js CHANGED
@@ -1881,43 +1881,36 @@ const useHasIntersected = ({
1881
1881
  return [hasIntersected];
1882
1882
  };
1883
1883
 
1884
+ function useMedia(query) {
1885
+ return shim.useSyncExternalStore(onStoreChange => {
1886
+ const mediaQueryList = window.matchMedia(query);
1887
+ mediaQueryList.addEventListener('change', onStoreChange);
1888
+ return () => {
1889
+ mediaQueryList.removeEventListener('change', onStoreChange);
1890
+ };
1891
+ }, () => typeof window !== 'undefined' ? window.matchMedia(query).matches : undefined, () => undefined);
1892
+ }
1893
+
1894
+ function useScreenSize(size) {
1895
+ return useMedia(`(min-width: ${size}px)`);
1896
+ }
1897
+
1898
+ /**
1899
+ * @deprecated Prefer `useScreenSize` instead.
1900
+ */
1884
1901
  const useLayout = () => {
1885
- const windowReference = typeof window === 'undefined' ? undefined : window;
1886
- const [breakpoint, setBreakpoint] = React.useState();
1887
- const [clientWidth] = useClientWidth({
1888
- ref: windowReference
1889
- });
1890
- React.useEffect(() => {
1891
- if (!clientWidth) {
1892
- return;
1893
- }
1894
- if (clientWidth <= exports.Breakpoint.EXTRA_SMALL) {
1895
- setBreakpoint(exports.Breakpoint.EXTRA_SMALL);
1896
- return;
1897
- }
1898
- if (exports.Breakpoint.EXTRA_SMALL < clientWidth && clientWidth <= exports.Breakpoint.SMALL) {
1899
- setBreakpoint(exports.Breakpoint.SMALL);
1900
- return;
1901
- }
1902
- if (exports.Breakpoint.SMALL < clientWidth && clientWidth <= exports.Breakpoint.MEDIUM) {
1903
- setBreakpoint(exports.Breakpoint.MEDIUM);
1904
- return;
1905
- }
1906
- if (exports.Breakpoint.MEDIUM < clientWidth && clientWidth <= exports.Breakpoint.LARGE) {
1907
- setBreakpoint(exports.Breakpoint.LARGE);
1908
- return;
1909
- }
1910
- if (exports.Breakpoint.LARGE < clientWidth) {
1911
- setBreakpoint(exports.Breakpoint.EXTRA_LARGE);
1912
- }
1913
- }, [clientWidth]);
1902
+ const screenXs = useScreenSize(exports.Breakpoint.EXTRA_SMALL);
1903
+ const screenSm = useScreenSize(exports.Breakpoint.SMALL);
1904
+ const screenMd = useScreenSize(exports.Breakpoint.MEDIUM);
1905
+ const screenLg = useScreenSize(exports.Breakpoint.LARGE);
1906
+ const screenXl = useScreenSize(exports.Breakpoint.EXTRA_LARGE);
1914
1907
  return {
1915
- isMobile: !!breakpoint && [exports.Breakpoint.EXTRA_SMALL, exports.Breakpoint.SMALL].includes(breakpoint),
1916
- isExtraSmall: breakpoint === exports.Breakpoint.EXTRA_SMALL,
1917
- isSmall: breakpoint === exports.Breakpoint.SMALL,
1918
- isMedium: breakpoint === exports.Breakpoint.MEDIUM,
1919
- isLarge: breakpoint === exports.Breakpoint.LARGE,
1920
- isExtraLarge: breakpoint === exports.Breakpoint.EXTRA_LARGE
1908
+ isMobile: screenSm != null ? !screenSm : undefined,
1909
+ isExtraSmall: screenXs,
1910
+ isSmall: screenSm,
1911
+ isMedium: screenMd,
1912
+ isLarge: screenLg,
1913
+ isExtraLarge: screenXl
1921
1914
  };
1922
1915
  };
1923
1916
 
@@ -2042,16 +2035,6 @@ Drawer.defaultProps = {
2042
2035
  };
2043
2036
  var Drawer$1 = Drawer;
2044
2037
 
2045
- function useMedia(query) {
2046
- return shim.useSyncExternalStore(onStoreChange => {
2047
- const mediaQueryList = window.matchMedia(query);
2048
- mediaQueryList.addEventListener('change', onStoreChange);
2049
- return () => {
2050
- mediaQueryList.removeEventListener('change', onStoreChange);
2051
- };
2052
- }, () => typeof window !== 'undefined' ? window.matchMedia(query).matches : undefined, () => undefined);
2053
- }
2054
-
2055
2038
  const INITIAL_Y_POSITION = 0;
2056
2039
  const CONTENT_SCROLL_THRESHOLD = 1;
2057
2040
  const MOVE_OFFSET_THRESHOLD = 50;
@@ -6060,14 +6043,13 @@ const Modal = ({
6060
6043
  }) => {
6061
6044
  const checkSpecialClasses = classToCheck => className?.split(' ').includes(classToCheck);
6062
6045
  const {
6063
- isMobile,
6064
- isMedium: isTablet
6046
+ isMedium
6065
6047
  } = useLayout();
6066
6048
  // These should be replaced with props in breaking change.
6067
6049
  const isCompact = checkSpecialClasses('compact');
6068
6050
  const noDivider = checkSpecialClasses('no-divider');
6069
6051
  const contentReference = React.useRef(null);
6070
- return isMobile || isTablet ? /*#__PURE__*/jsxRuntime.jsx(Drawer$1, {
6052
+ return !isMedium ? /*#__PURE__*/jsxRuntime.jsx(Drawer$1, {
6071
6053
  open: open,
6072
6054
  headerTitle: title,
6073
6055
  footerContent: footer,
@@ -6501,10 +6483,6 @@ const SearchInput = /*#__PURE__*/React.forwardRef(function SearchInput({
6501
6483
  });
6502
6484
  });
6503
6485
 
6504
- function useScreenSize(size) {
6505
- return useMedia(`(min-width: ${size}px)`);
6506
- }
6507
-
6508
6486
  const PolymorphicWithOverrides = /*#__PURE__*/React.forwardRef(function PolymorphicWithOverrides({
6509
6487
  __overrides: {
6510
6488
  as: Element,
@@ -8070,20 +8048,26 @@ class MoneyInput extends React.Component {
8070
8048
  maxLengthOverride
8071
8049
  } = this.props;
8072
8050
  const selectOptions = this.getSelectOptions();
8073
- const getFirstOption = () => {
8051
+ const getFirstSelectItem = () => {
8074
8052
  if (selectOptions.length !== 0) {
8075
- const firstOption = selectOptions[0];
8076
- if (firstOption.type === 'option') {
8077
- return firstOption.value;
8053
+ const firstItem = selectOptions[0];
8054
+ if (firstItem.type === 'option') {
8055
+ return {
8056
+ hasOneCurrency: selectOptions.length === 1,
8057
+ currency: firstItem.value.currency
8058
+ };
8078
8059
  }
8079
- if (firstOption.type === 'group' && firstOption.options.length !== 0) {
8080
- return firstOption.options[0].value;
8060
+ if (firstItem.type === 'group') {
8061
+ return {
8062
+ hasOneCurrency: firstItem.options.length === 1,
8063
+ currency: firstItem.options[0].value.currency
8064
+ };
8081
8065
  }
8082
8066
  }
8083
8067
  return null;
8084
8068
  };
8085
- const firstOption = getFirstOption();
8086
- const isFixedCurrency = !this.state.searchQuery && (selectOptions.length === 1 && firstOption.currency === selectedCurrency.currency || !onCurrencyChange);
8069
+ const firstSelectItem = getFirstSelectItem();
8070
+ const isFixedCurrency = !this.state.searchQuery && (firstSelectItem?.hasOneCurrency && firstSelectItem?.currency === selectedCurrency.currency || !onCurrencyChange);
8087
8071
  const disabled = !this.props.onAmountChange;
8088
8072
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
8089
8073
  className: classNames__default.default(this.style('tw-money-input'), this.style('input-group'), this.style(`input-group-${size}`)),
@@ -15762,5 +15746,6 @@ exports.isServerSide = isServerSide;
15762
15746
  exports.translations = translations;
15763
15747
  exports.useDirection = useDirection;
15764
15748
  exports.useLayout = useLayout;
15749
+ exports.useScreenSize = useScreenSize;
15765
15750
  exports.useSnackbar = useSnackbar;
15766
15751
  //# sourceMappingURL=index.js.map