about:me

Today's agenda

What is Polymer?


Working with Polymer


Example time


Let's go back in time...

ye olde timey website

Elements are the building blocks of the web

Elements are encapsulated

<select>
  <option>Small</option>
  <option>Medium</option>
  <option>Large</option>
</select>

Elements are configurable

<select id="schwag">
  ...
  <option disabled>Medium</option>
  <option disabled>Large</option>
  <option selected>XX-large</option>
</select>

<select size="4" multiple>
  <option>Do</option>
  <option>Re</option>
  <option>Mi</option>
  ...
</select>

Elements are composable

<select>
  <optgroup label="German Cars">
    <option>Mercedes</option>
    <option>Audi</option>
  </optgroup>
  ...
</select>

<form>
  <select name="size">
    <option value="s">Small</option>
    <option value="m">Medium</option>
    <option value="l">Large</option>
  </select>
</form>

Elements are programmable

var foo = mySelect.selectedIndex;

So what happened?

Building a tab component today

<x-tabs>
  <x-tab>Tab 1</x-tab>
  <x-tab>Tab 2</x-tab>
  <x-tab>Tab 3</x-tab>
</x-tabs>

Web Components are a set of emerging standards that allow developers to extend HTML.

Templates

Custom Elements

Shadow DOM

HTML Imports

Polymer is a library that uses the latest web technologies to let you create custom HTML elements.

Layers of Polymer

Elements

Reusable custom elements (in progress)

Polymer

An opinionated way to work with Web Components

Platform

Web Components polyfills for all
modern browsers

Native

The current browser landscape

Three ways to work with Polymer

Using elements

Creating elements

Utilizing the modern web platform

Using

polymer-project.org/docs/elements/

Everything is an element

Polymer UI elements

visual elements

<polymer-ui-accordion>

<polymer-ui-animated-pages>

<polymer-ui-overlay>

<polymer-ui-card> demo

<polymer-ui-sidebar-menu> demo

<polymer-ui-tabs> demo

<polymer-ui-toggle-button> demo

<polymer-ui-theme-aware>

Everything is an element

Tabs revisited

<script src="platform.js"></script>
<link rel="import" href="polymer-ui-tabs.html">
<polymer-ui-tabs selected="0">
  <span>Home</span>
  <span>About</span>
  <span>Contact</span>
</polymer-ui-tabs>
Home About Contact

Everything is an element

Collapsible elements

<script src="platform.js"></script>
<link rel="import" href="polymer-ui-collapsible.html">
<polymer-ui-collapsible>
  <h3 class="polymer-ui-collapsible-header">Click Me!</h3>
  <div>
    some content...
  </div>
</polymer-ui-collapsible>

Click Me!

Realm of the galaxies at the edge of forever, made in the interiors of collapsing stars dispassionate extraterrestrial observer, rings of Uranus extraplanetary rich in heavy atoms shores of the cosmic ocean, white dwarf finite but unbounded!

Realm of the galaxies at the edge of forever, made in the interiors of collapsing stars dispassionate extraterrestrial observer, rings of Uranus extraplanetary rich in heavy atoms shores of the cosmic ocean, white dwarf finite but unbounded!

Polymer elements

non-visual utility elements

Layout

<polymer-layout>

<polymer-flex-layout>

<polymer-grid-layout>

View

<polymer-media-query>

<polymer-page>

Services / libs

<polymer-shared-lib>

<polymer-google-jsapi>

Data

<polymer-localstorage>

<polymer-xhr>

<polymer-jsonp>

<polymer-file>

<polymer-meta>

Behavior / interaction

<polymer-signals>

<polymer-selector>

Everything is an element

flexbox...using DOM

<script src="platform.js"></script>
<link rel="import" href="polymer-flex-layout.html">
<polymer-flex-layout vertical iscontainer>
  <div>Header</div>
  <div flex>Body</div>
  <div>Footer</div>
</polymer-flex-layout>
Header
Body
Footer

Creating

polymer-project.org/polymer.html

Declarative element registration

Declarative registration

<link rel="import" href="polymer.html">
<polymer-element name="my-element" noscript>
  <template>
    <style>h2 { color: orange; }</style>
    <h2>Hello from my-element!</h2>
  </template>
</polymer-element>
<my-element></my-element>

Declarative registration

<link rel="import" href="polymer.html">
<polymer-element name="hello-element">
  <template>
    <h2>I can say hello</h2>
  </template>
  <script>
  Polymer('hello-element', {
    sayHello: function() { alert('Howdy folks!'); }
  });
  </script>
</polymer-element>

Binding expressions

Binding Expressions

<polymer-element name="owner-element">
  <template>
    <h2>{{owner}} built me with Polymer</h2>
  </template>
  <script>
  Polymer('owner-element', {
    owner: 'Rob'
  });
  </script>
</polymer-element>
<owner-element></owner-element>

Published properties

Published properties

<polymer-element name="owner-element" attributes="owner">
  <template>
    <h2>{{owner}} built me with Polymer</h2>
  </template>
  <script>
  Polymer('owner-element', {
    owner: 'Rob'
  });
  </script>
</polymer-element>
<owner-element owner="Alex"></owner-element>

Declarative event handlers

Declarative Event Handlers

<polymer-element name="click-element">
  <template>
    <button on-click="{{setMessage}}">Click me</button>
    <span>{{message}}</span>
  </template>
  <script>
  Polymer('click-element', {
    message: 'Waiting to be clicked...'
    setMessage: function() { this.message = 'I was clicked!' }
  });
  </script>
</polymer-element>

Automatic node finding

Automatic Node Finding

<polymer-element name="focus-element">
  <template>
    <button on-click="{{setFocus}}">Set Focus</button>
    <input id="nameInput" type="text">
  </template>
  <script>
  Polymer('focus-element', {
    setFocus: function() { this.$.nameInput.focus(); }
  });
  </script>
</polymer-element>

The

polymer-project.org/docs/start/platform

The platform is a layer of polyfills that adds support for emerging standards, like Web Components, to all modern browsers.

Platform polyfills

supporting new web technologies today

Templates

HTML Imports

Custom Elements

Shadow DOM

As browsers implement the specifications supported by the platform, the need for this
layer decreases.

...till eventually it's all gone.