-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Hi. I'd like to propose a generic API to register custom elements easier, and allow to customize the tag name if it's needed. I got the inspiration from this article from @mayank99.
The code:
class MyComponent extends HTMLElement {
static tagName = "my-component";
static register(tagName = this.tagName) {
customElements.define(this.tagName = tagName, this);
}
}This would allow to register the element in different ways:
import MyComponent from "./my-component.js";
MyComponent.register(); // Register as `<my-component>`.import MyComponent from "./my-component.js";
MyComponent.register("your-component"); // Register as `<your-component>`.import MyComponent from "./my-component.js";
MyComponent.tagName = "your-component";
MyComponent.register(); // Register as `<your-component>`.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels