@transferwise/components 45.28.1 → 46.0.0

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,
@@ -15762,5 +15740,6 @@ exports.isServerSide = isServerSide;
15762
15740
  exports.translations = translations;
15763
15741
  exports.useDirection = useDirection;
15764
15742
  exports.useLayout = useLayout;
15743
+ exports.useScreenSize = useScreenSize;
15765
15744
  exports.useSnackbar = useSnackbar;
15766
15745
  //# sourceMappingURL=index.js.map