Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 887324a

Browse files
committed
docs(component-styles): new guide chapter - ward's tweaks
1 parent 5f3232a commit 887324a

11 files changed

+43
-39
lines changed

public/docs/_examples/component-styles/ts/app/hero-app-main.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ import {QuestSummaryComponent} from './quest-summary.component';
1515
directives: [HeroDetailsComponent, HeroControlsComponent, QuestSummaryComponent]
1616
})
1717
export class HeroAppMainComponent {
18-
@Input() hero:Hero;
18+
@Input() hero: Hero;
1919
}

public/docs/_examples/component-styles/ts/app/hero-app.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {HeroAppMainComponent} from './hero-app-main.component';
1414
`],
1515
directives: [HeroAppMainComponent]
1616
})
17-
export class HeroAppComponent {
1817
// #enddocregion
18+
export class HeroAppComponent {
1919
hero = new Hero(
2020
'Human Torch',
2121
['Mister Fantastic', 'Invisible Woman', 'Thing']

public/docs/_examples/component-styles/ts/app/hero-controls.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {Hero} from './hero';
1515
<button (click)="activate()">Activate</button>
1616
`
1717
})
18-
export class HeroControlsComponent {
1918
// #enddocregion inlinestyles
19+
export class HeroControlsComponent {
2020

21-
@Input() hero:Hero;
21+
@Input() hero: Hero;
2222

2323
activate() {
2424
this.hero.active = true;

public/docs/_examples/component-styles/ts/app/hero-team.component.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import {Hero} from './hero';
1111
<li *ngFor="#member of hero.team">
1212
{{member}}
1313
</li>
14-
</ul>
15-
`
14+
</ul>`
1615
})
17-
export class HeroTeamComponent {
1816
// #enddocregion stylelink
19-
20-
@Input() hero:Hero;
17+
export class HeroTeamComponent {
18+
@Input() hero: Hero;
2119
}

public/docs/_examples/component-styles/ts/app/quest-summary.component.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Component, ViewEncapsulation} from 'angular2/core';
55
// Let TypeScript know about the special SystemJS __moduleName variable
66
declare var __moduleName: string;
77
// #enddocregion
8-
// moduleName doesn't work on Plunkr, set it explicitly
8+
// moduleName is not set in many module loaders; set it explicitly
99
if (!__moduleName) {
1010
__moduleName = `http://${location.host}/${location.pathname}/app/`;
1111
}
@@ -16,8 +16,13 @@ if (!__moduleName) {
1616
selector: 'quest-summary',
1717
template: 'No quests ongoing',
1818
styleUrls: ['quest-summary.component.css'],
19-
})
20-
export class QuestSummaryComponent {
19+
encapsulation: ViewEncapsulation.Emulated // default
20+
/*
21+
// #docregion encapsulation.native
22+
encapsulation: ViewEncapsulation.Native // warning: little browser support at this time
23+
// #enddocregion encapsulation.native
24+
*/
2125

22-
}
26+
})
27+
export class QuestSummaryComponent { }
2328
// #enddocregion

public/docs/_examples/component-styles/ts/app/quest-summary.native.component.css

-12
This file was deleted.

public/docs/dart/latest/guide/_data.json

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
"intro": "Attribute directives attach behavior to elements."
6363
},
6464

65+
"component-styles": {
66+
"title": "Component Styles",
67+
"intro": "Learn how to apply CSS styles to components."
68+
},
69+
6570
"hierarchical-dependency-injection": {
6671
"title": "Hierarchical Dependency Injectors",
6772
"navTitle": "Hierarchical Injectors",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!= partial("../../../_includes/_ts-temp")

public/docs/js/latest/guide/_data.json

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
"intro": "Attribute directives attach behavior to elements."
6363
},
6464

