SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
TOMORROW’S
COMPONENTS,TODAY!
<presentation>
HELLO
Mike North
UI Engineering Lead
@MichaelLNorth
THE WEB WAS BUILT FOR…
Document
Viewer
Document
2006 2007 2008 2009 2010 2011 2012 2013 201420052004
ES3 ES4 ES5 ES2015
1999
6 7 8 9 11
WHERE WE’VE BEEN
THE BROWSER AS AN
APPLICATION PLATFORM
• Powerful new language standards (TC39)
• Uniting around web standards (W3C)
• Use tomorrow’s technology today (Babel,
Web Frameworks)
HOW COMPONENTS HELP
• Encapsulation
• Maintainability
• Testability
• Scalability
• Extensibility
HTML5 WEB COMPONENTS
• HTMLTemplates
• Shadow DOM
• Custom Elements
• HTML Imports
HTMLTEMPLATES
What’s the point?
• Get some HTML into the DOM, and have it
remain inert
• Defer loading of resources
• Defer rendering of content
HTMLTEMPLATES
<script
type=“text/x-handlebars-template"
id="something">
<div class="frame">
<h3 class="title">{{title}}</h3>
<p class="body">{{body}}</p>
</div>
</script>
Handlebars
HTMLTEMPLATES
<template id="something">
<div class="frame">
<h3 class="title">I am a title</h3>
<p class="body">I am the body</p>
</div>
</template>
Native
HTMLTEMPLATES
<template id="something">
<!-- Some style -->
<style type="text/css">
.title {
font-size: 24px;
}
</style>
<!-- Some behavior -->
<script type="text/javascript">
</script>
<!-- Some structure and content -->
<div class="frame">
<h3 class="title">I am a title</h3>
<p class="body">I am the body</p>
</div>
</template>
HTMLTEMPLATES
Add to the DOM
Example: http://codepen.io/TrueNorth/pen/xbyVgL?editors=101
// Grab the template
var tmpl = document.querySelector('#something');
// Add the cloned document fragment to the DOM
document.body.appendChild(
// Clone the template's document fragment
document.importNode(tmpl.content, true)
);
SHADOW DOM
What’s the point?
• CSS rules bleeding into UI components is
annoying
• DOM encapsulation is poor, unless you iframe
• Shadow DOM is a subtree within the parent page
SHADOW DOM
• Shadow Root - root
element of DOM subtree
• Shadow Host - parent of a
shadow root
Application DOM
Component
Shadow DOM
SHADOW DOM
Creating a Shadow Root
// Grab an element
var elem = document.querySelector("#good-host");
// Create the shadow root
var root = elem.createShadowRoot();
// Create a new element
var h1 = document.createElement("h1");
h1.innerHTML = "Hello World";
// Append to the shadow root
root.appendChild(h1);
SHADOW DOM
Add a template to the mix
Example: http://codepen.io/TrueNorth/pen/OPBNmq?editors=101
<template id="something">
<h1>Hello, world!</h1>
<p>This is part of my component</p>
</template>
<div id="good-host"></div>
// Grab an element
var elem = document.querySelector("#good-host");
// Create the shadow root
var root = elem.createShadowRoot();
// Grab the template
var tmpl = document.querySelector('#something');
// Add the cloned document fragment to the DOM
root.appendChild(
// Clone the template's document fragment
document.importNode(tmpl.content, true)
);
SHADOW DOM
Styling
• Style defined/loaded within
the shadow DOM only
applies to shadow DOM
• :host pseudo-selector -
for outer element
:host {
border: 1px solid red;
}
:host(.hover) {
border: 1px solid blue;
}
SHADOW DOM
Styling
• The ::shadow pseudo-selector
penetrates a shadow root
• the /deep/ pseudo-selector penetrates all
shadow roots
SHADOW DOM
Styling
.example-host {
border: 1px solid purple;
padding: 10px;
margin: 10px;
}
#good-host p {
color: blue;
}
#better-host::shadow p {
color: red;
}
#better-host/deep/ h1 {
color: cyan;
}
<template id="something">
<h1>Hello, world!</h1>
<p>This is part of my component</p>
<content></content>
</template>
<div id="good-host" class="example-host"></div>
<div id="better-host" class="example-host">
<div id="best-host" class="example-host"></div>
</div>
Example: http://codepen.io/TrueNorth/pen/MYPyOe
SHADOW DOM
Content Projection
• <content> tag to project all content
• <content select=“”> to project selected
content
<template id="something">
<h1><content select=".h1"></content></h1>
<p>This is part of my component</p>
<content></content>
</template>
Examples: http://codepen.io/TrueNorth/pen/emPZMv
CUSTOM ELEMENTS
What’s the point?
• Compose larger parts of an app declaratively
• Provide a standard and consistent life-cycle
• Extensibility
CUSTOM ELEMENTS
Registering
// Extend a DOM element prototype
var MegaButtonProto = Object.create(HTMLButtonElement.prototype);
// Register your new element type
var MegaButton = document.registerElement("mega-button", {
prototype: MegaButtonProto,
extends: "button"
});
CUSTOM ELEMENTS
Adding templates
// Template
var infoBoxTemplate = document.querySelector('#info-pane-template');
// Register the custom element
var InfoBox = document.registerElement("info-pane", {
prototype: Object.create(HTMLElement.prototype, {
createdCallback: {
value: function () {
// Create the shadow root
this.createShadowRoot()
// Add the template to the shadow root
.appendChild(
document.importNode(
infoBoxTemplate.content, true)
);
}
}
})
});
Examples: http://codepen.io/TrueNorth/pen/gbBmMR
HTML IMPORTS
• #include for the web
• onload, onerror hooks
• Can include CSS, JS and HTML
• Content can be accessed from the
outside
• HTML Imported JS can reference
either the main DOM or imported
document fragment
<link rel="import"
href="myfile.html" />
// Get document fragment of an import
var content = document
.querySelector('link[rel="import"]')
.import;
// From a <script> included,
// with the import access,
// imported DOM
document
.currentScript
.ownerDocument
.querySelector('.abc');
A REAL USE CASE
• Declarative Syntax
• Responds to click
<hamburger-menu title="My Menu">
<hb-menu-item href="#abc"
caption="Better get on these soon">
Serious Bugs
</hb-menu-item>
<hb-menu-item href="#def"
caption="Oh %#@$!">
Really Serious Bugs
</hb-menu-item>
</hamburger-menu>
Starting Point: http://codepen.io/TrueNorth/pen/PwdLrj
Componentized: http://codepen.io/TrueNorth/pen/xbyqME
HTML Importified: http://codepen.io/TrueNorth/pen/ogawLm
• Content projection
• Style on shadow root
is recruiting
http://bit.ly/yahoo-recruit
</presentation>
<questions> ? </questions>

