Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions docs/api/doc-blocks/doc-block-tableofcontents.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: 'TableOfContents'
sidebar:
order: 14
title: TableOfContents
---

The `TableOfContents` block renders a table of contents for the current documentation page, allowing users to navigate between sections quickly. It appears as a fixed sidebar on the right side of the documentation page and is hidden on smaller screens (below 768px).

The table of contents is enabled and configured via the `docs.toc` [parameter](../../writing-stories/parameters.mdx) rather than being added directly to MDX files. When enabled, it is automatically rendered alongside the page content by [Storybook's docs container](../doc-blocks/doc-block-meta.mdx).

<Callout variant="info">

For a step-by-step guide on enabling and customizing the table of contents, see the [Generate a table of contents](../../writing-docs/autodocs.mdx#generate-a-table-of-contents) section in the Autodocs documentation.

</Callout>

## Enabling the table of contents

Enable the table of contents globally in your Storybook preview configuration:

{/* prettier-ignore-start */}

<CodeSnippets path="storybook-preview-enable-toc.md" />

{/* prettier-ignore-end */}

You can also enable or disable it for specific components in their stories file:

{/* prettier-ignore-start */}

<CodeSnippets path="my-component-disable-toc.md" />

{/* prettier-ignore-end */}

## `toc` parameter options

The `docs.toc` parameter accepts either `true` (to enable with defaults) or an object with the following properties:

### `contentsSelector`

Type: `string`

Default: `'.sbdocs-content'`

CSS selector for the container to search for headings. Use this if you have a custom docs page layout.

### `disable`

Type: `boolean`

Default: `false`

When `true`, it hides the table of contents for the documentation page. A hidden (empty) container is still rendered to preserve the page layout.

### `headingSelector`

Type: `string`

Default: `'h3'`

CSS selector that defines which heading levels to include in the table of contents. For example, use `'h1, h2, h3'` to include the top three heading levels.

### `ignoreSelector`

Type: `string`

Default: `'.docs-story *, .skip-toc'`

CSS selector for headings to exclude from the table of contents. By default, headings inside story blocks are excluded. To also exclude a specific heading, add the `skip-toc` class to it.

### `title`

Type: `string | null | ReactElement`

Default: `'Table of contents'` (visually hidden)

Text or element to display as the title above the table of contents. Set to `null` to render no title. When a string is provided, it is rendered as a visually hidden `<h2>` by default; pass a non-empty string to make it visible.

### `unsafeTocbotOptions`

Type: `object`

Provides additional configuration options passed directly to the underlying [`Tocbot`](https://tscanlin.github.io/tocbot/) library. These options are not guaranteed to remain available in future versions of Storybook.

{/* prettier-ignore-start */}

<CodeSnippets path="storybook-preview-custom-toc.md" />

{/* prettier-ignore-end */}
2 changes: 1 addition & 1 deletion docs/api/doc-blocks/doc-block-title.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'Title'
sidebar:
order: 14
order: 15
title: Title
---

Expand Down
2 changes: 1 addition & 1 deletion docs/api/doc-blocks/doc-block-typeset.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'Typeset'
sidebar:
order: 15
order: 16
title: Typeset
---

Expand Down
2 changes: 1 addition & 1 deletion docs/api/doc-blocks/doc-block-unstyled.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'Unstyled'
sidebar:
order: 16
order: 17
title: Unstyled
---

Expand Down
2 changes: 1 addition & 1 deletion docs/api/doc-blocks/doc-block-useof.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'useOf'
sidebar:
order: 17
order: 18
title: useOf
---

Expand Down
10 changes: 10 additions & 0 deletions docs/writing-docs/doc-blocks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ The `Subtitle` block can serve as a secondary heading for your docs entry.

![Screenshot of Subtitle block](../_assets/api/doc-block-title-subtitle-description.png)

### [TableOfContents](../api/doc-blocks/doc-block-tableofcontents.mdx)

<Callout variant="info">

Accepts parameters in the namespace `parameters.docs.toc`.

</Callout>

The `TableOfContents` block renders a table of contents for the current documentation page, allowing users to quickly navigate between sections. It appears as a fixed sidebar on the right side of the page.

### [Title](../api/doc-blocks/doc-block-title.mdx)

The `Title` block serves as the primary heading for your docs entry. It is typically used to provide the component or page name.
Expand Down