Class: DocsUI::OnThisPage
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- DocsUI::OnThisPage
- Defined in:
- app/components/docs_ui/on_this_page.rb
Overview
An "On this page" table of contents that auto-collects the current page's
/ and highlights the section you're reading (scroll-spy). It ships
EMPTY — the docs-nav Stimulus controller fills it from the DOM, so a page gets
a live, self-maintaining TOC with zero server-side knowledge of its headings.
Three placements, same data, chosen by mode: (see
DocsKit::Configuration::ON_PAGE_MODES):
:panel — a fixed card pinned to the top-right of the viewport (below the
topbar). On wide screens it's always visible; on narrower screens
it collapses to a floating toggle button (docs-nav#toggleToc).
:toggle — always the floating toggle button + dropdown (top-right).
:sidebar — a slot the controller fills under the active left-nav item.
The controller hides the whole thing when the page has too few headings, so short pages show nothing (data-docs-nav-target="tocRoot" + auto-hide).
render DocsUI::OnThisPage.new(mode: :panel)
Instance Method Summary collapse
-
#initialize(mode: :panel, title: "On this page") ⇒ OnThisPage
constructor
A new instance of OnThisPage.
- #view_template ⇒ Object
Constructor Details
#initialize(mode: :panel, title: "On this page") ⇒ OnThisPage
Returns a new instance of OnThisPage.
23 24 25 26 |
# File 'app/components/docs_ui/on_this_page.rb', line 23 def initialize(mode: :panel, title: "On this page") @mode = mode @title = title end |
Instance Method Details
#view_template ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/components/docs_ui/on_this_page.rb', line 28 def view_template case @mode when :toggle then toggle_only when :sidebar then nil # the controller injects under the active nav item; no content slot else panel end end |