| import { motion } from "framer-motion"; | |
| import { List } from "lucide-react"; | |
| interface TocItem { | |
| id: string; | |
| title: string; | |
| level: number; | |
| } | |
| interface BlogTableOfContentsProps { | |
| items: TocItem[]; | |
| } | |
| export function BlogTableOfContents({ items }: BlogTableOfContentsProps) { | |
| if (!items || items.length === 0) return null; | |
| const handleScroll = (id: string) => { | |
| const element = document.getElementById(id); | |
| if (element) { | |
| element.scrollIntoView({ behavior: "smooth", block: "start" }); | |
| } | |
| }; | |
| return ( | |
| <motion.div | |
| initial={{ opacity: 0, y: 15 }} | |
| animate={{ opacity: 1, y: 0 }} | |
| className="mb-8 rounded-2xl border border-white/10 bg-slate-950/40 p-5 backdrop-blur-md" | |
| > | |
| <div className="flex items-center gap-2 mb-4 font-bold text-gray-900 dark:text-white pb-3 border-b border-white/5"> | |
| <List className="h-5 w-5 text-primary" /> | |
| <span>Table of Contents</span> | |
| </div> | |
| <nav className="space-y-2"> | |
| {items.map((item) => { | |
| // Adjust padding/indentation based on heading level (e.g. H2, H3, H4) | |
| const indentClass = | |
| item.level === 3 | |
| ? "pl-4" | |
| : item.level >= 4 | |
| ? "pl-8" | |
| : "pl-0"; | |
| return ( | |
| <button | |
| key={item.id} | |
| onClick={() => handleScroll(item.id)} | |
| className={`block w-full text-left text-sm text-gray-600 dark:text-gray-400 hover:text-primary dark:hover:text-white transition-colors py-1 ${indentClass}`} | |
| > | |
| <span className="mr-1 text-primary/50">•</span> | |
| {item.title} | |
| </button> | |
| ); | |
| })} | |
| </nav> | |
| </motion.div> | |
| ); | |
| } | |
| export default BlogTableOfContents; | |
Xet Storage Details
- Size:
- 1.78 kB
- Xet hash:
- 22d80d38b788326bb0ab2074f575c30eae9610f9aaccab620c68adac19ea7159
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.