diff --git a/docs/p06-customElement.html b/docs/p06-customElement.html index 7235e83..07d94be 100644 --- a/docs/p06-customElement.html +++ b/docs/p06-customElement.html @@ -129,4 +129,64 @@ setTimeout( ()=> document.querySelector(HTMLCustomElement.tagName).setAttribute("attr", "New Value"), 3*750 ); -

# Mnemonic

\ No newline at end of file +

# Shadow DOM

Regarding to this.attachShadow({ mode: 'open' }) see quick overview Using Shadow DOM. An another source of information can be Shadow DOM in Depth. To sum up, there in basic three ways to render component body:

import { + el, + customElementRender, + customElementWithDDE, +} from "./esm-with-signals.js"; +function ddeComponent(){ + return el().append( + el("p", { className: "red" }).append( + "Hello from ", el("slot", "Custom Element"), "!" + ) + ); +} + +export class A extends HTMLElement{ + static tagName= "custom-element-without"; + connectedCallback(){ + customElementRender( + this, + this, + ddeComponent + ); + } +} +customElementWithDDE(A); +customElements.define(A.tagName, A); +export class B extends HTMLElement{ + static tagName= "custom-element-open"; + connectedCallback(){ + customElementRender( + this, + this.attachShadow({ mode: "open" }), + ddeComponent + ); + } +} +customElementWithDDE(B); +customElements.define(B.tagName, B); +export class C extends HTMLElement{ + static tagName= "custom-element-closed"; + connectedCallback(){ + customElementRender( + this, + this.attachShadow({ mode: "closed" }), + ddeComponent + ); + } +} +customElementWithDDE(C); +customElements.define(C.tagName, C); + +document.body.append( + el("style", ` + .red{ color: red; } + `), + el(A.tagName).append("Without shadowRoot"), + el("hr"), + el(B.tagName).append("Open shadowRoot"), + el("hr"), + el(C.tagName).append("Closed shadowRoot"), +); +

# Mnemonic

\ No newline at end of file diff --git a/docs_src/components/examples/customElement/shadowRoot.js b/docs_src/components/examples/customElement/shadowRoot.js new file mode 100644 index 0000000..900333b --- /dev/null +++ b/docs_src/components/examples/customElement/shadowRoot.js @@ -0,0 +1,60 @@ +import { + el, + customElementRender, + customElementWithDDE, +} from "deka-dom-el"; +function ddeComponent(){ + return el().append( + el("p", { className: "red" }).append( + "Hello from ", el("slot", "Custom Element"), "!" + ) + ); +} + +export class A extends HTMLElement{ + static tagName= "custom-element-without"; + connectedCallback(){ + customElementRender( + this, + this, + ddeComponent + ); + } +} +customElementWithDDE(A); +customElements.define(A.tagName, A); +export class B extends HTMLElement{ + static tagName= "custom-element-open"; + connectedCallback(){ + customElementRender( + this, + this.attachShadow({ mode: "open" }), + ddeComponent + ); + } +} +customElementWithDDE(B); +customElements.define(B.tagName, B); +export class C extends HTMLElement{ + static tagName= "custom-element-closed"; + connectedCallback(){ + customElementRender( + this, + this.attachShadow({ mode: "closed" }), + ddeComponent + ); + } +} +customElementWithDDE(C); +customElements.define(C.tagName, C); + +document.body.append( + el("style", ` + .red{ color: red; } + `), + el(A.tagName).append("Without shadowRoot"), + el("hr"), + el(B.tagName).append("Open shadowRoot"), + el("hr"), + el(C.tagName).append("Closed shadowRoot"), +); diff --git a/docs_src/p06-customElement.html.js b/docs_src/p06-customElement.html.js index bc08935..1b8702f 100644 --- a/docs_src/p06-customElement.html.js +++ b/docs_src/p06-customElement.html.js @@ -101,7 +101,7 @@ export function page({ pkg, info }){ information can be ${el("a", { textContent: t`Shadow DOM in Depth`, ...references.shadow_dom_depth })}. To sum up, there in basic three ways to render component body: `), - + el(example, { src: fileURL("./components/examples/customElement/shadowRoot.js"), page_id }), el(mnemonic) );