Repository navigation
Expand file tree
/
Copy path_ConditionalIcons.svelte
More file actions
95 lines (88 loc) · 2.4 KB
/
Copy path_ConditionalIcons.svelte
File metadata and controls
95 lines (88 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!--
Icons are normally discovered through their snippet, but Svelte snippets
cannot be conditional, so you can use a fragment with a conditional icon
inside and pass the `withLeadingIcon` or `withTrailingIcon` props to use
conditional icons.
-->
<div class="columns margins">
<div>
<Textfield
withLeadingIcon={showLeadingIcons}
withTrailingIcon={showTrailingIcons}
bind:value={valueA}
label="Standard"
>
{#snippet leadingIcon()}
{#if showLeadingIcons}
<Icon class="material-icons">event</Icon>
{/if}
{/snippet}
{#snippet trailingIcon()}
{#if showTrailingIcons}
<Icon class="material-icons">delete</Icon>
{/if}
{/snippet}
</Textfield>
<pre class="status">Value: {valueA}</pre>
</div>
<div>
<Textfield
withLeadingIcon={showLeadingIcons}
withTrailingIcon={showTrailingIcons}
variant="filled"
bind:value={valueB}
label="Filled"
>
{#snippet leadingIcon()}
{#if showLeadingIcons}
<Icon class="material-icons">event</Icon>
{/if}
{/snippet}
{#snippet trailingIcon()}
{#if showTrailingIcons}
<Icon class="material-icons">delete</Icon>
{/if}
{/snippet}
</Textfield>
<pre class="status">Value: {valueB}</pre>
</div>
<div>
<Textfield
withLeadingIcon={showLeadingIcons}
withTrailingIcon={showTrailingIcons}
variant="outlined"
bind:value={valueC}
label="Outlined"
>
{#snippet leadingIcon()}
{#if showLeadingIcons}
<Icon class="material-icons">event</Icon>
{/if}
{/snippet}
{#snippet trailingIcon()}
{#if showTrailingIcons}
<Icon class="material-icons">delete</Icon>
{/if}
{/snippet}
</Textfield>
<pre class="status">Value: {valueC}</pre>
</div>
</div>
<div>
<Button onclick={() => (showLeadingIcons = !showLeadingIcons)}>
Toggle Leading Icons
</Button>
<Button onclick={() => (showTrailingIcons = !showTrailingIcons)}>
Toggle Trailing Icons
</Button>
</div>
<script lang="ts">
import Textfield from '@smui/textfield';
import Icon from '@smui/textfield/icon';
import Button from '@smui/button';
let valueA = $state('');
let valueB = $state('');
let valueC = $state('');
let showLeadingIcons = $state(true);
let showTrailingIcons = $state(true);
</script>