Skip to content

Commit 37785e4

Browse files
committed
fix(playground): improve useRect demo interactivity and update docs
- Make rect-box resizable so width/height values update on drag - Add "Add block above" button to demonstrate top value changes - Update copy from incorrect "scroll to see values" to accurate description - Remove outdated deps parameter from useRect README (removed in v2.0) - Fix setDebounce reference in docs - Add .tldr to gitignore
1 parent 749ffcb commit 37785e4

4 files changed

Lines changed: 61 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
.DS_Store
33
dist
4-
bundled
4+
bundled
5+
.tldr

packages/react/src/use-rect/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ function App() {
3030

3131
The `useRect` hook accepts an options object with the following optional parameters:
3232

33-
- `parameters`: (object) An object containing the following optional parameters:
34-
- `ignoreTransform`: (boolean, default: `false`) If `true`, ignores CSS transform applied to the element and its parents. It's useful for animations such as parallax.
35-
- `ignoreSticky`: (boolean, default: `true`) If `true`, ignores sticky positioning of the element and its parents. See the difference [with](https://jsfiddle.net/Lk74do8u/) and [without](https://jsfiddle.net/3962n0ov/).
36-
- `debounce`: (number, default: `500`) Delay in milliseconds for debouncing measurement updates. Alternatively, you can set the global `useResizeObserver.setDebounce` function to change the default debounce delay.
37-
- `lazy`: (boolean, default: `false`) If `true`, doesn't trigger state update and return a getter instead.
38-
- `callback`: (function) A callback function to be invoked whenever the dimensions or position of the element change.
39-
- `deps`: (array) An array of dependencies.
33+
- `ignoreTransform`: (boolean, default: `false`) If `true`, ignores CSS transform applied to the element and its parents. It's useful for animations such as parallax.
34+
- `ignoreSticky`: (boolean, default: `true`) If `true`, ignores sticky positioning of the element and its parents. See the difference [with](https://jsfiddle.net/Lk74do8u/) and [without](https://jsfiddle.net/3962n0ov/).
35+
- `debounce`: (number, default: `500`) Delay in milliseconds for debouncing measurement updates. Alternatively, you can set the global `useRect.setDebounce` function to change the default debounce delay.
36+
- `lazy`: (boolean, default: `false`) If `true`, doesn't trigger state update and returns a getter instead.
37+
- `callback`: (function) A callback function to be invoked whenever the dimensions or position of the element change.
4038

4139
```jsx
4240
useRect.setDebounce(500)

playground/react/app.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ function ResizeObserverDemo() {
121121
}
122122

123123
function RectDemo() {
124+
const [extraBlocks, setExtraBlocks] = useState(0)
124125
const [setRef, rect] = useRect({
125126
ignoreTransform: false,
126127
ignoreSticky: true,
@@ -129,10 +130,26 @@ function RectDemo() {
129130
return (
130131
<Section title="useRect">
131132
<p className="description">
132-
Track element position and dimensions within the page. Scroll to see
133-
values update.
133+
Track element position and dimensions within the document. Resize the
134+
box or window to see values update.
134135
</p>
135-
<div ref={setRef} className="rect-box">
136+
<div className="button-row">
137+
<button type="button" onClick={() => setExtraBlocks((n) => n + 1)}>
138+
Add block above
139+
</button>
140+
{extraBlocks > 0 && (
141+
<button type="button" onClick={() => setExtraBlocks(0)}>
142+
Reset
143+
</button>
144+
)}
145+
</div>
146+
{Array.from({ length: extraBlocks }).map((_, i) => (
147+
<div key={i} className="extra-block">
148+
Block {i + 1}
149+
</div>
150+
))}
151+
<div ref={setRef} className="rect-box resizable">
152+
<span>Resize me!</span>
136153
<div className="values-grid compact">
137154
<Value
138155
label="top"

playground/react/style.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,40 @@ header p {
158158
border-radius: 8px;
159159
}
160160

161+
.rect-box.resizable {
162+
resize: both;
163+
overflow: auto;
164+
min-height: 120px;
165+
border: 2px dashed var(--color-border);
166+
cursor: se-resize;
167+
transition: border-color 0.15s;
168+
display: flex;
169+
flex-direction: column;
170+
gap: 12px;
171+
}
172+
173+
.rect-box.resizable:hover {
174+
border-color: var(--color-accent);
175+
}
176+
177+
.rect-box.resizable > span {
178+
font-family: monospace;
179+
font-size: 12px;
180+
color: var(--color-muted);
181+
text-align: center;
182+
}
183+
184+
.extra-block {
185+
padding: 16px;
186+
background: rgba(227, 6, 19, 0.1);
187+
border: 1px solid var(--color-accent);
188+
border-radius: 8px;
189+
font-family: monospace;
190+
font-size: 12px;
191+
color: var(--color-accent);
192+
text-align: center;
193+
}
194+
161195
.intersection-spacer {
162196
height: 60vh;
163197
display: flex;

0 commit comments

Comments
 (0)