Created
June 25, 2023 17:20
-
-
Save malisipi/ea237fecf7e00563a333c26f2048d348 to your computer and use it in GitHub Desktop.
You can use the gist to init your web component.
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
| "use strict"; | |
| // Licensed by MIT License | |
| // You can use the gist to init your web component. | |
| customElements.define('web-component', | |
| class extends HTMLElement { | |
| #root; | |
| constructor() { | |
| super(); | |
| this.attachShadow({mode: "open"}); | |
| this.#root = document.createElement("div"); | |
| this.#root.className = "root"; | |
| this.shadowRoot.append(document.createElement('slot')); | |
| this.shadowRoot.append(this.#root); | |
| let style = document.createElement("style"); | |
| style.textContent = ` | |
| :host { | |
| position: relative; | |
| display: block; | |
| width: 400px; | |
| height: 200px; | |
| background: #222222; | |
| border-radius: 5px; | |
| } | |
| .root { | |
| position: absolute; | |
| top: 0; | |
| bottom: 0; | |
| width: 100%; | |
| height: 100%; | |
| padding: 25px; | |
| box-sizing: border-box; | |
| } | |
| `; | |
| this.shadowRoot.append(style); | |
| } | |
| connectedCallback() {} | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment