-
-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy path_Showcase.svelte
More file actions
56 lines (52 loc) · 1.48 KB
/
_Showcase.svelte
File metadata and controls
56 lines (52 loc) · 1.48 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
<div class="margins">
<!--
Note: when you bind to `invalid`, but you only want to
monitor it instead of updating it yourself, you also
should include `updateInvalid`.
-->
<Textfield
type="email"
bind:dirty
bind:invalid
updateInvalid
bind:value
label="To"
style="min-width: 250px;"
input$autocomplete="email"
onfocus={() => (focused = true)}
onblur={() => (focused = false)}
withTrailingIcon={!disabled}
>
<!--
Since this icon is conditional, it needs to be wrapped
in a fragment, and we need to provide withTrailingIcon.
-->
{#snippet trailingIcon()}
{#if !disabled}
<Icon class="material-icons" role="button" onclick={clickHandler}
>send</Icon
>
{/if}
{/snippet}
{#snippet helper()}
<HelperText validationMsg>That's not a valid email address.</HelperText>
{/snippet}
</Textfield>
</div>
<pre
class="status">Focused: {focused}, Dirty: {dirty}, Invalid: {invalid}, Value: {value}</pre>
<script lang="ts">
import Textfield from '@smui/textfield';
import Icon from '@smui/textfield/icon';
import HelperText from '@smui/textfield/helper-text';
let focused = $state(false);
let value: string | null = $state(null);
let dirty = $state(false);
let invalid = $state(false);
const disabled = $derived(focused || !value || !dirty || invalid);
function clickHandler() {
alert(`Sending to ${value}!`);
value = null;
dirty = false;
}
</script>