1.0.0 • Published 5 months ago

sanity-table-of-contents v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Sanity Table of Contents Component

A lightweight and configurable table of contents component for Sanity.io and Next.js websites, built with React and TypeScript.

✨ Features

  • 📚 Automatic Heading Extraction from PortableText content
  • 🎯 Scroll Spy highlights current section
  • 🖱 Smooth Scrolling to sections
  • 🎨 Customizable UI with TailwindCSS
  • 📱 Responsive Design with dropdown variant

💻 Demo

Live Demo

🚀 Installation

npm install sanity-table-of-contents
# or
yarn add sanity-table-of-contents

🛠 Usage

Basic Implementation

// components/table-of-contents.tsx
"use client";

import { SanityTableOfContents } from "sanity-table-of-contents";
import { PortableTextBlock } from "@portabletext/types";

export default function TableOfContents({ content }: { content: PortableTextBlock[] }) {
  return (
    <SanityTableOfContents 
      value={content}
      title="Table of Contents"
      className="sticky top-4"
    />
  );
}

📌 Props

<SanityTableOfContents />

PropTypeRequiredDescription
valuePortableTextBlock | PortableTextBlock[]PortableText content to extract headings from
titlestringTitle for the table of contents
classNamestringCustom class for styling
variant"default" | "dropdown"Display variant (default or dropdown)

📜 License

MIT License © 2025 Imad Attif

🌟 Contributions

PRs and feedback are welcome! 🚀