Created
November 17, 2017 10:02
-
-
Save lipp/8722d313d9f97b43196cc1cef6abafa9 to your computer and use it in GitHub Desktop.
minimal web components test
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
const template = document.createElement('template') | |
template.innerHTML = ` | |
<style>#foobar {background: red;}</style> | |
<h1 id="foobar">I am foo bar</h1> | |
<slot></slot> | |
` | |
customElements.define('foo-bar', class extends HTMLElement { | |
constructor() { | |
super() | |
this.attachShadow({mode: 'open'}) | |
this.shadowRoot.appendChild(template.content.cloneNode(true)) | |
} | |
}) | |
</script> | |
</head> | |
<body> | |
<foo-bar> | |
<h2>I use the slot tunnel</h2> | |
</foo-bar> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment