Files
supabase/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsx
T
Francesco Sansalvadore 23c827bdda feat: nested mobile nav menu (#43333)
- consolidate `top level menu` and `contextual menu` into nested menu on
mobile
- remove legacy mobile submenu
2026-03-11 13:55:20 +01:00

63 lines
1.9 KiB
TypeScript

import { useBreakpoint } from 'common'
import { useEffect } from 'react'
import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
import { cn, ResizableHandle, ResizablePanel } from 'ui'
import { useMobileSheet } from '../NavigationBar/MobileSheetContext'
// Having these params as props as otherwise it's quite hard to visually check the sizes in DefaultLayout
// as react resizeable panels requires all these values to be valid to render correctly
interface LayoutSidebarProps {
minSize?: string | number
maxSize?: string | number
defaultSize?: string | number
}
export const LayoutSidebar = ({
minSize = '30',
maxSize = '50',
defaultSize = '30',
}: LayoutSidebarProps) => {
const { activeSidebar } = useSidebarManagerSnapshot()
const isMobile = useBreakpoint('md')
const { setContent: setMobileSheetContent } = useMobileSheet()
// On mobile, sidebar content is shown in the sheet. Sync sheet content with active sidebar; clear when none or when switching to desktop.
useEffect(() => {
if (!isMobile) {
setMobileSheetContent(null)
return
}
if (activeSidebar?.component) {
setMobileSheetContent(activeSidebar.id)
} else {
setMobileSheetContent(null)
}
}, [isMobile, activeSidebar, setMobileSheetContent])
if (!activeSidebar?.component) return null
if (isMobile) return null
return (
<>
<ResizableHandle withHandle />
<ResizablePanel
id="panel-side"
key={activeSidebar?.id ?? 'default'}
defaultSize={defaultSize}
minSize={minSize}
maxSize={maxSize}
className={cn(
'border-l bg fixed z-40 right-0 top-0 bottom-0',
'h-[100dvh]',
'md:absolute md:h-auto md:w-1/2',
'lg:w-2/5',
'xl:relative xl:border-l-0'
)}
>
{activeSidebar?.component()}
</ResizablePanel>
</>
)
}