Created
January 6, 2017 10:57
-
-
Save bendc/d32ad6f9afd55f16f99e869c832183e7 to your computer and use it in GitHub Desktop.
Web Components: todo-list-basic
This file contains hidden or 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
const state = ["Buy milk", "Call Sarah", "Pay bills"]; | |
customElements.define("todo-item", class extends HTMLElement { | |
constructor() { | |
super(); | |
const root = this.attachShadow({mode: "open"}); | |
root.innerHTML = ` | |
<label> | |
<input type=checkbox> | |
<slot></slot> | |
</label> | |
`; | |
} | |
}); | |
customElements.define("todo-list", class extends HTMLElement { | |
constructor() { | |
super(); | |
const root = this.attachShadow({mode: "open"}); | |
root.innerHTML = ` | |
<ul> | |
${state.map(todo => ` | |
<li> | |
<todo-item>${todo}</todo-item> | |
</li> | |
`).join("")} | |
</ul> | |
`; | |
} | |
}); | |
document.body.innerHTML = "<todo-list></todo-list>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment