Files
metabuilder/hooks/useWindowSize.ts
johndoe6345789 5aabff44cd refactor(fakemui): flatten QML components directory structure and update documentation
Directory Restructuring:
- qml/qml-components/qml-components/* → qml/components/ (flattens nesting)
- All 104 QML files moved with git history preserved
- Eliminates redundant qml-components nesting

Documentation Updates:
- ARCHITECTURE.md: Updated qml/components references (2 locations)
- GETTING_STARTED.md: Updated qml/components path (1 location, end of file)
- README.md: Updated qml/components references (3 locations)
- CODE_REVIEW.md: Updated qml/components file paths (4 locations)
- docs/ARCHITECTURE.md: Complete refactor with qml/components paths

Verification:
-  No remaining qml-components/ references in documentation
-  All 104 QML files present in flattened structure
-  Directory structure verified (12 component categories)
-  First-class directory naming convention

Structure Post-Refactor:
qml/
├── components/
│   ├── atoms/ (16 files)
│   ├── core/ (11 files)
│   ├── data-display/ (10 files)
│   ├── feedback/ (11 files)
│   ├── form/ (19 files)
│   ├── lab/ (11 files)
│   ├── layout/ (12 files)
│   ├── navigation/ (12 files)
│   ├── surfaces/ (7 files)
│   ├── theming/ (4 files)
│   └── utils/ (13 files)
├── hybrid/
└── widgets/

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-23 19:54:21 +00:00

73 lines
1.7 KiB
TypeScript

/**
* useWindowSize Hook
* Tracks browser window width and height with automatic resize listener
*
* Features:
* - Real-time window size tracking
* - Automatic cleanup on unmount
* - Memoized resize handler via useCallback
* - Initial size from window object
*
* @example
* const { width, height } = useWindowSize()
*
* return (
* <div>
* Window size: {width} x {height}
* {width < 768 && <MobileLayout />}
* {width >= 768 && <DesktopLayout />}
* </div>
* )
*
* @example
* // With responsive threshold
* const { width, height } = useWindowSize()
* const isMobile = width < 768
* const isTablet = width >= 768 && width < 1024
* const isDesktop = width >= 1024
*/
import { useState, useEffect, useCallback } from 'react'
export interface WindowSize {
/** Current window width in pixels */
width: number
/** Current window height in pixels */
height: number
}
export interface UseWindowSizeReturn extends WindowSize {}
export function useWindowSize(): UseWindowSizeReturn {
const [windowSize, setWindowSize] = useState<WindowSize>({
width: typeof window !== 'undefined' ? window.innerWidth : 0,
height: typeof window !== 'undefined' ? window.innerHeight : 0,
})
// Memoized resize handler
const handleResize = useCallback(() => {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
})
}, [])
useEffect(() => {
// Set initial size from window
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
})
// Add resize listener
window.addEventListener('resize', handleResize)
// Cleanup on unmount
return () => {
window.removeEventListener('resize', handleResize)
}
}, [handleResize])
return windowSize
}