Skip to content

astro-toc@0.2.0

Latest
Compare
Choose a tag to compare
@theisel theisel released this 26 Apr 03:52
6b2038b

Minor Changes

  • 8e73709: Feat: Apply HTML attributes (e.g. class, data-*) to root and nested list elements.

    ---
    const toc = [
      { depth: 1, title: "Level 1, Item 1" },
      { depth: 2, title: "Level 2, Item 1" },
      { depth: 2, title: "Level 2, Item 2" },
      { depth: 3, title: "Level 3, Item 1" },
      { depth: 1, title: "Level 1, Item 2" },
    ];
    ---
    
    <TOC toc={toc} class="toc-container" />
    
    <style>
      .toc-container {
        padding: 1rem;
      }
    </style>

    HTML Output:

    <ul data-astro-toc="1" class="toc-container" data-astro-cid-j7pv25f6="true">
      <li data-astro-toc="1">
        Level 1, Item 1
        <ul data-astro-toc="2" class="toc-container" data-astro-cid-j7pv25f6="true">
          <li data-astro-toc="2">Level 2, Item 1</li>
          <li data-astro-toc="2">
            Level 2, Item 2
            <ul data-astro-toc="3" class="toc-container" data-astro-cid-j7pv25f6="true">
              <li data-astro-toc="3">Level 3, Item 1</li>
            </ul>
          </li>
        </ul>
      </li>
      <li data-astro-toc="1">Level 1, Item 2</li>
    </ul>
  • fea06de: Feat: Use depth prop to set initial depth

    <TOC toc={toc} depth={2} />

    BREAKING CHANGE: use prop for custom component

    Previously use prop would default to <menu>. Default is now <ul>. Use as prop to define list type.

      <TOC
        toc={toc}
        use={MyComponent}
    - />
    +   as="menu"
    + />

    BREAKING CHANGE: Changed maxDepth prop type to number

      <TOC
        toc={toc}
    -   maxDepth="2"
    +   maxDepth={2}
      />

Patch Changes

  • 1dd1721: Fix TypeScript resolution by centralizing definitions in types.ts and refactoring the entry point (index.ts). Adds type safety and improves DX for TS users.