Phara UI v2.x

Sidebar TOC

A sticky sidebar navigation component that automatically tracks the active section as you scroll.

Basic

Automatic table of contents navigation with scroll tracking.

The Sidebar TOC (Table of Contents) component provides an elegant way to navigate through long-form content. It automatically highlights the current section as users scroll through the page.

This component uses Intersection Observer API to detect which section is currently visible and updates the active state accordingly with smooth scrolling behavior.

Blade
<x-ui::sidebar-toc :sections="$sections" />
Installation

Included in the Phara UI Kit package with Alpine.js dependency.

The component is included in the Phara UI Kit package. Make sure you have Alpine.js installed as it's required for the interactive functionality.

Bash
npm install alpinejs
Usage

Define sections array and pass it to the component.

Define your sections as an array with 'id' and 'title' keys, then pass it to the component.

Blade
@php
    $sections = [
        ['id' => 'intro', 'title' => 'Introduction'],
        ['id' => 'usage', 'title' => 'Usage'],
        ['id' => 'examples', 'title' => 'Examples'],
    ];
@endphp

<div class="lg:flex lg:gap-12">
    <div class="flex-1">
        <section id="intro">...</section>
        <section id="usage">...</section>
        <section id="examples">...</section>
    </div>

    <x-ui::sidebar-toc :sections="$sections" />
</div>
Props

Component properties and configuration options.

Prop Type Required Description
sections Array Yes Array of sections with 'id' and 'title' keys

Section Object Structure:

PHP
[
    'id' => 'string',    // Must match the section element's id attribute
    'title' => 'string'  // Display text shown in the navigation
]
Features

Key features and common use cases for the component.

Key Features

  • Automatic active section highlighting based on scroll position
  • Smooth scroll to section when clicking navigation links
  • Sticky positioning for persistent visibility
  • Responsive - hidden on mobile, visible on large screens
  • Uses Intersection Observer API for performance
  • Primary color theming support
  • Dark mode compatible

Common Use Cases

  • Documentation pages
  • Long-form articles
  • Component demos (like this page!)
  • Tutorial or guide pages
  • API reference documentation
Blade
<x-ui::sidebar-toc :sections="$sections" />