Code Monkey home page Code Monkey logo

declarative-shadow-dom's Introduction

<declarative-shadow-dom>

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

Demo

Check it live!

Install

Install the component using Bower:

$ bower install declarative-shadow-dom --save

Or download as ZIP.

Usage

  1. Import polyfill:

    <script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
  2. 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>
  3. Start using it!

    <anyelement>
        <template is="declarative-shadow-dom" mode="open">
            Shadow Content here
            <slot></slot>
        </template>
        Light DOM content here
    </anyelement>

How it works:

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.

How I would like it to work

  • 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 in constructor.

Speced behavior

See the Declarative-Shadow-DOM spec proposal and the test suite of this element

Options

Attribute Options Default Description
mode 'open','closed' required mode of the shadow root to create

Methods

Method Parameters Returns Description
appendToParentsShadowRoot() None Nothing Appends content to parent element's shadow root.

Events

Event Description
declarative-shadow-dom-stamped Fired on a parent/host when Shadow DOM is stamped

History

For detailed changelog, check Releases.

License

MIT

declarative-shadow-dom's People

Contributors

tomalec avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.