Vitral 0.2.18
Menu

TableOfContents

O sumário de uma página, lido dos seus títulos, com a seção sendo lida marcada conforme a página rola — o “Nesta página” ao lado de documentos longos.

Importação

main.ts
import { TableOfContents } from '@vitral/vue';

Lido dos títulos

`source` é onde procurar e `selector` quais títulos pegar; um h3 fica sob o h2 anterior. Role a página: o link da seção no topo da vista fica marcado, e `offset` é a altura de um cabeçalho fixo que a cobre.

Install

A few paragraphs stand in for the section's text. The outline beside it follows as the page scrolls past each heading.

Headings keep their own ids; the outline links to them, so a link to a section still works when shared.

With a package manager

A subsection, drawn one step in.

From a CDN

A subsection, drawn one step in.

Pick a theme

A few paragraphs stand in for the section's text. The outline beside it follows as the page scrolls past each heading.

Headings keep their own ids; the outline links to them, so a link to a section still works when shared.

Tokens

A subsection, drawn one step in.

Use a component

A few paragraphs stand in for the section's text. The outline beside it follows as the page scrolls past each heading.

Headings keep their own ids; the outline links to them, so a link to a section still works when shared.

Ship it

A few paragraphs stand in for the section's text. The outline beside it follows as the page scrolls past each heading.

Headings keep their own ids; the outline links to them, so a link to a section still works when shared.

<script setup lang="ts">import { TableOfContents } from '@vitral/vue'; const sections = [    { id: 'toc-install', title: 'Install', sub: [{ id: 'toc-npm', title: 'With a package manager' }, { id: 'toc-cdn', title: 'From a CDN' }] },    { id: 'toc-theme', title: 'Pick a theme', sub: [{ id: 'toc-tokens', title: 'Tokens' }] },    { id: 'toc-use', title: 'Use a component', sub: [] },    { id: 'toc-ship', title: 'Ship it', sub: [] }];</script> <template>    <div style="display: grid; grid-template-columns: minmax(0, 1fr) 13rem; gap: 2rem; align-items: start">        <article id="toc-demo-article" style="line-height: 1.7">            <template v-for="section in sections" :key="section.id">                <h2 :id="section.id" style="margin: 1.5rem 0 0.5rem; font-size: 1.25rem">{{ section.title }}</h2>                <p>A few paragraphs stand in for the section's text. The outline beside it follows as the page scrolls past each heading.</p>                <p>Headings keep their own ids; the outline links to them, so a link to a section still works when shared.</p>                <template v-for="sub in section.sub" :key="sub.id">                    <h3 :id="sub.id" style="margin: 1rem 0 0.25rem; font-size: 1.05rem">{{ sub.title }}</h3>                    <p>A subsection, drawn one step in.</p>                </template>            </template>        </article>        <TableOfContents source="#toc-demo-article" selector="h2, h3" :offset="72" style="position: sticky; top: 5rem" />    </div></template>

Um sumário seu

`items` dá o sumário pronto — ids, rótulos e níveis — para títulos desenhados depois ou rótulos mais curtos que os títulos. `v-model:active` é a seção sendo lida.

Reading: toc-install

<script setup lang="ts">import { TableOfContents } from '@vitral/vue';import { ref } from 'vue'; const active = ref<string | null>(null);const items = [    { id: 'toc-install', label: 'Install' },    { id: 'toc-npm', label: 'npm, pnpm, yarn', level: 2 },    { id: 'toc-theme', label: 'Theme' },    { id: 'toc-use', label: 'Usage' },    { id: 'toc-ship', label: 'Ship' }];</script> <template>    <div style="display: flex; flex-wrap: wrap; gap: 2rem; align-items: start">        <TableOfContents v-model:active="active" :items="items" title="Contents" />        <p>Reading: <strong>{{ active ?? '—' }}</strong></p>    </div></template>

API

Lido de packages/vue/src/components/TableOfContents/types.ts, então diz o que o componente aceita de fato.

Props

NomeTipoDescrição
items TableOfContentsItem[]O sumário, quando você o tem; caso contrário é lido de `source`.
source string | HTMLElementOnde ler os títulos: um seletor ou um elemento. O padrão é o documento.
selector stringQuais títulos ler, por seletor. O padrão é `'h2, h3'`.
offset numberPixels do topo da vista onde um título conta como alcançado: a altura de um cabeçalho fixo. O padrão é 80.
title string | falseUm título sobre a lista; o “Nesta página” do locale caso contrário. `false` para nenhum.
smooth booleanRola até um título suavemente quando seu link é seguido. O padrão é true.

Mais pt, dt e unstyled de BaseProps; veja pass-through e modo sem estilo.

Emits

EventoPayloadDescrição
navigate id: stringUm link foi seguido.