-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.vue
executable file
·116 lines (113 loc) · 3.4 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<script>
import TodoMVC from '@microstates/todomvc';
import classnames from 'classnames';
import TodoTextInput from './TodoTextInput';
const pluralize = (word, count) => (count === 1 ? word : `${word}s`);
export default {
functional: true,
props: {
app: {
type: TodoMVC,
required: true,
},
},
render(h, { props: { app } }) {
return (
<div class='todoapp'>
<header class='header'>
<h1>todos</h1>
<TodoTextInput
text={app.newTodo.state}
classes='new-todo'
onSave={app.insertNewTodo}
onBlur={app.insertNewTodo}
onInputChange={app.newTodo.set}
placeholder='What needs to be done?'
/>
</header>
<section class='main'>
{app.hasTodos && (
<span>
<input
id='toggle-all'
class='toggle-all'
type='checkbox'
checked={app.isAllComplete}
onChange={app.toggleAll}
/>
<label for='toggle-all' />
</span>
)}
<ul class='todo-list'>
{[...app.filtered].map(todo => (
<li
class={classnames({
completed: todo.completed.state,
editing: todo.editing.state,
})}
key={todo.id.state}
>
{todo.editing.state ? (
<TodoTextInput
text={todo.text.state}
classes='edit'
onSave={todo.save}
onBlur={todo.save}
onInputChange={todo.text.set}
/>
) : (
<div class='view'>
<input
class='toggle'
type='checkbox'
checked={todo.completed.state}
onChange={todo.completed.toggle}
/>
<label onDblclick={todo.edit}>{todo.text.state}</label>
<button
class='destroy'
onClick={() =>
app.todos.remove(todo)
}
/>
</div>
)}
</li>
))}
</ul>
{app.hasTodos && (
<footer class='footer'>
<span class='todo-count'>
<strong>{app.active.length || 'No'}</strong>{' '}
{pluralize('item', app.active.length)}
</span>
<ul class='filters'>
{app.filters.map(filter => (
<li key={filter.key}>
<button
class={classnames({ selected: filter.selected })}
style={{ cursor: 'pointer' }}
onClick={filter.select}
>
{filter.label}
</button>
</li>
))}
</ul>
{app.hasCompleted && (
<button
class='clear-completed'
onClick={app.clearCompleted}
>
Clear completed
</button>
)}
</footer>
)}
</section>
</div>
);
},
};
</script>
<style src='./styles.css'></style>