Files
lixiyu-net/components/readerpage/TOC.tsx

21 lines
753 B
TypeScript
Raw Normal View History

2023-12-25 17:21:39 +08:00
import { TTOCItem } from "@/types/toc.type";
import Link from "next/link";
export const TOC = (props: { data: TTOCItem[] }) => {
return (
2024-01-04 11:34:27 +08:00
<div className="sticky top-[5em] mx-5 p-2 border-gray-500">
<div className="p-2 font-bold text-center border border-gray-500">{"TABLE OF CONTENTS"}</div>
2023-12-25 17:21:39 +08:00
<ul className="flat-scrollbar my-1 px-1 h-[60vh] overflow-y-auto">
{props.data?.map((item) => (
<Link className="hover:text-sky-500" href={`#${item.anchorId}`} key={`toc-${item.anchorId}`}>
<li
className="my-2 text-sm target:text-blue-500"
style={{ paddingLeft: `${item.level - 1}em` }}
>{`${item.title}`}</li>
</Link>
))}
</ul>
</div>
);
};