The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add highlight on scroll to ref nav items
Terry Suttonf878ed52c4ce
diff --git a/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts b/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.tsindex 305ac4fa170..e5eb11d9466 100644--- a/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts+++ b/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts@@ -77,3 +77,19 @@ export const unHighlightSelectedTocItems = () => {const currentActiveItem = document.querySelector('.toc-menu .toc__menu-item--active')currentActiveItem?.classList.remove('toc__menu-item--active')}++export const highlightSelectedNavItem = (id: string) => {+ const navMenuItems = document.querySelectorAll('.function-link-item a')++ // find any currently active items and remove them+ const currentActiveItem = document.querySelector('.function-link-list .text-brand-900')+ currentActiveItem?.classList.remove('text-brand-900')++ // Add active class to the current item+ navMenuItems.forEach((item) => {+ // @ts-ignore+ if (item.href.split('/').at(-1) === id) {+ item.classList.add('text-brand-900')+ }+ })+}diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsxindex a9f2a4d766b..60f621ebf43 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx@@ -37,7 +37,7 @@ const NavigationMenuCliList = ({ currentLevel, setLevel, id }) => {icon?: string}) => {return (- <li key={id}>+ <li key={id} className="function-link-item text-scale-1000"><Link href={`#${id}`} passHref><a className="cursor-pointer transition text-scale-1000 text-sm hover:text-brand-900 flex gap-3">{icon && <img className="w-3" src={`${router.basePath}${icon}`} />}@@ -52,8 +52,8 @@ const NavigationMenuCliList = ({ currentLevel, setLevel, id }) => {return (<spanclassName="- font-mono text-xs uppercase- text-scale-1200 font-medium+ font-mono text-xs uppercase+ text-scale-1200 font-mediumtracking-widermb-3"@@ -138,7 +138,7 @@ const NavigationMenuCliList = ({ currentLevel, setLevel, id }) => {{menu.title ?? currentLevel}</h2></div>- <ul>+ <ul className="function-link-list">{MenuSections.map((section) => {return (<>diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsxindex 98444012e89..de8312ddc49 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx@@ -44,9 +44,9 @@ const NavigationMenuRefList = ({ currentLevel, setLevel, id }) => {slug: string}) => {return (- <li key={id}>+ <li key={id} className="function-link-item text-scale-1000"><Link href={`/reference/${library}/${slug}`} passHref>- <a className="cursor-pointer transition text-scale-1000 text-sm hover:text-brand-900 flex gap-3">+ <a className="cursor-pointer transition text-sm hover:text-brand-900 flex gap-3">{icon && <img className="w-3" src={`${router.basePath}${icon}`} />}{title}</a>@@ -122,7 +122,7 @@ const NavigationMenuRefList = ({ currentLevel, setLevel, id }) => {</h2></div>{/* )} */}- <ul className="">+ <ul className="function-link-list"><Divider /><SideMenuTitle title="Database" />{/* {console.log({ clientLibsCommon })} */}diff --git a/apps/docs/layouts/ref/RefSubLayout.tsx b/apps/docs/layouts/ref/RefSubLayout.tsxindex af31c8061d1..eaadc2a1107 100644--- a/apps/docs/layouts/ref/RefSubLayout.tsx+++ b/apps/docs/layouts/ref/RefSubLayout.tsx@@ -1,5 +1,6 @@import { useInView } from 'react-intersection-observer'import { FC } from 'react'+import { highlightSelectedNavItem } from '~/components/CustomHTMLElements/CustomHTMLElements.utils'interface ISectionContainer {id: string@@ -34,7 +35,7 @@ const RefSubLayout: FC<RefSubLayoutType> & RefSubLayoutSubComponents = (props) =const Section: FC<ISectionContainer> = (props) => {return (- <article key={props.id} className="scroll-mt-24">+ <article key={props.id}><StickyHeader id={props.slug} title={props.title} monoFont={props.monoFont} /><div className="grid lg:grid-cols-2 ref-container gap-16">{props.children}</div></article>@@ -46,7 +47,10 @@ const StickyHeader: FC<StickyHeader> = (props) => {threshold: 1,rootMargin: '30% 0% -35% 0px',onChange: (inView, entry) => {- if (inView && window) window.history.pushState(null, '', entry.target.id)+ if (inView && window) {+ window.history.pushState(null, '', entry.target.id)+ highlightSelectedNavItem(entry.target.id)+ }},})@@ -54,9 +58,10 @@ const StickyHeader: FC<StickyHeader> = (props) => {<h2ref={ref}id={props.id}- className={['text-xl font-medium text-scale-1200 mb-8 ', props.monoFont && 'font-mono'].join(- ' '- )}+ className={[+ 'text-xl font-medium text-scale-1200 mb-8 scroll-mt-24',+ props.monoFont && 'font-mono',+ ].join(' ')}>{props.title && <span className="max-w-xl">{props.title}</span>}</h2>