Web components

37
WEB COMPONENTS THE FUTURE WEB http://goo.gl/Nh8jd9

description

This presentation is about Web Components. What they are, why do we need them and how to go about creating a few of our own. We will also look at the browser support, make sure our Web Components work ~everywhere with the help of polyfills like Polymer. http://arvindr21.github.io/WebComponents

Transcript of Web components

Page 1: Web components

WEBCOMPONENTS

THE FUTURE WEBhttp://goo.gl/Nh8jd9

Page 2: Web components

HOW ARE WE DEVELOPING?

Let's say you want a build a page like

Page 3: Web components

DAY TO DAY APPROACH

1. Go to getbootstrap.com2. Get the CDN links for CSS and JS3. Copy the Starter Template and Make Changes

Page 4: Web components

WHAT ABOUT PLUGINS?

Say a Date Picker..

1. Go to jqueryui.com2. Download the source example3. Update and make changes

Page 5: Web components

PRIMARY PROBLEM

NAMESPACE COLLISION

window.$j = jQuery.noConflict();

NO ENCAPSULATION OF MARK UP AND STYLES

.search .datepicker{ background:green;}.widget-clock .datepicker{ background:yellow;}

Page 6: Web components

IFRAMES???

HOW CAN WE SOLVE THIS IN A BETTER WAY?

Page 7: Web components

and a date picker will be generated for you

And a Bootstrap Inverse Navbar will be scaffolded

JUST IMAGINE

If you can write a tag like

<date-picker data-start="today" data-disable="after 10 days"></date-picker>

Or this

<bootstrap-nav-inverse>

<proj>My Project</proj>

<link>Home</link>

<link>About</link>

<link>Contact</link>

</bootstrap-nav-inverse>

OR EVEN BETTER..

Page 8: Web components

<GANGNAM-STYLE></GANGNAM-STYLE>

Page 9: Web components

MORE REALISTIC

<TWITTER-BUTTON></TWITTER-BUTTON>

Tweet 1,114

Follow @zenorocha 17.5K followers

Tweet #customelements

Tweet to @zenorocha

Page 10: Web components

ONE MORE

<DROPBOX-BUTTON></DROPBOX-BUTTON>

Choose from Dropbox Save to Dropbox

Page 11: Web components

HOW CAN WE ACHIEVE THIS?

SURPISE!! SURPISE!!This is already present in our browser

WHAT DO I MEAN?

Page 12: Web components

HAVE YOU EVER WONDERED?

Inspect Me!!

Check : Inspecting Elements

Page 13: Web components

SOMETHING BIGGER?

0:12

<video width="320" height="240" controls=""> <source src="http://www.w3schools.com/html/movie.mp4" type="video/mp4"> <source src="http://www.w3schools.com/html/movie.ogg" type="video/ogg"> Your browser does not support the video tag.</video>

HOW CAN WE DO THIS?

Page 14: Web components

WEB COMPONENTS

Web Components === Write your own HTML tags & behaviours

Page 15: Web components

WEB COMPONENTSAre built using 4 key pieces

HTML TEMPLATES

SHADOW DOM

CUSTOM ELEMENTS

HTML IMPORTS

Page 16: Web components

BROWSER SUPPORT

More Details

Page 17: Web components

POLYFILLS

Polymer

Bosonic

x-tag

Page 18: Web components

HTML TEMPLATES

SHADOW DOM

CUSTOM ELEMENTS

HTML IMPORTS

Page 19: Web components

HTML TEMPLATESIn simple terms, these are just

These tags are inert - Parsed Not Rendered

Most importantly, the content inside the tag is hidden fromDOM ( $("template img") ordocument.querySelectorAll("template img"))

<template></template>

<template id="myTemplate"> <img src="flowers.png"> <audio controls=""> <source src="audio.ogg" type="audio/ogg"> <source src="audio.mp3" type="audio/mpeg"> Your browser does not support the audio tag. </audio></template>

Page 20: Web components

WHILE DEVELOPING

Encapsulate HTML will be stored here<template id="myTemplate">

<img src="image.png">

<audio controls="">

<source src="audio.ogg" type="audio/ogg">

<source src="audio.mp3" type="audio/mpeg">

Your browser does not support the audio tag.

</audio>

</template>

<script>

</script>

// Get the template content

var content = document.querySelector('#myTemplate').content;

// Modify if necessary

var img = content.querySelector('img');

img.src = "flowers.png";

// Append the content to DOM

document.body.appendChild(content.cloneNode());

Page 21: Web components
Page 22: Web components
Page 23: Web components
Page 24: Web components
Page 25: Web components
Page 26: Web components
Page 27: Web components
Page 28: Web components
Page 29: Web components
Page 30: Web components
Page 31: Web components
Page 32: Web components
Page 33: Web components
Page 34: Web components
Page 35: Web components
Page 36: Web components
Page 37: Web components