Weitere ähnliche Inhalte

Was ist angesagt?

WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperChandra Patel
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance DrupalJeff Geerling
 
Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Derek Jacoby
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"Binary Studio
 
Untangling spring week9
Untangling spring week9Untangling spring week9
Untangling spring week9Derek Jacoby
 
Untangling spring week4
Untangling spring week4Untangling spring week4
Untangling spring week4Derek Jacoby
 
Untangling fall2017 week1
Untangling fall2017 week1Untangling fall2017 week1
Untangling fall2017 week1Derek Jacoby
 
Performance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumPerformance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumMark Watson
 
How to make your Webpack builds 10x faster
How to make your Webpack builds 10x fasterHow to make your Webpack builds 10x faster
How to make your Webpack builds 10x fastertrueter
 
Herding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandboxHerding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandboxColdFusionConference
 
Untangling spring week8
Untangling spring week8Untangling spring week8
Untangling spring week8Derek Jacoby
 
Untangling the web10
Untangling the web10Untangling the web10
Untangling the web10Derek Jacoby
 
BP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesBP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesedm00se
 
Server Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.jsServer Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.jsJeff Geerling
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 
Production optimization with React and Webpack
Production optimization with React and WebpackProduction optimization with React and Webpack
Production optimization with React and Webpackk88hudson
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019Anam Ahmed
 
Afrimadoni the power of docker
Afrimadoni   the power of dockerAfrimadoni   the power of docker
Afrimadoni the power of dockerPHP Indonesia
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentIrfan Maulana
 

