From c694b7dafda84f55a0d8fdcf426717844f2aa05b Mon Sep 17 00:00:00 2001 From: andres Date: Fri, 17 May 2024 13:55:37 +0200 Subject: [PATCH] feat: add a toggle for sidebar --- app/layout.tsx | 31 +++++++++++++++++++--------- components/client-layout.tsx | 24 ++++++++++++++++++++++ components/sidebar.tsx | 4 ++-- components/sidebar/tool-link.tsx | 2 +- components/site-header.tsx | 34 +++++++++++++++---------------- contexts/sidebar.tsx | 35 ++++++++++++++++++++++++++++++++ next.config.mjs | 1 - package.json | 1 + pnpm-lock.yaml | 19 +++++++++++++++++ 9 files changed, 119 insertions(+), 32 deletions(-) create mode 100644 components/client-layout.tsx create mode 100644 contexts/sidebar.tsx diff --git a/app/layout.tsx b/app/layout.tsx index 797d4b2..ea508cc 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,15 +1,20 @@ import "@/styles/globals.css"; import { Metadata } from "next"; +import { CookiesProvider } from "next-client-cookies/server"; import { siteConfig } from "@/config/site"; import { fontMono, fontSans } from "@/lib/fonts"; import { cn } from "@/lib/style"; +import { ClientLayout } from "@/components/client-layout"; import { Sidebar } from "@/components/sidebar"; import { SiteHeader } from "@/components/site-header"; import { TailwindIndicator } from "@/components/tailwind-indicator"; import { ThemeProvider } from "@/components/theme-provider"; import { SearchTextProvider } from "@/contexts/search-text"; +import { SidebarProvider } from "@/contexts/sidebar"; + +export const dynamic = "force-dynamic"; export const metadata: Metadata = { metadataBase: new URL(siteConfig.url), @@ -54,16 +59,22 @@ export default function RootLayout({ children }: RootLayoutProps) { fontMono.variable )} > - - -
- - -
{children}
-
- -
-
+ + + + + + + +
+ {children} +
+
+ +
+
+
+
); diff --git a/components/client-layout.tsx b/components/client-layout.tsx new file mode 100644 index 0000000..86b20a7 --- /dev/null +++ b/components/client-layout.tsx @@ -0,0 +1,24 @@ +"use client"; + +import React, { PropsWithChildren } from "react"; + +import { cn } from "@/lib/style"; +import { SidebarStatus, useSidebarStatus } from "@/contexts/sidebar"; + +export function ClientLayout({ children }: PropsWithChildren) { + const sidebarStatus = useSidebarStatus(); + const isOpen = sidebarStatus === SidebarStatus.Open; + const isClosed = sidebarStatus === SidebarStatus.Closed; + + return ( +
+ {children} +
+ ); +} diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 1d39bcf..6dc45d9 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -7,11 +7,11 @@ import { ToolGroups } from "./sidebar/tool-groups"; export function Sidebar() { return ( -