diff --git a/docs/p06-customElement.html b/docs/p06-customElement.html index d9ea073..9685846 100644 --- a/docs/p06-customElement.html +++ b/docs/p06-customElement.html @@ -1,4 +1,4 @@ -`deka-dom-el` — Custom elements

`deka-dom-el` — Custom elements

Using custom elements in combinantion with DDE

Using custom elements in combinantion with DDE

// use NPM or for example https://cdn.jsdelivr.net/gh/jaandrle/deka-dom-el/dist/esm-with-signals.js +`deka-dom-el` — Web Components

`deka-dom-el` — Web Components

Using custom elements in combinantion with DDE

Using web components in combinantion with DDE

The DDE library allows for use within Web Components for dom-tree generation. However, in order to be able to use signals (possibly mapping to registered observedAttributes) and additional functionality is (unfortunately) required to use helpers provided by the library.

// use NPM or for example https://cdn.jsdelivr.net/gh/jaandrle/deka-dom-el/dist/esm-with-signals.js import { customElementRender, customElementWithDDE, @@ -10,7 +10,7 @@ S.observedAttributes; // “internal” utils import { lifecyclesToEvents } from "deka-dom-el"; -

# Custom Elements Introduction

Using custom elements

class CustomHTMLElement extends HTMLElement{ +

# Custom Elements Introduction

To start with, let’s see how to use native Custom Elements. As starting point please read Using Custom Elements on MDN. To sum up and for mnemonic see following code overview:

export class CustomHTMLElement extends HTMLElement{ static tagName= "custom-element"; // just suggestion, we can use `el(CustomHTMLElement.tagName)` static observedAttributes= [ "custom-attribute" ]; constructor(){ @@ -31,4 +31,4 @@ import { lifecyclesToEvents } from "deka-dom-el"; set customAttribute(value){ this.setAttribute("custom-attribute", value); } } customElements.define(CustomHTMLElement.tagName, CustomHTMLElement); -

Handy Custom Elements' Patterns

# Mnemonic

  • customElementRender(<custom-element>, <render-function>[, <properties>]) — use function to render DOM structure for given <custom-element>
  • customElementWithDDE(<custom-element>) — register <custom-element> to DDE library, see also `lifecyclesToEvents`, can be also used as decorator
  • observedAttributes(<custom-element>) — returns record of observed attributes (keys uses camelCase)
  • S.observedAttributes(<custom-element>) — returns record of observed attributes (keys uses camelCase and values are signals)
  • lifecyclesToEvents(<class-declaration>) — convert lifecycle methods to events, can be also used as decorator
\ No newline at end of file +

For more advanced use of Custom Elements, the summary Handy Custom Elements' Patterns may be useful. Especially pay attention to linking HTML attributes and defining setters/getters, this is very helpful to use in combination with the library (el(CustomHTMLElement.tagName, { customAttribute: "new-value" });).

# Mnemonic

\ No newline at end of file diff --git a/docs_src/components/examples/customElement/native-basic.js b/docs_src/components/examples/customElement/native-basic.js index 4fce871..d54fc3e 100644 --- a/docs_src/components/examples/customElement/native-basic.js +++ b/docs_src/components/examples/customElement/native-basic.js @@ -1,4 +1,4 @@ -class CustomHTMLElement extends HTMLElement{ +export class CustomHTMLElement extends HTMLElement{ static tagName= "custom-element"; // just suggestion, we can use `el(CustomHTMLElement.tagName)` static observedAttributes= [ "custom-attribute" ]; constructor(){ diff --git a/docs_src/p06-customElement.html.js b/docs_src/p06-customElement.html.js index b10b044..91ff4f7 100644 --- a/docs_src/p06-customElement.html.js +++ b/docs_src/p06-customElement.html.js @@ -1,6 +1,6 @@ import { T, t } from "./utils/index.js"; export const info= { - title: t`Custom elements`, + title: t`Web Components`, description: t`Using custom elements in combinantion with DDE`, }; @@ -13,13 +13,19 @@ import { code } from "./components/code.html.js"; /** @param {string} url */ const fileURL= url=> new URL(url, import.meta.url); const references= { - /** Custom Elements on MDN */ - custom_elements: { + mdn_web_components: { /** Web Components on MDN */ + title: t`MDN documentation page for Web Components`, + href: "https://developer.mozilla.org/en-US/docs/Web/API/Web_components", + }, + mdn_observedAttributes: { /** observedAttributes on MDN */ + title: t`MDN documentation page for observedAttributes`, + href: "https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes", + }, + mdn_custom_elements: { /** Custom Elements on MDN */ title: t`MDN documentation page for Custom Elements`, href: "https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements", }, - /** Custom Elements tips from WebReflection */ - custom_elements_tips: { + custom_elements_tips: { /** Custom Elements tips from WebReflection */ title: t`Ideas and tips from WebReflection`, href: "https://gist.github.com/WebReflection/ec9f6687842aa385477c4afca625bbf4", } @@ -28,18 +34,27 @@ const references= { export function page({ pkg, info }){ const page_id= info.id; return el(simplePage, { info, pkg }).append( - el("h2", t`Using custom elements in combinantion with DDE`), + el("h2", t`Using web components in combinantion with DDE`), el("p").append(...T` + The DDE library allows for use within ${el("a", references.mdn_web_components).append( el("strong", "Web Components") )} + for dom-tree generation. However, in order to be able to use signals (possibly mapping to registered + ${el("a", references.mdn_observedAttributes).append( el("code", "observedAttributes") )}) and additional + functionality is (unfortunately) required to use helpers provided by the library. `), el(code, { src: fileURL("./components/examples/customElement/intro.js"), page_id }), el(h3, t`Custom Elements Introduction`), el("p").append(...T` - ${el("a", { textContent: t`Using custom elements`, ...references.custom_elements })} + To start with, let’s see how to use native Custom Elements. As starting point please read + ${el("a", references.mdn_custom_elements).append( el("strong", "Using Custom Elements"), " on MDN" )}. + To sum up and for mnemonic see following code overview: `), el(code, { src: fileURL("./components/examples/customElement/native-basic.js"), page_id }), el("p").append(...T` - ${el("a", { textContent: t`Handy Custom Elements' Patterns`, ...references.custom_elements_tips })} + For more advanced use of Custom Elements, the summary ${el("a", references.custom_elements_tips) + .append( el("strong", t`Handy Custom Elements' Patterns`) )} may be useful. Especially pay attention to + linking HTML attributes and defining setters/getters, this is very helpful to use in combination with + the library (${el("code", "el(CustomHTMLElement.tagName, { customAttribute: \"new-value\" });")}). `), el(mnemonic)