react-boxmodel-inspector 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -0
- package/dist/react-boxmodel-inspector.es.js +737 -0
- package/dist/react-boxmodel-inspector.es.js.map +1 -0
- package/dist/react-boxmodel-inspector.umd.js +738 -0
- package/dist/react-boxmodel-inspector.umd.js.map +1 -0
- package/package.json +54 -0
- package/src/BoxModel.jsx +743 -0
- package/src/index.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# react-boxmodel-inspector
|
|
2
|
+
|
|
3
|
+
A zero-dependency React developer tool that wraps any element and visually debugs its CSS box model — margin, border, padding, and content — with live overlays and a draggable floating panel.
|
|
4
|
+
|
|
5
|
+
> ⚠️ This is a **developer tool**. Don't ship it to production.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🔍 **Long-press any element** to inspect it
|
|
12
|
+
- 📦 **Live layered overlays** — dashed rectangles for margin (orange), padding (green), and content (purple), each with pixel edge labels
|
|
13
|
+
- 🪟 **Draggable floating panel** showing T·R·B·L values for margin, border, padding, and content size
|
|
14
|
+
- 🔄 **Live updates** via `ResizeObserver`, `MutationObserver`, and scroll/resize listeners
|
|
15
|
+
- ⌨️ **Keyboard shortcuts** — press backtick (`` ` ``) to toggle, `ESC` to close
|
|
16
|
+
- ⚡ **Zero overhead when disabled** — renders only `children` when not in use
|
|
17
|
+
- 🎨 **Expandable CSS property groups** — typography, layout, flex/grid, color, transform, and more
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install react-boxmodel-inspector
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Basic Usage
|
|
30
|
+
|
|
31
|
+
Wrap your app (or any subtree) with `BoxModelInspector`:
|
|
32
|
+
|
|
33
|
+
```jsx
|
|
34
|
+
import BoxModelInspector from 'react-boxmodel-inspector';
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
return (
|
|
38
|
+
<BoxModelInspector>
|
|
39
|
+
<YourApp />
|
|
40
|
+
</BoxModelInspector>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then in the browser:
|
|
46
|
+
- Press `` ` `` (backtick) to activate the inspector
|
|
47
|
+
- **Long-press** any element to inspect it
|
|
48
|
+
- Press `ESC` or click `✕` to close the panel
|
|
49
|
+
- **Drag** the panel anywhere
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Props
|
|
54
|
+
|
|
55
|
+
| Prop | Type | Default | Description |
|
|
56
|
+
|------|------|---------|-------------|
|
|
57
|
+
| `children` | `ReactNode` | — | The component tree to wrap |
|
|
58
|
+
| `longPressDuration` | `number` | `500` | How long (ms) to hold before inspection triggers |
|
|
59
|
+
| `toggleKey` | `string` | `` "`" `` | Key to toggle the inspector on/off |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Usage with entry point (main.jsx / index.jsx)
|
|
64
|
+
|
|
65
|
+
```jsx
|
|
66
|
+
import { StrictMode } from 'react';
|
|
67
|
+
import { createRoot } from 'react-dom/client';
|
|
68
|
+
import App from './App.jsx';
|
|
69
|
+
import BoxModelInspector from 'react-boxmodel-inspector';
|
|
70
|
+
|
|
71
|
+
createRoot(document.getElementById('root')).render(
|
|
72
|
+
<StrictMode>
|
|
73
|
+
<BoxModelInspector>
|
|
74
|
+
<App />
|
|
75
|
+
</BoxModelInspector>
|
|
76
|
+
</StrictMode>
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Custom toggle key and duration
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
<BoxModelInspector toggleKey="F2" longPressDuration={300}>
|
|
86
|
+
<App />
|
|
87
|
+
</BoxModelInspector>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## How it works
|
|
93
|
+
|
|
94
|
+
1. Press the toggle key to activate inspector mode — a blue banner appears at the top of the screen.
|
|
95
|
+
2. Long-press any element in the page. A circular ripple indicates the progress.
|
|
96
|
+
3. On trigger, three dashed overlays appear directly on the element:
|
|
97
|
+
- **Orange** — margin box with T/R/B/L labels
|
|
98
|
+
- **Green** — padding box with T/R/B/L labels
|
|
99
|
+
- **Purple** — content box with width × height
|
|
100
|
+
4. A dark floating panel also appears to the right, showing numeric T·R·B·L values for margin, border, padding, and content size.
|
|
101
|
+
5. Expand "All properties" in the panel to see grouped CSS values (typography, layout, flex, color, etc).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Requirements
|
|
106
|
+
|
|
107
|
+
- React **17+** or **18+**
|
|
108
|
+
- Works in any browser with `ResizeObserver` and `MutationObserver` support (all modern browsers)
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|