Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Web Component Ecosystem

The Web Component Ecosystem

Web Components give us the power to invent our own HTML elements, designed to be future-facing, interoperable, and beautiful on the multi-device web. With tools like Polymer and X-Tag, we can start taking advantage of this new technology today. Let’s take a look at some of the amazing elements that are already being produced, and explore how you can start leveraging them in your own projects.

Rob Dodson

August 25, 2014
Tweet

More Decks by Rob Dodson

Other Decks in Programming

Transcript

  1. Layers · sugaring · polymer.js: declarative, data-binding, · property observation,

    gestures, …) · components · core elements, paper elements · polyfills · <script src=“platform.js”>
  2. declarative, readable meaningful HTML common way to extend → reusable

    Custom Elements define new HTML var tabs = document.querySelector('paper-tabs'); tabs.addEventListener('core-activate', function() { console.log(this.selected); });
  3. var shadow = el.createShadowRoot(); shadow.innerHTML = “<style>h2 { color: red;

    }</style>” +
 “<h2>I’m a profile-card</h2>”; vanilla polymer <polymer-element name=“profile-card” noscript> <template> <link rel=“stylesheet” href=“styles.css”> <h2>I’m a profile-card</h2> </template> </polymer-element>
  4. var shadow = el.createShadowRoot(); shadow.innerHTML = “<style>h2 { color: red;

    }</style>” +
 “<h2>I’m a profile-card</h2>”; vanilla polymer <polymer-element name=“profile-card” noscript> <template> <link rel=“stylesheet” href=“styles.css”> <h2>I’m a profile-card</h2> </template> </polymer-element>
  5. var shadow = el.createShadowRoot(); shadow.innerHTML = “<style>h2 { color: red;

    }</style>” +
 “<h2>I’m a profile-card</h2>”; vanilla polymer <polymer-element name=“profile-card” noscript> <template> <link rel=“stylesheet” href=“styles.css”> <h2>I’m a profile-card</h2> </template> </polymer-element>
  6. Custom Elements Create new HTML elements and extend existing ones

    Templates Native templating in the browser Shadow DOM Scoped CSS!!! + encapsulated markup HTML Imports Load custom element definitions and resources
  7. <core-toolbar> <core-header-panel> <core-drawer-panel> <core-menu> <core-icon> <core-overlay> Visual <core-ajax> <core-localstorage> <core-range>

    <core-shared-lib> <core-media-query> <core-iconset> Non-visual And many more… Image: http://bit.ly/1kuX889,
  8. A simple container with a header section and a content

    section <core-header-panel> <core-header-panel flex> <core-toolbar> <core-icon-button icon=“menu"> </core-icon-button> <div>MY APP</div> </core-toolbar> <div class=“content”>…</div> </core-header-panel> MY APP
  9. A simple container with a header section and a content

    section <core-header-panel flex> <core-toolbar> <core-icon-button icon=“menu"> </core-icon-button> <div>MY APP</div> </core-toolbar> <div class=“content”>…</div> </core-header-panel> <core-header-panel> MY APP
  10. A simple container with a header section and a content

    section <core-header-panel flex> <core-toolbar> <core-icon-button icon=“menu"> </core-icon-button> <div>MY APP</div> </core-toolbar> <div class=“content”>…</div> </core-header-panel> <core-header-panel> MY APP
  11. A simple container with a header section and a content

    section <core-header-panel flex> <core-toolbar> <core-icon-button icon=“menu"> </core-icon-button> <div>MY APP</div> </core-toolbar> <div class=“content”>…</div> </core-header-panel> <core-header-panel> MY APP
  12. <core-header-panel mode=“scroll” flex> <core-toolbar> <core-icon-button icon=“menu"> </core-icon-button> <div>MY APP</div> </core-toolbar>

    <div class=“content”>…</div> </core-header-panel> Toolbar will scroll with the page <core-header-panel>
  13. A responsive container that combines a left- or right-side drawer

    panel and a main content area. <core-drawer-panel> <core-drawer-panel> <div drawer> Drawer panel... </div> <div main> Main panel... </div> </core-drawer-panel>
  14. <core-drawer-panel> <div drawer> Drawer panel... </div> <div main> Main panel...

    </div> </core-drawer-panel> A responsive container that combines a left- or right-side drawer panel and a main content area. <core-drawer-panel>
  15. <core-drawer-panel> <div drawer> Drawer panel... </div> <div main> Main panel...

    </div> </core-drawer-panel> A responsive container that combines a left- or right-side drawer panel and a main content area. <core-drawer-panel>
  16. <div class=“card”> <paper-shadow z=“5” animated> </paper-shadow> </div> A dynamic shadow

    for conveying z-depth and spatial relationships <paper-shadow>
  17. <app-router> github.com/erikringsmuth/app-router my-site.com/order/:id <app-router> <!-- matches an exact path -->

    <app-route path="/home" import="/pages/home-page.html"></app-route> ! <!-- matches using a path variable --> <app-route path="/order/:id" import=“/pages/order-page.html"></app-route> </app-router>
  18. <page-er> github.com/addyosmani/page-er <page-er perpage="5" previous=“<< Previous" next=“Next >>"></page-er> ! var

    pager = document.querySelector("page-er"); document.addEventListener("polymer-ready", function() { pager.data = model.items; });
  19. <ajax-form> github.com/garstasio/ajax-form Full Name Country City Join newsletter √ <form

    is="ajax-form" action="my/form/handler"> <label>Full Name <input type="text" name=“full_name"> </label> … </form>
  20. <style> #map { height: 400px; } </style> ! <div id="map"></div>

    ! <script src=“http://maps.googleapis.com/maps/api/js?callback=mapReady"> </script> <script> var marker = null; function getCurrentLocation(callback) { navigator.geolocation.watchPosition(callback); } ! function addMarker(opts, info) { var marker = new google.maps.Marker(opts); ! var infoWindow = new google.maps.InfoWindow({content: info}); ! google.maps.event.addListener(marker, 'click', function() { infoWindow.open(opts.map, marker); }); ! return marker; } ! function mapReady() { var container = document.querySelector('#map'); var map = new google.maps.Map(container, { zoom: 14, disableDefaultUI: true }); getCurrentLocation(function(pos) { var current = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude); map.setCenter(current); ! // Re-position marker or create new one. if (marker) { marker.setPosition(map.getCenter()); } else { marker = addMarker({ position: current, map: map, title: 'Your location' }, '<b>Your location</b>'); } }); } </script> So much code for one map marker!
  21. { "name": "my-element", "version": "0.0.0", "description": "My awesome Custom Element",

    "license": "MIT", "keywords": [ "web-components" ], "ignore": [ "**/.*", "node_modules", "bower_components" ] } bower.json