mirror of https://github.com/sveltejs/svelte
parent
2aece987c3
commit
1830d57b4c
@ -1,3 +1,3 @@
|
||||
<!-- https://github.com/eugenkiss/7guis/wiki#counter -->
|
||||
<input type='number' bind:value='count'>
|
||||
<button on:click='set({ count: count + 1 })'>count</button>
|
||||
<input type=number bind:value={count}>
|
||||
<button on:click="{() => count += 1}">count</button>
|
@ -1,53 +1,53 @@
|
||||
<!-- https://github.com/eugenkiss/7guis/wiki#timer -->
|
||||
<label>
|
||||
elapsed time:
|
||||
<progress value='{elapsed / duration}'></progress>
|
||||
</label>
|
||||
|
||||
<div>{ ( elapsed / 1000 ).toFixed( 1 ) }s</div>
|
||||
|
||||
<label>
|
||||
duration:
|
||||
<input type='range' bind:value='duration' min='1' max='20000'>
|
||||
</label>
|
||||
<script>
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
|
||||
<button on:click='reset()'>reset</button>
|
||||
// [svelte-upgrade suggestion]
|
||||
// manually refactor all references to __this
|
||||
const __this = {};
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return { elapsed: 0, duration: 5000 };
|
||||
},
|
||||
export let elapsed = 0;
|
||||
export let duration = 5000;
|
||||
export let start;
|
||||
|
||||
oncreate() {
|
||||
this.reset();
|
||||
onMount(() => {
|
||||
reset();
|
||||
|
||||
const update = () => {
|
||||
this.frame = requestAnimationFrame(update);
|
||||
|
||||
const { start, duration } = this.get();
|
||||
__this.frame = requestAnimationFrame(update);
|
||||
const elapsed = window.performance.now() - start;
|
||||
|
||||
if (elapsed > duration) return;
|
||||
|
||||
this.set({ elapsed });
|
||||
elapsed = elapsed;
|
||||
};
|
||||
|
||||
update();
|
||||
},
|
||||
});
|
||||
|
||||
ondestroy() {
|
||||
if (this.frame) {
|
||||
cancelAnimationFrame(this.frame);
|
||||
onDestroy(() => {
|
||||
if (__this.frame) {
|
||||
cancelAnimationFrame(__this.frame);
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
reset() {
|
||||
this.set({
|
||||
start: window.performance.now()
|
||||
});
|
||||
|
||||
// [svelte-upgrade suggestion]
|
||||
// review these functions and remove unnecessary 'export' keywords
|
||||
export function reset() {
|
||||
start = window.performance.now();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<!-- https://github.com/eugenkiss/7guis/wiki#timer -->
|
||||
<label>
|
||||
elapsed time:
|
||||
<progress value='{elapsed / duration}'></progress>
|
||||
</label>
|
||||
|
||||
<div>{ ( elapsed / 1000 ).toFixed( 1 ) }s</div>
|
||||
|
||||
<label>
|
||||
duration:
|
||||
<input type='range' bind:value='duration' min='1' max='20000'>
|
||||
</label>
|
||||
|
||||
<button on:click='{reset}'>reset</button>
|
@ -1,15 +1,15 @@
|
||||
<label>
|
||||
<input type='checkbox' bind:group='selected' value='red'>
|
||||
<input type=checkbox bind:group={selected} value="red">
|
||||
red
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type='checkbox' bind:group='selected' value='green'>
|
||||
<input type=checkbox bind:group={selected} value="green">
|
||||
green
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type='checkbox' bind:group='selected' value='blue'>
|
||||
<input type=checkbox bind:group={selected} value="blue">
|
||||
blue
|
||||
</label>
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
<label>
|
||||
<input type='radio' bind:group='selected' value='red'>
|
||||
<input type=radio bind:group={selected} value="red">
|
||||
red
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type='radio' bind:group='selected' value='green'>
|
||||
<input type=radio bind:group={selected} value="green">
|
||||
green
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type='radio' bind:group='selected' value='blue'>
|
||||
<input type=radio bind:group={selected} value="blue">
|
||||
blue
|
||||
</label>
|
||||
|
||||
<p style='color: {selected};'>selected {selected}</p>
|
||||
<p style="color: {selected};">selected {selected}</p>
|
@ -1,2 +1,2 @@
|
||||
<input bind:value='name' placeholder='enter your name'>
|
||||
<input bind:value={name} placeholder="enter your name">
|
||||
<p>Hello {name || 'stranger'}!</p>
|
@ -1,17 +1,19 @@
|
||||
<!-- the text will flash red whenever
|
||||
the `todo` object changes -->
|
||||
<span ref:span>{todo.text}</span>
|
||||
<svelte:meta immutable/>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
// try commenting this out
|
||||
immutable: true,
|
||||
import { afterRender } from 'svelte';
|
||||
|
||||
export let todo;
|
||||
let span;
|
||||
|
||||
onupdate({ changed, current, previous }) {
|
||||
this.refs.span.style.color = 'red';
|
||||
afterRender(() => {
|
||||
span.style.color = 'red';
|
||||
setTimeout(() => {
|
||||
this.refs.span.style.color = 'black';
|
||||
span.style.color = 'black';
|
||||
}, 400);
|
||||
}
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- the text will flash red whenever
|
||||
the `todo` object changes -->
|
||||
<span ref:span>{todo.text}</span>
|
||||
|
@ -1,14 +1,17 @@
|
||||
<span ref:span>{todo.text}</span>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
immutable: false,
|
||||
import { afterRender } from 'svelte';
|
||||
|
||||
export let todo;
|
||||
let span;
|
||||
|
||||
onupdate({ changed, current, previous }) {
|
||||
this.refs.span.style.color = 'red';
|
||||
afterRender(() => {
|
||||
span.style.color = 'red';
|
||||
setTimeout(() => {
|
||||
this.refs.span.style.color = 'black';
|
||||
span.style.color = 'black';
|
||||
}, 400);
|
||||
}
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- the text will flash red whenever
|
||||
the `todo` object changes -->
|
||||
<span ref:span>{todo.text}</span>
|
||||
|
@ -1,12 +1,6 @@
|
||||
<p>This is a top-level element.</p>
|
||||
<Nested/>
|
||||
|
||||
<script>
|
||||
import Nested from './Nested.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Nested
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<p>This is a top-level element.</p>
|
||||
<Nested/>
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@ -1,13 +1,11 @@
|
||||
<input type='checkbox' bind:checked=visible> visible
|
||||
|
||||
{#if visible}
|
||||
<p transition:fade>fades in and out</p>
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
import { fade } from 'svelte-transitions';
|
||||
|
||||
export default {
|
||||
transitions: { fade }
|
||||
};
|
||||
export let visible;
|
||||
</script>
|
||||
|
||||
<input type=checkbox bind:checked={visible}> visible
|
||||
|
||||
{#if visible}
|
||||
<p transition:fade>fades in and out</p>
|
||||
{/if}
|
@ -1,13 +1,11 @@
|
||||
<input type='checkbox' bind:checked=visible> visible
|
||||
|
||||
{#if visible}
|
||||
<p transition:fly='{y: 200, duration: 1000}'>flies 200 pixels up, slowly</p>
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
import { fly } from 'svelte-transitions';
|
||||
|
||||
export default {
|
||||
transitions: { fly }
|
||||
};
|
||||
export let visible;
|
||||
</script>
|
||||
|
||||
<input type=checkbox bind:checked={visible}> visible
|
||||
|
||||
{#if visible}
|
||||
<p transition:fly="{{y: 200, duration: 1000}}">flies 200 pixels up, slowly</p>
|
||||
{/if}
|
@ -1,13 +1,11 @@
|
||||
<input type='checkbox' bind:checked=visible> visible
|
||||
|
||||
{#if visible}
|
||||
<p in:fly='{y: 50}' out:fade>flies up, fades out</p>
|
||||
{/if}
|
||||
|
||||
<script>
|
||||
import { fade, fly } from 'svelte-transitions';
|
||||
|
||||
export default {
|
||||
transitions: { fade, fly }
|
||||
};
|
||||
export let visible;
|
||||
</script>
|
||||
|
||||
<input type=checkbox bind:checked={visible}> visible
|
||||
|
||||
{#if visible}
|
||||
<p in:fly="{{y: 50}}" out:fade>flies up, fades out</p>
|
||||
{/if}
|
Loading…
Reference in new issue