This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
forked from sveltejs/svelte-atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svelte-syntax-test.svelte
267 lines (231 loc) · 6.08 KB
/
svelte-syntax-test.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!--
These are copy and pasted examples from: https://svelte.dev/docs
⚠️ The code doesn't work and it's not supposed to work. It's only for checking
if the ../grammar/svelte.json works.
-->
<script context="module">
const one = "two";
</script>
<script>
const three = "four";
</script>
<style>
.test-css-class {
border: 1px solid red;
}
</style>
<!-- Tags -->
<div class="test-css-class">ok!</div>
<!-- Attributes and props -->
<div class="foo">
<button disabled>can't touch this</button>
</div>
<input type=checkbox>
<a href="page/{p}">page {p}</a>
<button disabled={!clickable}>button text</button>
<button disabled="{number !== 42}">...</button>
<button disabled={disabled}>...</button>
<button {disabled}>...</button>
<Widget foo={bar} answer={42} text="hello"/>
<Widget {...things}/>
<Widget {...$$props}/>
<!-- Text expressions -->
<h1>Hello {name}!</h1>
<p>{a} + {b} = {a + b}.</p>
<!-- Comments -->
<!-- svelte-ignore a11y-autofocus -->
<input bind:value={name} autofocus>
<!-- {#if ...} -->
{#if answer === 42}
<p>what was the question?</p>
{/if}
{#if porridge.temperature > 100}
<p>too hot!</p>
{:else if 80 > porridge.temperature}
<p>too cold!</p>
{:else}
<p>just right!</p>
{/if}
<!-- {#each ...} -->
<h1>Shopping list</h1>
<ul>
{#each items as item}
<li>{item.name} x {item.qty}</li>
{/each}
</ul>
{#each items as item, i}
<li>{i + 1}: {item.name} x {item.qty}</li>
{/each}
{#each items as item, i (item.id)}
<li>{i + 1}: {item.name} x {item.qty}</li>
{/each}
{#each items as { id, name, qty }, i (id)}
<li>{i + 1}: {name} x {qty}</li>
{/each}
{#each objects as { id, ...rest }}
<li><span>{id}</span><MyComponent {...rest}/></li>
{/each}
{#each items as [id, ...rest]}
<li><span>{id}</span><MyComponent values={rest}/></li>
{/each}
{#each todos as todo}
<p>{todo.text}</p>
{:else}
<p>No tasks today!</p>
{/each}
<!-- {#await ...} -->
{#await promise}
<!-- promise is pending -->
<p>waiting for the promise to resolve...</p>
{:then value}
<!-- promise was fulfilled -->
<p>The value is {value}</p>
{:catch error}
<!-- promise was rejected -->
<p>Something went wrong: {error.message}</p>
{/await}
{#await promise}
<!-- promise is pending -->
<p>waiting for the promise to resolve...</p>
{:then value}
<!-- promise was fulfilled -->
<p>The value is {value}</p>
{/await}
{#await promise then value}
<p>The value is {value}</p>
{/await}
<!-- {@html ...} -->
<div class="blog-post">
<h1>{post.title}</h1>
{@html post.content}
</div>
<!-- {@debug ...} -->
{@debug user}
{@debug user1, user2, user3}
{@debug user.firstname}
{@debug myArray[0]}
{@debug !isReady}
{@debug typeof user === 'object'}
<!-- Element directives -->
<button on:click={handleClick}>
count: {count}
</button>
<button on:click="{() => count += 1}">
count: {count}
</button>
<form on:submit|preventDefault={handleSubmit}>
<!-- the `submit` event's default is prevented,
so the page won't reload -->
</form>
<button on:click>
The component itself will emit the click event
</button>
<button on:click={increment} on:click={track}>Click me!</button>
<!-- bind:property -->
<input bind:value={name}>
<textarea bind:value={text}></textarea>
<input type="checkbox" bind:checked={yes}>
<input bind:value={value}>
<input bind:value>
<input type="number" bind:value={num}>
<input type="range" bind:value={num}>
<select bind:value={selected}>
<option value={a}>a</option>
<option value={b}>b</option>
<option value={c}>c</option>
</select>
<select multiple bind:value={fillings}>
<option value="Rice">Rice</option>
<option value="Beans">Beans</option>
<option value="Cheese">Cheese</option>
<option value="Guac (extra)">Guac (extra)</option>
</select>
<video
src={clip}
bind:duration
bind:buffered
bind:seekable
bind:seeking
bind:played
bind:ended
bind:currentTime
bind:paused
bind:volume
bind:videoWidth
bind:videoHeight
></video>
<!-- bind:group -->
<input type="radio" bind:group={tortilla} value="Plain">
<input type="radio" bind:group={tortilla} value="Whole wheat">
<input type="radio" bind:group={tortilla} value="Spinach">
<input type="checkbox" bind:group={fillings} value="Rice">
<input type="checkbox" bind:group={fillings} value="Beans">
<input type="checkbox" bind:group={fillings} value="Cheese">
<input type="checkbox" bind:group={fillings} value="Guac (extra)">
<!-- bind:this -->
<canvas bind:this={canvasElement}></canvas>
<!-- class:name -->
<div class="{active ? 'active' : ''}">...</div>
<div class:active={active}>...</div>
<div class:active>...</div>
<div class:active class:inactive={!active} class:isAdmin>...</div>
<!-- use:action -->
<div use:foo></div>
<div use:foo={bar}></div>
<!-- transition:fn -->
<div transition:fade>fades in and out</div>
<div transition:fade="{{ duration: 2000 }}">
flies in, fades out over two seconds
</div>
<div in:whoosh>whooshes in</div>
<p in:typewriter="{{ speed: 20 }}">
The quick brown fox jumps over the lazy dog
</p>
<p
transition:fly="{{ y: 200, duration: 2000 }}"
on:introstart="{() => status = 'intro started'}"
on:outrostart="{() => status = 'outro started'}"
on:introend="{() => status = 'intro ended'}"
on:outroend="{() => status = 'outro ended'}"
>
Flies in and out
</p>
<!-- in:fn/out:fn -->
<div in:fly out:fade>flies in, fades out</div>
<!-- animate:fn -->
<li animate:flip>{item}</li>
<li animate:flip="{{ delay: 500 }}">{item}</li>
<div animate:whizz>{item}</div>
<!-- <slot> -->
<slot/>
<slot></slot>
<slot name="header"></slot>
<slot name="footer"></slot>
<FancyList {items} let:item={item}>
<div>{item.text}</div>
</FancyList>
<ul>
{#each items as item}
<li class="fancy">
<slot item={item}></slot>
</li>
{/each}
</ul>
<!-- <svelte:self> -->
<svelte:self count="{count - 1}"/>
<!-- <svelte:component> -->
<svelte:component this={currentSelection.component} foo={bar}/>
<!-- <svelte:window> -->
<svelte:window on:keydown={handleKeydown}/>
<svelte:window bind:scrollY={y}/>
<!-- <svelte:body> -->
<svelte:body
on:mouseenter={handleMouseenter}
on:mouseleave={handleMouseleave}
/>
<!-- <svelte:head> -->
<svelte:head>
<link rel="stylesheet" href="tutorial/dark-theme.css">
</svelte:head>
<!-- <svelte:options> -->
<svelte:options tag="my-custom-element"/>