+ All Categories
Home > Technology > Web Components Basics / Overview by Abdella Ali at rangle.io

Web Components Basics / Overview by Abdella Ali at rangle.io

Date post: 04-Jul-2015
Category:
Upload: rangleio
View: 211 times
Download: 1 times
Share this document with a friend
Description:
For a weekly lunch and learn, front-end developer Abdella Ali presented to the team on Web Components.
21
Web Components! They’re gonna be everywhere (probably) Presentation by Abdella Ali front-end developer at rangle.io
Transcript
Page 1: Web Components Basics / Overview by Abdella Ali at rangle.io

Web Components!They’re gonna be everywhere (probably)

Presentation by Abdella Ali front-end developer at rangle.io

Page 2: Web Components Basics / Overview by Abdella Ali at rangle.io

Okay, what are they?

● Think Directives! ● Collection of W3 standards ● Includes both javascript and css ● http://www.w3.org/TR/components-intro/

Page 3: Web Components Basics / Overview by Abdella Ali at rangle.io

Sounds complicated● X-Tags ● Polymer ● Other Libraries

Page 4: Web Components Basics / Overview by Abdella Ali at rangle.io

But I like angular!You don’t have to choose! !“One of the main goals of Angular 2.0 is the ability to work with WebComponents. This means *any* WebComponent, including those built with WebComponent libraries such as Polymer and XTags. We've got some of this working already in our templating engine, including two-way databinding to XTags components. We've also go a demo that shows Angular's depdency injection working to inject a custom Polymer component with services. Integration is a pretty important story for us.”

Page 5: Web Components Basics / Overview by Abdella Ali at rangle.io

Fine, but why use them?

● Interoperability ● Web component libraries are focused ● Self-contained

Page 6: Web Components Basics / Overview by Abdella Ali at rangle.io

Tell me about Polymer!

● Backed by Google ● Plenty of pre-made components ● Supports Web Animations ● Based on flexbox ● Has ‘paper’ themed components

Page 7: Web Components Basics / Overview by Abdella Ali at rangle.io

Convince me with a cool demohttp://www.polymer-project.org/components/paper-elements/demo.html#core-toolbar

Page 8: Web Components Basics / Overview by Abdella Ali at rangle.io

What does the code look like?

<paper-button class="colored hover" label="colored" >

</paper-button>

Page 9: Web Components Basics / Overview by Abdella Ali at rangle.io

What does it really look like?!!Let’s take a look in WebStorm ~

Page 10: Web Components Basics / Overview by Abdella Ali at rangle.io

That seems like a lot

● Very customizable ● Components can be very complex ● This ‘Button’ component covers all paper buttons in

the example ● It doesn’t have to be a lot.

Page 11: Web Components Basics / Overview by Abdella Ali at rangle.io

Show me something simple<polymer-element name="preview-hero"> <template> <link rel="stylesheet"

href="preview-hero.css"/> <paper-shadow z="1"animated="true"></paper-shadow> <content> </content> </template> <script> Polymer('preview-hero', { ready: function() { } }); </script> </polymer-element>

:host{ height: 30%; opacity: 0.6; transition: opacity 200ms ease-in-out; } !:host(:hover) { opacity: 1; }

Page 12: Web Components Basics / Overview by Abdella Ali at rangle.io

So how do I style it?

● :host is for the element ● ::content is for the ‘transcluded’ content ● Polyfills for non-native components ● http://www.polymer-project.org/docs/polymer/

styling.html

Page 13: Web Components Basics / Overview by Abdella Ali at rangle.io

How do I get’m?

● bower install Polymer/paper-button

<link rel="import" href="components/paper-button/paper-button.html">

!<paper-button label=“hi”> </paper-button> !

Page 14: Web Components Basics / Overview by Abdella Ali at rangle.io

What are all these tags?

● <polymer-element> ● <template> ● <content>

Page 15: Web Components Basics / Overview by Abdella Ali at rangle.io

polymer-element

● Declares your custom element ● Special attributes:

o name (required) - self explanatory o attributes - can declare a bunch at once o extends - use to extend another element o noscript - for simple elements o constructor - global name for javascript

Page 16: Web Components Basics / Overview by Abdella Ali at rangle.io

template

● Between the open and close is your markup ● can put other custom elements in here

Page 17: Web Components Basics / Overview by Abdella Ali at rangle.io

content

● Allows for transclusion of content ● Can have multiple content tags ● Can specify what element types are allowed and

where they go using the select attribute (ie select=“h1”)

Page 18: Web Components Basics / Overview by Abdella Ali at rangle.io

Demo!!!!!

Page 19: Web Components Basics / Overview by Abdella Ali at rangle.io

What do I need?

● Chrome 36+ or polyfills ● bower install polymer ● bower install polymer/core-elements ● bower install polymer/paper-elements

Page 20: Web Components Basics / Overview by Abdella Ali at rangle.io

What about web animations?

var elem = document.querySelector('.pulse'); var player = document.timeline.play(new Animation(elem, [ {opacity: "0.5", transform: "scale(0.5)"}, {opacity: "1.0", transform: "scale(1)"} ],{ direction: "alternate", duration: 500, iterations: Infinity }));

Here's a simple example of an animation that scales and changes the opacity of a

<div> over 0.5 seconds. The animation alternates producing a pulsing effect.!

!

Page 21: Web Components Basics / Overview by Abdella Ali at rangle.io

Links/References● http://customelements.io/ ● http://css-tricks.com/modular-

future-web-components/ ● http://webcomponents.org/ ● http://www.x-tags.org/ ● http://www.polymer-project.org/ ● https://github.com/web-

animations/web-animations-js

https://groups.google.com/forum/#!topic/polymer-dev/fAvqDo40tMk !http://updates.html5rocks.com/2014/05/Web-Animations---element-animate-is-now-in-Chrome-36


Recommended