Created
December 3, 2016 15:40
-
-
Save domfarolino/3cc609b871f534c9a7a6c2575938f30c 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
class CoolCard extends HTMLElement { | |
constructor() { | |
// MUST to allow HTMLElement interface to set | |
// itself up so we can take advantage of it | |
super(); | |
} | |
connectedCallback() { | |
// Every time a cool-card gets inserted into a | |
// document this asynchronous callback gets called | |
const shadow = this.attachShadow({mode: 'open'}); | |
shadow.innerHTML = ` | |
<style> | |
div.card { | |
width: 100%; | |
max-width: 300px; | |
display: inline-block; | |
box-shadow: 0px 1px 3px rgba(0, 0, 0, .6); | |
margin: 10px; | |
padding: 10px; | |
background: white; | |
} | |
</style> | |
<div class="card"> | |
<h2>CoolCard Title</h2> | |
</div> | |
`; | |
} | |
} | |
// Tell the browser about our 'cool-card' custom element | |
customElements.define('cool-card', CoolCard); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment