0.1.2 • Published 4 years ago

custom-element-helpers v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Custom Element Helpers (CEH)

Helper functions for defining custom elements.

Modules

custom-element

createCustomElementDefinition(params: CustomElementDefinitionParams)

CustomElementDefinitionParams

CustomElement type
type CustomElement = HTMLElement & {
  useAttribute: (attributeName: string, defaultValue?: string) => [
    attributeValue: string,
    setValue: (newValueOrCallback: string | (value: string) => string),
  ];
};
NameTypeDescriptionDefault
extendskeyof HTMLElementTagNameMapTag name of the extended HTML element.
init(element: CustomElement) => voidFunction run at the end of the constructor.
namestringName of the custom element.init function name
observeAttributesRecord<string, (oldValue: string, newValue: string, element: CustomElement) => void>Object, where keys are attribute names to be observed, and values are callback functions for corresponding attributes.
observedAttributesstring[]Array of attribute names to observe. Unlike observeAttributes, with this parameter you can't provide callback function directly mapped to specific attribute, instead you have to rely on the onAttributeChange callback. So generally, it's recommended to use the observeAttributes instead.
onAdopt(element: CustomElement) => voidCalled when element is transferred to other DOM tree.
onAttributeChange(attributeName: string, oldValue: string, newValue: string, element: CustomElement) => voidCalled when one of the observed attributes changes.
onConnect(element: CustomElement) => voidCalled when element is mounted into the DOM tree.
onDisconnect(element: CustomElement) => voidCalled when element is dismounted from the DOM tree.
stylesCSSStyleSheet \| CSSStyleSheet[]CSS stylesheets to be attached to the shadowRoot of the element. Note, in case of an extended element, shadowRoot is not attached, so style sheets will be ignored.
templatestring \| [templateRelativePath: string, moduleURL: string] \| NodePath to the HTML file with a template element or template element node. Path can be a tuple, where first value is the relative path to the template file in regards to the module that uses it, and the second value is the URL of the module; or if template file and module file share the same name, then path can be just the module URL.
0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago