Table of contents
An "On this page" list that marks the section the reader has scrolled to.
Usage
After the one-time setup, call the helper directly from ERB. No component import is needed.
<%= lc_toc class: "w-full max-w-56" do |toc| %>
<%= toc.link "Overview", "#overview" %>
<%= toc.link "Usage", "#usage" %>
<%= toc.link "Sizes", "#sizes", indent: true %>
<%= toc.link "API reference", "#api" %>
<% end %>
Examples
Links you list
<%= lc_toc class: "w-full max-w-56" do |toc| %>
<%= toc.link "Overview", "#overview" %>
<%= toc.link "Usage", "#usage" %>
<%= toc.link "Sizes", "#sizes", indent: true %>
<%= toc.link "API reference", "#api" %>
<% end %>
From rendered headings
Getting started
Markdown renderers such as Kiln give every heading an id.
Install
The list and the links come from the same HTML.
<% article = capture do %>
<h2 id="getting-started">Getting started</h2>
<p>Markdown renderers such as Kiln give every heading an id.</p>
<h3 id="install">Install</h3>
<p>The list and the links come from the same HTML.</p>
<% end %>
<div class="flex w-full flex-col gap-section sm:flex-row-reverse sm:items-start">
<%= lc_toc headings: article, class: "w-full sm:max-w-44" %>
<%= lc_prose(anchors: true) { article } %>
</div>
API reference
Helpers render semantic HTML and include their interaction wiring. Pass native attributes through class:, data:, aria: and the usual Rails options. Blocks use captured ERB content.
lc_toc
lc_toc(label: lc_t("lostcoords.ui.toc.label"), headings: nil, levels: 2..3, **attributes, &block)
| Input | Default | Values |
|---|---|---|
| label | lc_t("lostcoords.ui.toc.label") | Accessible name, visible where applicable |
| headings | nil | — |
| levels | 2..3 | — |
| attributes | {} | Native HTML attributes; class:, data: and aria: merge with defaults |
| block | Captured block | Captured Rails ERB content |
lc_toc yields a builder, toc, with these parts. Each part carries data-slot and merges class: and native attributes.
toc.link
toc.link(label, url, indent: false, **attributes)
| Input | Default | Values |
|---|---|---|
| label | Required | Accessible name, visible where applicable |
| url | Required | — |
| indent | false | true · false |
| attributes | {} | Native HTML attributes; class:, data: and aria: merge with defaults |
The examples also use lc_prose. Each is documented on its own page.
Styling and extension
Use class: to merge utilities, native attributes for application behavior, and the theming guide for the shared palette. For custom markup, the advanced class helpers expose the same styles, including glass surfaces and class merging.