TableOfContent
A beautiful TableOfContent that can make your life easier and also looks good.
import { TableOfContent } from "@schukai/monster/source/components/navigation/table-of-content.mjs";Introduction
Use the table of content to jump between headings in long pages.
Setup
Place headings inside the component so it can scan and build the navigation.
Details
Nested headings are shown with indentation in the navigation list.
Introduction
The monster-table-of-content component scans headings in its slotted content and builds a navigable table of contents. It renders a compact control that opens a popper list of headings and supports quick scrolling to each section.
Basic Usage
<monster-table-of-content>
<h2>Introduction</h2>
<p>...</p>
<h2>Setup</h2>
<p>...</p>
<h3>Details</h3>
<p>...</p>
</monster-table-of-content>
Heading Selection
The component collects h1 to h6 elements from its slotted content. To exclude a heading, add data-monster-table-of-content-omit.
Table Of Content
A simple table of content that scans headings inside the component and renders a popper navigation list.
Introduction
Use the table of content to jump between headings in long pages.
Setup
Place headings inside the component so it can scan and build the navigation.
Details
Nested headings are shown with indentation in the navigation list.
Javascript
import '@schukai/monster/source/components/navigation/table-of-content.mjs';HTML
<monster-table-of-content>
<h2>Introduction</h2>
<p>Use the table of content to jump between headings in long pages.</p>
<h2>Setup</h2>
<p>Place headings inside the component so it can scan and build the navigation.</p>
<h3>Details</h3>
<p>Nested headings are shown with indentation in the navigation list.</p>
</monster-table-of-content>Stylesheet
/** no additional stylesheet is defined **/Component Design
The table of content renders a navigation control and a popper list. Use exported parts to style the container, navigation area, and list.
Available Part Attributes
control: Main wrapper of the component.navigation: The navigation panel containing the popper control.navigation-control: The button that toggles the popper list.navigation-list: The list of headings displayed in the popper.
monster-table-of-content::part(control) {
border: 1px solid #e2e8f0;
border-radius: 10px;
}
monster-table-of-content::part(navigation-list) {
max-height: 240px;
overflow: auto;
}
HTML Structure
<monster-table-of-content></monster-table-of-content>JavaScript Initialization
const element = document.createElement('monster-table-of-content');
document.body.appendChild(element);Exported
TableOfContentDerived from
CustomElementOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.
- since
- deprecated
Properties and Attributes
The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.
data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.data-monster-option-[name]: Sets the value of the configuration option[name]for the collapse component when used as an HTML attribute.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.
Static methods
[instanceSymbol]()- {symbol}
instanceof operator.getCSSStyleSheet()- {CSSStyleSheet[]}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {Components.Navigation.TableOfContent
connectedCallback()- {void}
disconnectedCallback()- {void}
Events
The component emits the following events:
new-top
The new top position
For more information on how to handle events, see the mdn documentation.