Table of contents
UI::TableOfContentsAn "On this page" list that follows the reader's scroll.
bin/rails generate velvetkit:add table_of_contents
- Also adds
- Nothing else
- Stimulus
- ui--table-of-contents
- Installs
- Nothing
Examples
Nested sections
Contribution process
Every change goes through the same four steps.
1. Create an issue or open a merge request
Describe the change and why it matters. Link related issues, add screenshots for visual changes, and note anything reviewers should try by hand.
Keep each change focused on one thing, so it is quick to review and easy to revert.
2. Classify as core or extended
Describe the change and why it matters. Link related issues, add screenshots for visual changes, and note anything reviewers should try by hand.
Keep each change focused on one thing, so it is quick to review and easy to revert.
3. Define level of support
Describe the change and why it matters. Link related issues, add screenshots for visual changes, and note anything reviewers should try by hand.
Keep each change focused on one thing, so it is quick to review and easy to revert.
4. Merge your changes
Describe the change and why it matters. Link related issues, add screenshots for visual changes, and note anything reviewers should try by hand.
Keep each change focused on one thing, so it is quick to review and easy to revert.
Resources
Guides, design files and the component checklist.
Ask in the discussion board when something is unclear.
Code of conduct
Be kind, assume good intent, and keep feedback about the work.
<%# The article scrolls in its own box here; on a real page leave out `container:`. %>
<div class="grid grid-cols-[1fr_14rem] gap-8 max-w-3xl">
<div id="toc-default-article" class="h-96 overflow-y-auto rounded-md border p-6 space-y-6">
<section class="space-y-2">
<h2 id="toc-default-process" class="text-lg font-semibold">Contribution process</h2>
<p class="text-sm text-muted-foreground">Every change goes through the same four steps.</p>
</section>
<% [
["toc-default-issue", "1. Create an issue or open a merge request"],
["toc-default-classify", "2. Classify as core or extended"],
["toc-default-support", "3. Define level of support"],
["toc-default-merge", "4. Merge your changes"]
].each do |id, heading| %>
<section class="space-y-2">
<h3 id="<%= id %>" class="font-medium"><%= heading %></h3>
<p class="text-sm text-muted-foreground">Describe the change and why it matters. Link related issues, add screenshots for visual changes, and note anything reviewers should try by hand.</p>
<p class="text-sm text-muted-foreground">Keep each change focused on one thing, so it is quick to review and easy to revert.</p>
</section>
<% end %>
<section class="space-y-2">
<h2 id="toc-default-resources" class="text-lg font-semibold">Resources</h2>
<p class="text-sm text-muted-foreground">Guides, design files and the component checklist.</p>
<p class="text-sm text-muted-foreground">Ask in the discussion board when something is unclear.</p>
</section>
<section class="min-h-80 space-y-2">
<h2 id="toc-default-conduct" class="text-lg font-semibold">Code of conduct</h2>
<p class="text-sm text-muted-foreground">Be kind, assume good intent, and keep feedback about the work.</p>
</section>
</div>
<%= render(UI::TableOfContents.new(title: "On this page", container: "#toc-default-article", offset: 24)) do |toc| %>
<% toc.with_item(href: "#toc-default-process", text: "Contribution process") do |item| %>
<% item.with_item(href: "#toc-default-issue", text: "1. Create an issue or open a merge request") %>
<% item.with_item(href: "#toc-default-classify", text: "2. Classify as core or extended") %>
<% item.with_item(href: "#toc-default-support", text: "3. Define level of support") %>
<% item.with_item(href: "#toc-default-merge", text: "4. Merge your changes") %>
<% end %>
<% toc.with_item(href: "#toc-default-resources", text: "Resources") %>
<% toc.with_item(href: "#toc-default-conduct", text: "Code of conduct") %>
<% end %>
</div>
Flat
Install
Each section starts with what you need and ends with how to check it worked.
Commands run from the root of your Rails app.
Configure
Each section starts with what you need and ends with how to check it worked.
Commands run from the root of your Rails app.
Theme
Each section starts with what you need and ends with how to check it worked.
Commands run from the root of your Rails app.
Deploy
Each section starts with what you need and ends with how to check it worked.
Commands run from the root of your Rails app.
<div class="grid grid-cols-[1fr_12rem] gap-8 max-w-2xl">
<div id="toc-flat-article" class="h-72 overflow-y-auto rounded-md border p-6 space-y-6 [&>section:last-child]:min-h-60">
<% %w[Install Configure Theme Deploy].each do |heading| %>
<section class="space-y-2">
<h2 id="toc-flat-<%= heading.downcase %>" class="font-semibold"><%= heading %></h2>
<p class="text-sm text-muted-foreground">Each section starts with what you need and ends with how to check it worked.</p>
<p class="text-sm text-muted-foreground">Commands run from the root of your Rails app.</p>
</section>
<% end %>
</div>
<%= render(UI::TableOfContents.new(container: "#toc-flat-article", offset: 24)) do |toc| %>
<% %w[Install Configure Theme Deploy].each do |heading| %>
<% toc.with_item(href: "#toc-flat-#{heading.downcase}", text: heading) %>
<% end %>
<% end %>
</div>
API
UI::TableOfContents.new(title: nil, label: nil, offset: 80, container: nil, class: nil, **html_attrs)