Questions tagged [polymer-2.x]

Polymer 2.x is designed to support the new custom elements v1 and shadow DOM v1 specifications being implemented by most major browser vendors, while providing a smooth migration path for Polymer 1.x users.

Polymer 2.x also makes improvements in several areas:

  • Improved interoperability. By removing the need to use Polymer.dom for DOM manipulation, Polymer 2.0 makes it easier to use Polymer components with other libraries and frameworks. In addition, the shady DOM code has been separated out into a reusable polyfill, instead of being integrated into Polymer.

  • Data system improvements. Polymer 2.0 includes targeted improvements to the data system. These changes make it easier to reason about and debug the propagation of data through and between elements. They also improve compatibility with top-down data flow approaches, like Flux.

  • More standard. Polymer 2.x uses standard ES6 classes and the standard custom elements v1 methods for defining elements, instead of a Polymer factory method. You can mix in features using standard JavaScript (class expression mixins) instead of Polymer behaviors. (The Polymer factory method is still supported using a compatibility layer.)


Example:

HTML:my-element.html

<!-- import polymer-element -->
<link rel="import"  href="https://polygit.org/components/polymer/polymer-element.html">

<dom-module id="my-element">

  <template>
        <style>
              /* scoped CSS rules for this element */
        </style>
        <!-- local DOM for your element -->
        <p>I'm a DOM element. This is my shadow DOM!</p>

        <!-- bind to the "owner" property -->
        This is <b>[[owner]]</b>'s creation.
  </template>

  <script>
    // Define the class for a new element called custom-element
    class MyElement extends Polymer.Element {

      static get is() { return "my-element"; }

      // configure owner property
      static get properties() {
        return {
          owner: {
            type: String,
            value: "Google",
          }
        };
      }

    }
    // Register the new element with the browser
    customElements.define(MyElement.is, MyElement );
  </script>

</dom-module>

Using my-element in other document:

<!-- Add the <link> tag in the head/top of your markup -->
<link rel="import" href="my-element.html">

<!-- Use your new element anywhere in the document -->
<my-element></my-element>

Source

More Examples

799 questions
4
votes
1 answer

Update shared styles with JavaScript application wide in Polymer 2.0

I have a shared-styles element that keeps most of my applications colors. I can easily change the colors manually in shared-styles.html, and all of my other components can inherit from there if I use the CSS variables. My problem is I need to…
Gilberg
  • 2,514
  • 4
  • 31
  • 41
4
votes
2 answers

How to style inner elements of custom Polymer element using external styles?

Unable to style an element using Shadow DOM with Polymer 1.x or 2.x. Consider the following custom element in Polymer 2.0:
djthoms
  • 3,026
  • 2
  • 31
  • 56
3
votes
1 answer

:host getting oveerirden by universal selector css

We have CSS resets (margin:0px;padding:0px;) in a common style file which we have authored as one component and have included as a part of other components which we are developing. We are using universal selectors like…
3
votes
0 answers

ReCaptcha v3 stalling out in Safari(Mac and IOS)

I've stuck ReCaptcha 3 in a polymer 2 app and it works great, except that in Safari, when I try to get the token, the call to grecaptcha.execute stalls. Every. Single. Time. I've tried implementing different ways, sticking all captcha stuff straight…
Daniel Nielson
  • 381
  • 1
  • 8
3
votes
1 answer

Is it possible to pass data from Polymer component to Vue component?

The below code is what I'd like to do but it currently doesn't work. I'm trying to start building Vue components inside my Polymer app as a way to slowly migrate off Polymer. I've been able to get a Vue component working inside my Polymer app, but…
Nic Stelter
  • 641
  • 2
  • 7
  • 19
3
votes
1 answer

when use webcomponents-loader instead of webcomponents-lite

I have these two dependencies in my bower.json: Polymer/polymer#^2.6.0 and webcomponents/webcomponentsjs#^v1.1.0. In my index.html I don't see any difference if I add