65+
"component-styles": {
66+
"title": "Component Styles",
67+
"intro": "Learn how to apply CSS styles to components."
68+
},
69+
6570
"hierarchical-dependency-injection": {
6671
"title": "Hierarchical Dependency Injectors",
6772
"navTitle": "Hierarchical Injectors",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!= partial("../../../_includes/_ts-temp")

public/docs/ts/latest/guide/component-styles.jade

+15-14
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ include ../_util-fns
1616
* [Using Component Styles](#using-component-styles)
1717
* [Loading Styles into Components](#loading-styles-into-components)
1818
* [Controlling View Encapsulation: Emulated, Native, and None](#controlling-view-encapsulation-native-emulated-and-none)
19-
* [Appendix 1: Inspecting the generated runtime component styles](#appendix-1-inspecting-the-css-generated-in-emulated-view-encapsulation)
20-
* [Appendix 2: Loading Styles with Relative URLs](#appendix-2-loading-styles-with-relative-urls)
19+
* [Appendix 1: Inspecting the generated runtime component styles](#inspect-generated-css)
20+
* [Appendix 2: Loading Styles with Relative URLs](#load-styles-with-relative-urls)
2121

2222
**[Run the live code](/resources/live-examples/component-styles/ts/plnkr.html)
2323
shown in this chapter.**
@@ -191,33 +191,33 @@ include ../_util-fns
191191
As described above, the CSS styles of a component are *encapsulated* into its own view and do
192192
not affect the rest of the application.
193193

194-
We can actually control how this encapsulation happens, and we can do that on a component per
195-
component basis. This is done by setting the *view encapsulation mode* of each component. There
196-
are three modes we can choose from:
194+
We can actually control how this encapsulation happens, and we can do that on a *per
195+
component* basis by setting the *view encapsulation mode* in the component metadata. There
196+
are three modes to choose from:
197197

198198
* `Native` view encapsulation uses the browser's native [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM)
199199
implementation to attach a Shadow DOM to the component's host element, and then puts the component
200200
view inside that Shadow DOM. The component's styles are included within the Shadow DOM.
201+
201202
* `Emulated` view encapsulation (**this is the default**) emulates the behavior of Shadow DOM by preprocessing
202203
the CSS code in a way that scopes it to the component's view. See
203-
[Appendix 1](#appendix-1-inspecting-the-css-generated-in-emulated-view-encapsulation) for details.
204+
[Appendix 1](#inspect-generated-css) for details.
205+
204206
* `None` means that no view encapsulation is applied to the component's view. All CSS styles
205207
are applied globally, and the scoping rules discussed above do not apply. This is essentially the
206208
same as adding the component's styles as a global stylesheet to the page.
207209

208-
`Native` view encapsulation will only work on [browsers that have native support
209-
for Shadow DOM](http://caniuse.com/#feat=shadowdom). The support is still limited,
210-
which is why `Emulated` view encapsulation is the default mode and recommended
211-
in most cases.
212-
213210
We can set the view encapsulation of a component by using the `encapsulation`
214211
attribute in the component metadata:
215212

216-
+makeExample('component-styles/ts/app/quest-summary.native.component.ts', 'encapsulation')
217-
213+
+makeExample('component-styles/ts/app/quest-summary.component.ts', 'encapsulation.native')
218214
:marked
219-
215+
`Native` view encapsulation only works on [browsers that have native support
216+
for Shadow DOM](http://caniuse.com/#feat=shadowdom). The support is still limited,
217+
which is why `Emulated` view encapsulation is the default mode and recommended
218+
in most cases.
220219

220+
a(id="#inspect-generated-css")
221221
.l-main-section
222222
:marked
223223
## Appendix 1: Inspecting The CSS Generated in Emulated View Encapsulation
@@ -266,6 +266,7 @@ code-example(format="").
266266
secret sauce that enables the scoping rules described in this guide. At least until
267267
Shadow DOM becomes more widely supported natively.
268268

269+
a(id="load-styles-with-relative-urls")
269270
.l-main-section
270271
:marked
271272
## Appendix 2: Loading Styles with Relative URLs

0 commit comments

Comments
 (0)