From a376558b2f9a87693187fbd4ba9a3ba94a19ad9c Mon Sep 17 00:00:00 2001 From: "santasri.pachhal" Date: Thu, 9 Jul 2026 11:54:16 +0530 Subject: [PATCH] refactor(layout): improve module header and sidebar toggle UX --- .../_components/module-shell-header.tsx | 27 ++++++++++++ src/app/(modules)/layout.tsx | 19 +++----- src/components/app-sidebar.tsx | 44 ++++++++++++++----- src/components/ui/sidebar.tsx | 41 ++++++++++++++--- 4 files changed, 100 insertions(+), 31 deletions(-) create mode 100644 src/app/(modules)/_components/module-shell-header.tsx diff --git a/src/app/(modules)/_components/module-shell-header.tsx b/src/app/(modules)/_components/module-shell-header.tsx new file mode 100644 index 0000000..74a5973 --- /dev/null +++ b/src/app/(modules)/_components/module-shell-header.tsx @@ -0,0 +1,27 @@ +'use client'; + +import { BreadcrumbBasic } from '@/components/app-breadcrumb'; +import { ModeToggle } from '@/components/mode-toogle'; +import { Separator } from '@/components/ui/separator'; +import { SidebarTrigger, useSidebar } from '@/components/ui/sidebar'; + +export function ModuleShellHeader() { + const { isMobile } = useSidebar(); + + return ( +
+
+ {isMobile ? ( + <> + + + + ) : null} +
+ +
+
+ +
+ ); +} diff --git a/src/app/(modules)/layout.tsx b/src/app/(modules)/layout.tsx index 08a24cb..b6d61b6 100644 --- a/src/app/(modules)/layout.tsx +++ b/src/app/(modules)/layout.tsx @@ -1,10 +1,8 @@ -import { BreadcrumbBasic } from '@/components/app-breadcrumb'; import { AppSidebar } from '@/components/app-sidebar'; -import { ModeToggle } from '@/components/mode-toogle'; -import { SidebarProvider, SidebarTrigger } from '@/components/ui/sidebar'; -import { Separator } from '@/components/ui/separator'; +import { SidebarProvider } from '@/components/ui/sidebar'; import { AuthGuard } from '@/guards'; import React from 'react'; +import { ModuleShellHeader } from './_components/module-shell-header'; const ModulesLayout = ({ children, @@ -15,16 +13,11 @@ const ModulesLayout = ({ -
+
-
-
- - - - -
-
{children}
+
+ +
{children}
diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index b32252a..026c13c 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -18,16 +18,17 @@ import { Sidebar, SidebarContent, SidebarFooter, + SidebarGroup, SidebarHeader, - SidebarRail, SidebarMenu, - SidebarMenuItem, SidebarMenuButton, + SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, - SidebarGroup, - SidebarGroupLabel, + SidebarRail, + SidebarTrigger, + useSidebar, } from '@/components/ui/sidebar'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; @@ -41,6 +42,7 @@ function isRouteActive(pathname: string, path?: string) { export function AppSidebar({ ...props }: React.ComponentProps) { const pathname = usePathname(); const { hasPermission } = usePermissions(); + const { isMobile } = useSidebar(); const authUser = useAppStore((state) => state.user); const navItems = filterMenuItems(menuItems, hasPermission); const user = { @@ -53,17 +55,21 @@ export function AppSidebar({ ...props }: React.ComponentProps) { return ( - -
- + +
+
RoadMonitor Road Intelligence
+
- - + + {navItems.map((item) => ( ) { - + @@ -83,6 +89,23 @@ export function AppSidebar({ ...props }: React.ComponentProps) { ); } +function SidebarBrandControl({ isMobile }: { isMobile: boolean }) { + return ( +
+ + +
+ ); +} + function SidebarNavItem({ item, pathname, @@ -159,4 +182,3 @@ function SidebarNavItem({ ); } - diff --git a/src/components/ui/sidebar.tsx b/src/components/ui/sidebar.tsx index 1fe8642..6993967 100644 --- a/src/components/ui/sidebar.tsx +++ b/src/components/ui/sidebar.tsx @@ -256,29 +256,56 @@ function Sidebar({ function SidebarTrigger({ className, onClick, + tooltip, ...props -}: React.ComponentProps) { - const { toggleSidebar } = useSidebar(); +}: React.ComponentProps & { + tooltip?: string | React.ComponentProps; +}) { + const { isMobile, toggleSidebar } = useSidebar(); - return ( + const button = ( ); -} + if (!tooltip) { + return button; + } + + if (typeof tooltip === 'string') { + tooltip = { + children: tooltip, + }; + } + + return ( + + {button} + + ); +} function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) { const { toggleSidebar } = useSidebar();