Skip to content

Commit 2ef7e87

Browse files
chore: fix sidebar for small width screens
1 parent 220107e commit 2ef7e87

4 files changed

Lines changed: 74 additions & 47 deletions

File tree

packages/web/src/app/(app)/@sidebar/components/sidebarBase.tsx

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ import { KeymapType } from "@/lib/types";
3232
import { cn } from "@/lib/utils";
3333
import {
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";
3738
import { Session } from "next-auth";
3839
import { signOut } from "next-auth/react";
3940
import { useTheme } from "next-themes";
@@ -45,6 +46,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
4546
import { Separator } from "@/components/ui/separator";
4647
import { WhatsNewSidebarButton } from "./whatsNewSidebarButton";
4748
import { UpgradeButton } from "./upgradeButton";
49+
import { useIsMobile } from "@/hooks/use-mobile";
4850

4951
interface SidebarBaseProps {
5052
session: Session | null;
@@ -57,6 +59,7 @@ interface SidebarBaseProps {
5759
export 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

packages/web/src/app/(app)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default async function Layout(props: LayoutProps) {
175175
<div className="fixed inset-0 flex bg-shell">
176176
<SidebarProvider defaultOpen={cookieStore.get("sidebar_state")?.value !== "false"}>
177177
{sidebar}
178-
<div className="flex-1 min-h-0 flex flex-col pt-2 pb-2 pr-2">
178+
<div className="flex-1 min-h-0 flex flex-col pt-2 pb-2 pr-2 pl-2 md:pl-0">
179179
<div className="flex-1 min-h-0 bg-background flex flex-col border border-[#e6e6e6] dark:border-[#1d1d1f] rounded-xl overflow-hidden">
180180
<BannerSlot
181181
role={role}

packages/web/src/components/ui/sidebar.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,6 @@ const Sidebar = React.forwardRef<
192192
) => {
193193
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
194194

195-
if (collapsible === "none") {
196-
return (
197-
<div
198-
className={cn(
199-
"flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",
200-
className
201-
)}
202-
ref={ref}
203-
{...props}
204-
>
205-
{children}
206-
</div>
207-
)
208-
}
209-
210195
if (isMobile) {
211196
return (
212197
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
@@ -231,6 +216,21 @@ const Sidebar = React.forwardRef<
231216
)
232217
}
233218

219+
if (collapsible === "none") {
220+
return (
221+
<div
222+
className={cn(
223+
"hidden h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground md:flex",
224+
className
225+
)}
226+
ref={ref}
227+
{...props}
228+
>
229+
{children}
230+
</div>
231+
)
232+
}
233+
234234
return (
235235
<div
236236
ref={ref}

packages/web/src/features/chat/components/chatBox/chatBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ const ChatBoxComponent = ({
367367
className={cn("flex flex-col justify-between gap-0.5 w-full px-3 py-2", className)}
368368
>
369369
<Editable
370-
className="w-full focus-visible:outline-none focus-visible:ring-0 bg-background text-base disabled:cursor-not-allowed disabled:opacity-50 md:text-sm max-h-64 overflow-y-auto"
370+
className="w-full focus-visible:outline-none focus-visible:ring-0 bg-background text-sm disabled:cursor-not-allowed disabled:opacity-50 max-h-64 overflow-y-auto"
371371
placeholder="Ask a question about your code. @mention files or select search scopes to refine your query."
372372
renderElement={renderElement}
373373
renderLeaf={renderLeaf}

0 commit comments

Comments
 (0)