Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix TOC highlighting

Terry Sutton7453c05226b4
diff --git a/apps/temp-docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts b/apps/temp-docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts
index af959573bee..fbf05c39a7b 100644
--- a/apps/temp-docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts
+++ b/apps/temp-docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts
@@ -33,3 +33,9 @@ export const highlightSelectedTocItem = (id: string) => {
}
})
}
+
+// find any currently active items and remove them on route change
+export const unHighlightSelectedTocItems = () => {
+ const currentActiveItem = document.querySelector('.toc-menu .toc__menu-item--active')
+ currentActiveItem?.classList.remove('toc__menu-item--active')
+}
diff --git a/apps/temp-docs/components/CustomHTMLElements/Heading.tsx b/apps/temp-docs/components/CustomHTMLElements/Heading.tsx
index bf81989b26c..478ad47ab32 100644
--- a/apps/temp-docs/components/CustomHTMLElements/Heading.tsx
+++ b/apps/temp-docs/components/CustomHTMLElements/Heading.tsx
@@ -1,4 +1,9 @@
-import { getAnchor, removeAnchor, highlightSelectedTocItem } from './CustomHTMLElements.utils'
+import {
+ getAnchor,
+ removeAnchor,
+ highlightSelectedTocItem,
+ unHighlightSelectedTocItems,
+} from './CustomHTMLElements.utils'
import { useInView } from 'react-intersection-observer'
const Heading = ({ tag, children }) => {
@@ -11,6 +16,7 @@ const Heading = ({ tag, children }) => {
const { ref, inView, entry } = useInView({
threshold: 1,
onChange: (inView, entry) => {
+ if (window.scrollY === 0) unHighlightSelectedTocItems()
if (inView) highlightSelectedTocItem(entry.target.id)
},
})
diff --git a/apps/temp-docs/components/Navigation/SideBar.tsx b/apps/temp-docs/components/Navigation/SideBar.tsx
index 19285ac73cc..1741071694b 100644
--- a/apps/temp-docs/components/Navigation/SideBar.tsx
+++ b/apps/temp-docs/components/Navigation/SideBar.tsx
@@ -42,7 +42,7 @@ const SideBar = ({ menuItems = [] }: { menuItems: any }) => {
return (
<div
- className="dark:bg-scale-200 dark:border-scale-400 sidebar-width sticky top-0
+ className="dark:bg-scale-200 dark:border-scale-400 sidebar-width sticky top-8
h-screen overflow-y-scroll border-r py-8 px-6 sidebar-menu-container"
>
{isInReferencePages && (
@@ -82,7 +82,7 @@ const SideBar = ({ menuItems = [] }: { menuItems: any }) => {
'py-1.5 px-5 rounded text-sm transition',
`${
item.url === asPath
- ? 'bg-scale-400 text-brand-900'
+ ? 'bg-scale-200 text-brand-900'
: 'text-scale-1100 hover:text-scale-1200'
}`,
].join(' ')}
@@ -124,7 +124,7 @@ const SideBar = ({ menuItems = [] }: { menuItems: any }) => {
'py-1.5 px-5 rounded text-sm transition',
`${
section.url === asPath
- ? 'bg-scale-400 text-brand-900'
+ ? 'bg-scale-200 text-brand-900'
: 'text-scale-1100 hover:text-scale-1200'
}`,
].join(' ')}
@@ -164,7 +164,7 @@ const SideBar = ({ menuItems = [] }: { menuItems: any }) => {
'py-1.5 ml-4 px-5 rounded text-sm transition',
`${
item.url === asPath
- ? 'bg-scale-400 text-brand-900'
+ ? 'bg-scale-200 text-brand-900'
: 'text-scale-1100 hover:text-scale-1200'
}`,
].join(' ')}
diff --git a/apps/temp-docs/layouts/Default.tsx b/apps/temp-docs/layouts/Default.tsx
index 6060552d33d..a33e192b490 100644
--- a/apps/temp-docs/layouts/Default.tsx
+++ b/apps/temp-docs/layouts/Default.tsx
@@ -59,18 +59,24 @@ const Layout: FC<Props> = ({ meta, children, toc, menuItems, currentPage }) => {
{toc && !meta?.hide_table_of_contents && (
<div className="border-scale-400 dark:bg-scale-200 thin-scrollbar table-of-contents-height col-span-3 border-l px-4">
<ul className="toc-menu list-none pl-4 text-[0.8rem] grid gap-1 mt-1">
- {toc.json.map((item: any, i: number) => {
- return (
- <li key={i} className={`${item.lvl === 3 ? 'ml-4' : ''}`}>
- <a
- className="text-scale-1000 hover:text-brand-900 transition-colors"
- href={`#${item.slug}`}
+ {toc.json
+ .filter((item) => item.lvl !== 1)
+ .map((item: any, i: number) => {
+ return (
+ <li
+ key={i}
+ className={`${item.lvl === 3 && i !== 0 ? 'ml-4' : ''}`}
+ id={item.lvl}
>
- {item.content}
- </a>
- </li>
- )
- })}
+ <a
+ className="text-scale-1000 hover:text-brand-900 transition-colors"
+ href={`#${item.slug}`}
+ >
+ {item.content}
+ </a>
+ </li>
+ )
+ })}
</ul>
</div>
)}
diff --git a/apps/temp-docs/lib/docs.ts b/apps/temp-docs/lib/docs.ts
index 50b0e64cdb1..9380a21c1c3 100644
--- a/apps/temp-docs/lib/docs.ts
+++ b/apps/temp-docs/lib/docs.ts
@@ -27,8 +27,6 @@ export function getDocsBySlug(slug: string) {
? getPathToGeneratedDoc(realSlug)
: realSlug
- console.log('getDocsBySlug', { slug, formattedSlug })
-
// files can either be .md or .mdx
// we need to check which one exists
let fullPath