SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
Componentization:
CSS & Angular
David Amend @
Typical Angular project
https://angular.io/guide/styleguide#overall-structural-guidelines
> ng generate component mycomponent
CREATE src/app/componentB/componentB.component.html (30 bytes)
CREATE src/app/componentB/componentB.component.spec.ts (663 bytes)
CREATE src/app/componentB/componentB.component.ts (290 bytes)
CREATE src/app/componentB/componentB.component.scss (0 bytes)
UPDATE src/app/app.module.ts (10744 bytes)
CSS
- Where?
- Reuse?
- Componentize?
CSS in angular business component
#contact-form {
.navigation-buttons {
height: 71px;
padding-top: 30px;
position: relative;
.c-FormLinkButton {
line-height: 41px;
}
> div {
display: inline-block;
vertical-align: middle;
&:last-child {
position: absolute;
right: 0;
}}}
@media only screen and
(max-width: $mobile-max-width) {
.navigation-buttons {
height: 160px;
.c-FormLinkButton {
height: 50px;
line-height: 50px;
}
.c-MobileButton--secondary {
bottom: 10px;
position: absolute;
> a > span {
display: none;
}}
.c-FormButton--next {
top: 30px;
}}}
.target-form /deep/ {
button {
background-color: #1980d0;
border: 0;
border-radius: 3px;
color: #fff;
cursor: pointer;
font-size: 14px;
font-weight: bold;
font-family: Arial, sans-serif;
height: 39px;
min-width: 156px;
padding: 0 20px;
width: 290px;
}
.cta {
margin: 15px 0 15px 0;
}
}
@media screen and
(max-width: $mobile-max-width) {
button {
font-size: 18px;
font-weight: normal;
height: 50px;
width: 100%;
}
.pq .aw-wrapper-webui-de header.aw-pagehead
.aw-pagehead-meta.aw-bg-is-complex .aw-pagehead-metanav .aw-delimiter button {
color: #FE2E2E
}
Bad CSS quality & no reuse
Agenda
1. Style isolation/WC support by Angular
2. CSS Basic Rules
3. Summary
What is your level of CSS skills?
???
???
???
???
Novice
Expert
Angulars
Emulated View Encapsulation
(no Shadow DOM)
- _nghost-c*
- host-(element)
- host-context(.theme)
- ::ng-deepNative
Emulated
None
Angulars
Emulated View Encapsulation
(no Shadow DOM)
Example: setup
@Component({
selector: 'blue-button',
template: ` <h2>Blue</h2>
<button class="blue-button">click </button>`,
styles: [`
.blue-button {
color: blue;
}
h2 { font-size: 2rem;}
`]
}) export class BlueButtonComponent { }
@Component({
selector: 'app-root',
styleUrls:['./app.component.css'],
template: ` <h2>Buttons</h2>
<button class="red-button">click</button>
<blue-button></blue-button>
`})
export class AppComponent {
...
}
Example: Compiled, ngcontent
<app-root _nghost-c0="">
<h2 _ngcontent-c0="">Buttons</h2>
<button _ngcontent-c0="" class="red-button">Button</button>
<blue-button _nghost-c1="" _ngcontent-c0="">
<h2 _ngcontent-c1="">Blue</h2>
<button _ngcontent-c1="" class="blue-button">click</button>
</blue-button>
</app-root>
<style>
.blue-button[_ngcontent-c1] {
color: blue;
}
h2[_ngcontent-c1] {
font-size: 2rem;
}
</style>
.blue-button {
color:blue;
}
h2 { font-size: 2rem;}
:host(.red) h2 {
color: red;
}
<app-root _nghost-c0="">
<h2 _ngcontent-c0="">Button</h2>
<blue-button class=”red” _nghost-c1="" _ngcontent-c0="">
<h2 _ngcontent-c1="">Button</h2>
...
</app-root>
[_nghost-c1] h2[_ngcontent-c1] {
color: red;
}
:host {
padding: 20px;
}
[_nghost-c1] {
padding: 20px;
}
@Component({
selector: 'themeable-button',
template: `
<button>Themeable Button </button>`
, styles: [`
:host-context(.red-theme) button{
background: red;
}
:host-context(.blue-theme) button {
background: blue;
}`]
}) export class ThemeableButtonComponent {}
<root-context class="blue-theme">
<childs> …
<childs>
<themeable-button></themeable-button>
<childs>
</childs>
</root-context>
.blue-theme[_nghost-c1] button[_ngcontent-c1],
.blue-theme [_nghost-c1] button[_ngcontent-c1] {
background: blue;
}
ng-deep
:host ::ng-deep h2
{
color: black;
}
[_nghost-c1] h2 {
color: black;
}
Native
<app-root _nghost-c0="">
<h2 _ngcontent-c0="">Button</h2>
<blue-button class=”red” _nghost-c1="" _ngcontent-c0="">
<h2 _ngcontent-c1="">Button</h2>
...
</app-root>
Shadow Piercing combinators
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13348719/
https://medium.com/@andreygoncharov/edge-hates-you-attributes-d15faf162939
mike k. Oct 10, 2017
Please, increase the priority of the issue.
The thing is Angular 2+ uses attributes to apply emulated
view encapsulation.
So the application performance may slow down when scaling.
Francois R. Jan 8, 2018 MICROSOFT EDGE TEAM
FYI, some performance improvements in this scenario should start to appear in the next release of Edge as we
improved some key scenarios. We don’t want to claim this issue is fixed yet because we aren’t on par with the other
browsers in all scenarios yet, so we will keep this issue open despite the current improvements, and will report any
further improvement towards our goal in the future as we get the opportunity to work on this further.
Web Components: Acceptance & Performance
<input type="date" name="bday">
<gold-cc-cvc-input card-type="amex"></gold-cc-cvc-input>
<progress value="1" max="4"></progress>
Step 2/4
→ iFrame alternative
→ framework-independant components
→ non corporate design
<video>
http://vic.github.io/prefix-css/
.angular-cli.json
"defaults": {
"component": {
"viewEncapsulation":
"None"
}
CSS Encapsulation: When?
.btn .btn-primary
.btn-xs-block
.btn btn-secondary
.cancel-button
.btn
.loading-contact-button
Problems
→ DOM specific rendering
→ no control of your styles
→ unstructured style components
- CSS first components
- Modular & Extendable by SCSS/Less
→ OOCSS
→ BEM
→ SMACSS
OOCSS
Object Oriented CSS
https://css-tricks.com/methods-organize-css/
Keep structure and skin separate
OOCSS: Structure & Style
<a href="#" class="btn btn-primary btn-lg disabled">click</a>
<a href="#" class="login-submit-button-disabled">Yes</a>
Style Structure
.btn {
display: inline-block;
font-weight: $btn-font-weight;
text-align: center;
white-space: nowrap;
vertical-align: middle;
user-select: none;
border: $btn-border-width solid transparent;
@include button-size($btn-padding-y, $btn-padding-x, $font-size-base, $btn-line-height, $btn-border-radius);
@include transition($btn-transition);
@each $color, $value in $theme-colors {
.btn-#{$color} {
@include button-variant($value, $value);
}
}
&.disabled,
&:disabled {
opacity: $btn-disabled-opacity;
@include box-shadow(none);
}
.row {
@include make-row();
}
> .col,
> [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
}
+ Flex
Separate container and content
<div class=”row”>
<span class=”col-8”>Are you sure?</span>
<a href="#" class="col-4 btn btn-primary btn-lg disabled">click</a>
</div>
ContentContainer
<div>
<span style=”width:60%;”>Are you sure?</span>
<a href="#" class="login-submit-button-disabled">Yes</a>
</div>
OOCSS: Container & Content
Depth of Applicability (DOA) → parent dependencies
Specifity → Which rule is actually applied?
button {
padding: 5px;
}
.btn {
padding: 10px;
}
.btn-lg {
padding: 10px;
}
.btn-xxl {
padding: 20px;
}
https://specificity.keegan.st/
https://jonassebastianohlsson.com/specificity-graph/
https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css
https://www.hypovereinsbank.de/etc/designs/hypovereinsbank/css/public.min.css
#sidebar div > button {
padding: 10px;
}
#sidebar div > div.border button.lg {
padding: 20px;
}
BEM
Block, Element, Modifier
<button class="btn">
<div class="btn__dropdown">
<a class="btn__dropdown__li
btn--disabled"
href="#">delete</a>
</div>
</button>
.block {}
.block__element {}
.block--modifier {}
<button class="btn">
<div class="btn__dropdown">
<a class="btn__li
btn--disabled"
href="#">delete</a>
</div>
</button>
.btn {}
.btn__dropdown {}
.btn--disabled {}
SMACSS
Scalable & Modular
Architecture for CSS
SMACSS—Scalable and Modular Architecture for CSS
● vendor/
○ _bootstrap.scss
● base/
○ _functions.scss
○ _mixins.scss
○ _variables.scss
○ _base.scss
■ state
● layout/
○ _grid.scss
○ _header.scss
○ _sidebar.scss
● main.scss
● module/
○ _navigations.scss
■ main-nav
● state
■ sub-nav
■ side-nav
○ _buttons.scss
■ state
○ _forms.scss
→ Separation of Style-Components
→ Style-State-directives
→ ViewEncapsulation.None
Use case considerations of CSS architecture
- Small application
- CSS-skills vary in team
- Integrate multiple frameworks
- Static content pages
Recap
- Corporate Design required. Performance restricted.
.angular-cli.json
"defaults": {
"component": {
"viewEncapsulation":
"None"
}
- Separation of Concerns
- /src/shared/styles/grid[fonts] Style Only Components
- /src/core/functions Angular Functional Components
- /src/core/styles/button/button.scss Style Component
- /src/core/styles/button/button.direcive.ts Angular Style-Support Component
- /src/app/ Angular Business Components
- Write Clean CSS code by OOCSS, BEM, SMACSS
Any Questions?

Contenu connexe

Tendances

Tendances (18)

Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworks
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
 
Work and play with SASS & Compass
Work and play with SASS & CompassWork and play with SASS & Compass
Work and play with SASS & Compass
 
Worth the hype - styled components
Worth the hype - styled componentsWorth the hype - styled components
Worth the hype - styled components
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programs
 
Finding a Better Way to CSS: Navigating Sass with Compass
Finding a Better Way to CSS: Navigating Sass with CompassFinding a Better Way to CSS: Navigating Sass with Compass
Finding a Better Way to CSS: Navigating Sass with Compass
 
$.Template
$.Template$.Template
$.Template
 
Document
DocumentDocument
Document
 
Shortcodes In-Depth
Shortcodes In-DepthShortcodes In-Depth
Shortcodes In-Depth
 
Routing System In Symfony 1.2
Routing System In Symfony 1.2Routing System In Symfony 1.2
Routing System In Symfony 1.2
 
Profit statement 00
Profit statement 00Profit statement 00
Profit statement 00
 
Teddy Bear Blue
Teddy Bear BlueTeddy Bear Blue
Teddy Bear Blue
 
12121212
1212121212121212
12121212
 
Imageslider
ImagesliderImageslider
Imageslider
 
WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
Date difference[1]
Date difference[1]Date difference[1]
Date difference[1]
 
Drawing images
Drawing imagesDrawing images
Drawing images
 

Similaire à Componentization css angular

My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docxMy discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
gilpinleeanna
 
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docxcssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
faithxdunce63732
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Even Wu
 

Similaire à Componentization css angular (20)

Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
 
Intro to CSS
Intro to CSSIntro to CSS
Intro to CSS
 
Polymer 1.0
Polymer 1.0Polymer 1.0
Polymer 1.0
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with Angular
 
Start your app the better way with Styled System
Start your app the better way with Styled SystemStart your app the better way with Styled System
Start your app the better way with Styled System
 
CSS in React - Will Change Transform
CSS in React - Will Change TransformCSS in React - Will Change Transform
CSS in React - Will Change Transform
 
Resume
ResumeResume
Resume
 
Resume
ResumeResume
Resume
 
Resume
ResumeResume
Resume
 
Webtech File.docx
Webtech File.docxWebtech File.docx
Webtech File.docx
 
The road to &lt;> styled-components: CSS in component-based systems by Max S...
The road to &lt;> styled-components: CSS in component-based systems by Max S...The road to &lt;> styled-components: CSS in component-based systems by Max S...
The road to &lt;> styled-components: CSS in component-based systems by Max S...
 
[ WrocLoveRb 2012] user perspective testing using ruby
[ WrocLoveRb 2012] user perspective testing using ruby[ WrocLoveRb 2012] user perspective testing using ruby
[ WrocLoveRb 2012] user perspective testing using ruby
 
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docxMy discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
 
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docxcssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
 
Responsive Web Design e a Ubiquidade da Web
Responsive Web Design e a Ubiquidade da WebResponsive Web Design e a Ubiquidade da Web
Responsive Web Design e a Ubiquidade da Web
 
LessCSS Presentation @ April 2015 GTALUG Meeting
LessCSS Presentation @ April 2015 GTALUG MeetingLessCSS Presentation @ April 2015 GTALUG Meeting
LessCSS Presentation @ April 2015 GTALUG Meeting
 
Presentation html5 css3 by thibaut
Presentation html5 css3 by thibautPresentation html5 css3 by thibaut
Presentation html5 css3 by thibaut
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
Sass Essentials
Sass EssentialsSass Essentials
Sass Essentials
 
Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3
 

Plus de David Amend

Multi modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsMulti modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.js
David Amend
 

Plus de David Amend (14)

Angular 2 : learn TypeScript already with Angular 1
Angular 2 : learn TypeScript already with Angular 1Angular 2 : learn TypeScript already with Angular 1
Angular 2 : learn TypeScript already with Angular 1
 
Performance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomasPerformance monitoring measurement angualrjs single page apps with phantomas
Performance monitoring measurement angualrjs single page apps with phantomas
 
Angularjs practical project experiences with javascript development in a bank
Angularjs practical project experiences with javascript development in a bankAngularjs practical project experiences with javascript development in a bank
Angularjs practical project experiences with javascript development in a bank
 
Story about module management with angular.js
Story about module management with angular.jsStory about module management with angular.js
Story about module management with angular.js
 
Multi modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsMulti modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.js
 
Reasons to migrate to modern web development with JavaScript
Reasons to migrate to modern web development with JavaScriptReasons to migrate to modern web development with JavaScript
Reasons to migrate to modern web development with JavaScript
 
Thin Server Architecture SPA, 5 years old presentation
Thin Server Architecture SPA, 5 years old presentationThin Server Architecture SPA, 5 years old presentation
Thin Server Architecture SPA, 5 years old presentation
 
Javascript & Angular .js for the enterprise, lessons learned, typescript scal...
Javascript & Angular .js for the enterprise, lessons learned, typescript scal...Javascript & Angular .js for the enterprise, lessons learned, typescript scal...
Javascript & Angular .js for the enterprise, lessons learned, typescript scal...
 
Grunt Advanced Vol 2, Plugins Text I/O with fun
Grunt Advanced Vol 2, Plugins Text I/O with funGrunt Advanced Vol 2, Plugins Text I/O with fun
Grunt Advanced Vol 2, Plugins Text I/O with fun
 
Client Vs. Server Rendering
Client Vs. Server RenderingClient Vs. Server Rendering
Client Vs. Server Rendering
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
 
Grunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
Grunt js for the Enterprise Vol.1: Frontend Performance with PhantomasGrunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
Grunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
 
Gwt widget frameworks_presentation
Gwt widget frameworks_presentationGwt widget frameworks_presentation
Gwt widget frameworks_presentation
 
Grunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous Integration
 

Dernier

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Dernier (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

Componentization css angular

  • 2. Typical Angular project https://angular.io/guide/styleguide#overall-structural-guidelines > ng generate component mycomponent CREATE src/app/componentB/componentB.component.html (30 bytes) CREATE src/app/componentB/componentB.component.spec.ts (663 bytes) CREATE src/app/componentB/componentB.component.ts (290 bytes) CREATE src/app/componentB/componentB.component.scss (0 bytes) UPDATE src/app/app.module.ts (10744 bytes) CSS - Where? - Reuse? - Componentize?
  • 3. CSS in angular business component #contact-form { .navigation-buttons { height: 71px; padding-top: 30px; position: relative; .c-FormLinkButton { line-height: 41px; } > div { display: inline-block; vertical-align: middle; &:last-child { position: absolute; right: 0; }}} @media only screen and (max-width: $mobile-max-width) { .navigation-buttons { height: 160px; .c-FormLinkButton { height: 50px; line-height: 50px; } .c-MobileButton--secondary { bottom: 10px; position: absolute; > a > span { display: none; }} .c-FormButton--next { top: 30px; }}} .target-form /deep/ { button { background-color: #1980d0; border: 0; border-radius: 3px; color: #fff; cursor: pointer; font-size: 14px; font-weight: bold; font-family: Arial, sans-serif; height: 39px; min-width: 156px; padding: 0 20px; width: 290px; } .cta { margin: 15px 0 15px 0; } } @media screen and (max-width: $mobile-max-width) { button { font-size: 18px; font-weight: normal; height: 50px; width: 100%; }
  • 4. .pq .aw-wrapper-webui-de header.aw-pagehead .aw-pagehead-meta.aw-bg-is-complex .aw-pagehead-metanav .aw-delimiter button { color: #FE2E2E } Bad CSS quality & no reuse
  • 5. Agenda 1. Style isolation/WC support by Angular 2. CSS Basic Rules 3. Summary
  • 6. What is your level of CSS skills? ??? ??? ??? ??? Novice Expert
  • 8. - _nghost-c* - host-(element) - host-context(.theme) - ::ng-deepNative Emulated None Angulars Emulated View Encapsulation (no Shadow DOM)
  • 9. Example: setup @Component({ selector: 'blue-button', template: ` <h2>Blue</h2> <button class="blue-button">click </button>`, styles: [` .blue-button { color: blue; } h2 { font-size: 2rem;} `] }) export class BlueButtonComponent { } @Component({ selector: 'app-root', styleUrls:['./app.component.css'], template: ` <h2>Buttons</h2> <button class="red-button">click</button> <blue-button></blue-button> `}) export class AppComponent { ... }
  • 10. Example: Compiled, ngcontent <app-root _nghost-c0=""> <h2 _ngcontent-c0="">Buttons</h2> <button _ngcontent-c0="" class="red-button">Button</button> <blue-button _nghost-c1="" _ngcontent-c0=""> <h2 _ngcontent-c1="">Blue</h2> <button _ngcontent-c1="" class="blue-button">click</button> </blue-button> </app-root> <style> .blue-button[_ngcontent-c1] { color: blue; } h2[_ngcontent-c1] { font-size: 2rem; } </style> .blue-button { color:blue; } h2 { font-size: 2rem;}
  • 11. :host(.red) h2 { color: red; } <app-root _nghost-c0=""> <h2 _ngcontent-c0="">Button</h2> <blue-button class=”red” _nghost-c1="" _ngcontent-c0=""> <h2 _ngcontent-c1="">Button</h2> ... </app-root> [_nghost-c1] h2[_ngcontent-c1] { color: red; } :host { padding: 20px; } [_nghost-c1] { padding: 20px; }
  • 12. @Component({ selector: 'themeable-button', template: ` <button>Themeable Button </button>` , styles: [` :host-context(.red-theme) button{ background: red; } :host-context(.blue-theme) button { background: blue; }`] }) export class ThemeableButtonComponent {} <root-context class="blue-theme"> <childs> … <childs> <themeable-button></themeable-button> <childs> </childs> </root-context> .blue-theme[_nghost-c1] button[_ngcontent-c1], .blue-theme [_nghost-c1] button[_ngcontent-c1] { background: blue; }
  • 13. ng-deep :host ::ng-deep h2 { color: black; } [_nghost-c1] h2 { color: black; } Native <app-root _nghost-c0=""> <h2 _ngcontent-c0="">Button</h2> <blue-button class=”red” _nghost-c1="" _ngcontent-c0=""> <h2 _ngcontent-c1="">Button</h2> ... </app-root> Shadow Piercing combinators
  • 14. https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13348719/ https://medium.com/@andreygoncharov/edge-hates-you-attributes-d15faf162939 mike k. Oct 10, 2017 Please, increase the priority of the issue. The thing is Angular 2+ uses attributes to apply emulated view encapsulation. So the application performance may slow down when scaling. Francois R. Jan 8, 2018 MICROSOFT EDGE TEAM FYI, some performance improvements in this scenario should start to appear in the next release of Edge as we improved some key scenarios. We don’t want to claim this issue is fixed yet because we aren’t on par with the other browsers in all scenarios yet, so we will keep this issue open despite the current improvements, and will report any further improvement towards our goal in the future as we get the opportunity to work on this further.
  • 15. Web Components: Acceptance & Performance <input type="date" name="bday"> <gold-cc-cvc-input card-type="amex"></gold-cc-cvc-input> <progress value="1" max="4"></progress> Step 2/4
  • 16. → iFrame alternative → framework-independant components → non corporate design <video> http://vic.github.io/prefix-css/ .angular-cli.json "defaults": { "component": { "viewEncapsulation": "None" } CSS Encapsulation: When? .btn .btn-primary .btn-xs-block .btn btn-secondary .cancel-button .btn .loading-contact-button Problems → DOM specific rendering → no control of your styles → unstructured style components
  • 17. - CSS first components - Modular & Extendable by SCSS/Less → OOCSS → BEM → SMACSS
  • 20. OOCSS: Structure & Style <a href="#" class="btn btn-primary btn-lg disabled">click</a> <a href="#" class="login-submit-button-disabled">Yes</a> Style Structure
  • 21. .btn { display: inline-block; font-weight: $btn-font-weight; text-align: center; white-space: nowrap; vertical-align: middle; user-select: none; border: $btn-border-width solid transparent; @include button-size($btn-padding-y, $btn-padding-x, $font-size-base, $btn-line-height, $btn-border-radius); @include transition($btn-transition); @each $color, $value in $theme-colors { .btn-#{$color} { @include button-variant($value, $value); } } &.disabled, &:disabled { opacity: $btn-disabled-opacity; @include box-shadow(none); } .row { @include make-row(); } > .col, > [class*="col-"] { padding-right: 0; padding-left: 0; } } + Flex
  • 22. Separate container and content <div class=”row”> <span class=”col-8”>Are you sure?</span> <a href="#" class="col-4 btn btn-primary btn-lg disabled">click</a> </div> ContentContainer <div> <span style=”width:60%;”>Are you sure?</span> <a href="#" class="login-submit-button-disabled">Yes</a> </div>
  • 23. OOCSS: Container & Content Depth of Applicability (DOA) → parent dependencies Specifity → Which rule is actually applied? button { padding: 5px; } .btn { padding: 10px; } .btn-lg { padding: 10px; } .btn-xxl { padding: 20px; } https://specificity.keegan.st/ https://jonassebastianohlsson.com/specificity-graph/ https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css https://www.hypovereinsbank.de/etc/designs/hypovereinsbank/css/public.min.css #sidebar div > button { padding: 10px; } #sidebar div > div.border button.lg { padding: 20px; }
  • 25. <button class="btn"> <div class="btn__dropdown"> <a class="btn__dropdown__li btn--disabled" href="#">delete</a> </div> </button> .block {} .block__element {} .block--modifier {} <button class="btn"> <div class="btn__dropdown"> <a class="btn__li btn--disabled" href="#">delete</a> </div> </button> .btn {} .btn__dropdown {} .btn--disabled {}
  • 27. SMACSS—Scalable and Modular Architecture for CSS ● vendor/ ○ _bootstrap.scss ● base/ ○ _functions.scss ○ _mixins.scss ○ _variables.scss ○ _base.scss ■ state ● layout/ ○ _grid.scss ○ _header.scss ○ _sidebar.scss ● main.scss ● module/ ○ _navigations.scss ■ main-nav ● state ■ sub-nav ■ side-nav ○ _buttons.scss ■ state ○ _forms.scss
  • 28. → Separation of Style-Components → Style-State-directives → ViewEncapsulation.None
  • 29. Use case considerations of CSS architecture - Small application - CSS-skills vary in team - Integrate multiple frameworks - Static content pages
  • 30. Recap - Corporate Design required. Performance restricted. .angular-cli.json "defaults": { "component": { "viewEncapsulation": "None" } - Separation of Concerns - /src/shared/styles/grid[fonts] Style Only Components - /src/core/functions Angular Functional Components - /src/core/styles/button/button.scss Style Component - /src/core/styles/button/button.direcive.ts Angular Style-Support Component - /src/app/ Angular Business Components - Write Clean CSS code by OOCSS, BEM, SMACSS