Skip to content

Instantly share code, notes, and snippets.

@domfarolino
Created December 3, 2016 15:40
Show Gist options
  • Save domfarolino/3cc609b871f534c9a7a6c2575938f30c to your computer and use it in GitHub Desktop.
Save domfarolino/3cc609b871f534c9a7a6c2575938f30c to your computer and use it in GitHub Desktop.
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