Table of Contents

Description

Navigational aid to semantically organize hierarchical content, facilitating easy navigation and comprehension within a web page's structure.

PRO
This component is part of our professional component suite. See the installation instructions below for more on how to use it.

Arguments

Name Default Type Description
title String The text title of the TOC component
html_attributes {} Hash Any attributes for the used html wrapper tag

Examples

Default

<%= render Railsboot::TableOfContentsComponent.new do |toc| %>
  <% toc.with_item { link_to("Topic 1", anchor: "topic-1") } %>
  <% toc.with_item { link_to("Topic 2", anchor: "topic-2") } %>
  <% toc.with_item { link_to("Topic 3", anchor: "topic-3") } %>
<% end %>
<div class="py-4 text-left bg-light">
  <details open>
    <summary class="py-2 ms-6 fw-bold">Table of Contents</summary>
    <ul class="ms-6">
      <li><a href="/components/table_of_contents#topic-1">Topic 1</a></li>
      <li><a href="/components/table_of_contents#topic-2">Topic 2</a></li>
      <li><a href="/components/table_of_contents#topic-3">Topic 3</a></li>
    </ul>
  </details>
</div>

With title

<%= render Railsboot::TableOfContentsComponent.new(title: "List of topics") do |toc| %>
  <% toc.with_item { link_to("Topic 1", anchor: "topic-1") } %>
  <% toc.with_item { link_to("Topic 2", anchor: "topic-2") } %>
  <% toc.with_item { link_to("Topic 3", anchor: "topic-3") } %>
<% end %>
<div class="py-4 text-left bg-light">
  <details open>
    <summary class="py-2 ms-6 fw-bold">List of topics</summary>
    <ul class="ms-6">
      <li><a href="/components/table_of_contents#topic-1">Topic 1</a></li>
      <li><a href="/components/table_of_contents#topic-2">Topic 2</a></li>
      <li><a href="/components/table_of_contents#topic-3">Topic 3</a></li>
    </ul>
  </details>
</div>

Slots

items Railsboot::TableOfContents::ItemComponent

Items represent the individual link in the list. The item slot can be passed a content block, which will be rendered inside.

Name Default Type Description
html_attributes {} Hash Any attributes for the used html wrapper tag

Installation

Simply download this component with all its related files and assets. Unpackage the downloaded ZIP-file, copy all relevant files into your app and adapt the things you need. The ZIP-folder contains:

  • A parent component class (app/components/railsboot/component.rb) of which all components inherit from.
  • A base component class (app/components/railsboot/base_component.rb) which is used for rendering internally.
  • The desired component itself (app/components/railsboot/table_of_contents_component.rb).
  • A view template (app/components/railsboot/table_of_contents_component.html.erb) for the component unless it's rendered inline.
  • Any other dependent components such as Slots (just if the component needs those)
  • Any dependent assets (JS-Files, CSS-Files) (just if the component needs those)
  • A test file for the components (test/components/railsboot/table_of_contents_component_test.rb) including potential slot or dependency tests.

For more information please refer to the installation section.

Download

Download the component and its related files (e.g. templates, assets, slots etc.), unpackage the zip file and adapt the things you need.

Get access You need to purchase a professional license to download this component.