add examples for exportparts and slotted children
Neue Datei |
| | |
| | | <!DOCTYPE html>
|
| | | <html lang="en">
|
| | | <head>
|
| | | <meta charset="UTF-8">
|
| | | <title>exportparts</title>
|
| | | <script defer src="exportparts.js"></script>
|
| | | </head>
|
| | | <body>
|
| | | <style>
|
| | | outer-component::part(/* insert part */) {
|
| | | color: red;
|
| | | }
|
| | |
|
| | | outer-component::part(/* insert part */) {
|
| | | color: blue;
|
| | | }
|
| | | </style>
|
| | | <outer-component></outer-component>
|
| | | </body>
|
| | | </html>
|
Neue Datei |
| | |
| | | class InnerComponent extends HTMLElement {
|
| | | constructor() {
|
| | | super();
|
| | |
|
| | | const shadowRoot = this.attachShadow({mode: "open"});
|
| | |
|
| | | shadowRoot.innerHTML = `
|
| | | <style>
|
| | | :host {
|
| | | display: inline;
|
| | | }
|
| | | </style>
|
| | | |
| | | <div>Inner Text</div>
|
| | | `;
|
| | | }
|
| | | }
|
| | |
|
| | | class OuterComponent extends HTMLElement {
|
| | | constructor() {
|
| | | super();
|
| | |
|
| | | const shadowRoot = this.attachShadow({mode: "open"});
|
| | |
|
| | | shadowRoot.innerHTML = `
|
| | | <style>
|
| | | :host {
|
| | | display: inline;
|
| | | }
|
| | | </style>
|
| | | |
| | | <div>Outer Text</div>
|
| | | <inner-component></inner-component>
|
| | | `;
|
| | | }
|
| | | }
|
| | |
|
| | | window.customElements.define("inner-component", InnerComponent);
|
| | | window.customElements.define("outer-component", OuterComponent);
|
Neue Datei |
| | |
| | | <!DOCTYPE html>
|
| | | <html lang="en">
|
| | | <head>
|
| | | <meta charset="UTF-8">
|
| | | <title>Slotted Children</title>
|
| | | <script defer src="slotted.js"></script>
|
| | | </head>
|
| | | <body>
|
| | | <slot-styler>
|
| | | <!-- Slotted children -->
|
| | | </slot-styler>
|
| | | </body>
|
| | | </html>
|
Neue Datei |
| | |
| | | class SlotStyler extends HTMLElement {
|
| | | constructor() {
|
| | | super();
|
| | |
|
| | | const shadowRoot = this.attachShadow({mode: "open"});
|
| | |
|
| | | shadowRoot.innerHTML = `
|
| | | <style>
|
| | | :host {
|
| | | display: block;
|
| | | }
|
| | | |
| | | /* Slotted Styles here */
|
| | | </style>
|
| | | |
| | | <slot></slot>
|
| | | `;
|
| | | }
|
| | | }
|
| | |
|
| | | window.customElements.define("slot-styler", SlotStyler);
|