Skip to content

Commit 6448624

Browse files
committed
WIP: add WrapperComponent to test resizing
1 parent 88fafe3 commit 6448624

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

packages/__docs__/src/App/index.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
createContext,
3030
LegacyRef,
3131
ReactElement,
32-
SyntheticEvent
32+
SyntheticEvent,
33+
useEffect,
34+
useState
3335
} from 'react'
3436

3537
import { Alert } from '@instructure/ui-alerts'
@@ -93,6 +95,30 @@ export const AppContext = createContext<AppContextType>({
9395
library: undefined
9496
})
9597

98+
const WrapperComponent = (props) => {
99+
const [isSmallScreen, setIsSmallScreen] = useState(false)
100+
101+
const SmallScreen = () => <h1>Small screen</h1>
102+
const BigScreen = () => <h1>Big screen</h1>
103+
104+
useEffect(() => {
105+
const handleResize = () => {
106+
setIsSmallScreen(window.innerWidth <= 768)
107+
}
108+
109+
// Check on component mount
110+
handleResize()
111+
112+
// Add event listener for window resize
113+
window.addEventListener('resize', handleResize)
114+
115+
// Cleanup listener on component unmount
116+
return () => window.removeEventListener('resize', handleResize)
117+
}, [])
118+
119+
return <>{isSmallScreen ? <SmallScreen /> : <BigScreen />}</>
120+
}
121+
96122
@withStyle(generateStyle, generateComponentTheme)
97123
class App extends Component<AppProps, AppState> {
98124
static propTypes = propTypes
@@ -769,6 +795,7 @@ class App extends Component<AppProps, AppState> {
769795
boxSizing: 'border-box'
770796
}}
771797
>
798+
<WrapperComponent />
772799
<MobileTopNav brand={brandSvg} lightMode={this.state.lightMode}>
773800
<MobileTopNav.BtnRow>
774801
<IconButton
@@ -789,7 +816,11 @@ class App extends Component<AppProps, AppState> {
789816
</IconButton>
790817
</MobileTopNav.BtnRow>
791818
<MobileTopNav.BreadCrumb>
792-
<Link href="#" isWithinText={false} color={this.state.lightMode ? 'link' : 'link-inverse'}>
819+
<Link
820+
href="#"
821+
isWithinText={false}
822+
color={this.state.lightMode ? 'link' : 'link-inverse'}
823+
>
793824
<div
794825
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
795826
>

0 commit comments

Comments
 (0)