Skip to content

Commit 79c24b9

Browse files
authored
docs: add declarative template documentation to 3.x docs site (#7495)
# Pull Request ## 📖 Description Adds a new **Declarative HTML** documentation section to the 3.x docs site with four pages covering the full declarative template authoring workflow: - **Overview** — Purpose of declarative templates, when to use them, a hello world example, and comparison with imperative `html` tagged templates. - **Writing f-templates** — Template syntax including content/attribute/boolean/event bindings, directives (`f-when`, `f-repeat`, `f-ref`, `f-slotted`, `f-children`), dot-notation paths, execution context access (`$e`, `$c`), and expression limitations. - **Defining Elements** — `TemplateElement` registration, `templateOptions: "defer-and-hydrate"`, lifecycle callbacks (`config()`), element configuration (`options()`), `observerMap` and `attributeMap` usage. - **Server-Side Rendering** — The renderer-agnostic SSR contract, hydration flow, Declarative Shadow DOM output, state propagation, and `@microsoft/fast-build` CLI usage. Also adds cross-references from `packages/fast-element/README.md` and `DECLARATIVE_HTML.md` to the new docs. Based on the declarative template features from PRs #7490, #7491, #7492, and #7493. ## 📑 Test Plan - Website builds successfully with `npm run build -w sites/website` - All four pages render correctly in the 11ty output - `npm run checkchange` passes (no change files needed for docs-only changes to the website) ## ✅ Checklist ### General - [x] I have included a change request file using `$ npm run change` - [ ] I have added tests for my changes. - [x] I have tested my changes. - [x] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
1 parent 3af0ed5 commit 79c24b9

12 files changed

Lines changed: 1108 additions & 18 deletions

File tree

packages/fast-element/DECLARATIVE_HTML.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ For package installation, importing `TemplateElement`, basic registration, and
1414
the package-level hydration overview, see the
1515
[FAST Element README](./README.md#declarative-html) and
1616
[Prerendered Content Optimization](./README.md#prerendered-content-optimization).
17+
For user-facing guides covering f-template syntax, element definition, and
18+
server-side rendering, see the
19+
[Declarative HTML docs](https://fast.design/docs/3.x/declarative-templates/overview/).
1720

1821
## Template Structure
1922

packages/fast-element/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ TemplateElement.define({ name: "f-template" });
100100

101101
Declarative utilities such as `deepMerge` are available from
102102
`@microsoft/fast-element/declarative/utilities.js`. See
103-
[`DECLARATIVE_HTML.md`](./DECLARATIVE_HTML.md) for declarative usage details.
104-
Declarative event bindings use `$e` for the DOM event object and `$c` for the
105-
execution context.
103+
[`DECLARATIVE_HTML.md`](./DECLARATIVE_HTML.md) for declarative implementation
104+
details and the
105+
[Declarative HTML docs](https://fast.design/docs/3.x/declarative-templates/overview/)
106+
for guides on writing f-templates, defining declarative elements, and
107+
server-side rendering. Declarative event bindings use `$e` for the DOM event
108+
object and `$c` for the execution context.
106109

107110
## Prerendered Content Optimization
108111

packages/fast-element/src/declarative/attribute-map.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export interface AttributeMapConfig {
2121
/**
2222
* Strategy for mapping template binding keys to HTML attribute names.
2323
*
24-
* - `"none"` (default): the binding key is used as-is for both the
25-
* property name and the attribute name (e.g. `{{foo-bar}}` →
26-
* property `foo-bar`, attribute `foo-bar`).
27-
* - `"camelCase"`: the binding key is treated as a camelCase property
24+
* - `"camelCase"` (default): the binding key is treated as a camelCase property
2825
* name and the attribute name is derived by converting it to
2926
* kebab-case (e.g. `{{fooBar}}` → property `fooBar`, attribute
3027
* `foo-bar`). This matches the build-time `attribute-name-strategy`
3128
* option in `@microsoft/fast-build`.
29+
* - `"none"`: the binding key is used as-is for both the
30+
* property name and the attribute name (e.g. `{{foo-bar}}` →
31+
* property `foo-bar`, attribute `foo-bar`).
3232
*/
3333
"attribute-name-strategy"?: "none" | "camelCase";
3434
}
@@ -59,14 +59,14 @@ function camelToKebab(str: string): string {
5959
* A property is a candidate for @attr when its schema entry has no nested `properties`,
6060
* no `type`, and no `anyOf` — i.e. it is a plain binding like {{foo}} or id="{{foo-bar}}".
6161
*
62-
* When `attribute-name-strategy` is `"none"` (the default), the binding key is used
63-
* as both the attribute name and property name — no normalization is applied.
64-
*
65-
* When `attribute-name-strategy` is `"camelCase"`, the binding key is treated as a
62+
* When `attribute-name-strategy` is `"camelCase"` (the default), the binding key is treated as a
6663
* camelCase property name and the HTML attribute name is derived by converting it to
6764
* kebab-case (e.g. property `fooBar` → attribute `foo-bar`). This matches the
6865
* build-time `attribute-name-strategy` option in `@microsoft/fast-build`.
6966
*
67+
* When `attribute-name-strategy` is `"none"`, the binding key is used
68+
* as both the attribute name and property name — no normalization is applied.
69+
*
7070
* Properties already decorated with `@attr` or `@observable` on the class are left
7171
* untouched.
7272
*/
@@ -93,7 +93,7 @@ export class AttributeMap {
9393
const existingAccessorNames = new Set(
9494
Observable.getAccessors(this.classPrototype).map(a => a.name),
9595
);
96-
const strategy = this.config?.["attribute-name-strategy"] ?? "none";
96+
const strategy = this.config?.["attribute-name-strategy"] ?? "camelCase";
9797

9898
for (const propertyName of propertyNames) {
9999
const propertySchema = this.schema.getSchema(propertyName);

sites/website/src/docs/3.x/api/fast-element/declarative/fast-element.attributemap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ AttributeMap provides functionality for detecting simple (leaf) properties in a
1919

2020
A property is a candidate for when its schema entry has no nested `properties`<!-- -->, no `type`<!-- -->, and no `anyOf` — i.e. it is a plain binding like {<!-- -->{<!-- -->foo<!-- -->}<!-- -->} or id="<!-- -->{<!-- -->{<!-- -->foo-bar<!-- -->}<!-- -->}<!-- -->".
2121

22-
When `attribute-name-strategy` is `"none"` (the default), the binding key is used as both the attribute name and property name — no normalization is applied.
22+
When `attribute-name-strategy` is `"camelCase"` (the default), the binding key is treated as a camelCase property name and the HTML attribute name is derived by converting it to kebab-case (e.g. property `fooBar` → attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->.
2323

24-
When `attribute-name-strategy` is `"camelCase"`<!-- -->, the binding key is treated as a camelCase property name and the HTML attribute name is derived by converting it to kebab-case (e.g. property `fooBar` → attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->.
24+
When `attribute-name-strategy` is `"none"`<!-- -->, the binding key is used as both the attribute name and property name — no normalization is applied.
2525

2626
Properties already decorated with `@attr` or `@observable` on the class are left untouched.
2727

sites/website/src/docs/3.x/api/fast-element/declarative/fast-element.attributemapconfig._attribute-name-strategy_.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ navigationOptions:
1717

1818
Strategy for mapping template binding keys to HTML attribute names.
1919

20-
- `"none"` (default): the binding key is used as-is for both the property name and the attribute name (e.g. `{{foo-bar}}` → property `foo-bar`<!-- -->, attribute `foo-bar`<!-- -->). - `"camelCase"`<!-- -->: the binding key is treated as a camelCase property name and the attribute name is derived by converting it to kebab-case (e.g. `{{fooBar}}` → property `fooBar`<!-- -->, attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->.
20+
- `"camelCase"` (default): the binding key is treated as a camelCase property name and the attribute name is derived by converting it to kebab-case (e.g. `{{fooBar}}` → property `fooBar`<!-- -->, attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->. - `"none"`<!-- -->: the binding key is used as-is for both the property name and the attribute name (e.g. `{{foo-bar}}` → property `foo-bar`<!-- -->, attribute `foo-bar`<!-- -->).
2121

2222
**Signature:**
2323

sites/website/src/docs/3.x/api/fast-element/declarative/fast-element.attributemapconfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Description
6363

6464
_(Optional)_ Strategy for mapping template binding keys to HTML attribute names.
6565

66-
- `"none"` (default): the binding key is used as-is for both the property name and the attribute name (e.g. `{{foo-bar}}` → property `foo-bar`<!-- -->, attribute `foo-bar`<!-- -->). - `"camelCase"`<!-- -->: the binding key is treated as a camelCase property name and the attribute name is derived by converting it to kebab-case (e.g. `{{fooBar}}` → property `fooBar`<!-- -->, attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->.
66+
- `"camelCase"` (default): the binding key is treated as a camelCase property name and the attribute name is derived by converting it to kebab-case (e.g. `{{fooBar}}` → property `fooBar`<!-- -->, attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->. - `"none"`<!-- -->: the binding key is used as-is for both the property name and the attribute name (e.g. `{{foo-bar}}` → property `foo-bar`<!-- -->, attribute `foo-bar`<!-- -->).
6767
6868
6969
</td></tr>

sites/website/src/docs/3.x/api/fast-element/declarative/fast-element.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ AttributeMap provides functionality for detecting simple (leaf) properties in a
3838

3939
A property is a candidate for when its schema entry has no nested `properties`<!-- -->, no `type`<!-- -->, and no `anyOf` — i.e. it is a plain binding like {<!-- -->{<!-- -->foo<!-- -->}<!-- -->} or id="<!-- -->{<!-- -->{<!-- -->foo-bar<!-- -->}<!-- -->}<!-- -->".
4040

41-
When `attribute-name-strategy` is `"none"` (the default), the binding key is used as both the attribute name and property name — no normalization is applied.
41+
When `attribute-name-strategy` is `"camelCase"` (the default), the binding key is treated as a camelCase property name and the HTML attribute name is derived by converting it to kebab-case (e.g. property `fooBar` → attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->.
4242

43-
When `attribute-name-strategy` is `"camelCase"`<!-- -->, the binding key is treated as a camelCase property name and the HTML attribute name is derived by converting it to kebab-case (e.g. property `fooBar` → attribute `foo-bar`<!-- -->). This matches the build-time `attribute-name-strategy` option in `@microsoft/fast-build`<!-- -->.
43+
When `attribute-name-strategy` is `"none"`<!-- -->, the binding key is used as both the attribute name and property name — no normalization is applied.
4444

4545
Properties already decorated with `@attr` or `@observable` on the class are left untouched.
4646

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
layout: 3x
3+
eleventyNavigation:
4+
key: declarative-templates3x
5+
title: Declarative HTML
6+
order: 3
7+
navigationOptions:
8+
activeKey: declarative-templates3x
9+
permalink: false
10+
---

0 commit comments

Comments
 (0)