diff --git a/src/components/HTMLViewer.tsx b/src/components/HTMLViewer.tsx index 7d96236..e1d00c9 100644 --- a/src/components/HTMLViewer.tsx +++ b/src/components/HTMLViewer.tsx @@ -5,6 +5,7 @@ import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { useHTML } from '@/contexts/HTMLContext'; import { DocumentSkeleton } from '@/components/DocumentSkeleton'; +import { TableOfContents } from '@/components/TableOfContents'; interface HTMLViewerProps { className?: string; @@ -19,6 +20,7 @@ export function HTMLViewer({ className = '' }: HTMLViewerProps) { totalChapters, goToNextChapter, goToPreviousChapter, + goToChapter, } = useHTML(); const containerRef = useRef(null); @@ -48,13 +50,20 @@ export function HTMLViewer({ className = '' }: HTMLViewerProps) { Previous - - - {currentChapter?.title || `Chapter ${currentChapterIndex + 1}`} - - - ({currentChapterIndex + 1} of {totalChapters}) - + + + + {currentChapter?.title || `Chapter ${currentChapterIndex + 1}`} + + + ({currentChapterIndex + 1} of {totalChapters}) + + + void; +} + +export function TableOfContents({ chapters, currentChapterIndex, onChapterSelect }: TableOfContentsProps) { + const [isOpen, setIsOpen] = useState(false); + + const handleChapterClick = (index: number) => { + onChapterSelect(index); + setIsOpen(false); + }; + + return ( + <> + {/* Table of Contents Button */} + setIsOpen(true)} + className="inline-flex items-center px-3 py-1 text-sm rounded-md border border-muted bg-base text-foreground hover:bg-offbase transition-all duration-200 ease-in-out hover:scale-[1.04] hover:text-accent" + aria-label="Table of contents" + title="Table of contents" + > + + + + {/* Table of Contents Modal */} + + setIsOpen(false)} + > + + + + + + + + + + Table of Contents + + + {/* Chapters List */} + + + {chapters.map((chapter, index) => ( + handleChapterClick(index)} + className={`w-full text-left px-4 py-3 rounded-lg transition-all duration-200 ease-in-out + ${index === currentChapterIndex + ? 'bg-accent text-background font-medium' + : 'bg-offbase text-foreground hover:bg-muted hover:text-accent hover:scale-[1.02]' + }`} + > + + + + {chapter.title} + + + + {index + 1} / {chapters.length} + + + + ))} + + + + {/* Close Button */} + + setIsOpen(false)} + > + Close + + + + + + + + + > + ); +}