Was ist angesagt? (20)

WP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of DeveloperWP-CLI - A Good Friend of Developer
WP-CLI - A Good Friend of Developer
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Untangling - fall2017 - week 8
Untangling - fall2017 - week 8
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"
 
Untangling spring week9
Untangling spring week9Untangling spring week9
Untangling spring week9
 
Untangling spring week4
Untangling spring week4Untangling spring week4
Untangling spring week4
 
Untangling fall2017 week1
Untangling fall2017 week1Untangling fall2017 week1
Untangling fall2017 week1
 
Performance Metrics in a Day with Selenium
Performance Metrics in a Day with SeleniumPerformance Metrics in a Day with Selenium
Performance Metrics in a Day with Selenium
 
How to make your Webpack builds 10x faster
How to make your Webpack builds 10x fasterHow to make your Webpack builds 10x faster
How to make your Webpack builds 10x faster
 
Herding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandboxHerding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandbox
 
Untangling spring week8
Untangling spring week8Untangling spring week8
Untangling spring week8
 
Untangling the web10
Untangling the web10Untangling the web10
Untangling the web10
 
BP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPagesBP101: A Modernized Workflow w/ Domino/XPages
BP101: A Modernized Workflow w/ Domino/XPages
 
Server Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.jsServer Check.in case study - Drupal and Node.js
Server Check.in case study - Drupal and Node.js
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
Production optimization with React and Webpack
Production optimization with React and WebpackProduction optimization with React and Webpack
Production optimization with React and Webpack
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019
 
Afrimadoni the power of docker
Afrimadoni   the power of dockerAfrimadoni   the power of docker
Afrimadoni the power of docker
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 

Andere mochten auch

16 Web & Graphic Design Trends to Watch in 2016
16 Web & Graphic Design Trends to Watch in 201616 Web & Graphic Design Trends to Watch in 2016
16 Web & Graphic Design Trends to Watch in 2016Ernesto Olivares
 
Web Design 101
Web Design 101Web Design 101
Web Design 101T.S. Lim
 
Introduction to Layouts in Graphic Design
Introduction to Layouts in Graphic DesignIntroduction to Layouts in Graphic Design
Introduction to Layouts in Graphic DesignCasey Robertson
 
UX & UI Design - Differentiate through design
UX & UI Design - Differentiate through designUX & UI Design - Differentiate through design
UX & UI Design - Differentiate through designDMI
 
How UX Design Has Changed The World
How UX Design Has Changed The WorldHow UX Design Has Changed The World
How UX Design Has Changed The WorldBuiltByHQ
 
UX Design + UI Design: Injecting a brand persona!
UX Design + UI Design: Injecting a brand persona!UX Design + UI Design: Injecting a brand persona!
UX Design + UI Design: Injecting a brand persona!Jayan Narayanan
 

Andere mochten auch (11)

Web Design Trends for 2016
Web Design Trends for 2016Web Design Trends for 2016
Web Design Trends for 2016
 
UI/UX Design
UI/UX DesignUI/UX Design
UI/UX Design
 
16 Web & Graphic Design Trends to Watch in 2016
16 Web & Graphic Design Trends to Watch in 201616 Web & Graphic Design Trends to Watch in 2016
16 Web & Graphic Design Trends to Watch in 2016
 
Web Design 101
Web Design 101Web Design 101
Web Design 101
 
UI / UX Design Presentation
UI / UX Design PresentationUI / UX Design Presentation
UI / UX Design Presentation
 
Introduction to Layouts in Graphic Design
Introduction to Layouts in Graphic DesignIntroduction to Layouts in Graphic Design
Introduction to Layouts in Graphic Design
 
UX & UI Design - Differentiate through design
UX & UI Design - Differentiate through designUX & UI Design - Differentiate through design
UX & UI Design - Differentiate through design
 
How UX Design Has Changed The World
How UX Design Has Changed The WorldHow UX Design Has Changed The World
How UX Design Has Changed The World
 
Graphic Design 101
Graphic Design 101Graphic Design 101
Graphic Design 101
 
What is ux?
What is ux?What is ux?
What is ux?
 
