Skip to content

Commit 86b7fdd

Browse files
committed
Update docs
1 parent ddea974 commit 86b7fdd

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

docs-app/public/docs/6-utils/get-section-heading-level.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ In this example, we dynamically create a TextNode and Element, where, since the
2121

2222
<section class="featured-demo">
2323

24-
```gjs live preview
24+
```gjs live
2525
import Component from "@glimmer/component";
2626
import { element } from "ember-element-helper";
2727
import { getSectionHeadingLevel } from "which-heading-do-i-need";
2828
2929
class Heading extends Component {
30-
constructor(owner, args) {
31-
super(owner, args);
32-
33-
this.markerNode = document.createTextNode("");
34-
}
30+
markerNode = document.createTextNode("");
3531
3632
get hLevel() {
3733
return `h${getSectionHeadingLevel(this.markerNode)}`;
@@ -135,8 +131,43 @@ class Heading extends Component {
135131

136132
</section>
137133

134+
<br>
135+
<details><summary>using Ember</summary>
136+
137+
This version:
138+
- caller can pass attributes to the generated heading
139+
- only element generated is the heading
140+
- synchronous, so there are no extra renders
141+
142+
```gjs
143+
import Component from "@glimmer/component";
144+
import { getSectionHeadingLevel } from "which-heading-do-i-need";
145+
146+
class Heading extends Component {
147+
markerNode = document.createTextNode("");
148+
149+
get hLevel() {
150+
return `h${getSectionHeadingLevel(this.markerNode)}`;
151+
}
152+
153+
<template>
154+
{{this.markerNode}}
155+
156+
{{#let (element this.hLevel) as |El|}}
157+
<El ...attributes>{{yield}}</El>
158+
{{/let}}
159+
</template>
160+
}
161+
```
162+
163+
</details>
138164
<details><summary>using Svelte</summary>
139165

166+
downside to this approach is that it requires two renders.
167+
first time is a span, second the span is replaced with the heading.
168+
169+
See [Feature: Bind to text nodes with `svelte:text`](https://github.com/sveltejs/svelte/issues/7424) on svelte's GitHub.
170+
140171
```svelte
141172
<script>
142173
import { getSectionHeadingLevel } from "which-heading-do-i-need";

0 commit comments

Comments
 (0)