Created
May 28, 2018 14:12
-
-
Save kyuwoo-choi/59352c9e7e25fdc35741d08fec77f6a4 to your computer and use it in GitHub Desktop.
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
<!-- add dependencies --> | |
<link rel="import" href="./dependent-element.html"> | |
<!-- web component template --> | |
<template id="nameTagTemplate"> | |
<style> | |
.outer { | |
border: 2px solid brown; | |
background: red; | |
} | |
.name { | |
color: black; | |
} | |
</style> | |
<div class="outer"> | |
<div class="name"> | |
Bob | |
</div> | |
<dependent-element></dependent-element> | |
</div> | |
</template> | |
<!-- web component class --> | |
<script> | |
class NameTag extends HTMLElement { | |
... | |
const shadowRoot = this.attachShadow({mode: 'open'}); | |
const template = document.querySelector('#nameTagTemplate'); | |
const clone = document.importNode(template.content, true); | |
shadowRoot.appendChild(clone); | |
... | |
} | |
customElements.define('name-tag', NameTag); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment