+
Date: Mon, 3 Mar 2025 18:40:27 +1300
Subject: [PATCH 2/3] feat: add mobile table of contents
---
app/components/Doc.tsx | 83 +++++++++++++++++++-----------------
app/components/TocMobile.tsx | 50 ++++++++++++++++++++++
2 files changed, 94 insertions(+), 39 deletions(-)
create mode 100644 app/components/TocMobile.tsx
diff --git a/app/components/Doc.tsx b/app/components/Doc.tsx
index 60d5c7633..eab308320 100644
--- a/app/components/Doc.tsx
+++ b/app/components/Doc.tsx
@@ -7,6 +7,7 @@ import { DocTitle } from '~/components/DocTitle'
import { Markdown } from '~/components/Markdown'
import { Toc } from './Toc'
import { twMerge } from 'tailwind-merge'
+import { TocMobile } from './TocMobile'
type DocProps = {
title: string
@@ -89,55 +90,59 @@ export function Doc({
}, [])
return (
-
+
+ {shouldRenderToc ? : null}
- {title ?
{title} : null}
-
-
-
-
-
-
-
-
-
-
- {isTocVisible && (
-
-
-
- )}
-
+ {isTocVisible && (
+
+
+
+ )}
+
+
)
}
diff --git a/app/components/TocMobile.tsx b/app/components/TocMobile.tsx
new file mode 100644
index 000000000..43da1dc6e
--- /dev/null
+++ b/app/components/TocMobile.tsx
@@ -0,0 +1,50 @@
+import React from 'react'
+import { Link } from '@tanstack/react-router'
+import type { HeadingData } from 'marked-gfm-heading-id'
+import { FaCaretRight, FaCaretDown } from 'react-icons/fa6'
+
+interface TocMobileProps {
+ headings: Array
+}
+
+export function TocMobile({ headings }: TocMobileProps) {
+ const [isOpen, setIsOpen] = React.useState(false)
+
+ const handleToggle = (event: React.SyntheticEvent) => {
+ setIsOpen(event.currentTarget.open)
+ }
+
+ if (headings.length === 0) {
+ return null
+ }
+
+ return (
+
+
+
+ {isOpen ? : }
+ On this page
+
+
+
+ {headings.map((heading) => (
+ -
+
+
+ ))}
+
+
+
+
+ )
+}
From a494940c8a9689f8d41245e41f1f4ffb4ef1970f Mon Sep 17 00:00:00 2001
From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com>
Date: Mon, 3 Mar 2025 18:53:53 +1300
Subject: [PATCH 3/3] chore: more accessible and lessen the indentation
---
app/components/TocMobile.tsx | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/app/components/TocMobile.tsx b/app/components/TocMobile.tsx
index 43da1dc6e..eb3caf4a5 100644
--- a/app/components/TocMobile.tsx
+++ b/app/components/TocMobile.tsx
@@ -21,7 +21,10 @@ export function TocMobile({ headings }: TocMobileProps) {
return (
-
+
{isOpen ? : }
On this page
@@ -29,9 +32,9 @@ export function TocMobile({ headings }: TocMobileProps) {
{headings.map((heading) => (
-
]+(>|$)/g, '')}
/>
))}