Created
June 15, 2021 12:41
-
-
Save mevius6/e9871f451370771350eb973e138d7e33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 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