Custom Element to create Shadow DOM in a declarative manner
It's supposed to work closely with proposal given at w3c/webcomponents/proposals/Declarative-Shadow-DOM
Install the component using Bower:
$ bower install declarative-shadow-dom --save
Or download as ZIP.
-
Import polyfill:
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
-
Import custom element:
<link rel="import" href="bower_components/declarative-shadow-dom/declarative-shadow-dom.html"> <!-- or if you are not using HTML Imports --> <script src="bower_components/declarative-shadow-dom/declarative-shadow-dom.html"></script>
-
Start using it!
<anyelement> <template is="declarative-shadow-dom" mode="open"> Shadow Content here <slot></slot> </template> Light DOM content here </anyelement>
When it's connected
or appendToParentsShadowRoot
is called it "stamps" - appends it create shadow root in its parent node and appends its content there, then removes itself from the parent node.
- Ha! Work natively, without any JavaScript,
- to stamp only when created declaratively (parsing,
.innerHTML
), - do nothing when created imperatively,
- to stamp when the element is created, not when connected - Unfortunately, CE does not allow us to get the reference to
.parentNode
inconstructor
.
See the Declarative-Shadow-DOM spec proposal and the test suite of this element
Attribute | Options | Default | Description |
---|---|---|---|
mode | 'open','closed' | required | mode of the shadow root to create |
Method | Parameters | Returns | Description |
---|---|---|---|
appendToParentsShadowRoot() |
None | Nothing | Appends content to parent element's shadow root. |
Event | Description |
---|---|
declarative-shadow-dom-stamped |
Fired on a parent/host when Shadow DOM is stamped |
For detailed changelog, check Releases.
MIT