2021-08-01 21:33:31 +02:00
|
|
|
<script>
|
2021-08-01 22:22:34 +02:00
|
|
|
import {todos} from "$lib/stores/todos.js";
|
|
|
|
let todo_text = "";
|
2021-08-02 07:59:31 +02:00
|
|
|
let todo_type = "active";
|
2021-08-01 23:04:31 +02:00
|
|
|
let filteredTodo = [];
|
2021-08-01 21:33:31 +02:00
|
|
|
let addTodo = () => {
|
|
|
|
if (todo_text.length > 0) {
|
|
|
|
const todo = {
|
|
|
|
text: todo_text,
|
|
|
|
date: Date.now,
|
|
|
|
done: false
|
|
|
|
}
|
2021-08-03 09:43:26 +02:00
|
|
|
todo_text = "";
|
2021-08-01 23:04:31 +02:00
|
|
|
if (todo_type == "done") todo_type = "all";
|
2021-08-01 21:33:31 +02:00
|
|
|
$todos = [todo, ...$todos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let clearTodo = (todo) => {
|
2021-08-01 23:04:31 +02:00
|
|
|
if(todo.done) {
|
2021-08-01 21:33:31 +02:00
|
|
|
$todos = $todos.filter(x => x != todo)
|
2021-08-01 23:04:31 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-08-01 21:33:31 +02:00
|
|
|
todo.done = true;
|
2021-08-01 23:04:31 +02:00
|
|
|
$todos = $todos
|
|
|
|
}
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
2021-08-01 22:22:34 +02:00
|
|
|
let filterTodo = (type) => {
|
2021-08-01 23:04:31 +02:00
|
|
|
todo_type = type;
|
2021-08-01 22:22:34 +02:00
|
|
|
switch (type) {
|
|
|
|
case 'active':
|
|
|
|
filteredTodo = $todos.filter(todo => !todo.done);
|
|
|
|
break;
|
|
|
|
case 'done':
|
|
|
|
filteredTodo = $todos.filter(todo => todo.done);
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
filteredTodo = $todos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-08-01 23:04:31 +02:00
|
|
|
$: {
|
|
|
|
filteredTodo = $todos;
|
|
|
|
filterTodo(todo_type)
|
|
|
|
}
|
2021-08-01 21:33:31 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class = "panel">
|
2021-08-03 13:26:56 +02:00
|
|
|
<h2 class= "title">todo</h2>
|
2021-08-01 22:22:34 +02:00
|
|
|
<hr/>
|
2021-08-03 09:43:26 +02:00
|
|
|
<div class="todo-input">
|
|
|
|
<input class="todo-text" bind:value="{todo_text}" placeholder="title"/>
|
|
|
|
<button on:click="{addTodo}" disabled = {todo_text.length == 0} class = "todo-add {todo_text.length == 0 ? 'disabled' : ''}">add</button>
|
|
|
|
</div>
|
2021-08-01 22:22:34 +02:00
|
|
|
<div class="todo-filter">
|
2021-08-02 07:59:31 +02:00
|
|
|
<button on:click="{() => filterTodo('active')}" class = {todo_type == 'active' ? 'disabled' : ''}>active</button>
|
|
|
|
<button on:click="{() => filterTodo('done')}" class = {todo_type == 'done' ? 'disabled' : ''}>done</button>
|
|
|
|
<button on:click="{() => filterTodo('all')}" class = {todo_type == 'all' ? 'disabled' : ''}>all</button>
|
2021-08-01 21:33:31 +02:00
|
|
|
</div>
|
2021-08-01 22:22:34 +02:00
|
|
|
<ul class = "todo-list">
|
|
|
|
{#each filteredTodo as todo}
|
|
|
|
<li class = "todo {todo.done ? 'done' : ''}">
|
|
|
|
<p>{todo.text}</p>
|
|
|
|
<button on:click="{() => clearTodo(todo)}">{todo.done ? '✗' : '✓'}</button>
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
2021-08-01 21:33:31 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
* {
|
|
|
|
--cream: #FEF9EF;
|
|
|
|
--blue: #227c9d;
|
2021-08-03 13:26:56 +02:00
|
|
|
--blue-disabled: #aabac0;
|
2021-08-03 09:43:26 +02:00
|
|
|
--green: #17C3B2;
|
|
|
|
--yellow: #FFCB77;
|
|
|
|
--red: #FE6D73;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.panel {
|
2021-08-03 13:26:56 +02:00
|
|
|
padding-top: 1rem;
|
|
|
|
padding-bottom: 1rem;
|
2021-08-03 09:43:26 +02:00
|
|
|
background-color: var(--cream);
|
2021-08-03 13:26:56 +02:00
|
|
|
font-size: 1rem;
|
|
|
|
font-family: 'Atkinson Hyperlegible', sans-serif;
|
2021-08-03 09:43:26 +02:00
|
|
|
}
|
|
|
|
@media only screen and (min-width: 500px) {
|
|
|
|
.panel {
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
width: 500px;
|
2021-08-03 13:26:56 +02:00
|
|
|
border: solid var(--cream) 0px;
|
|
|
|
border-radius: 10px;
|
2021-08-03 09:43:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 13:26:56 +02:00
|
|
|
.title {
|
|
|
|
margin-left: 2rem;
|
|
|
|
font-weight: 400;
|
|
|
|
font-size: 3rem;
|
|
|
|
color: var(--yellow);
|
|
|
|
}
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
hr {
|
2021-08-03 13:26:56 +02:00
|
|
|
margin-left: 1rem;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
border: 2px solid var(--yellow);
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
button {
|
|
|
|
padding: 5px;
|
|
|
|
margin: 0px;
|
2021-08-03 09:43:26 +02:00
|
|
|
background-color: var(--blue);
|
|
|
|
border: solid var(--blue) 1px;
|
2021-08-01 21:33:31 +02:00
|
|
|
border-radius: 5px;
|
2021-08-03 13:26:56 +02:00
|
|
|
color: white;
|
|
|
|
font-family: 'Atkinson Hyperlegible', sans-serif;
|
|
|
|
font-size: 1rem;
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
.todo-input {
|
|
|
|
font-size: 0px;
|
2021-08-03 13:26:56 +02:00
|
|
|
margin: 1rem;
|
2021-08-03 09:43:26 +02:00
|
|
|
}
|
|
|
|
.todo-text {
|
2021-08-03 13:26:56 +02:00
|
|
|
padding: 4px;
|
2021-08-03 09:43:26 +02:00
|
|
|
margin: 0px;
|
2021-08-03 10:55:38 +02:00
|
|
|
border: solid white 2px;
|
2021-08-03 09:43:26 +02:00
|
|
|
border-right: 0px;
|
|
|
|
border-radius: 0px;
|
|
|
|
border-bottom-left-radius: 5px;
|
|
|
|
border-top-left-radius: 5px;
|
2021-08-03 13:26:56 +02:00
|
|
|
font-family: 'Atkinson Hyperlegible', sans-serif;
|
|
|
|
font-size: 1rem;
|
2021-08-02 07:59:31 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
.todo-text:focus {
|
|
|
|
outline: none;
|
2021-08-03 10:55:38 +02:00
|
|
|
border-bottom-color: var(--blue);
|
2021-08-02 07:59:31 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
.todo-add {
|
2021-08-03 13:26:56 +02:00
|
|
|
border-bottom-left-radius: 0px;
|
|
|
|
border-top-left-radius: 0px;
|
2021-08-01 22:22:34 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
.disabled {
|
2021-08-03 13:26:56 +02:00
|
|
|
background-color: var(--blue-disabled);
|
|
|
|
border-color: var(--blue-disabled);
|
2021-08-03 09:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
button:active {
|
|
|
|
background-color: var(--yellow);
|
2021-08-03 13:26:56 +02:00
|
|
|
border-color: var(--yellow);
|
2021-08-03 09:43:26 +02:00
|
|
|
color: black;
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
2021-08-03 13:26:56 +02:00
|
|
|
button:active.disabled {
|
|
|
|
background-color: var(--blue-disabled);
|
|
|
|
border-color: var(--blue-disabled);
|
|
|
|
color: white;
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 22:22:34 +02:00
|
|
|
.todo-filter {
|
2021-08-03 13:26:56 +02:00
|
|
|
margin-top: 1rem;
|
2021-08-01 22:22:34 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.todo-filter button {
|
2021-08-03 13:26:56 +02:00
|
|
|
margin-right: 0.5rem;
|
|
|
|
border-bottom-left-radius: 0px;
|
|
|
|
border-bottom-right-radius: 0px;
|
2021-08-01 22:22:34 +02:00
|
|
|
}
|
|
|
|
|
2021-08-02 07:59:44 +02:00
|
|
|
.todo-list {
|
2021-08-03 13:26:56 +02:00
|
|
|
padding: 1rem;
|
|
|
|
padding-bottom: 0.5rem;
|
|
|
|
background-color: var(--blue-disabled);
|
|
|
|
/* list
|
|
|
|
* padding 1.5rem
|
|
|
|
todo
|
|
|
|
* content 1.0rem
|
|
|
|
* padding 1.0rem
|
|
|
|
* marging 0.5rem
|
|
|
|
button
|
|
|
|
* padding 6px
|
|
|
|
* border 6px
|
|
|
|
total
|
|
|
|
(1.5 + 2.5*3)rem (9rem)
|
|
|
|
+ (12*3)px (36px)
|
|
|
|
*/
|
|
|
|
min-height: calc(11.5rem + 48px);
|
|
|
|
|
2021-08-02 07:59:44 +02:00
|
|
|
}
|
2021-08-01 21:33:31 +02:00
|
|
|
|
|
|
|
.todo {
|
2021-08-03 13:26:56 +02:00
|
|
|
padding: 0.5rem;
|
|
|
|
margin-bottom: 0.5rem;
|
2021-08-03 09:43:26 +02:00
|
|
|
background-color: var(--yellow);
|
2021-08-01 21:33:31 +02:00
|
|
|
border-radius: 5px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
2021-08-03 09:43:26 +02:00
|
|
|
.todo.done {
|
2021-08-03 13:26:56 +02:00
|
|
|
background-color: var(--cream);
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.todo button {
|
2021-08-03 13:26:56 +02:00
|
|
|
padding: 3px;
|
2021-08-01 21:33:31 +02:00
|
|
|
margin-left: auto;
|
2021-08-03 09:43:26 +02:00
|
|
|
background-color: var(--green);
|
2021-08-03 13:26:56 +02:00
|
|
|
border: solid 3px var(--green);
|
2021-08-03 09:43:26 +02:00
|
|
|
color: var(--cream)
|
|
|
|
}
|
|
|
|
|
|
|
|
.todo.done button {
|
|
|
|
background-color: var(--red);
|
|
|
|
border-color: var(--red);
|
2021-08-03 13:26:56 +02:00
|
|
|
color: var(--cream);
|
|
|
|
}
|
|
|
|
|
|
|
|
.todo button:active {
|
|
|
|
background-color: var(--yellow);
|
|
|
|
color: black;
|
2021-08-01 21:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|