useEffectiveBreakpoint.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Grid } from 'antd';
  2. import { useEffect, useState } from 'react';
  3. const { useBreakpoint } = Grid;
  4. /**
  5. * A wrapper around antd's Grid.useBreakpoint that respects the application's minimum width.
  6. * If the window width is less than 1700px (the min-width set in CSS), it forces the breakpoints
  7. * to behave as if the screen is large (xxl), preventing the layout from switching to mobile/tablet modes
  8. * when the user scrolls horizontally.
  9. */
  10. const useEffectiveBreakpoint = () => {
  11. const screens = useBreakpoint();
  12. // const [isForcedLarge, setIsForcedLarge] = useState(false);
  13. // useEffect(() => {
  14. // const handleResize = () => {
  15. // // Check if window width is less than the min-width (1700px)
  16. // // We use a slightly smaller buffer or exact match depending on needs,
  17. // // but strictly < 1700 matches the CSS min-width logic.
  18. // setIsForcedLarge(window.innerWidth < 1700);
  19. // };
  20. // // Initial check
  21. // handleResize();
  22. // window.addEventListener('resize', handleResize);
  23. // return () => window.removeEventListener('resize', handleResize);
  24. // }, []);
  25. // if (isForcedLarge) {
  26. // // Return a breakpoint object that mimics a very large screen
  27. // return {
  28. // xs: true,
  29. // sm: true,
  30. // md: true,
  31. // lg: true,
  32. // xl: true,
  33. // xxl: true,
  34. // };
  35. // }
  36. return screens;
  37. };
  38. export default useEffectiveBreakpoint;