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.
150 lines
3.2 KiB
150 lines
3.2 KiB
6 years ago
|
<script>
|
||
|
import { quintOut } from 'svelte/easing';
|
||
6 years ago
|
import { crossfade } from 'svelte/transition';
|
||
6 years ago
|
|
||
6 years ago
|
const [send, receive] = crossfade({
|
||
2 years ago
|
duration: (d) => Math.sqrt(d * 200),
|
||
6 years ago
|
|
||
6 years ago
|
fallback(node, params) {
|
||
|
const style = getComputedStyle(node);
|
||
|
const transform = style.transform === 'none' ? '' : style.transform;
|
||
|
|
||
|
return {
|
||
|
duration: 600,
|
||
|
easing: quintOut,
|
||
2 years ago
|
css: (t) => `
|
||
6 years ago
|
transform: ${transform} scale(${t});
|
||
|
opacity: ${t}
|
||
|
`
|
||
|
};
|
||
|
}
|
||
|
});
|
||
|
|
||
6 years ago
|
let uid = 1;
|
||
|
|
||
6 years ago
|
let todos = [
|
||
6 years ago
|
{ id: uid++, done: false, description: 'write some docs' },
|
||
|
{ id: uid++, done: false, description: 'start writing blog post' },
|
||
2 years ago
|
{ id: uid++, done: true, description: 'buy some milk' },
|
||
6 years ago
|
{ id: uid++, done: false, description: 'mow the lawn' },
|
||
|
{ id: uid++, done: false, description: 'feed the turtle' },
|
||
2 years ago
|
{ id: uid++, done: false, description: 'fix some bugs' }
|
||
6 years ago
|
];
|
||
|
|
||
|
function add(input) {
|
||
|
const todo = {
|
||
|
id: uid++,
|
||
|
done: false,
|
||
|
description: input.value
|
||
|
};
|
||
|
|
||
|
todos = [todo, ...todos];
|
||
|
input.value = '';
|
||
|
}
|
||
|
|
||
|
function remove(todo) {
|
||
2 years ago
|
todos = todos.filter((t) => t !== todo);
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
function mark(todo, done) {
|
||
|
todo.done = done;
|
||
|
remove(todo);
|
||
|
todos = todos.concat(todo);
|
||
6 years ago
|
}
|
||
|
</script>
|
||
|
|
||
2 years ago
|
<div class="board">
|
||
6 years ago
|
<input
|
||
|
placeholder="what needs to be done?"
|
||
2 years ago
|
on:keydown={(e) => e.key === 'Enter' && add(e.target)}
|
||
|
/>
|
||
6 years ago
|
|
||
2 years ago
|
<div class="left">
|
||
6 years ago
|
<h2>todo</h2>
|
||
2 years ago
|
{#each todos.filter((t) => !t.done) as todo (todo.id)}
|
||
6 years ago
|
<label>
|
||
2 years ago
|
<input type="checkbox" on:change={() => mark(todo, true)} />
|
||
6 years ago
|
{todo.description}
|
||
2 years ago
|
<button on:click={() => remove(todo)}>remove</button>
|
||
6 years ago
|
</label>
|
||
|
{/each}
|
||
|
</div>
|
||
|
|
||
2 years ago
|
<div class="right">
|
||
6 years ago
|
<h2>done</h2>
|
||
2 years ago
|
{#each todos.filter((t) => t.done) as todo (todo.id)}
|
||
6 years ago
|
<label class="done">
|
||
2 years ago
|
<input type="checkbox" checked on:change={() => mark(todo, false)} />
|
||
6 years ago
|
{todo.description}
|
||
2 years ago
|
<button on:click={() => remove(todo)}>remove</button>
|
||
6 years ago
|
</label>
|
||
|
{/each}
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
6 years ago
|
<style>
|
||
|
.board {
|
||
6 years ago
|
display: grid;
|
||
|
grid-template-columns: 1fr 1fr;
|
||
|
grid-gap: 1em;
|
||
6 years ago
|
max-width: 36em;
|
||
|
margin: 0 auto;
|
||
|
}
|
||
|
|
||
6 years ago
|
.board > input {
|
||
6 years ago
|
font-size: 1.4em;
|
||
|
grid-column: 1/3;
|
||
6 years ago
|
}
|
||
|
|
||
|
h2 {
|
||
|
font-size: 2em;
|
||
|
font-weight: 200;
|
||
|
user-select: none;
|
||
6 years ago
|
margin: 0 0 0.5em 0;
|
||
6 years ago
|
}
|
||
|
|
||
|
label {
|
||
6 years ago
|
position: relative;
|
||
|
line-height: 1.2;
|
||
|
padding: 0.5em 2.5em 0.5em 2em;
|
||
6 years ago
|
margin: 0 0 0.5em 0;
|
||
6 years ago
|
border-radius: 2px;
|
||
|
user-select: none;
|
||
6 years ago
|
border: 1px solid hsl(240, 8%, 70%);
|
||
2 years ago
|
background-color: hsl(240, 8%, 93%);
|
||
6 years ago
|
color: #333;
|
||
6 years ago
|
}
|
||
|
|
||
2 years ago
|
input[type='checkbox'] {
|
||
6 years ago
|
position: absolute;
|
||
|
left: 0.5em;
|
||
|
top: 0.6em;
|
||
|
margin: 0;
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
.done {
|
||
6 years ago
|
border: 1px solid hsl(240, 8%, 90%);
|
||
2 years ago
|
background-color: hsl(240, 8%, 98%);
|
||
6 years ago
|
}
|
||
|
|
||
|
button {
|
||
6 years ago
|
position: absolute;
|
||
|
top: 0;
|
||
|
right: 0.2em;
|
||
|
width: 2em;
|
||
|
height: 100%;
|
||
2 years ago
|
background: no-repeat 50% 50%
|
||
|
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23676778' d='M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M17,7H14.5L13.5,6H10.5L9.5,7H7V9H17V7M9,18H15A1,1 0 0,0 16,17V10H8V17A1,1 0 0,0 9,18Z'%3E%3C/path%3E%3C/svg%3E");
|
||
6 years ago
|
background-size: 1.4em 1.4em;
|
||
6 years ago
|
border: none;
|
||
|
opacity: 0;
|
||
|
transition: opacity 0.2s;
|
||
6 years ago
|
text-indent: -9999px;
|
||
|
cursor: pointer;
|
||
6 years ago
|
}
|
||
|
|
||
|
label:hover button {
|
||
|
opacity: 1;
|
||
|
}
|
||
2 years ago
|
</style>
|