UX Design + UI Design: Injecting a brand persona!
UX Design + UI Design: Injecting a brand persona!UX Design + UI Design: Injecting a brand persona!
UX Design + UI Design: Injecting a brand persona!
 

Ähnlich wie Modern Web UI - Web components

Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is HereGil Fink
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Browsers. Magic is inside.
Browsers. Magic is inside.Browsers. Magic is inside.
Browsers. Magic is inside.Devexperts
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!Aleks Zinevych
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven developmentGil Fink
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedGil Fink
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsGil Fink
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform AppsFITC
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is hereGil Fink
 
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScriptDYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScriptSoumen Santra
 
Web components
Web componentsWeb components
Web componentsNoam Kfir
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)BOSS Webtech
 
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCRDrupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCRGaurav Mishra
 

Ähnlich wie Modern Web UI - Web components (20)

Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 
Web components
Web componentsWeb components
Web components
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Browsers. Magic is inside.
Browsers. Magic is inside.Browsers. Magic is inside.
Browsers. Magic is inside.
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has Arrived
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is here
 
Web components
Web componentsWeb components
Web components
 
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScriptDYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
 
Polymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot CampPolymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot Camp
 
Web components
Web componentsWeb components
Web components
 
HTML literals, the JSX of the platform
HTML literals, the JSX of the platformHTML literals, the JSX of the platform
HTML literals, the JSX of the platform
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCRDrupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
 
Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design
 

Mehr von Mike North

Web Security: A Primer for Developers
Web Security: A Primer for DevelopersWeb Security: A Primer for Developers
Web Security: A Primer for DevelopersMike North
 
A Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueA Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueMike North
 
Anatomy of a Progressive Web App
Anatomy of a Progressive Web AppAnatomy of a Progressive Web App
Anatomy of a Progressive Web AppMike North
 
Web and Native: Bridging the Gap
Web and Native: Bridging the GapWeb and Native: Bridging the Gap
Web and Native: Bridging the GapMike North
 
The Road to Native Web Components
The Road to Native Web ComponentsThe Road to Native Web Components
The Road to Native Web ComponentsMike North
 
Enemy of the state
Enemy of the stateEnemy of the state
Enemy of the stateMike North
 
Phoenix for Rubyists - Rubyconf Brazil 2016
Phoenix for Rubyists - Rubyconf Brazil 2016Phoenix for Rubyists - Rubyconf Brazil 2016
Phoenix for Rubyists - Rubyconf Brazil 2016Mike North
 
Phoenix for Rubyists
Phoenix for RubyistsPhoenix for Rubyists
Phoenix for RubyistsMike North
 
Write Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js MunichWrite Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js MunichMike North
 
Delightful UX for Distributed Systems
Delightful UX for Distributed SystemsDelightful UX for Distributed Systems
Delightful UX for Distributed SystemsMike North
 
Modern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.jsModern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.jsMike North
 
CI/CD and Asset Serving for Single Page Apps
CI/CD and Asset Serving for Single Page AppsCI/CD and Asset Serving for Single Page Apps
CI/CD and Asset Serving for Single Page AppsMike North
 
User percieved performance
User percieved performanceUser percieved performance
User percieved performanceMike North
 
User-percieved performance
User-percieved performanceUser-percieved performance
User-percieved performanceMike North
 
Write Once, Run Everywhere
Write Once, Run EverywhereWrite Once, Run Everywhere
Write Once, Run EverywhereMike North
 
Compose all the things (Wicked Good Ember 2015)
Compose all the things (Wicked Good Ember 2015)Compose all the things (Wicked Good Ember 2015)
Compose all the things (Wicked Good Ember 2015)Mike North
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7Mike North
 
Test like a pro with Ember.js
Test like a pro with Ember.jsTest like a pro with Ember.js
Test like a pro with Ember.jsMike North
 

Mehr von Mike North (18)

Web Security: A Primer for Developers
Web Security: A Primer for DevelopersWeb Security: A Primer for Developers
Web Security: A Primer for Developers
 
A Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js GlueA Debugging Adventure: Journey through Ember.js Glue
A Debugging Adventure: Journey through Ember.js Glue
 
Anatomy of a Progressive Web App
Anatomy of a Progressive Web AppAnatomy of a Progressive Web App
Anatomy of a Progressive Web App
 
