SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
Web Components and Modular CSS 
@AndrewRota | CSS Dev Conf 2014
Modularity
UI Libraries
CSS Features 
Encapsulation 
Scope 
Interfaces 
Modularity
Modular CSS Patterns 
BEM 
SMACSS 
Atomic CSS 
OOCSS
BEM 
/* Block */ 
.nav { } 
/* Element */ 
.nav__item { } 
/* Block with Modifier */ 
.nav--hidden { } 
/* Element with Modifier */ 
.nav__item--current { }
SMACSS 
/* Module */ 
.nav { } 
/* Module with State */ 
.nav.is-current { } 
/* Module with Semantic Element Selector */ 
.nav > h2 { } 
/* Layout Style */ 
.l-inline { }
Web Components 
Web Components usher in a 
new era of web development 
based on encapsulated and 
interoperable custom elements 
that extend HTML itself. - Polymer
Web Components APIs 
Custom Elements 
HTML Templates 
HTML Imports 
Shadow DOM
Custom Elements 
<my-element>Hello World.</my-element> 
var MyElement = document.registerElement('my-element', { 
prototype: Object.create(HTMLElement.prototype) 
});
HTML Templates 
<template id="my-template"> 
<p>Hello World.</p> 
<!-- This image won't be downloaded on page load --> 
<img src="example.jpg" alt="Example"> 
</template> 
document.importNode( 
document.getElementById('my-template').content, 
true 
);
HTML Imports 
<link rel="import" href="/imports/my-component.html">
Shadow DOM 
// Create Shadow Root 
document.getElementById('my-element').createShadowRoot(); 
// Access Shadow Root 
document.getElementById('my-element').shadowRoot;
User Agent Shadow DOM 
<video src="#" controls></video> 
0:00
User Agent Shadow DOM 
<input type="date"> 
mm/dd/yyyy
Shadow DOM 
Shadow DOM. 
Light DOM. 
<div id="my-first-element"></div><p>Light DOM.</p> 
// Create Shadow Root 
var s = document.getElementById('my-first-element').createShadowRoot 
// Add Styles and Text 
s.innerHTML += '<style>p { color: crimson; margin: 5px 0 5px 0;}</s.innerHTML += '<p>Shadow DOM.</p>';
Content Insertion Points 
<div id="my-second-element"> 
<content></content> 
</div>
Shadow DOM and <content> 
Shadow DOM Start. 
Hello! 
Shadow DOM End. 
<div id="my-second-element"><p>Hello!</p></div> 
var s = document.getElementById('my-second-element').createShadowRoot 
s.innerHTML += '<p>Shadow DOM Start.</p>'; 
s.innerHTML += '<style>p { color: crimson; margin: 5px 0; }</style>' 
s.innerHTML += '<content></content>'; 
s.innerHTML += '<p>Shadow DOM End.</p>';
Into the Light 
/* pseudo-class for host element*/ 
:host { } 
/* functional pseudo-class, for host if it matches the selector argument :host() { } 
/* functional pseudo-class, for host context that matches selector :host-context() { } 
/* pseudo-element, for distributed notes rendered via a <content> ::content { }
Into the Dark 
/* pseudo-element for shadow roots */ 
::shadow { } 
/* combinator for selecting through shadow boundaries */ 
body /deep/ p { } 
[/deep/] is basically a super-descendant 
combinator. 
- CSS Scoping Module Draft, Issue 6
Let's Write a Component 
Hello world, I am a web component. 
<link rel="import" href="../assets/hello-world.html"> 
<hello-world>I am a <strong>web component</strong></hello-world
Let's Write a Component 
Hello world, I am a web component. 
<template id="hw"> 
<style> 
::content strong { color: crimson; } 
p { margin: 2px 20px 2px 0; } 
:host { border: 1px solid FireBrick; display: block; margin-right 
.hello { color: #91D4D; } 
</style> 
<p><span class="hello">Hello world</span>, <content></content 
</template>
Let's Write a Component 
Hello world, I am a web component. 
var importedDoc = document.currentScript.ownerDocument; 
var elementPrototype = Object.create(HTMLElement.prototype); 
elementPrototype.createdCallback = function() { 
var template = importedDoc.getElementById('hw').content; 
var clone = document.importNode(template, true); 
this.createShadowRoot().appendChild(clone); 
}; 
document.registerElement('hello-world', {prototype: elementPrototype
Can I Use??? 
Custom 
Elements 
HTML 
Templates 
HTML 
Imports 
Shadow 
DOM 
- - - - 
- - - - 
Flag - Flag Flag 
X - X X 
X X X X
Polyfills
When To Use Web Components? 
Third Party Widgets? 
Third Party UI Libraries? 
Internal UI Libraries? 
Web Component All the Things!?
Third Party Widgets 
<google-map 
latitude="29.954356" 
longitude="-90.067863"> 
</google-map>
Third Party UI Libraries 
CSS HTML JS 
<paper-radio-group selected="css"> 
<paper-radio-button name="css" label="CSS"></paper-radio-button 
</paper-radio-group> 
<paper-slider value="10"></paper-slider>
Internal UI Libraries 
<acme-corp--menu> 
<acme-corp--menu-item>Home</acme-corp--menu-item> 
<acme-corp--menu-item selected>About</acme-corp--menu-item> 
<acme-corp--menu-item>Contact Us</acme-corp--menu-item> 
</acme-corp--menu> 
<acme-corp--login-form 
ajax 
url="login.php"> 
</acme-corp--login-form>
Web Component Everything?? 
<acme-corp--app> 
<acme-corp--menu></acme-corp--menu> 
<acme-corp--content></acme-corp--content> 
<acme-corp--footer></acme-corp--footer> 
</acme-corp--app>
Probably Not (and that's OK) 
I don't ever see us going all in 
on Custom Elements for every 
possible thing ... Use native 
elements and controls when 
possible and supplement with 
custom elements. 
- Joshua Peek, Github Programmer
Small 
Open for Extension 
Documented 
Unit Tested 
Accessible 
Responsive 
Best Practices
Tooling
Frameworks
Towards a Component Driven Web
Thanks! 
Resources 
- WebComponents.org 
- Web Components: A Tectonic Shift for Web Development by Eric Bidelman 
- Web Components by Jarrod Overson and Jason Strimpel 
- Ten Principles for Great General Purpose Web Components 
Colophon 
This presentation was built with Shadow DOM, HTML Templates, HTML 
Imports, and the Custom Elements <slide-show> and <slide-content> 
using Web Component Slides.
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS
Web Components and Modular CSS

Weitere ähnliche Inhalte

Was ist angesagt?

Polymer
Polymer Polymer
Polymer
jskvara
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
Imam Raza
 

Was ist angesagt? (20)

Google Polymer Framework
Google Polymer FrameworkGoogle Polymer Framework
Google Polymer Framework
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
Polymer, A Web Component Polyfill Library
Polymer, A Web Component Polyfill LibraryPolymer, A Web Component Polyfill Library
Polymer, A Web Component Polyfill Library
 
Polymer
Polymer Polymer
Polymer
 
Polymer
PolymerPolymer
Polymer
 
Web Components
Web ComponentsWeb Components
Web Components
 
A brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsA brave new web - A talk about Web Components
A brave new web - A talk about Web Components
 
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
 
Web Components & Polymer 1.0 (Webinale Berlin)
Web Components & Polymer 1.0 (Webinale Berlin)Web Components & Polymer 1.0 (Webinale Berlin)
Web Components & Polymer 1.0 (Webinale Berlin)
 
HTML5 - Introduction
HTML5 - IntroductionHTML5 - Introduction
HTML5 - Introduction
 
Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
 
Polymer & the web components revolution 6:25:14
Polymer & the web components revolution 6:25:14Polymer & the web components revolution 6:25:14
Polymer & the web components revolution 6:25:14
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
Web components
Web componentsWeb components
Web components
 
Web Components
Web ComponentsWeb Components
Web Components
 
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
 
Intro to html 5
Intro to html 5Intro to html 5
Intro to html 5
 
Web Components with Polymer (extra Polymer 2.0)
Web Components with Polymer (extra Polymer 2.0)Web Components with Polymer (extra Polymer 2.0)
Web Components with Polymer (extra Polymer 2.0)
 
Custom Elements with Polymer Web Components #econfpsu16
Custom Elements with Polymer Web Components #econfpsu16Custom Elements with Polymer Web Components #econfpsu16
Custom Elements with Polymer Web Components #econfpsu16
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is here
 

Andere mochten auch

Andere mochten auch (20)

Καβάφης Κωνσταντίνος
Καβάφης ΚωνσταντίνοςΚαβάφης Κωνσταντίνος
Καβάφης Κωνσταντίνος
 
ΟΙ ΖΟΥΛΟΥ Παναγιώτα
ΟΙ ΖΟΥΛΟΥ  ΠαναγιώταΟΙ ΖΟΥΛΟΥ  Παναγιώτα
ΟΙ ΖΟΥΛΟΥ Παναγιώτα
 
Mεσαιωνικο καστρο λεμεσου
Mεσαιωνικο καστρο λεμεσουMεσαιωνικο καστρο λεμεσου
Mεσαιωνικο καστρο λεμεσου
 
بحث د عهد حوري
بحث د عهد حوريبحث د عهد حوري
بحث د عهد حوري
 
Μάγια Ζαχαρίας
Μάγια ΖαχαρίαςΜάγια Ζαχαρίας
Μάγια Ζαχαρίας
 
49201940 schaffer-psihologia-copilului-partea-1
49201940 schaffer-psihologia-copilului-partea-149201940 schaffer-psihologia-copilului-partea-1
49201940 schaffer-psihologia-copilului-partea-1
 
Το καστρο της λεμεσου
Το καστρο της λεμεσου Το καστρο της λεμεσου
Το καστρο της λεμεσου
 
What is a startup
What is a startupWhat is a startup
What is a startup
 
Short film festivals
Short film festivalsShort film festivals
Short film festivals
 
Το μεσαιωνικό κάστρο λεμεσού
Το μεσαιωνικό κάστρο λεμεσούΤο μεσαιωνικό κάστρο λεμεσού
Το μεσαιωνικό κάστρο λεμεσού
 
Packpin SV2B presentation
Packpin SV2B presentationPackpin SV2B presentation
Packpin SV2B presentation
 
Passive voive
Passive voivePassive voive
Passive voive
 
3d printing....science....
3d printing....science....3d printing....science....
3d printing....science....
 
ΟΔΟΣ ΔΗΜΟΣΘΕΝΗ ΜΙΤΣΗ ΛΕΜΕΣΟΣ
ΟΔΟΣ ΔΗΜΟΣΘΕΝΗ ΜΙΤΣΗ ΛΕΜΕΣΟΣΟΔΟΣ ΔΗΜΟΣΘΕΝΗ ΜΙΤΣΗ ΛΕΜΕΣΟΣ
ΟΔΟΣ ΔΗΜΟΣΘΕΝΗ ΜΙΤΣΗ ΛΕΜΕΣΟΣ
 
Καβάφης Κωνσταντίνος
Καβάφης ΚωνσταντίνοςΚαβάφης Κωνσταντίνος
Καβάφης Κωνσταντίνος
 
Senarai nama tahun 1 (linus)
Senarai nama tahun 1 (linus)Senarai nama tahun 1 (linus)
Senarai nama tahun 1 (linus)
 
RENNIE COWAN - DIRECTOR REEL
RENNIE COWAN - DIRECTOR REEL RENNIE COWAN - DIRECTOR REEL
RENNIE COWAN - DIRECTOR REEL
 
ΟΔΟΣ Δ. ΜΙΤΣΗ ΛΕΜΕΣΟΣ
ΟΔΟΣ Δ. ΜΙΤΣΗ ΛΕΜΕΣΟΣΟΔΟΣ Δ. ΜΙΤΣΗ ΛΕΜΕΣΟΣ
ΟΔΟΣ Δ. ΜΙΤΣΗ ΛΕΜΕΣΟΣ
 
κάστρο του κολοσσιού
κάστρο του κολοσσιούκάστρο του κολοσσιού
κάστρο του κολοσσιού
 
RENNIE COWAN PHOTOGRAPHY
RENNIE COWAN PHOTOGRAPHYRENNIE COWAN PHOTOGRAPHY
RENNIE COWAN PHOTOGRAPHY
 

Ähnlich wie Web Components and Modular CSS

Front End Good Practices
Front End Good PracticesFront End Good Practices
Front End Good Practices
Hernan Mammana
 

Ähnlich wie Web Components and Modular CSS (20)

Polymer 1.0
Polymer 1.0Polymer 1.0
Polymer 1.0
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Introduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon GauvinIntroduction to Polymer and Firebase - Simon Gauvin
Introduction to Polymer and Firebase - Simon Gauvin
 
Polymer - Lego for the web!
Polymer - Lego for the web!Polymer - Lego for the web!
Polymer - Lego for the web!
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the future
 
Web components
Web componentsWeb components
Web components
 
Up & Running with Polymer
Up & Running with PolymerUp & Running with Polymer
Up & Running with Polymer
 
Web Components: The future of Web Application Development
Web Components: The future of Web Application DevelopmentWeb Components: The future of Web Application Development
Web Components: The future of Web Application Development
 
Devoxx 2014-webComponents
Devoxx 2014-webComponentsDevoxx 2014-webComponents
Devoxx 2014-webComponents
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Polytechnic 1.0 Granada
Polytechnic 1.0 GranadaPolytechnic 1.0 Granada
Polytechnic 1.0 Granada
 
Introduction to web compoents
Introduction to web compoentsIntroduction to web compoents
Introduction to web compoents
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Orchard Harvest 2014 - The Future of Widgets?
Orchard Harvest 2014 - The Future of Widgets?Orchard Harvest 2014 - The Future of Widgets?
Orchard Harvest 2014 - The Future of Widgets?
 
Front End Good Practices
Front End Good PracticesFront End Good Practices
Front End Good Practices
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Polymer Code Lab in Dart - DevFest Kraków 2014
Polymer Code Lab in Dart - DevFest Kraków 2014Polymer Code Lab in Dart - DevFest Kraków 2014
Polymer Code Lab in Dart - DevFest Kraków 2014
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 

Mehr von Andrew Rota

Mehr von Andrew Rota (16)

Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
 
Getting Started with GraphQL && PHP
Getting Started with GraphQL && PHPGetting Started with GraphQL && PHP
Getting Started with GraphQL && PHP
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
Component Based UI Architectures for the Web
Component Based UI Architectures for the WebComponent Based UI Architectures for the Web
Component Based UI Architectures for the Web
 
Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Effectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side PerformanceEffectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side Performance
 
UI Rendering at Wayfair
UI Rendering at WayfairUI Rendering at Wayfair
UI Rendering at Wayfair
 
Better PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.jsBetter PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.js
 
Tungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular FrameworkTungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular Framework
 
Why Static Type Checking is Better
Why Static Type Checking is BetterWhy Static Type Checking is Better
Why Static Type Checking is Better
 
An Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our OwnAn Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our Own
 
Bem methodology
Bem methodologyBem methodology
Bem methodology
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Web Components and Modular CSS

  • 1. Web Components and Modular CSS @AndrewRota | CSS Dev Conf 2014
  • 4. CSS Features Encapsulation Scope Interfaces Modularity
  • 5. Modular CSS Patterns BEM SMACSS Atomic CSS OOCSS
  • 6. BEM /* Block */ .nav { } /* Element */ .nav__item { } /* Block with Modifier */ .nav--hidden { } /* Element with Modifier */ .nav__item--current { }
  • 7. SMACSS /* Module */ .nav { } /* Module with State */ .nav.is-current { } /* Module with Semantic Element Selector */ .nav > h2 { } /* Layout Style */ .l-inline { }
  • 8. Web Components Web Components usher in a new era of web development based on encapsulated and interoperable custom elements that extend HTML itself. - Polymer
  • 9. Web Components APIs Custom Elements HTML Templates HTML Imports Shadow DOM
  • 10. Custom Elements <my-element>Hello World.</my-element> var MyElement = document.registerElement('my-element', { prototype: Object.create(HTMLElement.prototype) });
  • 11. HTML Templates <template id="my-template"> <p>Hello World.</p> <!-- This image won't be downloaded on page load --> <img src="example.jpg" alt="Example"> </template> document.importNode( document.getElementById('my-template').content, true );
  • 12. HTML Imports <link rel="import" href="/imports/my-component.html">
  • 13. Shadow DOM // Create Shadow Root document.getElementById('my-element').createShadowRoot(); // Access Shadow Root document.getElementById('my-element').shadowRoot;
  • 14. User Agent Shadow DOM <video src="#" controls></video> 0:00
  • 15. User Agent Shadow DOM <input type="date"> mm/dd/yyyy
  • 16. Shadow DOM Shadow DOM. Light DOM. <div id="my-first-element"></div><p>Light DOM.</p> // Create Shadow Root var s = document.getElementById('my-first-element').createShadowRoot // Add Styles and Text s.innerHTML += '<style>p { color: crimson; margin: 5px 0 5px 0;}</s.innerHTML += '<p>Shadow DOM.</p>';
  • 17. Content Insertion Points <div id="my-second-element"> <content></content> </div>
  • 18. Shadow DOM and <content> Shadow DOM Start. Hello! Shadow DOM End. <div id="my-second-element"><p>Hello!</p></div> var s = document.getElementById('my-second-element').createShadowRoot s.innerHTML += '<p>Shadow DOM Start.</p>'; s.innerHTML += '<style>p { color: crimson; margin: 5px 0; }</style>' s.innerHTML += '<content></content>'; s.innerHTML += '<p>Shadow DOM End.</p>';
  • 19. Into the Light /* pseudo-class for host element*/ :host { } /* functional pseudo-class, for host if it matches the selector argument :host() { } /* functional pseudo-class, for host context that matches selector :host-context() { } /* pseudo-element, for distributed notes rendered via a <content> ::content { }
  • 20. Into the Dark /* pseudo-element for shadow roots */ ::shadow { } /* combinator for selecting through shadow boundaries */ body /deep/ p { } [/deep/] is basically a super-descendant combinator. - CSS Scoping Module Draft, Issue 6
  • 21. Let's Write a Component Hello world, I am a web component. <link rel="import" href="../assets/hello-world.html"> <hello-world>I am a <strong>web component</strong></hello-world
  • 22. Let's Write a Component Hello world, I am a web component. <template id="hw"> <style> ::content strong { color: crimson; } p { margin: 2px 20px 2px 0; } :host { border: 1px solid FireBrick; display: block; margin-right .hello { color: #91D4D; } </style> <p><span class="hello">Hello world</span>, <content></content </template>
  • 23. Let's Write a Component Hello world, I am a web component. var importedDoc = document.currentScript.ownerDocument; var elementPrototype = Object.create(HTMLElement.prototype); elementPrototype.createdCallback = function() { var template = importedDoc.getElementById('hw').content; var clone = document.importNode(template, true); this.createShadowRoot().appendChild(clone); }; document.registerElement('hello-world', {prototype: elementPrototype
  • 24. Can I Use??? Custom Elements HTML Templates HTML Imports Shadow DOM - - - - - - - - Flag - Flag Flag X - X X X X X X
  • 26. When To Use Web Components? Third Party Widgets? Third Party UI Libraries? Internal UI Libraries? Web Component All the Things!?
  • 27. Third Party Widgets <google-map latitude="29.954356" longitude="-90.067863"> </google-map>
  • 28. Third Party UI Libraries CSS HTML JS <paper-radio-group selected="css"> <paper-radio-button name="css" label="CSS"></paper-radio-button </paper-radio-group> <paper-slider value="10"></paper-slider>
  • 29. Internal UI Libraries <acme-corp--menu> <acme-corp--menu-item>Home</acme-corp--menu-item> <acme-corp--menu-item selected>About</acme-corp--menu-item> <acme-corp--menu-item>Contact Us</acme-corp--menu-item> </acme-corp--menu> <acme-corp--login-form ajax url="login.php"> </acme-corp--login-form>
  • 30. Web Component Everything?? <acme-corp--app> <acme-corp--menu></acme-corp--menu> <acme-corp--content></acme-corp--content> <acme-corp--footer></acme-corp--footer> </acme-corp--app>
  • 31. Probably Not (and that's OK) I don't ever see us going all in on Custom Elements for every possible thing ... Use native elements and controls when possible and supplement with custom elements. - Joshua Peek, Github Programmer
  • 32. Small Open for Extension Documented Unit Tested Accessible Responsive Best Practices
  • 35. Towards a Component Driven Web
  • 36. Thanks! Resources - WebComponents.org - Web Components: A Tectonic Shift for Web Development by Eric Bidelman - Web Components by Jarrod Overson and Jason Strimpel - Ten Principles for Great General Purpose Web Components Colophon This presentation was built with Shadow DOM, HTML Templates, HTML Imports, and the Custom Elements <slide-show> and <slide-content> using Web Component Slides.