Skip to content

Commit e5d601b

Browse files
committed
rewording pass
1 parent fc975fd commit e5d601b

File tree

10 files changed

+66
-65
lines changed

10 files changed

+66
-65
lines changed

.remarkrc.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default {
6767
{
6868
noBinary: true,
6969
// TODO: Reduce this list
70-
ignore: ["primitive", "just", "easy", "easily", "straightforward", "invalid", "obvious"],
70+
ignore: ["primitive", "just", "easy", "easily", "straightforward", "invalid", "obvious", "host", "hosts"],
7171
},
7272
],
7373
// TODO: Lower this threshold to 5 / 7

.spelling

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,11 @@ http
141141
metasyntactic
142142
callout
143143
callouts
144+
stylesheet
145+
stylesheets
146+
Stylesheets
147+
programmatically
148+
deeppink
149+
unstyled
150+
preload
151+
Constructable

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ Contributions are always welcome! Before contributing, please read the
1111
[good first issue label](https://github.com/WebComponentsGuide/webcomponents.guide/labels/good%20first%20issue).
1212
- If you're contributing to larger pieces, like an idea or new section, tutorial, or blog post, then please raise an
1313
issue first! This way we can discuss an action plan and figure out a high level overview of what we should write.
14-
- [Reading the styleguide](./STYLEGUIDE.md) will help you write content that fits with our intended style.
14+
- [Reading the style guide](./STYLEGUIDE.md) will help you write content that fits with our intended style.
1515

1616
### Setup
1717

1818
You can run the code locally by cloning the repository, and running `npm install` followed by `npm start`:
1919

2020
```sh
21-
$ git clone [email protected]:WebComponentsGuide/webcomponents.guide
22-
$ cd webcomponents.guide
23-
$ npm install
24-
$ npm start
21+
git clone [email protected]:WebComponentsGuide/webcomponents.guide
22+
cd webcomponents.guide
23+
npm install
24+
npm start
2525
```
2626

2727
You can now visit <http://localhost:8080/> to see the local copy of the website. As you edit files the website will

STYLEGUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Do not try to write prose transitioning to the next page, as not only is this un
252252
pages around more difficult.
253253

254254
Summaries can be useful for reinforcing complex information throughout the document, but use them sparingly. A summary
255-
should stand a lone as useful content, and not attempt to clarify unclear content.
255+
should stand a lone as useful content, and not try to clarify unclear content.
256256

257257
[how-users-read-web]: https://www.nngroup.com/articles/how-users-read-on-the-web/
258258
[active-voice]: https://en.wikipedia.org/wiki/Active_voice

learn/components/autonomous-vs-customized-elements.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ title: Autonomous vs Customized Elements
33
order: 2
44
---
55

6-
In the [previous section][defining-a-component] we learned about _Autonomous Custom Elements_ vs _Customized Built-in
7-
Elements_. The most popular way to make elements is to use the _Autonomous Custom Element_ style, by making up your own
8-
tag and extending `HTMLElement`. Each style comes with different trade-offs.
9-
10-
Choosing a type of component to build will depend on a lot of factors. _Autonomous Custom Elements_ give you a blank
11-
canvas to work with. _Customized Built-ins_ **extend** the element you're customizing. Here are some considerations to
12-
think about:
6+
The most popular way to make elements is to use the _Autonomous Custom Element_ style, by making up your own tag and
7+
extending `HTMLElement`. Each style comes with different trade-offs. Choosing a type of component to build will depend
8+
on a lot of factors. _Autonomous Custom Elements_ give you a blank canvas to work with. _Customized Built-ins_
9+
**extend** the element you're customizing. Here are some considerations to think about:
1310

1411
### Tag Name
1512

@@ -136,7 +133,6 @@ Custom Element_ is a good choice. To help drive your decision, here's a table su
136133

137134
{% stub %}
138135

139-
[defining-a-component]: /learn/components/
140136
[shadowdom]: /learn/components/shadowdom
141137
[content-categories]: https://developer.mozilla.org/en-US/docs/Web/HTML/Content_categories
142138
[phrasing-content]: https://developer.mozilla.org/en-US/docs/Web/HTML/Content_categories#phrasing_content

learn/components/rendering.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ title: Rendering
33
order: 5
44
---
55

6-
When a Web Component is initialized, it can start interacting with the document and make changes to it. While a
7-
component **could** make changes to the DOM the element is within, there's a better way. Each component can have its own
8-
DOM, that is _encapsulated_ from the rest of the page. This is called the _ShadowDOM_. A component can create and attach
9-
a _ShadowDOM_ to itself by using `attachShadow({ mode: 'open' })`:
6+
When a Web Component initializes, it can start interacting with the document and make changes to it. While a component
7+
**could** make manipulate other parts of DOM or even it's children, there's a better way. Each component can have its
8+
own DOM, _encapsulated_ from the rest of the page. This is called the _ShadowDOM_. A component can create and attach a
9+
_ShadowDOM_ to itself by using `attachShadow({ mode: 'open' })`:
1010

1111
```js
1212
class StopWatchElement extends HTMLElement {
@@ -19,14 +19,21 @@ class StopWatchElement extends HTMLElement {
1919
}
2020
```
2121

22-
This DOM tree is exclusive to your Web Component, and the rest of the document can't accidentally influence it. You can
23-
append new elements into a components _ShadowDOM_ (even stylesheets) and it won't impact other parts of the page. Other
24-
elements can't accidentally reach in to another elements _ShadowDOM_; DOM APIs like `.querySelector()` won't reach into
25-
different _ShadowDOMs_. All this means the _ShadowDOM_ is your components safe space to put whatever content it needs to
26-
render.
22+
{% tip "info" %}
2723

28-
One way to make use of this _ShadowDOM_ is to set the `.innerHTML` whenever your element gets connected. To do this you
29-
can use the `connectedCallback()` lifecycle function:
24+
The `.shadowRoot` property is always present on an element. It will return an elements _open shadow root_ or `null` if
25+
it doesn't have one. Setting `shadowRoot =` isn't necessary - it's redundant - but it makes the code more readable.
26+
27+
{% endtip %}
28+
29+
This _ShadowDOM_ tree is exclusive to your Web Component. The rest of the document can't accidentally influence it. You
30+
can add new elements into a _ShadowDOM_ - even stylesheets - and it won't impact the rest of the DOM. Other logic or
31+
styles won't get access to a components _ShadowDOM_. CSS selectors do not cross the boundary between the main _light
32+
DOM_ and the _ShadowDOM_. APIs like `.querySelector()`, or `.children` also don't cross this boundary. All this means
33+
the _ShadowDOM_ is your components safe space to put whatever content it needs to render.
34+
35+
One way to make use of this _ShadowDOM_ is to use the same DOM APIs to construct the contents. For example setting the
36+
`.innerHTML` whenever your element gets connected. To do this you can use the `connectedCallback()` lifecycle function:
3037

3138
```js
3239
class StopWatchElement extends HTMLElement {
@@ -46,12 +53,13 @@ class StopWatchElement extends HTMLElement {
4653
<my-component></my-component>
4754
```
4855

49-
Perhaps a slightly better way to do this is using a `<template>` element, and cloning the contents of it. A key reason
50-
for this is that cloning from a template requires less computation than setting `innerHTML`. It also separates your
51-
template from your logic, which will keep code cleaner as your component grows in complexity.
56+
You can define a `<template>` element up front. Using the `cloneNode()` API efficiently copies the template into the
57+
_Shadow Root_. This requires less computation than setting `innerHTML` each time, and can be easier to read. It also
58+
separates your template from your logic. Keeping templates away from logic keeps code cleaner as your component grows in
59+
complexity.
5260

5361
```js
54-
// The template can be defined up front
62+
// The template can be defined up front and re-used
5563
const template = document.createElement("template")
5664
template.innerHTML = `<p>Hello World!</p>`
5765

learn/components/styling.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
22
title: Styling
3-
order: 5
3+
order: 6
44
---
55

66
Web Components have powerful styling capabilities which make them portable and extensible. Styles declared within the
7-
Shadow DOM serve as a Web Component’s default styling. It’s similar to writing a user-agent stylesheet for your custom
8-
element and it works quite similarily as well.
7+
Shadow DOM serve as a Web Component's default styling. They work similarly to writing a user-agent stylesheet.
98

109
## Shadow Encapsulation: Scoped Styles
1110

1211
Shadow DOM offers a boundary line between styles outside the tree, and styles inside the tree. Styles cannot cross this
13-
boundary unintentionally. This is different to regular CSS where a selector can effect every element on a page.
12+
boundary unintentionally. This is different to regular CSS where a selector can affect every element on a page.
1413

1514
```html
1615
<style>
@@ -33,7 +32,7 @@ boundary unintentionally. This is different to regular CSS where a selector can
3332
</fancy-p>
3433
```
3534

36-
The `<p>` element within the shadow tree is not effected by the styles declared outside of the shadow tree.
35+
The `<p>` element within the shadow tree is not affected by the styles declared outside of the shadow tree.
3736

3837
## Inheritance
3938

@@ -65,20 +64,19 @@ element itself (also known as the shadow host).
6564
</article>
6665
```
6766

68-
The `<article-meta>` custom element inherits its `color` from the `<article>` element where it is set to `deeppink`. The
67+
The `<article-meta>` custom element inherits its `color` from the `<article>` element where it's set to `deeppink`. The
6968
`<span>` element within the shadow tree inherits its `color` from the `<article-meta>` custom element which means the
7069
value will also be `deeppink`.
7170

7271
## Styling elements outside of a shadow tree
7372

74-
In order to be portable, Web Components can provide default styles for the element itself (also known as the shadow
75-
host). They can also style slotted elements with some default styles.
73+
In order to be portable, Web Components can add default styles for the element itself (also known as the shadow host).
74+
They can also style slotted elements with some default styles.
7675

7776
### Writing default styles for the shadow host with `:host` and `:host()`
7877

79-
There are two selectors which can be used to style the shadow host from within the shadow tree. They are the `:host`
80-
pseudo-class and the `:host()` pseudo-class function. The first will always select the shadow host. Here’s `:host` in
81-
action:
78+
You can use host selectors to style an element from within the shadow tree. The `:host` pseudo-class always applies
79+
styles to the custom element, aka the _shadow host_:
8280

8381
```html
8482
<fancy-p>
@@ -92,9 +90,10 @@ action:
9290
</fancy-p>
9391
```
9492

95-
The `:host()` selector will select the shadow host if it matches a given selector. For example, it can be used to select
96-
for hosts that have a given attribute. While `:host` may apply to `<fancy-p>` component, `:host([extra])` would apply
97-
only to `<fancy-p extra>` elements:
93+
You can also add conditional styles to the _shadow host_ using `:host()` _selector function_. This can be used to style
94+
the host so long as it matches the given selector. For example, it can be used to select for hosts that have a given
95+
attribute. While `:host` may apply to `<fancy-p>` component, `:host([extra])` would apply only to `<fancy-p extra>`
96+
elements:
9897

9998
```css
10099
:host([extra]) {
@@ -239,11 +238,12 @@ fancy-article::part(header) slot {
239238

240239
## How to include default styles for a Web Component
241240

242-
There are a variety of methods to include styles for a Web Component. Some will be familiar, but others are newer.
241+
You can load a stylesheet for a Web Component with a variety of methods. Some may be familiar, but others are newer.
243242

244243
### Using `<style>`
245244

246-
The `<style>` tag is the most simple way to write styles for a Web Component. Just include it in your shadow tree:
245+
You can include a `<style>` tag within your Shadow Tree, and it'll only apply to the Shadow Tree itself - it won't
246+
affect the rest of the page:
247247

248248
```html
249249
<style>
@@ -261,16 +261,16 @@ Using a `<link rel="stylesheet">` element in the shadow tree will allow you to w
261261
<link rel="stylesheet" href="/fancy-article-element.css" />
262262
```
263263

264-
If you do this, the stylesheet will be loaded after the script is loaded. This will likely cause a “flash of unstyled
265-
content” (FOUC). To circumvent this, you can preload the stylesheet like this:
264+
If you do this, the stylesheet will be loaded after the script is loaded. This will likely cause a _flash of unstyled
265+
content_ (FOUC). To circumvent this, you can preload the stylesheet like this:
266266

267267
```html
268268
<link rel="preload" href="/fancy-article-element.css" as="style" />
269269
```
270270

271271
### Using Constructable Stylesheets
272272

273-
Constructable Stylesheets are stylesheets which are programmatically created in JavaScript. You can create a new
273+
_Constructable Stylesheets_ are stylesheets which are programmatically created in JavaScript. You can create a new
274274
stylesheet using the `CSSStyleSheet` constructor and set styles with the `.replaceSync()` method:
275275

276276
```js
@@ -293,7 +293,7 @@ class FancyArticleElement extends HTMLElement {
293293

294294
CSS Module scripts allow developers to import stylesheets as if they were a module script. To do so, use an import
295295
assertion where the `type` is `css` and then you can add the imported stylesheet to the `adoptedStyleSheets` array for
296-
the elements shadow root.
296+
the element's shadow root.
297297

298298
```js
299299
import stylesheet from "./fancy-article-element.css" assert { type: "css" }

learn/javascript/classes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ myupper.#original = "Hello"
177177
Private fields work like public fields with regards to evaluation. They get evaluated with the class _instantiation_, so
178178
`this` will refer to the class instance, and function calls will be called each time the class is constructed.
179179

180-
### Using private fields with public APIs to make changeable, _read only state_
180+
### _Read only fields_ using private state & public APIs
181181

182182
_Private fields_ are useful to have a value that the internals of a class can change, but that outside code cannot. It's
183183
also often useful to allow outside code to _read_ a classes _private state_, but not change it. To do this you can
@@ -212,7 +212,7 @@ myupper.sentence = "Hello Universe"
212212
myupper.firstWord = "Hola"
213213
```
214214

215-
### Using private fields with public APIs to make reactive fields
215+
### _Reactive fields_ using private state & public APIs
216216

217217
A _public field_ can be changed on a class instance, and the class will not know when that happens. To make a class
218218
react to a change in its public fields, you can combine a private field with `get` and `set` functions, like so:

learn/javascript/events-in-more-detail.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ title: Events in more detail
33
order: 4
44
---
55

6-
In the [previous section][events] we learned about `EventTarget` - the class that gives us an event system, with
7-
`addEventListener` and `dispatchEvent`. We also learned about the `Event` class which `EventTarget` takes and propagates
8-
to all listeners.
9-
10-
In this section we'll learn about these features in more detail, covering some more advanced topics, techniques, and
11-
potential pitfalls you'll need to watch out for. It's a good idea to make sure you've got a good understanding of
12-
everything covered in the [previous section][events] before reading on.
13-
146
#### Adding multiple listeners
157

168
The [previous section][events] showed how you can add an _Event listener_ with `.addEventListener()`, but you can add

learn/javascript/events.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ order: 3
55

66
Web browsers (and server side engines like [NodeJS][node] and [Deno][deno]) include an Event API which has become a
77
foundational concept in JavaScript, and is particularly important when we talk about Web Components. The two classes
8-
that drive all these events are the `Event` class, and the `EventTarget` class.
9-
10-
This section will go over the concepts of Events, the basics of the `EventTarget` and `Event` classes, and the next
11-
section will touch on some more advanced topics but - as always - if you're interested in learning more MDN has many
12-
resources that cover Events:
8+
that drive all these events are the `Event` class, and the `EventTarget` class. MDN has some great in depth guides for
9+
dealing with Events that go beyond this guide:
1310

1411
- [Introduction to Events](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events)
1512
- [The EventTarget API](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)

0 commit comments

Comments
 (0)