Skip to content

Instantly share code, notes, and snippets.

@malisipi
Created June 25, 2023 17:20
Show Gist options
  • Select an option

  • Save malisipi/ea237fecf7e00563a333c26f2048d348 to your computer and use it in GitHub Desktop.

Select an option

Save malisipi/ea237fecf7e00563a333c26f2048d348 to your computer and use it in GitHub Desktop.
You can use the gist to init your web component.
"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