Skip to content

Commit b7ddb98

Browse files
committed
linting and updating readme
1 parent 51b9d52 commit b7ddb98

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

README.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,64 @@ To use, add bit-docs-html-toc to your bit-docs dependencies in package.json:
2929

3030
Where `$VERSION` is the latest version on npm.
3131

32-
In your template add a class **on-this-page-container**:
32+
In your template add a `<bit-toc>` element:
3333

3434
```html
35-
<div class="on-this-page-container"></div>
35+
<bit-toc></bit-toc>
3636
```
3737

38-
By default, all heading tags children of the first `article` tag on the page will
38+
## Attributes
39+
40+
`<bit-toc>` supports the following attributes:
41+
42+
### heading-container-selector
43+
44+
By default, all heading tags children of the first `article` tag on the page will
3945
be collected to create the table of contents; if you want to use a different element
4046
just do:
4147

4248
```html
43-
<div
44-
class="on-this-page-container"
45-
data-heading-container-selector="#my-custom-selector"
49+
<bit-toc
50+
heading-container-selector="#my-custom-selector"
4651
>
47-
</div>
52+
</bit-toc>
4853
```
4954

5055
The table of contents will be injected into this element at run time.
5156

57+
### depth
58+
59+
By default, only `h2` elements are collected. You
60+
can change to include `<h3>` elements by setting depth like:
5261

53-
To control the number of child headers that will be included in the TOC, use the
62+
```html
63+
<bit-toc depth="2"></bit-toc>
64+
```
65+
66+
Alternatively, the number of child headers that will be included in the TOC, use the
5467
`@outline` tag like so:
5568

5669
```
5770
@outline 2
5871
```
5972

60-
This will include `<h2>` and `<h3>` elements, rather than the normal `<h2>` only.
73+
### child-tag
74+
75+
If you want `<li>`'s to be within an `<ol>` instead of a `<ul>`, this
76+
can be configured like:
77+
78+
```html
79+
<bit-toc child-tag="ol"></bit-toc>
80+
```
81+
82+
## Methods
83+
84+
Call `.highlight()` to force an update of the `active` or `completed`
85+
class names on the `<li>` elements:
86+
87+
```js
88+
document.querySelector("bit-toc").highlight()
89+
```
90+
91+
This happens automatically when the `heading-container-selector`
92+
element is scrolled.

toc-control.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ var prototype = {
152152
header: header,
153153
rect: header.getBoundingClientRect(),
154154
button: buttons[i]
155-
}
155+
};
156156
});
157157
// this simulates a header at the end of the page
158158
positions.push({
@@ -187,7 +187,7 @@ var prototype = {
187187
else if( nextDistance >= (articleRect.height / 2) && curDistance < (articleRect.height / 2) ) {
188188
position.button.classList.add("active");
189189
}
190-
})
190+
});
191191
},
192192
disconnectedCallback: function(){
193193
this.teardowns.forEach(function(teardown){
@@ -209,7 +209,7 @@ lazy(prototype,"titleTree", function(){
209209
return makeTree(this.titles);
210210
});
211211
lazy(prototype,"buttons", function(){
212-
return this.querySelectorAll("li")
212+
return this.querySelectorAll("li");
213213
});
214214

215215

0 commit comments

Comments
 (0)