Created
September 8, 2020 15:57
-
-
Save perjo927/0105f7b6f34bae995d036ae8644e392d to your computer and use it in GitHub Desktop.
TodoList template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { html } from "lit-html"; | |
const Todo = ({ onToggleClick, onDeleteClick, text, done }) => { | |
const toggleClass = "todo toggle"; | |
const deleteClass = "todo delete"; | |
const textClass = `todo text ${done ? " done" : ""}`; | |
const checkMark = done ? "✔" : ""; | |
return html` | |
<li> | |
<div class=${toggleClass} @click=${onToggleClick}>${checkMark}</div> | |
<div class=${textClass}>${text}</div> | |
<div class=${deleteClass} @click=${onDeleteClick}>X</div> | |
</li> | |
`; | |
}; | |
export const TodoList = ({ todos, toggleTodo, deleteTodo }) => html` | |
<ul> | |
${todos.map(({ id, text, done }) => | |
Todo({ | |
onToggleClick: () => toggleTodo(id), | |
onDeleteClick: () => deleteTodo(id), | |
text, | |
done, | |
}) | |
)} | |
</ul> | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment