All Projects → LssPolymerElements → polymer2-ts

LssPolymerElements / polymer2-ts

Licence: other
Typescript decorators and type definitions for Polymer 2.0.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
HTML
75241 projects

Labels

Projects that are alternatives of or similar to polymer2-ts

resizable-panels
Web Component that allows to resize its childrens vertically or horizontally
Stars: ✭ 18 (+28.57%)
Mutual labels:  polymer2
obvi
A Polymer 3+ webcomponent / button for doing speech recognition
Stars: ✭ 54 (+285.71%)
Mutual labels:  polymer2
vaadin-select
Customizable Web Component similar to a native browser select. Part of the Vaadin components.
Stars: ✭ 18 (+28.57%)
Mutual labels:  polymer2
vaadin-icons
Vaadin Icons is a collection of 600+ unique icons designed for web applications
Stars: ✭ 59 (+321.43%)
Mutual labels:  polymer2
vaadin-split-layout
The Web Component which allows you to partition a layout into resizeable areas. Part of the Vaadin components.
Stars: ✭ 40 (+185.71%)
Mutual labels:  polymer2
vaadin-context-menu
The responsive Web Component for showing context dependent items for any element on the page. Part of the Vaadin components.
Stars: ✭ 26 (+85.71%)
Mutual labels:  polymer2
toggle-icon
toggle-icon is a custom element created with Polymer. It provides an extremely powerful and customizable switch that looks like a paper-icon-button.
Stars: ✭ 21 (+50%)
Mutual labels:  polymer2
vaadin-dialog
High quality web component for modal dialogs. Part of the Vaadin platform.
Stars: ✭ 15 (+7.14%)
Mutual labels:  polymer2
mapbox-gl
Polymer 2.0 custom element for mapbox-gl-js. Uses WebGL to render interactive maps from vector tiles and Mapbox styles - compatible with deck-gl.
Stars: ✭ 24 (+71.43%)
Mutual labels:  polymer2
paper-chip
A chip web component made with Polymer 2 following Material Design guidelines
Stars: ✭ 30 (+114.29%)
Mutual labels:  polymer2
page-title
A Polymer element for easily updating a webpage's title, such as in a SPA.
Stars: ✭ 13 (-7.14%)
Mutual labels:  polymer2
identicon-avatar
👾 GitHub style identicon avatar
Stars: ✭ 15 (+7.14%)
Mutual labels:  polymer2

polymer2-ts -DEPRECATED

2-14-2018: With the recent annoucement of OFFICIAL support for Polymer Decorators and type definitions, we have decided to deprecate this project. Thanks to everyone for the contributions and support.


Build status

To install use: bower install --save polymer2-ts

Overview

Typescript decorators and type definitions for Polymer 2.0.

Available Behaviors

@customElement()

This class decorator will automatically add the is() getter and register your element.

@customElement("my-element")
class MyElement extends Polymer.Element {

}

@property(options?: PropertyOptions)

This property decorator will register your properties for you. Do not declare a properties getter. The type is inferred by the type declared in TypeScript. Assign defaults to the property directly.

class MyElement extends Polymer.Element {

    @property({ reflectToAttribute: true, notify: true })
    shape: string = "circle";
    
    @property()
    size: number = 60;    
}

Available PropertyOptions:

    notify?: boolean;
    reflectToAttribute?: boolean;
    readOnly?: boolean;

@listen(eventName: string, targetElem?: string)

This function decorator adds an event listener for the provided event name and calls back the function when the event is fired.

TypeScript:

class MyElement extends Polymer.Element {

 //Listen for tap events on the element with an id="submitButton"
  @listen("tap", "submitButton")
  submitButtonTapHandler(e){
      doSomething();
  }
  
  //Listen for all tap events on MyElement
  @listen("tap")
  tapHandler(e){
      doSomething();
  }
}

HTML:

<paper-button id="submitButton">Submit</paper-button>

@gestureListen(eventName: string, targetElem?: string)

This function decorator adds an polymer gesture listener for the provided event name and calls back the function when the event is fired.

IMPORTANT: When using this decorator your class must apply the gesture mix-in.

<link rel="import" href="polymer/lib/mixins/gesture-event-listeners.html">

<script>
    class TestEvent extends Polymer.GestureEventListeners(Polymer.Element) {
      ...
</script>

TypeScript:

class MyElement extends Polymer.Element {

 //Listen for tap events on the element with an id="submitButton"
  @listen("tap", "submitButton")
  submitButtonTapHandler(e){
      doSomething();
  }
  
  //Listen for all tap events on MyElement
  @listen("tap")
  tapHandler(e){
      doSomething();
  }
}

HTML:

<paper-button id="submitButton">Submit</paper-button>

computed(name: string)

This function decorator registers a computed property with the provided name. When one or more associated properties change, the computed property is updated.

TypeScript:
class MyElement extends Polymer.Element {
  @property( )
  numOne: number = 1;
    
  @property( )
  numTwo: number = 2;
        
  @computed('total')
  getSrc(numOne: number, numTwo: number) : number {
    return numOne + numTwo;
  }
}

HTML:

<h1>[[total]]</h1>

Result:

<h1>3</h1>

Recommended TypeScript Config

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es2015",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "sourceMap": false,
    "lib": ["es2017", "dom"],
    "typeRoots": ["types"]
  },
  "exclude": [    
    "node_modules",
    "bower_components/reflect-metadata/"
  ]
}

Example

my-element.ts

@customElement("my-element")
class MyElement extends Polymer.Element {

    @property({ notify: true })
    personId: number = 44;

    @property()
    size: number = 60;

    @observe('size')
    _sizeChanged(size) {
        console.log("size changed to " + size);
    }
    
    @computed('src')
    _computePictureSrc(personId: number, size: number) {
        var baseUrl = this.isDev() ? "https://dev.example.com/" : "https://example.com/";
        return `${baseUrl}Picture(${personId})/Default.Picture(size=${size})`;
    }
}

my-element.html

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../polymer2-ts/polymer2-ts.html">

<dom-module id="my-element">
    <template>
        <style>
             :host {
                display: block;
            }            
        </style>
        <img src="{{src}}" style="height:[[size]]"></img>
    </template>
    <script type="text/javascript" src="my-element.js"></script>
</dom-module>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].