Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
TGlide committed Mar 11, 2024
1 parent 16797b3 commit c55a72d
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions sites/docs/content/functions/with-element-size.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,15 @@ import { WithElementSizeDemo } from '$lib/components/demos';

```svelte
<script lang="ts">
<script lang="ts">
import { withElementSize } from "withrunes";
let count = $state(0);
let logged = $state("");
let isFirstTime = $state(true);
const logCount = withElementSize(() => {
if (isFirstTime) {
isFirstTime = false;
logged = `You pressed the button ${count} times!`;
} else {
logged = `You pressed the button ${count} times since last time!`;
}
count = 0;
}, 1000);
function ding() {
count++;
logCount();
}
let el: HTMLElement | undefined = $state(undefined);
const size = withElementSize(() => el);
</script>
<div>
<button onclick={ding}>DING DING DING</button>
<p>{logged || "Press the button!"}</p>
<textarea bind:this={el} />
<p>Width: {size.width} Height: {size.height}</p>
</div>
```

0 comments on commit c55a72d

Please sign in to comment.