mirror of https://github.com/sveltejs/svelte
parent
2aece987c3
commit
1830d57b4c
@ -1,3 +1,3 @@
|
|||||||
<!-- https://github.com/eugenkiss/7guis/wiki#counter -->
|
<!-- https://github.com/eugenkiss/7guis/wiki#counter -->
|
||||||
<input type='number' bind:value='count'>
|
<input type=number bind:value={count}>
|
||||||
<button on:click='set({ count: count + 1 })'>count</button>
|
<button on:click="{() => count += 1}">count</button>
|
@ -1,53 +1,53 @@
|
|||||||
<!-- https://github.com/eugenkiss/7guis/wiki#timer -->
|
<script>
|
||||||
<label>
|
import { onDestroy, onMount } from 'svelte';
|
||||||
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>
|
// [svelte-upgrade suggestion]
|
||||||
|
// manually refactor all references to __this
|
||||||
|
const __this = {};
|
||||||
|
|
||||||
<script>
|
export let elapsed = 0;
|
||||||
export default {
|
export let duration = 5000;
|
||||||
data() {
|
export let start;
|
||||||
return { elapsed: 0, duration: 5000 };
|
|
||||||
},
|
|
||||||
|
|
||||||
oncreate() {
|
onMount(() => {
|
||||||
this.reset();
|
reset();
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
this.frame = requestAnimationFrame(update);
|
__this.frame = requestAnimationFrame(update);
|
||||||
|
|
||||||
const { start, duration } = this.get();
|
|
||||||
const elapsed = window.performance.now() - start;
|
const elapsed = window.performance.now() - start;
|
||||||
|
|
||||||
if (elapsed > duration) return;
|
if (elapsed > duration) return;
|
||||||
|
|
||||||
this.set({ elapsed });
|
elapsed = elapsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
update();
|
update();
|
||||||
},
|
});
|
||||||
|
|
||||||
ondestroy() {
|
onDestroy(() => {
|
||||||
if (this.frame) {
|
if (__this.frame) {
|
||||||
cancelAnimationFrame(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>
|
</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>
|
<label>
|
||||||
<input type='checkbox' bind:group='selected' value='red'>
|
<input type=checkbox bind:group={selected} value="red">
|
||||||
red
|
red
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<input type='checkbox' bind:group='selected' value='green'>
|
<input type=checkbox bind:group={selected} value="green">
|
||||||
green
|
green
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<input type='checkbox' bind:group='selected' value='blue'>
|
<input type=checkbox bind:group={selected} value="blue">
|
||||||
blue
|
blue
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<label>
|
<label>
|
||||||
<input type='radio' bind:group='selected' value='red'>
|
<input type=radio bind:group={selected} value="red">
|
||||||
red
|
red
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<input type='radio' bind:group='selected' value='green'>
|
<input type=radio bind:group={selected} value="green">
|
||||||
green
|
green
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<input type='radio' bind:group='selected' value='blue'>
|
<input type=radio bind:group={selected} value="blue">
|
||||||
blue
|
blue
|
||||||
</label>
|
</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>
|
<p>Hello {name || 'stranger'}!</p>
|
@ -1,17 +1,19 @@
|
|||||||
<!-- the text will flash red whenever
|
<svelte:meta immutable/>
|
||||||
the `todo` object changes -->
|
|
||||||
<span ref:span>{todo.text}</span>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
import { afterRender } from 'svelte';
|
||||||
// try commenting this out
|
|
||||||
immutable: true,
|
export let todo;
|
||||||
|
let span;
|
||||||
|
|
||||||
onupdate({ changed, current, previous }) {
|
afterRender(() => {
|
||||||
this.refs.span.style.color = 'red';
|
span.style.color = 'red';
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.refs.span.style.color = 'black';
|
span.style.color = 'black';
|
||||||
}, 400);
|
}, 400);
|
||||||
}
|
});
|
||||||
};
|
|
||||||
</script>
|
</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>
|
<script>
|
||||||
export default {
|
import { afterRender } from 'svelte';
|
||||||
immutable: false,
|
|
||||||
|
export let todo;
|
||||||
|
let span;
|
||||||
|
|
||||||
onupdate({ changed, current, previous }) {
|
afterRender(() => {
|
||||||
this.refs.span.style.color = 'red';
|
span.style.color = 'red';
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.refs.span.style.color = 'black';
|
span.style.color = 'black';
|
||||||
}, 400);
|
}, 400);
|
||||||
}
|
});
|
||||||
};
|
|
||||||
</script>
|
</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>
|
<script>
|
||||||
import Nested from './Nested.html';
|
import Nested from './Nested.html';
|
||||||
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
Nested
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</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>
|
<script>
|
||||||
import { fade } from 'svelte-transitions';
|
import { fade } from 'svelte-transitions';
|
||||||
|
|
||||||
export default {
|
export let visible;
|
||||||
transitions: { fade }
|
|
||||||
};
|
|
||||||
</script>
|
</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>
|
<script>
|
||||||
import { fly } from 'svelte-transitions';
|
import { fly } from 'svelte-transitions';
|
||||||
|
|
||||||
export default {
|
export let visible;
|
||||||
transitions: { fly }
|
|
||||||
};
|
|
||||||
</script>
|
</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>
|
<script>
|
||||||
import { fade, fly } from 'svelte-transitions';
|
import { fade, fly } from 'svelte-transitions';
|
||||||
|
|
||||||
export default {
|
export let visible;
|
||||||
transitions: { fade, fly }
|
|
||||||
};
|
|
||||||
</script>
|
</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