From a668aea1fdbd82e0403b25cf15549deadeac92fa Mon Sep 17 00:00:00 2001 From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Mon, 3 Mar 2025 18:22:19 +1300 Subject: [PATCH 1/3] refactor: move `space-y-` margin utils to the single caller's source --- app/components/DocContainer.tsx | 2 +- app/routes/_libraries/blog.$.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/DocContainer.tsx b/app/components/DocContainer.tsx index 7f2566469..62260beec 100644 --- a/app/components/DocContainer.tsx +++ b/app/components/DocContainer.tsx @@ -9,7 +9,7 @@ export function DocContainer({
diff --git a/app/routes/_libraries/blog.$.tsx b/app/routes/_libraries/blog.$.tsx index d0a9bdf4e..e0bdc4e7c 100644 --- a/app/routes/_libraries/blog.$.tsx +++ b/app/routes/_libraries/blog.$.tsx @@ -82,7 +82,7 @@ ${content}` return ( -
+
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} -
-
-
- -
-
-
-
- {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, '')} />
  • ))}