@@ -32,8 +32,9 @@ import { KeymapType } from "@/lib/types";
3232import { cn } from "@/lib/utils" ;
3333import {
3434 ArrowLeftToLineIcon , ArrowRightToLineIcon , ChevronsUpDown , CodeIcon ,
35- Laptop , LogIn , LogOut , Moon , SettingsIcon , Sun , UserIcon
35+ Laptop , LogIn , LogOut , Menu , Moon , SettingsIcon , Sun , UserIcon
3636} from "lucide-react" ;
37+ import { Button } from "@/components/ui/button" ;
3738import { Session } from "next-auth" ;
3839import { signOut } from "next-auth/react" ;
3940import { useTheme } from "next-themes" ;
@@ -45,6 +46,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
4546import { Separator } from "@/components/ui/separator" ;
4647import { WhatsNewSidebarButton } from "./whatsNewSidebarButton" ;
4748import { UpgradeButton } from "./upgradeButton" ;
49+ import { useIsMobile } from "@/hooks/use-mobile" ;
4850
4951interface SidebarBaseProps {
5052 session : Session | null ;
@@ -57,6 +59,7 @@ interface SidebarBaseProps {
5759export function SidebarBase ( { session, collapsible = "icon" , headerContent, children, isValidLicenseActive } : SidebarBaseProps ) {
5860 const [ isScrolled , setIsScrolled ] = useState ( false ) ;
5961 const contentRef = useRef < HTMLDivElement > ( null ) ;
62+ const isMobile = useIsMobile ( ) ;
6063
6164 useEffect ( ( ) => {
6265 const el = contentRef . current ;
@@ -69,36 +72,60 @@ export function SidebarBase({ session, collapsible = "icon", headerContent, chil
6972 } , [ ] ) ;
7073
7174 return (
72- < Sidebar
73- collapsible = { collapsible }
74- className = "!border-r-0"
75+ < >
76+ < MobileSidebarTrigger />
77+ < Sidebar
78+ collapsible = { collapsible }
79+ className = "!border-r-0"
80+ >
81+ < SidebarHeader className = { cn ( "pt-4 border-b transition-[border-color] duration-200" , isScrolled ? "border-sidebar-border" : "border-transparent" ) } >
82+ < Link href = "/" >
83+ < div className = "group-data-[state=collapsed]:hidden" >
84+ < SourcebotLogo className = "w-fit h-8" size = "large" />
85+ </ div >
86+ < div className = "hidden group-data-[state=collapsed]:block" >
87+ < SourcebotLogo className = "w-fit h-8" size = "small" />
88+ </ div >
89+ </ Link >
90+ { headerContent }
91+ </ SidebarHeader >
92+ < SidebarContent ref = { contentRef } >
93+ { children }
94+ </ SidebarContent >
95+ < SidebarFooter className = "border-t border-sidebar-border" >
96+ { ! isValidLicenseActive && < UpgradeButton /> }
97+ {
98+ ( collapsible !== "none" && ! isMobile ) &&
99+ < CollapseSidebarButton />
100+ }
101+ < WhatsNewSidebarButton />
102+ { session ? (
103+ < MeControlDropdownMenu session = { session } />
104+ ) : (
105+ < GuestDropdownMenu />
106+ ) }
107+ </ SidebarFooter >
108+ { collapsible !== "none" && < SidebarRail /> }
109+ </ Sidebar >
110+ </ >
111+ ) ;
112+ }
113+
114+ function MobileSidebarTrigger ( ) {
115+ const { isMobile, setOpenMobile } = useSidebar ( ) ;
116+ if ( ! isMobile ) {
117+ return null ;
118+ }
119+ return (
120+ < Button
121+ variant = "outline"
122+ size = "icon"
123+ onClick = { ( ) => setOpenMobile ( true ) }
124+ className = "fixed bottom-4 left-4 z-50 shadow-md rounded-full"
125+ aria-label = "Open sidebar"
75126 >
76- < SidebarHeader className = { cn ( "pt-4 border-b transition-[border-color] duration-200" , isScrolled ? "border-sidebar-border" : "border-transparent" ) } >
77- < Link href = "/" >
78- < div className = "group-data-[state=collapsed]:hidden" >
79- < SourcebotLogo className = "w-fit h-8" size = "large" />
80- </ div >
81- < div className = "hidden group-data-[state=collapsed]:block" >
82- < SourcebotLogo className = "w-fit h-8" size = "small" />
83- </ div >
84- </ Link >
85- { headerContent }
86- </ SidebarHeader >
87- < SidebarContent ref = { contentRef } >
88- { children }
89- </ SidebarContent >
90- < SidebarFooter className = "border-t border-sidebar-border" >
91- { ! isValidLicenseActive && < UpgradeButton /> }
92- { collapsible !== "none" && < CollapseSidebarButton /> }
93- < WhatsNewSidebarButton />
94- { session ? (
95- < MeControlDropdownMenu session = { session } />
96- ) : (
97- < GuestDropdownMenu />
98- ) }
99- </ SidebarFooter >
100- { collapsible !== "none" && < SidebarRail /> }
101- </ Sidebar >
127+ < Menu className = "h-4 w-4" />
128+ </ Button >
102129 ) ;
103130}
104131
0 commit comments