mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem on mobile docs pages with a sidebar have two menu buttons: the burger opens the global menu, and a second bar opens the sidebar while kb has its own full-screen accordion menu making two apps sharing no mobile nav code ## Solution - adds `MobileNavDrawer`, `MobileNavTabs` and `MobileNavThemeButton` to `packages/ui-patterns/src/MobileNav` - makes docs and kb use the same three parts - adds a full-width drawer in `MobileNavDrawer` under `--header-height`. It sets `inert` while it is closed - adds a tab row in `MobileNavTabs`, with a dropdown below `@xl` to avoid multiple tab lines - adds a theme button in `MobileNavThemeButton`. Each tap moves to the next theme in `singleThemes` - shows the group tabs, the theme button and the links of the selected group above the sidebar | before | after | | -------|------| | <img width="619" height="802" alt="image" src="https://github.com/user-attachments/assets/09d441c6-b4f3-4768-bb29-1e1d4f23fad1" /> | <img width="619" height="802" alt="image" src="https://github.com/user-attachments/assets/53043083-f05f-45aa-b30e-3db6fccdd443" /> | <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions Provide a clear numbered procedure that the PR reviewer can walk through. 1. For example, `Open the live and preview links side-by-side.` 2. For example, `See the issue is fixed.` ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
'use client'
|
|
|
|
import { createContext, useCallback, useContext, type PropsWithChildren } from 'react'
|
|
import { createPortal } from 'react-dom'
|
|
|
|
interface MobileHeaderSlots {
|
|
tocSlot: HTMLElement | null
|
|
onTitleScroll?: (title: string | null) => void
|
|
}
|
|
|
|
// the mobile header sits in the layout, above the page that knows the headings and the title
|
|
export const MobileHeaderSlotsContext = createContext<MobileHeaderSlots>({ tocSlot: null })
|
|
|
|
export const MobileTocSlotPortal = ({ children }: PropsWithChildren) => {
|
|
const { tocSlot } = useContext(MobileHeaderSlotsContext)
|
|
return tocSlot ? createPortal(children, tocSlot) : null
|
|
}
|
|
|
|
// placed inside the page title's element, it tells the header when that element scrolls under it
|
|
export const PageTitleObserver = ({ title }: { title: string }) => {
|
|
const { onTitleScroll } = useContext(MobileHeaderSlotsContext)
|
|
|
|
const observeTitle = useCallback(
|
|
(marker: HTMLSpanElement | null) => {
|
|
const titleElement = marker?.parentElement
|
|
if (!titleElement || !onTitleScroll) return
|
|
|
|
const observer = new IntersectionObserver(
|
|
([entry]) => onTitleScroll(entry.isIntersecting ? null : title),
|
|
// -90px is the header plus the toc bar, so the title counts as hidden under them
|
|
{ rootMargin: '-90px 0px 0px 0px' }
|
|
)
|
|
observer.observe(titleElement)
|
|
return () => {
|
|
observer.disconnect()
|
|
onTitleScroll(null)
|
|
}
|
|
},
|
|
[title, onTitleScroll]
|
|
)
|
|
|
|
return <span ref={observeTitle} hidden />
|
|
}
|