media-query-debugger
Version:
Advanced responsive debugger and responsive design testing tool with device mockups, media query monitoring, and debugging features for React applications
217 lines (169 loc) • 5.05 kB
Markdown
[](https://badge.fury.io/js/media-query-debugger)
[](https://opensource.org/licenses/MIT)
Advanced media query debugger and responsive design testing tool for React applications. Features device mockups, real-time media query monitoring, and comprehensive debugging tools.
- 🔍 **Real-time Media Query Detection** - Live monitoring of active breakpoints and media queries
- 📱 **Device Mockups** - Realistic device frames with live site rendering
- 🎯 **Visual Debugging Tools** - Grid overlays, rulers, and measurement tools
- ⚡ **Performance Optimized** - Lightweight with minimal bundle impact
- 🎨 **Customizable** - Configurable breakpoints, devices, and themes
- ⌨️ **Keyboard Shortcuts** - Quick access with customizable hotkeys
- 🌙 **Dark/Light Theme** - Built-in theme support
- 📦 **TypeScript Ready** - Full TypeScript support with type definitions
```bash
npm install media-query-debugger
yarn add media-query-debugger
pnpm add media-query-debugger
```
```tsx
import { MediaQueryDebugger } from 'media-query-debugger'
import 'media-query-debugger/styles'
function App() {
return (
<div>
{/* Your app content */}
<MediaQueryDebugger />
</div>
)
}
```
```tsx
import { MediaQueryDebugger } from 'media-query-debugger'
const customBreakpoints = {
mobile: 480,
tablet: 768,
desktop: 1024,
wide: 1440,
}
function App() {
return (
<div>
<MediaQueryDebugger
breakpoints={customBreakpoints}
position="top-right"
theme="dark"
defaultOpen={false}
onBreakpointChange={(breakpoint) => {
console.log('Current breakpoint:', breakpoint)
}}
enableKeyboardShortcuts={true}
/>
</div>
)
}
```
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `breakpoints` | `BreakpointConfig` | Tailwind defaults | Custom breakpoint configuration |
| `devices` | `Device[]` | Built-in devices | Custom device presets |
| `position` | `'top-left' \| 'top-right' \| 'bottom-left' \| 'bottom-right'` | `'bottom-right'` | Debugger position |
| `theme` | `'light' \| 'dark' \| 'auto'` | `'dark'` | Theme configuration |
| `defaultOpen` | `boolean` | `false` | Whether to show debugger by default |
| `onBreakpointChange` | `(breakpoint: string) => void` | - | Callback when breakpoint changes |
| `onViewportChange` | `(viewport: ViewportInfo) => void` | - | Callback when viewport changes |
| `enableKeyboardShortcuts` | `boolean` | `true` | Enable keyboard shortcuts |
```tsx
import { useMediaQuery } from 'media-query-debugger'
function MyComponent() {
const isMobile = useMediaQuery('(max-width: 768px)')
return (
<div>
{isMobile ? 'Mobile View' : 'Desktop View'}
</div>
)
}
```
```tsx
import { useViewport } from 'media-query-debugger'
function MyComponent() {
const viewport = useViewport()
return (
<div>
Current size: {viewport.width} × {viewport.height}
</div>
)
}
```
```tsx
import { useBreakpoint } from 'media-query-debugger'
function MyComponent() {
const { current, isAbove, isBelow } = useBreakpoint()
return (
<div>
<p>Current: {current}</p>
<p>Above md: {isAbove('md') ? 'Yes' : 'No'}</p>
<p>Below lg: {isBelow('lg') ? 'Yes' : 'No'}</p>
</div>
)
}
```
The package includes default styles that work with Tailwind CSS. Import the styles in your main CSS file or component:
```css
@import 'media-query-debugger/styles';
```
You can override the default styles by targeting the component classes:
```css
.media-query-debugger {
/* Custom styles */
}
```
| Shortcut | Action |
|----------|--------|
| `Cmd/Ctrl + Shift + D` | Toggle debugger |
| `Escape` | Close debugger |
```tsx
const customDevices = [
{
name: 'Custom Mobile',
width: 375,
height: 812,
category: 'mobile' as const,
pixelRatio: 3,
userAgent: 'Custom',
},
// ... more devices
]
<MediaQueryDebugger devices={customDevices} />
```
```tsx
// With Chakra UI
import { ChakraProvider } from '@chakra-ui'
import { MediaQueryDebugger } from 'media-query-debugger'
function App() {
return (
<ChakraProvider>
<YourApp />
<MediaQueryDebugger
breakpoints={{
base: 0,
sm: 480,
md: 768,
lg: 992,
xl: 1280,
}}
/>
</ChakraProvider>
)
}
```
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.