| |
| export const validateLayout = () => { |
| const issues = []; |
| |
| |
| const sidebar = document.querySelector('.sidebar'); |
| const mainContainer = document.querySelector('.main-container'); |
| |
| if (sidebar && mainContainer) { |
| const sidebarWidth = sidebar.offsetWidth; |
| const mainContainerMargin = window.getComputedStyle(mainContainer).marginLeft; |
| |
| |
| if (sidebarWidth > 0 && mainContainerMargin) { |
| const marginValue = parseInt(mainContainerMargin); |
| if (Math.abs(sidebarWidth - marginValue) > 10) { |
| issues.push({ |
| type: 'layout', |
| message: `Sidebar width (${sidebarWidth}px) doesn't match main container margin (${marginValue}px)`, |
| severity: 'warning' |
| }); |
| } |
| } |
| } |
| |
| |
| const isMobile = window.innerWidth < 1024; |
| if (isMobile) { |
| const sidebar = document.querySelector('.sidebar'); |
| if (sidebar && sidebar.style.position === 'fixed') { |
| |
| } else { |
| issues.push({ |
| type: 'responsive', |
| message: 'Mobile sidebar should use fixed positioning', |
| severity: 'warning' |
| }); |
| } |
| } |
| |
| |
| const sidebarZIndex = sidebar ? parseInt(window.getComputedStyle(sidebar).zIndex) : 0; |
| const overlayZIndex = document.querySelector('.sidebar-overlay') ? |
| parseInt(window.getComputedStyle(document.querySelector('.sidebar-overlay')).zIndex) : 0; |
| |
| if (sidebarZIndex >= overlayZIndex && overlayZIndex > 0) { |
| issues.push({ |
| type: 'z-index', |
| message: 'Sidebar z-index should be higher than overlay', |
| severity: 'error' |
| }); |
| } |
| |
| return { |
| isValid: issues.length === 0, |
| issues, |
| timestamp: new Date().toISOString() |
| }; |
| }; |
|
|
| |
| export const setupLayoutValidation = () => { |
| let validationTimeout; |
| |
| const validate = () => { |
| clearTimeout(validationTimeout); |
| validationTimeout = setTimeout(() => { |
| const result = validateLayout(); |
| console.log('Layout validation result:', result); |
| |
| |
| window.dispatchEvent(new CustomEvent('layoutValidation', { detail: result })); |
| }, 300); |
| }; |
| |
| |
| validate(); |
| |
| |
| window.addEventListener('resize', validate); |
| |
| |
| document.addEventListener('sidebarToggle', validate); |
| |
| return validate; |
| }; |