Skip to content

Commit 90b8481

Browse files
committed
docs: add demo of toggle icon button using events
Closes #38.
1 parent c6c0574 commit 90b8481

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

site/src/routes/demo/icon-button.svelte

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@
1414
<div style="display: flex; align-items: center;">
1515
<IconButton class="material-icons" on:click={() => clicked++} ripple={false}>add_shopping_cart</IconButton> (no ripple)
1616
</div>
17+
18+
Toggle buttons:
1719
<div style="display: flex; align-items: center;">
1820
<IconButton on:click={() => clicked++} toggle bind:pressed={initialOff}>
1921
<Icon class="material-icons" on>star</Icon>
2022
<Icon class="material-icons">star_border</Icon>
2123
</IconButton>
22-
{initialOff ? '(on)' : '(off)'}
2324
</div>
2425
<div style="display: flex; align-items: center;">
2526
<IconButton on:click={() => clicked++} toggle bind:pressed={initialOn}>
2627
<Icon class="material-icons" on>alarm_on</Icon>
2728
<Icon class="material-icons">alarm_off</Icon>
2829
</IconButton>
29-
{initialOn ? '(on)' : '(off)'}
30-
&nbsp;
3130
<Button on:click={() => initialOn = !initialOn}><Label>Toggle Programmatically</Label></Button>
3231
</div>
32+
<div style="display: flex; align-items: center;">
33+
<IconButton on:click={() => clicked++} on:click={() => usingEvents = !usingEvents} pressed={usingEvents}>
34+
<Icon class="material-icons" on>bookmark</Icon>
35+
<Icon class="material-icons">bookmark_border</Icon>
36+
</IconButton>
37+
(Using events instead of bound variables. Note: don't use&nbsp;<code>toggle</code>&nbsp;prop in this case.)
38+
</div>
3339

3440
<pre class="status">Clicked: {clicked}</pre>
3541
</section>
@@ -41,4 +47,5 @@
4147
let clicked = 0;
4248
let initialOff = false;
4349
let initialOn = true;
50+
let usingEvents = false;
4451
</script>

0 commit comments

Comments
 (0)