Web and Native: Bridging the Gap
Web and Native: Bridging the GapWeb and Native: Bridging the Gap
Web and Native: Bridging the Gap
 
The Road to Native Web Components
The Road to Native Web ComponentsThe Road to Native Web Components
The Road to Native Web Components
 
Enemy of the state
Enemy of the stateEnemy of the state
Enemy of the state
 
Phoenix for Rubyists - Rubyconf Brazil 2016
Phoenix for Rubyists - Rubyconf Brazil 2016Phoenix for Rubyists - Rubyconf Brazil 2016
Phoenix for Rubyists - Rubyconf Brazil 2016
 
Phoenix for Rubyists
Phoenix for RubyistsPhoenix for Rubyists
Phoenix for Rubyists
 
Write Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js MunichWrite Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js Munich
 
Delightful UX for Distributed Systems
Delightful UX for Distributed SystemsDelightful UX for Distributed Systems
Delightful UX for Distributed Systems
 
Modern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.jsModern, Scalable, Ambitious apps with Ember.js
Modern, Scalable, Ambitious apps with Ember.js
 
CI/CD and Asset Serving for Single Page Apps
CI/CD and Asset Serving for Single Page AppsCI/CD and Asset Serving for Single Page Apps
CI/CD and Asset Serving for Single Page Apps
 
User percieved performance
User percieved performanceUser percieved performance
User percieved performance
 
User-percieved performance
User-percieved performanceUser-percieved performance
User-percieved performance
 
Write Once, Run Everywhere
Write Once, Run EverywhereWrite Once, Run Everywhere
Write Once, Run Everywhere
 
Compose all the things (Wicked Good Ember 2015)
Compose all the things (Wicked Good Ember 2015)Compose all the things (Wicked Good Ember 2015)
Compose all the things (Wicked Good Ember 2015)
 
Async JavaScript in ES7
Async JavaScript in ES7Async JavaScript in ES7
Async JavaScript in ES7
 
