Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toc updated #8

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/components/mdx/toc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ export function DashboardTableOfContents({ toc }: TocProps) {
const mounted = useMounted();

return mounted ? (
<div className="h-[calc(100vh-3.5rem)] flex flex-col justify-between pb-10">
{/* Added a wrapper div with overflow styling */}
<div className="space-y-2 overflow-y-auto pr-4 scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-transparent">
<p className="font-medium sticky top-0 bg-background pt-2 pb-2">On this page</p>
<div className="relative h-fit">
<span className= "w-1 h-full bg-neutral-900 absolute -z-10"></span>

<Tree tree={toc} activeItem={activeHeading} />
<div className="space-y-2">
<p className="font-medium">On this page</p>
<div className="flex flex-col space-x-1 relative">
<div className="w-1 flex h-full bg-neutral-900 absolute"></div>
<Tree tree={toc} activeItem={activeHeading} />
</div>
</div>

Expand All @@ -63,7 +60,7 @@ function useActiveItem(itemIds: (string | undefined)[]) {
}
});
},
{ rootMargin: `0% 0% -60% 0%` }
{ rootMargin: `0% 0% -40% 0%` }
);

itemIds?.forEach((id) => {
Expand Down Expand Up @@ -101,20 +98,24 @@ interface TreeProps {
}

function Tree({ tree, level = 1, activeItem }: TreeProps) {
return tree.length && level < 3 ? (
<ul className={cn("m-0 list-none text-sm", { "pl-4": level !== 1 })}>
console.log
return tree.length && level < 5 ? (
<ul className={cn("m-0 list-none text-sm")}>
{tree.map((item, index) => {
return (
<li key={index} className={cn("mt-0 pt-2")}>
<li key={index} className={cn("mt-0 ")}>
<a
href={item.url}
className={cn(
"inline-block no-underline px-1 py-0.5 rounded",
"inline-block no-underline py-2 p-2 relative rounded hover:text-neutral-200 transition-all duration-300 ease-in-out",
item.url === `#${activeItem}`
? "text-primary font-medium bg-secondary"
? "text-primary font-medium "
: "text-muted-foreground"
)}
>
{item.url === `#${activeItem}` && (
<span className="bg-neutral-400 rounded h-full w-1 ml-[-3px] absolute left-0 top-0"></span>
)}
{item.title}
</a>
{item.items?.length ? (
Expand Down
Loading