-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.svelte
65 lines (57 loc) · 1.02 KB
/
example.svelte
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
<script>
let firstName = 'Alon';
let lastName = 'Kolyakov';
let color = 'blue';
let showText = false;
let users = [
{
id: '1',
name : 'John'
},
{
id: '2',
name : 'Mary'
},
{
id: '3',
name : 'Alon'
},
]
$: name = firstName + ' ' + lastName;
const toggle = () => {
color = color === 'blue' ? 'red' : 'blue'
showText = !showText
users = [...users, {id: 4, name: 'Jen'}] // Spread operator
}
</script>
<main>
<h1 style="color: {color}">Hello {name}!</h1>
{#if showText}
<p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p>
{:else}
<p>No text</p>
{/if}
<button on:click={toggle}>Click</button>
{#each users as user (user.id)}
<h3>{user.id}: {user.name}</h3>
{/each}
</main>
<style>
main {
text-align: center;
padding: 1em;
max-width: 240px;
margin: 0 auto;
}
h1 {
color: #ff3e00;
text-transform: uppercase;
font-size: 4em;
font-weight: 100;
}
@media (min-width: 640px) {
main {
max-width: none;
}
}
</style>