Test like a pro with Ember.js
Test like a pro with Ember.jsTest like a pro with Ember.js
Test like a pro with Ember.js
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Modern Web UI - Web components

  • 2. HELLO Mike North UI Engineering Lead @MichaelLNorth
  • 3. THE WEB WAS BUILT FOR… Document Viewer Document
  • 4. 2006 2007 2008 2009 2010 2011 2012 2013 201420052004 ES3 ES4 ES5 ES2015 1999 6 7 8 9 11 WHERE WE’VE BEEN
  • 5. THE BROWSER AS AN APPLICATION PLATFORM • Powerful new language standards (TC39) • Uniting around web standards (W3C) • Use tomorrow’s technology today (Babel, Web Frameworks)
  • 6. HOW COMPONENTS HELP • Encapsulation • Maintainability • Testability • Scalability • Extensibility
  • 7. HTML5 WEB COMPONENTS • HTMLTemplates • Shadow DOM • Custom Elements • HTML Imports
  • 8. HTMLTEMPLATES What’s the point? • Get some HTML into the DOM, and have it remain inert • Defer loading of resources • Defer rendering of content
  • 10. HTMLTEMPLATES <template id="something"> <div class="frame"> <h3 class="title">I am a title</h3> <p class="body">I am the body</p> </div> </template> Native
  • 11. HTMLTEMPLATES <template id="something"> <!-- Some style --> <style type="text/css"> .title { font-size: 24px; } </style> <!-- Some behavior --> <script type="text/javascript"> </script> <!-- Some structure and content --> <div class="frame"> <h3 class="title">I am a title</h3> <p class="body">I am the body</p> </div> </template>
  • 12. HTMLTEMPLATES Add to the DOM Example: http://codepen.io/TrueNorth/pen/xbyVgL?editors=101 // Grab the template var tmpl = document.querySelector('#something'); // Add the cloned document fragment to the DOM document.body.appendChild( // Clone the template's document fragment document.importNode(tmpl.content, true) );
  • 13. SHADOW DOM What’s the point? • CSS rules bleeding into UI components is annoying • DOM encapsulation is poor, unless you iframe • Shadow DOM is a subtree within the parent page
  • 14. SHADOW DOM • Shadow Root - root element of DOM subtree • Shadow Host - parent of a shadow root Application DOM Component Shadow DOM
  • 15. SHADOW DOM Creating a Shadow Root // Grab an element var elem = document.querySelector("#good-host"); // Create the shadow root var root = elem.createShadowRoot(); // Create a new element var h1 = document.createElement("h1"); h1.innerHTML = "Hello World"; // Append to the shadow root root.appendChild(h1);
  • 16. SHADOW DOM Add a template to the mix Example: http://codepen.io/TrueNorth/pen/OPBNmq?editors=101 <template id="something"> <h1>Hello, world!</h1> <p>This is part of my component</p> </template> <div id="good-host"></div> // Grab an element var elem = document.querySelector("#good-host"); // Create the shadow root var root = elem.createShadowRoot(); // Grab the template var tmpl = document.querySelector('#something'); // Add the cloned document fragment to the DOM root.appendChild( // Clone the template's document fragment document.importNode(tmpl.content, true) );
  • 17. SHADOW DOM Styling • Style defined/loaded within the shadow DOM only applies to shadow DOM • :host pseudo-selector - for outer element :host { border: 1px solid red; } :host(.hover) { border: 1px solid blue; }
  • 18. SHADOW DOM Styling • The ::shadow pseudo-selector penetrates a shadow root • the /deep/ pseudo-selector penetrates all shadow roots
  • 19. SHADOW DOM Styling .example-host { border: 1px solid purple; padding: 10px; margin: 10px; } #good-host p { color: blue; } #better-host::shadow p { color: red; } #better-host/deep/ h1 { color: cyan; } <template id="something"> <h1>Hello, world!</h1> <p>This is part of my component</p> <content></content> </template> <div id="good-host" class="example-host"></div> <div id="better-host" class="example-host"> <div id="best-host" class="example-host"></div> </div> Example: http://codepen.io/TrueNorth/pen/MYPyOe
  • 20. SHADOW DOM Content Projection • <content> tag to project all content • <content select=“”> to project selected content <template id="something"> <h1><content select=".h1"></content></h1> <p>This is part of my component</p> <content></content> </template> Examples: http://codepen.io/TrueNorth/pen/emPZMv
  • 21. CUSTOM ELEMENTS What’s the point? • Compose larger parts of an app declaratively • Provide a standard and consistent life-cycle • Extensibility
  • 22. CUSTOM ELEMENTS Registering // Extend a DOM element prototype var MegaButtonProto = Object.create(HTMLButtonElement.prototype); // Register your new element type var MegaButton = document.registerElement("mega-button", { prototype: MegaButtonProto, extends: "button" });
  • 23. CUSTOM ELEMENTS Adding templates // Template var infoBoxTemplate = document.querySelector('#info-pane-template'); // Register the custom element var InfoBox = document.registerElement("info-pane", { prototype: Object.create(HTMLElement.prototype, { createdCallback: { value: function () { // Create the shadow root this.createShadowRoot() // Add the template to the shadow root .appendChild( document.importNode( infoBoxTemplate.content, true) ); } } }) }); Examples: http://codepen.io/TrueNorth/pen/gbBmMR
  • 24. HTML IMPORTS • #include for the web • onload, onerror hooks • Can include CSS, JS and HTML • Content can be accessed from the outside • HTML Imported JS can reference either the main DOM or imported document fragment <link rel="import" href="myfile.html" /> // Get document fragment of an import var content = document .querySelector('link[rel="import"]') .import; // From a <script> included, // with the import access, // imported DOM document .currentScript .ownerDocument .querySelector('.abc');
  • 25. A REAL USE CASE • Declarative Syntax • Responds to click <hamburger-menu title="My Menu"> <hb-menu-item href="#abc" caption="Better get on these soon"> Serious Bugs </hb-menu-item> <hb-menu-item href="#def" caption="Oh %#@$!"> Really Serious Bugs </hb-menu-item> </hamburger-menu> Starting Point: http://codepen.io/TrueNorth/pen/PwdLrj Componentized: http://codepen.io/TrueNorth/pen/xbyqME HTML Importified: http://codepen.io/TrueNorth/pen/ogawLm • Content projection • Style on shadow root