Skip to content

Instantly share code, notes, and snippets.

@lipp
Created November 17, 2017 10:02
Show Gist options
  • Save lipp/8722d313d9f97b43196cc1cef6abafa9 to your computer and use it in GitHub Desktop.
Save lipp/8722d313d9f97b43196cc1cef6abafa9 to your computer and use it in GitHub Desktop.
minimal web components test
<!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