Skip to content

Instantly share code, notes, and snippets.

@mevius6
Created June 15, 2021 12:41
Show Gist options
  • Select an option

  • Save mevius6/e9871f451370771350eb973e138d7e33 to your computer and use it in GitHub Desktop.

Select an option

Save mevius6/e9871f451370771350eb973e138d7e33 to your computer and use it in GitHub Desktop.
// https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/main/CSSModules/v1Explainer.md
import styles from './html5Element.css';
class HTML5Element extends HTMLElement {
constructor() {
super();
let shadowRoot = this.attachShadow({ mode: "closed" });
this.shadowRoot.adoptedStyleSheets = [styles];
let outerDiv = document.createElement("div");
outerDiv.className = "outerDiv";
let mainImage = document.createElement("img");
mainImage.className = "mainImage";
mainImage.src = "https://www.w3.org/html/logo/downloads/HTML5_Logo_512.png";
let devText = document.createElement("div");
devText.className = "devText";
devText.innerText = "CSS Modules Are Great!";
shadowRoot.appendChild(outerDiv);
outerDiv.appendChild(mainImage);
outerDiv.appendChild(devText);
}
}
window.customElements.define("my-html5-element", HTML5Element);
// CSSModuleExample — https://twitter.com/argyleink/status/1157402358394920960
// Import styles as a stylesheet natively 👇🏻
// import styleSheet from "./styles.css" assert { type: "css" };
// document.AdoptedStyleSheets = [styleSheet];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment