can-element
Allows you to create customelement classes with CanJS. Safari only supports custom elements that derive from HTMLElement, so you'll usually want to use Element.
CustomElement(Element)
Create a base Element class based on Element
, any element that derives from HTMLElement.
Important: Safari only supports custom elements that derive from [HTMLElement].
import CustomElement from "can-element";
const SuperButton = class extends CustomElement( HTMLButtonElement ) {
};
customElements.define( "super-button", SuperButton );
Parameters
- Element
{HTMLElement}
:The base element from which to derive.
Use
can-element
makes it possible to create standard custom elements (part of web components).
Use can-element to create a class that can be passed into customElements.define to register the element in the window.
import { Element } from "can-element";
import stache from "can-stache";
import define from "can-define";
const view = stache( "Hello {{name}}" );
const MyApp = class extends Element {
static get view() {
return view;
}
};
define( MyApp.prototype, {
name: {
value: "world"
}
} );
customElements.define( "my-app", MyApp );
const el = document.createElement( "my-app" );
el.name; // -> "world"