Skip to content

Instantly share code, notes, and snippets.

@rajatk16
Last active April 24, 2019 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajatk16/571c22972cc602050630b3eeb1a34351 to your computer and use it in GitHub Desktop.
Save rajatk16/571c22972cc602050630b3eeb1a34351 to your computer and use it in GitHub Desktop.
const template = document.createElement('template');
template.innerHTML = `
<style>
:host {
display: block;
text-align: center;
}
button {
border: 2px solid blue;
cursor: pointer;
margin: 25px;
}
input {
border: 2px solid black;
margin: 5px;
}
ul {
list-style: none;
padding: 25px;
}
</style>
<h1>My Movie List (2019)</h1>
<div>
<input id="name" type="text" placeholder="Enter movie name"/>
</div>
<div>
<input id="date" type="text" placeholder="Enter release date"/>
</div>
<button>Add</button>
<ul id="movies"></ul>
`;
class MovieList extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({'mode': 'open'});
this._shadowRoot.appendChild(template.content.cloneNode(true));
this.$movieList = this._shadowRoot.querySelector('ul');
}
}
window.customElements.define('movie-list', MovieList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment