{% set toc_items %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section One',
url: '#section-one',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Two',
url: '#section-two',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Three',
url: '#section-three',
} only %}
{% endset %}
{% include '@bolt-components-toc/toc.twig' with {
header: 'This is the header',
content: toc_items
} only %}
Prop Name | Description | Type | Default Value | Option(s) |
---|---|---|---|---|
attributes
|
A Drupal attributes object. Applies extra HTML attributes to the outer <bolt-toc> tag. |
object
| — |
|
header
|
Renders a header for the table of contents. If not specified, the default value will be used and the header will be visually hidden but accessible to screen readers. |
string
|
Table of Contents
|
|
sticky
|
When enabled, TOC will automatically use sticky positioning + add a |
boolean
| — |
|
variant
|
Set the visual variant. |
string
|
card
|
|
scroll_offset
|
Additional offset for smooth scrolling, an integer converted to pixel value. |
integer
| — |
|
content
|
Generates toc items. Accepts @bolt-components-toc-item |
object
| — |
|
Prop Name | Description | Type | Default Value | Option(s) |
---|---|---|---|---|
attributes
|
A Drupal attributes object. Applies extra HTML attributes to the outer <bolt-toc> tag. |
object
| — |
|
text
|
Renders the text for the linked item. |
string
| — |
|
url
|
Renders the |
string
| — |
|
active
|
Indicates that the item represents the current section being viewed. |
boolean
| — |
|
npm install @bolt/components-toc
{% set toc_items %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section One',
url: '#section-one',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Two',
url: '#section-two',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Three',
url: '#section-three',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Four',
url: '#section-four',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Five',
url: '#section-five',
} only %}
{% endset %}
{% include '@bolt-components-toc/toc.twig' with {
content: toc_items
} only %}
<div class="c-bolt-toc">
<nav aria-label="Table of Contents">
<h2 class="c-bolt-toc__header c-bolt-toc__header--hidden">
Table of Contents
</h2>
<ul class="c-bolt-toc__list">
<li>
<a href="#section-one" class="c-bolt-toc__item">
Section One
</a>
</li>
<li>
<a href="#section-two" class="c-bolt-toc__item">
Section Two
</a>
</li>
<li>
<a href="#section-three" class="c-bolt-toc__item">
Section Three
</a>
</li>
</ul>
</nav>
</div>
active
to indicate that the page is anchored to the respective section.
{% set toc_items %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section One',
url: '#section-one',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Two',
url: '#section-two',
active: true
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Three',
url: '#section-three',
} only %}
{% endset %}
{% include '@bolt-components-toc/toc.twig' with {
content: toc_items
} only %}
<div class="c-bolt-toc">
<nav aria-label="Table of Contents">
<h2 class="c-bolt-toc__header c-bolt-toc__header--hidden">
Table of Contents
</h2>
<ul class="c-bolt-toc__list">
<li>
<a href="#section-one" class="c-bolt-toc__item">
Section One
</a>
</li>
<li>
<a href="#section-two" class="c-bolt-toc__item c-bolt-toc__item--current">
Section Two
</a>
</li>
<li>
<a href="#section-three" class="c-bolt-toc__item">
Section Three
</a>
</li>
</ul>
</nav>
</div>
header
prop.
{% set toc_items %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section One',
url: '#section-one',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Two',
url: '#section-two',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Three',
url: '#section-three',
} only %}
{% endset %}
{% include '@bolt-components-toc/toc.twig' with {
header: 'This is the header',
content: toc_items
} only %}
<div class="c-bolt-toc">
<nav aria-label="This is the header">
<h2 class="c-bolt-toc__header">
This is the header
</h2>
<ul class="c-bolt-toc__list">
<li>
<a href="#section-one" class="c-bolt-toc__item">
Section One
</a>
</li>
<li>
<a href="#section-two" class="c-bolt-toc__item">
Section Two
</a>
</li>
<li>
<a href="#section-three" class="c-bolt-toc__item">
Section Three
</a>
</li>
</ul>
</nav>
</div>
variant
prop.
{% set toc_items %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section One',
url: '#section-one',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Two',
url: '#section-two',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Three',
url: '#section-three',
} only %}
{% endset %}
{% include '@bolt-components-toc/toc.twig' with {
header: 'This is the transparent variant',
content: toc_items,
variant: 'transparent',
} only %}
<div class="c-bolt-toc c-bolt-toc--variant-transparent">
<nav aria-label="This is the transparent variant">
<h2 class="c-bolt-toc__header">
This is the transparent variant
</h2>
<ul class="c-bolt-toc__list">
<li>
<a href="#section-one" class="c-bolt-toc__item c-bolt-toc__item--current">
Section One
</a>
</li>
<li>
<a href="#section-two" class="c-bolt-toc__item">
Section Two
</a>
</li>
<li>
<a href="#section-three" class="c-bolt-toc__item">
Section Three
</a>
</li>
</ul>
</nav>
</div>
sticky
prop.
{% set toc_items %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section One',
url: '#section-one',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Two',
url: '#section-two',
} only %}
{% include '@bolt-components-toc/toc-item.twig' with {
text: 'Section Three',
url: '#section-three',
} only %}
{% endset %}
{% include '@bolt-components-toc/toc.twig' with {
header: 'Table of Contents',
content: toc_items,
sticky: true,
scroll_offset: 20,
} only %}
<div class="c-bolt-toc c-bolt-toc--sticky" data-bolt-scroll-offset="20">
<nav aria-label="Table of Contents with a sticky position">
<h2 class="c-bolt-toc__header">
Table of Contents with a sticky position
</h2>
<ul class="c-bolt-toc__list">
<li>
<a href="#section-one" class="c-bolt-toc__item">
Section One
</a>
</li>
<li>
<a href="#section-two" class="c-bolt-toc__item">
Section Two
</a>
</li>
<li>
<a href="#section-three" class="c-bolt-toc__item">
Section Three
</a>
</li>
</ul>
</nav>
</div>