Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created May 5, 2021 12:25
Show Gist options
  • Save smpnjn/1e1ec5996b08c20e3fa1be7e1ce27792 to your computer and use it in GitHub Desktop.
Save smpnjn/1e1ec5996b08c20e3fa1be7e1ce27792 to your computer and use it in GitHub Desktop.
class Paragraph extends HTMLElement {
constructor() {
super()
// Attach shadow DOM
let shadow = this.attachShadow({mode: 'open'});
// Append our Paragraph
shadow.innerHTML = `
<slot name="paragraph-text"><p>Default Text</p></slot>
<p>Another, unchangeable paragraph</p>
`;
// Add in our CSS
let style = document.createElement('style');
let elCss = style.textContent = `
p {
color: red;
font-size: 1.25rem;
}
`;
// Append our CSS
shadow.appendChild(style);
}
}
customElements.define('alpha-paragraph', Paragraph);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment