mirror of https://github.com/sveltejs/svelte
parent
c5b401254c
commit
ab84aeef11
@ -1,14 +0,0 @@
|
|||||||
<script>
|
|
||||||
import Square from './Square.svelte';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
svg {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<svg viewBox="0 0 100 100">
|
|
||||||
<Square cx={50} cy={50} size={40} style="fill: #ff3e00"/>
|
|
||||||
</svg>
|
|
@ -1,15 +0,0 @@
|
|||||||
<svelte:options namespace="svg"/>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export let cx;
|
|
||||||
export let cy;
|
|
||||||
export let size;
|
|
||||||
export let style;
|
|
||||||
|
|
||||||
$: x1 = cx - size / 2;
|
|
||||||
$: y1 = cy - size / 2;
|
|
||||||
$: x2 = x1 + size;
|
|
||||||
$: y2 = y1 + size;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<polygon points="{x1},{y1} {x2},{y1} {x2},{y2} {x1},{y2}" {style}/>
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "<svelte:options>"
|
|
||||||
}
|
|
@ -1,13 +1,11 @@
|
|||||||
import { afterUpdate } from 'svelte';
|
export default function flash(element) {
|
||||||
|
element.style.transition = 'none';
|
||||||
export default function flash(fn) {
|
element.style.color = 'rgba(255,62,0,1)';
|
||||||
afterUpdate(() => {
|
element.style.backgroundColor = 'rgba(255,62,0,0.2)';
|
||||||
const span = fn();
|
|
||||||
|
|
||||||
span.style.color = 'red';
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
span.style.color = 'black';
|
element.style.transition = 'color 1s, background 1s';
|
||||||
}, 400);
|
element.style.color = '';
|
||||||
|
element.style.backgroundColor = '';
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -1,14 +1,30 @@
|
|||||||
<script>
|
<script>
|
||||||
import Square from './Square.svelte';
|
import Todo from './Todo.svelte';
|
||||||
</script>
|
|
||||||
|
let todos = [
|
||||||
|
{ id: 1, done: true, text: 'wash the car' },
|
||||||
|
{ id: 2, done: false, text: 'take the dog for a walk' },
|
||||||
|
{ id: 3, done: false, text: 'mow the lawn' }
|
||||||
|
];
|
||||||
|
|
||||||
<style>
|
function toggle(toggled) {
|
||||||
svg {
|
todos = todos.map(todo => {
|
||||||
width: 100%;
|
if (todo === toggled) {
|
||||||
height: 100%;
|
// return a new object
|
||||||
|
return {
|
||||||
|
id: todo.id,
|
||||||
|
text: todo.text,
|
||||||
|
done: !todo.done
|
||||||
|
};
|
||||||
}
|
}
|
||||||
</style>
|
|
||||||
|
|
||||||
<svg viewBox="0 0 100 100">
|
// return the same object
|
||||||
<Square cx={50} cy={50} size={40} style="fill: #ff3e00"/>
|
return todo;
|
||||||
</svg>
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h2>Todos</h2>
|
||||||
|
{#each todos as todo}
|
||||||
|
<Todo {todo} on:click={() => toggle(todo)}/>
|
||||||
|
{/each}
|
@ -1,13 +0,0 @@
|
|||||||
<script>
|
|
||||||
export let cx;
|
|
||||||
export let cy;
|
|
||||||
export let size;
|
|
||||||
export let style;
|
|
||||||
|
|
||||||
$: x1 = cx - size / 2;
|
|
||||||
$: y1 = cy - size / 2;
|
|
||||||
$: x2 = x1 + size;
|
|
||||||
$: y2 = y1 + size;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<polygon points="{x1},{y1} {x2},{y1} {x2},{y2} {x1},{y2}" {style}/>
|
|
@ -0,0 +1,26 @@
|
|||||||
|
<script>
|
||||||
|
import { afterUpdate } from 'svelte';
|
||||||
|
import flash from './flash.js';
|
||||||
|
|
||||||
|
export let todo;
|
||||||
|
export let toggle;
|
||||||
|
|
||||||
|
let div;
|
||||||
|
|
||||||
|
afterUpdate(() => {
|
||||||
|
flash(div);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div {
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- the text will flash red whenever
|
||||||
|
the `todo` object changes -->
|
||||||
|
<div bind:this={div} on:click>
|
||||||
|
{todo.done ? '👍': ''} {todo.text}
|
||||||
|
</div>
|
@ -0,0 +1,11 @@
|
|||||||
|
export default function flash(element) {
|
||||||
|
element.style.transition = 'none';
|
||||||
|
element.style.color = 'rgba(255,62,0,1)';
|
||||||
|
element.style.backgroundColor = 'rgba(255,62,0,0.2)';
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
element.style.transition = 'color 1s, background 1s';
|
||||||
|
element.style.color = '';
|
||||||
|
element.style.backgroundColor = '';
|
||||||
|
});
|
||||||
|
}
|
@ -1,14 +1,30 @@
|
|||||||
<script>
|
<script>
|
||||||
import Square from './Square.svelte';
|
import Todo from './Todo.svelte';
|
||||||
</script>
|
|
||||||
|
let todos = [
|
||||||
|
{ id: 1, done: true, text: 'wash the car' },
|
||||||
|
{ id: 2, done: false, text: 'take the dog for a walk' },
|
||||||
|
{ id: 3, done: false, text: 'mow the lawn' }
|
||||||
|
];
|
||||||
|
|
||||||
<style>
|
function toggle(toggled) {
|
||||||
svg {
|
todos = todos.map(todo => {
|
||||||
width: 100%;
|
if (todo === toggled) {
|
||||||
height: 100%;
|
// return a new object
|
||||||
|
return {
|
||||||
|
id: todo.id,
|
||||||
|
text: todo.text,
|
||||||
|
done: !todo.done
|
||||||
|
};
|
||||||
}
|
}
|
||||||
</style>
|
|
||||||
|
|
||||||
<svg viewBox="0 0 100 100">
|
// return the same object
|
||||||
<Square cx={50} cy={50} size={40} style="fill: #ff3e00"/>
|
return todo;
|
||||||
</svg>
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h2>Todos</h2>
|
||||||
|
{#each todos as todo}
|
||||||
|
<Todo {todo} on:click={() => toggle(todo)}/>
|
||||||
|
{/each}
|
@ -1,15 +0,0 @@
|
|||||||
<svelte:options namespace="svg"/>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export let cx;
|
|
||||||
export let cy;
|
|
||||||
export let size;
|
|
||||||
export let style;
|
|
||||||
|
|
||||||
$: x1 = cx - size / 2;
|
|
||||||
$: y1 = cy - size / 2;
|
|
||||||
$: x2 = x1 + size;
|
|
||||||
$: y2 = y1 + size;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<polygon points="{x1},{y1} {x2},{y1} {x2},{y2} {x1},{y2}" {style}/>
|
|
@ -0,0 +1,28 @@
|
|||||||
|
<svelte:options immutable={true}/>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { afterUpdate } from 'svelte';
|
||||||
|
import flash from './flash.js';
|
||||||
|
|
||||||
|
export let todo;
|
||||||
|
export let toggle;
|
||||||
|
|
||||||
|
let div;
|
||||||
|
|
||||||
|
afterUpdate(() => {
|
||||||
|
flash(div);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div {
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- the text will flash red whenever
|
||||||
|
the `todo` object changes -->
|
||||||
|
<div bind:this={div} on:click>
|
||||||
|
{todo.done ? '👍': ''} {todo.text}
|
||||||
|
</div>
|
@ -0,0 +1,11 @@
|
|||||||
|
export default function flash(element) {
|
||||||
|
element.style.transition = 'none';
|
||||||
|
element.style.color = 'rgba(255,62,0,1)';
|
||||||
|
element.style.backgroundColor = 'rgba(255,62,0,0.2)';
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
element.style.transition = 'color 1s, background 1s';
|
||||||
|
element.style.color = '';
|
||||||
|
element.style.backgroundColor = '';
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue