mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
738 B
40 lines
738 B
6 years ago
|
<script>
|
||
|
let todos = [
|
||
|
{ done: false, text: 'finish Svelte tutorial' },
|
||
|
{ done: false, text: 'build an app' },
|
||
|
{ done: false, text: 'world domination' }
|
||
|
];
|
||
|
|
||
|
function add() {
|
||
|
todos = todos.concat({ done: false, text: '' });
|
||
|
}
|
||
|
|
||
|
function clear() {
|
||
1 year ago
|
todos = todos.filter((t) => !t.done);
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
1 year ago
|
$: remaining = todos.filter((t) => !t.done).length;
|
||
6 years ago
|
</script>
|
||
|
|
||
|
<h1>Todos</h1>
|
||
|
|
||
|
{#each todos as todo}
|
||
6 years ago
|
<div class:done={todo.done}>
|
||
1 year ago
|
<input type="checkbox" checked={todo.done} />
|
||
|
|
||
|
<input placeholder="What needs to be done?" value={todo.text} />
|
||
6 years ago
|
</div>
|
||
|
{/each}
|
||
|
|
||
6 years ago
|
<p>{remaining} remaining</p>
|
||
|
|
||
1 year ago
|
<button on:click={add}> Add new </button>
|
||
6 years ago
|
|
||
1 year ago
|
<button on:click={clear}> Clear completed </button>
|
||
4 years ago
|
|
||
|
<style>
|
||
|
.done {
|
||
|
opacity: 0.4;
|
||
|
}
|
||
1 year ago
|
</style>
|