🎨 Add Table of Contents component and type definitions

This commit is contained in:
pheralb
2025-09-16 13:27:45 +01:00
parent f411ffef8a
commit 5bc3616dec
2 changed files with 34 additions and 0 deletions
@@ -0,0 +1,28 @@
<script lang="ts">
import type { TableOfContentsProps } from "./toc.types";
import { cn } from "@/utils/cn";
let { toc, className }: TableOfContentsProps = $props();
</script>
<div
class={cn(
"flex flex-col text-sm text-neutral-600 dark:text-neutral-400",
className,
)}
>
{#each toc as tocItem (tocItem.id)}
<a
href={"#" + tocItem.slug}
class={cn(
"pt-1 pb-1.5 transition-colors hover:text-neutral-900 dark:hover:text-neutral-50",
tocItem.level === 2 && "ml-0 font-medium",
tocItem.level === 3 &&
"border-l border-neutral-200 pl-4 dark:border-neutral-800",
tocItem.level === 4 && "ml-8",
)}
>
{tocItem.text}
</a>
{/each}
</div>
@@ -0,0 +1,6 @@
import type { ToCItem } from "@/markdown/generateToC";
export interface TableOfContentsProps {
toc: ToCItem[];
className?: string;
}