From 6448624199bee095c212a6ae0a7772573392e560 Mon Sep 17 00:00:00 2001 From: Peter Pal Hudak Date: Fri, 20 Sep 2024 16:11:25 +0200 Subject: [PATCH] WIP: add WrapperComponent to test resizing --- packages/__docs__/src/App/index.tsx | 35 +++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/__docs__/src/App/index.tsx b/packages/__docs__/src/App/index.tsx index e0f6581b0b..9e6fbcaba8 100644 --- a/packages/__docs__/src/App/index.tsx +++ b/packages/__docs__/src/App/index.tsx @@ -29,7 +29,9 @@ import { createContext, LegacyRef, ReactElement, - SyntheticEvent + SyntheticEvent, + useEffect, + useState } from 'react' import { Alert } from '@instructure/ui-alerts' @@ -93,6 +95,30 @@ export const AppContext = createContext({ library: undefined }) +const WrapperComponent = (props) => { + const [isSmallScreen, setIsSmallScreen] = useState(false) + + const SmallScreen = () =>

Small screen

+ const BigScreen = () =>

Big screen

+ + useEffect(() => { + const handleResize = () => { + setIsSmallScreen(window.innerWidth <= 768) + } + + // Check on component mount + handleResize() + + // Add event listener for window resize + window.addEventListener('resize', handleResize) + + // Cleanup listener on component unmount + return () => window.removeEventListener('resize', handleResize) + }, []) + + return <>{isSmallScreen ? : } +} + @withStyle(generateStyle, generateComponentTheme) class App extends Component { static propTypes = propTypes @@ -769,6 +795,7 @@ class App extends Component { boxSizing: 'border-box' }} > + { - +