TableOfContents
«On this page»: the headings of the article, with the light on the section being read.
import TableOfContents from '@sypnia/ui/astro/TableOfContents.astro'
Beside the article
On wide screens it stays in view while the article scrolls; the light follows what is being read (<sy-toc>).
Code
---
import TableOfContents from '@sypnia/ui/astro/TableOfContents.astro';
const headings = [
{ id: 'toc-install', text: 'Install the SDK', depth: 2 },
{ id: 'toc-token', text: 'Save your token', depth: 3 },
{ id: 'toc-connect', text: 'Connect your project', depth: 2 },
{ id: 'toc-api', text: 'Through the API', depth: 2 },
];
---
<div class="sy-docs" style="min-height:0;background:none"><div style="max-width:14rem"><TableOfContents headings={headings} /></div></div> Folded, and its skeleton
On narrower screens it folds into the head of the article (inline). TableOfContentsSkeleton on the right.
Code
---
// Folded into the head of the article on screens narrower than 80rem (here it is shown open on every width).
import TableOfContents from '@sypnia/ui/astro/TableOfContents.astro';
import TableOfContentsSkeleton from '@sypnia/ui/astro/TableOfContentsSkeleton.astro';
const headings = [{ id: 'a', text: 'Install the SDK', depth: 2 }, { id: 'b', text: 'Connect your project', depth: 2 }, { id: 'c', text: 'Through the API', depth: 2 }];
---
<div class="sy-docs sy-cols g-toc-demo" style="min-height:0;background:none;--cols:2">
<TableOfContents headings={headings} inline />
<TableOfContentsSkeleton items={3} />
</div> When to use it
Use it when
- An article with three or more sections.
Do not use it when
- A short page with one or two headings: it adds nothing (with fewer than two it does not show).
For everyone
- It is a named navigation landmark; the section being read is marked
aria-current. - It only lists headings two levels deep, so it stays short.