You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Responsive design utilities for media query matching and user preferences.
Quick Start
import{MediaQuery}from'@zappzarapp/browser-utils/media';// Check media queryif(MediaQuery.matches('(min-width: 768px)')){// Desktop layout}// Dark mode detectionif(MediaQuery.prefersDarkMode()){applyDarkTheme();}// Listen for changesconstcleanup=MediaQuery.onDarkModeChange((isDark)=>{updateTheme(isDark ? 'dark' : 'light');});
API Reference
Core API
Method
Returns
Description
matches(query)
boolean
Check if media query matches
onChange(query, handler)
CleanupFn
Listen for media query changes
User Preferences
Method
Returns
Description
prefersDarkMode()
boolean
Check if user prefers dark color scheme
prefersLightMode()
boolean
Check if user prefers light color scheme
prefersReducedMotion()
boolean
Check if user prefers reduced motion
prefersReducedTransparency()
boolean
Check if user prefers reduced transparency
prefersHighContrast()
boolean
Check if user prefers high contrast
onDarkModeChange(handler)
CleanupFn
Listen for dark mode changes
onReducedMotionChange(handler)
CleanupFn
Listen for reduced motion changes
Device Type
Method
Returns
Description
isMobile()
boolean
Check if device appears to be mobile
isTablet()
boolean
Check if device appears to be tablet
isDesktop()
boolean
Check if device appears to be desktop
isPortrait()
boolean
Check if screen is in portrait orientation
isLandscape()
boolean
Check if screen is in landscape orientation
Breakpoints
Method
Returns
Description
breakpoint(breakpoints?)
Breakpoint
Get current breakpoint name
isAtLeast(breakpoint, breakpoints?)
boolean
Check if width is at or above breakpoint
isBelow(breakpoint, breakpoints?)
boolean
Check if width is below breakpoint
onBreakpointChange(handler, breakpoints?)
CleanupFn
Listen for breakpoint changes
Display Features
Method
Returns
Description
hasHover()
boolean
Check if device supports hover
hasCoarsePointer()
boolean
Check if device has coarse pointer (touch)
hasFinePointer()
boolean
Check if device has fine pointer (mouse)
isStandalone()
boolean
Check if app is in standalone mode (PWA)
Types
typeBreakpoint='xs'|'sm'|'md'|'lg'|'xl'|'2xl';
Default Breakpoints
Breakpoint
Min Width
xs
0px
sm
640px
md
768px
lg
1024px
xl
1280px
2xl
1536px
Usage Examples
Responsive Component
functionResponsiveLayout(): void{constbreakpoint=MediaQuery.breakpoint();if(MediaQuery.isMobile()){renderMobileLayout();}elseif(MediaQuery.isTablet()){renderTabletLayout();}else{renderDesktopLayout();}}// React to breakpoint changesconstcleanup=MediaQuery.onBreakpointChange((bp)=>{console.log(`Breakpoint changed to: ${bp}`);ResponsiveLayout();});
Dark Mode Support
functioninitTheme(): void{// Set initial themeconstisDark=MediaQuery.prefersDarkMode();document.documentElement.dataset.theme=isDark ? 'dark' : 'light';// Listen for system changesMediaQuery.onDarkModeChange((isDark)=>{document.documentElement.dataset.theme=isDark ? 'dark' : 'light';});}
Reduced Motion Support
functionanimate(element: HTMLElement): void{if(MediaQuery.prefersReducedMotion()){// Skip animation, apply final stateelement.style.opacity='1';return;}// Full animationelement.animate([{opacity: 0},{opacity: 1}],{duration: 300,easing: 'ease-out',});}// Listen for preference changesMediaQuery.onReducedMotionChange((prefersReduced)=>{if(prefersReduced){pauseAllAnimations();}else{resumeAnimations();}});
functioninitApp(): void{if(MediaQuery.isStandalone()){// Running as installed PWAhideInstallPrompt();enableOfflineFeatures();}else{// Running in browsershowInstallPrompt();}}
Orientation-Based Layout
functionupdateLayout(): void{if(MediaQuery.isPortrait()){enableVerticalLayout();}else{enableHorizontalLayout();}}// Listen for orientation changes via resizeconstcleanup=MediaQuery.onChange('(orientation: portrait)',(isPortrait)=>{updateLayout();});
Accessibility Considerations
Reduced Motion - Always check prefersReducedMotion() before animations
High Contrast - Respect prefersHighContrast() for better visibility
Color Scheme - Support both light and dark modes
Touch Targets - Use hasCoarsePointer() to size interactive elements
appropriately