Skip to content

Commit 166dfc9

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/multi-c8afcbbcd8
2 parents 97b906c + 9aa21fa commit 166dfc9

File tree

355 files changed

+54629
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

355 files changed

+54629
-96
lines changed

cspell-wordlist.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ usingtheplatform
4141
vnode
4242
webapps
4343
wdio
44-
webdriverio
44+
webdriverio
45+
hyperscript

docs/components/api.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Once all the metadata has been collected, all the decorators are removed from th
2525
- [@Listen()](./events.md#listen-decorator) listens for DOM events
2626
- [@AttrDeserialize()](./serialization-deserialization.md#the-attrdeserialize-decorator-attrdeserialize) declares a hook to translate a component's attribute string to its JS property
2727
- [@PropSerialize()](./serialization-deserialization.md#the-propserialize-decorator-propserialize) declares a hook that translates a component's JS property to its attribute string
28+
- [@AttachInternals()](./attach-internals.md) attaches ElementInternals to a component
2829

2930

3031
## Lifecycle hooks
@@ -119,9 +120,11 @@ The following primitives can be imported from the `@stencil/core` package and us
119120

120121
### [**h()**](./templating-and-jsx.md):
121122

122-
It's used within the `render()` to turn the JSX into Virtual DOM elements.
123+
Turns JSX syntax into Virtual DOM elements. Read more on the [Templating and JSX](./templating-and-jsx.md#the-h-and-fragment-functions) page.
123124

124-
- **render()**: a utility method to render a virtual DOM created by `h()` into a container.
125+
### **render()**:
126+
127+
A utility method to render a virtual DOM created by `h()` into a container.
125128

126129
__Type:__ `(vnode: VNode, container: Element) => void`
127130
__Example:__
@@ -290,7 +293,7 @@ Compose multiple classes into a single constructor using factory functions.
290293
@Component({
291294
tag: 'its-mixing-time',
292295
})
293-
export class X extends Mixin(aFactory, aFactory, cFactory) {
296+
export class X extends Mixin(aFactory, bFactory, cFactory) {
294297
render() {
295298
return <div>{this.propA} {this.propB} {this.propC}</div>
296299
}
@@ -302,7 +305,8 @@ If your Stencil component library uses `Mixin()` (or `extends`) and *might* be u
302305
The static-analysis that Stencil uses to find mixed-in classes does not work within 3rd party (node_module) barrel files.
303306
:::
304307

308+
For detailed guidance on using `Mixin()` and `extends` for component architecture, including when to use inheritance vs composition patterns, see the [Extends & Mixins](../guides/extends.md) guide.
305309

306-
### [**setTagTransformer()** and **tagTransform()**](../guides/tag-transformation.md):
310+
### [**setTagTransformer()** and **transformTag()**](../guides/tag-transformation.md):
307311

308312
Manage tag name transformation at runtime. Refer to the [Tag Transformation](../guides/tag-transformation.md) page for usage info.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Attach Internals
3+
sidebar_label: Attach Internals
4+
description: attach internals decorator
5+
slug: /attach-internals
6+
---
7+
8+
# Attach Internals Decorator
9+
10+
The `@AttachInternals` decorator is used to attach [ElementInternals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals) to a Stencil component.
11+
This allows you to leverage features such as [Custom States](https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet) and [Form Association](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals#form_association).
12+
13+
## Form Association
14+
15+
Read the dedicated guide on [Form Associated Components](./form-associated.md) and how to use `@AttachInternals` there.
16+
17+
## Custom States
18+
19+
You can use the `@AttachInternals` decorator to define [Custom States](https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet) for your component.
20+
21+
```tsx
22+
import { Component, h, AttachInternals } from '@stencil/core';
23+
/**
24+
* My Element component
25+
*/
26+
@Component({
27+
tag: 'my-element',
28+
styleUrl: 'my-element.css',
29+
})
30+
export class MyElement {
31+
@AttachInternals({
32+
states: {
33+
/** A custom state for my element */
34+
'my-custom-state': true,
35+
/** Another custom state for my element */
36+
'another-state': false
37+
}
38+
}) internals: ElementInternals;
39+
render() {
40+
return <div>My Element</div>;
41+
}
42+
}
43+
```
44+
45+
In the example above, we define two custom states: `my-custom-state` and `another-state`.
46+
47+
The initial values of the custom states can be set via the `states` object and
48+
later on, you can update the states dynamically using the `internals.states` property. For example:
49+
50+
```tsx
51+
handleClick() {
52+
this.internals.states.add('another-state'); // to add a state
53+
this.internals.states.delete('my-custom-state'); // to remove a state
54+
}
55+
```
56+
57+
You or your element users can then use custom states in CSS like so:
58+
59+
```css
60+
/* Use them internally... */
61+
:host(:state(my-custom-state)) {
62+
background-color: yellow;
63+
}
64+
/* ... Or use them externally */
65+
my-element:state(another-state) {
66+
border: 2px solid red;
67+
}
68+
```

docs/components/component.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,7 @@ export class MyParentComponent {
394394
```
395395

396396
The `my-parent-component` includes a reference to the `my-embedded-component` in the `render()` function.
397+
398+
## Component Architecture Patterns
399+
400+
Stencil supports advanced component architecture patterns including class inheritance and composition. Learn more about organizing component logic with controllers in the [Extends & Mixins](../guides/extends.md) guide.

docs/components/templating-and-jsx.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,59 @@ Stencil components are rendered using JSX, a popular, declarative template synta
1111

1212
## Basics
1313

14-
The `render` function is used to output a tree of components that will be drawn to the screen.
14+
### The `h` and `Fragment` functions
15+
16+
The `h` function (short for "hyperscript") is a factory function that creates virtual DOM elements. When you write JSX like `<div>Hello</div>`, it gets transformed into function calls like `h('div', null, 'Hello')`. The `Fragment` function is used to group a list of children without adding extra nodes to the DOM.
17+
18+
#### Set up in Stencil
19+
20+
Within your Stencil project, make sure to add or modify your `tsconfig.json` file, adding:
21+
22+
```json
23+
{
24+
"compilerOptions": {
25+
"jsx": "react",
26+
"jsxFactory": "h",
27+
"jsxFragmentFactory": "Fragment"
28+
}
29+
}
30+
```
31+
32+
You will then need to import `h` (and `Fragment` if you plan to use it) from `@stencil/core` at the top of your component file:
33+
34+
```tsx
35+
import { h, Fragment, Component } from '@stencil/core';
36+
37+
@Component({
38+
tag: 'my-component',
39+
})
40+
class MyComponent { ... }
41+
```
42+
43+
(Read more about using the `Fragment` component in the [Complex Template Content](#complex-template-content) section below.)
44+
45+
### `jsxImportSource` alternative
46+
47+
`jsxImportSource` is a more modern approach that automatically imports the necessary JSX runtime functions instead of manually importing `h`; the compiler automatically imports what it needs from the specified package.
48+
49+
#### Set up in Stencil
50+
51+
To use `jsxImportSource`, modify your `tsconfig.json` file as follows:
52+
53+
```json
54+
{
55+
"compilerOptions": {
56+
"jsx": "react-jsx",
57+
"jsxImportSource": "@stencil/core"
58+
}
59+
}
60+
```
61+
62+
Using this approach means you do not need to manually import `h` or `Fragment` in your component files.
63+
64+
### The `render` function
65+
66+
The `render` function is used within your component to output a tree of elements that will be drawn to the screen.
1567

1668
```tsx
1769
class MyComponent {
@@ -416,6 +468,23 @@ export class AppHome {
416468

417469
In this example we are using `ref` to get a reference to our input `ref={(el) => this.textInput = el as HTMLInputElement}`. We can then use that ref to do things such as grab the value from the text input directly `this.textInput.value`.
418470

471+
## Explicitly setting attributes or properties
472+
473+
By default, Stencil tries to intelligently determine whether to set an attribute or (more commonly) a property on an element when using JSX.
474+
However, in some cases you may want to explicitly set one or the other. You can do this by using the `attr:` or `prop:` prefixes. For example:
475+
476+
```tsx
477+
<input attr:value="Hello" />
478+
```
479+
480+
will set the `value` attribute on the input element, while:
481+
482+
```tsx
483+
<input prop:value="Hello" />
484+
```
485+
486+
will explicitly set the `value` property on the input element.
487+
419488

420489
## Avoid Shared JSX Nodes
421490

docs/config/dev-server.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ If set to `null`, no route will be registered.
130130

131131
Sets the server's port.
132132

133+
### `strictPort`
134+
135+
**Optional**
136+
137+
**Type: `boolean`**
138+
139+
**Default: `false`**
140+
141+
When set to `true`, the dev server will fail to start if the specified `port` is already in use. When set to `false`, the dev server will try the next available port if the specified port is in use.
142+
133143
### `reloadStrategy`
134144

135145
**Optional**

docs/config/extras.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,5 @@ You can turn this behavior off by setting this flag to `false`.
184184

185185
### additionalTagTransformers
186186

187-
Auto-apply `tagTransform` to most static tag names within your component library (including CSS selectors).
187+
Auto-apply `transformTag` to most static tag names within your component library (including CSS selectors).
188188
Refer to the [Tag Transformation](../guides/tag-transformation.md) page for more information.

docs/documentation-generation/01-overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ slug: /doc-generation
99

1010
- [`docs-readme`: Documentation readme files formatted in markdown](./docs-readme.md)
1111
- [`docs-json`: Documentation data formatted in JSON](./docs-json.md)
12+
- [`docs-custom-elements-manifest`: Custom Elements Manifest (CEM) format](./docs-custom-elements-manifest.md)
1213
- [`docs-custom`: Custom documentation generation](./docs-custom.md)
1314
- [`docs-vscode`: Documentation generation for VS Code](./docs-vscode.md)
1415
- [`stats`: Stats about the compiled files](./docs-stats.md)

0 commit comments

Comments
 (0)