Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: close sidebar on dataroom

Marc Seitzdb303909f2d2
diff --git a/components/layouts/app.tsx b/components/layouts/app.tsx
index 5fabd9a5..5cc620e3 100644
--- a/components/layouts/app.tsx
+++ b/components/layouts/app.tsx
@@ -1,4 +1,5 @@
import Cookies from "js-cookie";
+import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { AppBreadcrumb } from "@/components/layouts/breadcrumb";
@@ -12,16 +13,26 @@ import {
SidebarTrigger,
} from "@/components/ui/sidebar";
-import { usePlan } from "@/lib/swr/use-billing";
+// import { usePlan } from "@/lib/swr/use-billing";
// import YearlyUpgradeBanner from "@/components/billing/yearly-upgrade-banner";
import { BlockingModal } from "./blocking-modal";
export default function AppLayout({ children }: { children: React.ReactNode }) {
- // Default to open (true) if no cookie exists, otherwise use the stored preference
+ const router = useRouter();
+ const isDataroom = router.pathname.startsWith("/datarooms/[id]");
+
const cookieValue = Cookies.get(SIDEBAR_COOKIE_NAME);
- const isSidebarOpen =
- cookieValue === undefined ? true : cookieValue === "true";
+ const defaultOpen = cookieValue === undefined ? true : cookieValue === "true";
+
+ const [sidebarOpen, setSidebarOpen] = useState(defaultOpen);
+
+ // Close sidebar when entering a dataroom
+ useEffect(() => {
+ if (isDataroom) {
+ setSidebarOpen(false);
+ }
+ }, [isDataroom]);
// const { isAnnualPlan, isFree } = usePlan();
// const [showYearlyBanner, setShowYearlyBanner] = useState<boolean | null>(null);
@@ -43,7 +54,7 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {
// }, [isFree, isAnnualPlan]);
return (
- <SidebarProvider defaultOpen={isSidebarOpen}>
+ <SidebarProvider open={sidebarOpen} onOpenChange={setSidebarOpen}>
<div className="flex flex-1 flex-col gap-x-1 bg-gray-50 dark:bg-black md:flex-row">
<AppSidebar />
<SidebarInset className="ring-1 ring-gray-200 dark:ring-gray-800">
diff --git a/components/ui/sidebar.tsx b/components/ui/sidebar.tsx
index 26724035..bd9a6109 100644
--- a/components/ui/sidebar.tsx
+++ b/components/ui/sidebar.tsx
@@ -2,7 +2,6 @@ import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { VariantProps, cva } from "class-variance-authority";
-import { PanelLeft } from "lucide-react";
import { useIsMobile } from "@/lib/hooks/use-mobile";
import { cn } from "@/lib/utils";
@@ -19,6 +18,53 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip";
+// Custom PanelLeft icon with filled state support
+const PanelLeftIcon = ({ filled = false }: { filled?: boolean }) => (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ >
+ {filled ? (
+ <>
+ {/* Filled left panel background */}
+ <path
+ d="M10 3 H5 a2 2 0 0 0 -2 2 V19 a2 2 0 0 0 2 2 H10 Z"
+ fill="currentColor"
+ stroke="none"
+ />
+ {/* Menu item lines (centered in sidebar panel) */}
+ <path d="M5.25 8h2.5" className="stroke-background" strokeWidth="1.5" />
+ <path
+ d="M5.25 12h2.5"
+ className="stroke-background"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M5.25 16h2.5"
+ className="stroke-background"
+ strokeWidth="1.5"
+ />
+ </>
+ ) : (
+ <>
+ {/* Menu item lines (centered in sidebar panel) */}
+ <path d="M5.25 8h2.5" strokeWidth="1.5" />
+ <path d="M5.25 12h2.5" strokeWidth="1.5" />
+ <path d="M5.25 16h2.5" strokeWidth="1.5" />
+ </>
+ )}
+ <rect width="18" height="18" x="3" y="3" rx="2" />
+ <path d="M10 3v18" />
+ </svg>
+);
+
export const SIDEBAR_COOKIE_NAME = "sidebar:state";
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
const SIDEBAR_WIDTH = "16rem";
@@ -286,12 +332,13 @@ const SidebarTrigger = React.forwardRef<
React.ElementRef<typeof Button>,
React.ComponentProps<typeof Button>
>(({ className, onClick, ...props }, ref) => {
- const { toggleSidebar } = useSidebar();
+ const { toggleSidebar, open } = useSidebar();
return (
<Button
ref={ref}
data-sidebar="trigger"
+ data-state={open ? "open" : "closed"}
variant="ghost"
size="icon"
className={cn("h-7 w-7", className)}
@@ -301,7 +348,7 @@ const SidebarTrigger = React.forwardRef<
}}
{...props}
>
- <PanelLeft />
+ <PanelLeftIcon filled={open} />
<span className="sr-only">Toggle Sidebar</span>
</Button>
);