From 547212cd9e85bd67854663b9d62002e243ea6d97 Mon Sep 17 00:00:00 2001 From: headlessdev Date: Fri, 18 Apr 2025 00:07:21 +0200 Subject: [PATCH] Sidebar Design Update --- components/app-sidebar.tsx | 158 ++++++++++++++++++++++++---------- components/ui/collapsible.tsx | 33 +++++++ package-lock.json | 20 +---- package.json | 1 + 4 files changed, 149 insertions(+), 63 deletions(-) create mode 100644 components/ui/collapsible.tsx diff --git a/components/app-sidebar.tsx b/components/app-sidebar.tsx index a616da3..4291609 100644 --- a/components/app-sidebar.tsx +++ b/components/app-sidebar.tsx @@ -1,10 +1,25 @@ -import * as React from "react" +"use client" + +import type * as React from "react" import Image from "next/image" -import { AppWindow, Settings, LayoutDashboardIcon, Briefcase, Server, Network, Activity } from "lucide-react" +import { usePathname } from "next/navigation" +import { + AppWindow, + Settings, + LayoutDashboardIcon, + Briefcase, + Server, + Network, + Activity, + LogOut, + ChevronDown, +} from "lucide-react" import { Sidebar, SidebarContent, SidebarGroup, + SidebarGroupContent, + SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, @@ -13,12 +28,15 @@ import { SidebarMenuSubButton, SidebarMenuSubItem, SidebarRail, + SidebarFooter, } from "@/components/ui/sidebar" import { Button } from "@/components/ui/button" import Link from "next/link" import Cookies from "js-cookie" import { useRouter } from "next/navigation" import packageJson from "@/package.json" +import { cn } from "@/lib/utils" +import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" interface NavItem { title: string @@ -33,7 +51,7 @@ const data: { navMain: NavItem[] } = { { title: "Dashboard", icon: LayoutDashboardIcon, - url: "/dashboard" + url: "/dashboard", }, { title: "My Infrastructure", @@ -59,7 +77,7 @@ const data: { navMain: NavItem[] } = { title: "Network", icon: Network, url: "/dashboard/network", - }, + }, ], }, { @@ -72,71 +90,119 @@ const data: { navMain: NavItem[] } = { export function AppSidebar({ ...props }: React.ComponentProps) { const router = useRouter() - + const pathname = usePathname() + const logout = async () => { - Cookies.remove('token') + Cookies.remove("token") router.push("/") } + // Check if a path is active (exact match or starts with path for parent items) + const isActive = (path: string) => { + if (path === "#") return false + return pathname === path || (path !== "/dashboard" && pathname?.startsWith(path)) + } + + // Check if any child item is active + const hasActiveChild = (items?: NavItem[]) => { + if (!items) return false + return items.some((item) => isActive(item.url)) + } + return ( - + - - - Logo + + +
+ CoreControl Logo +
- CoreControl - v{packageJson.version} + CoreControl + v{packageJson.version}
- - + + - - {data.navMain.map((item) => ( - - - - {item.icon && } - {item.title} - - - {item.items?.length && ( - - {item.items.map((subItem) => ( - - + Main Navigation + + + + {data.navMain.map((item) => + item.items?.length ? ( + + + + - - {subItem.icon && } - {subItem.title} - - - - ))} - - )} - - ))} - + {item.icon && } + {item.title} + + + + + + {item.items.map((subItem) => ( + + + + {subItem.icon && } + {subItem.title} + + + + ))} + + + + + ) : ( + + + + {item.icon && } + {item.title} + + + + ), + )} + + -
- -
+
) -} \ No newline at end of file +} diff --git a/components/ui/collapsible.tsx b/components/ui/collapsible.tsx new file mode 100644 index 0000000..ae9fad0 --- /dev/null +++ b/components/ui/collapsible.tsx @@ -0,0 +1,33 @@ +"use client" + +import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" + +function Collapsible({ + ...props +}: React.ComponentProps) { + return +} + +function CollapsibleTrigger({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function CollapsibleContent({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { Collapsible, CollapsibleTrigger, CollapsibleContent } diff --git a/package-lock.json b/package-lock.json index 4e5a164..0dccfed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,19 @@ { "name": "corecontrol", - "version": "0.0.5", + "version": "0.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "corecontrol", - "version": "0.0.5", + "version": "0.0.6", "dependencies": { "@prisma/client": "^6.6.0", "@prisma/extension-accelerate": "^1.3.0", "@radix-ui/react-accordion": "^1.2.4", "@radix-ui/react-alert-dialog": "^1.1.7", "@radix-ui/react-checkbox": "^1.1.5", + "@radix-ui/react-collapsible": "^1.1.4", "@radix-ui/react-dialog": "^1.1.7", "@radix-ui/react-dropdown-menu": "^2.1.7", "@radix-ui/react-label": "^2.1.3", @@ -4576,21 +4577,6 @@ "optional": true } } - }, - "node_modules/@next/swc-win32-x64-msvc": { - "version": "15.3.0", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.3.0.tgz", - "integrity": "sha512-vHUQS4YVGJPmpjn7r5lEZuMhK5UQBNBRSB+iGDvJjaNk649pTIcRluDWNb9siunyLLiu/LDPHfvxBtNamyuLTw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } } } } diff --git a/package.json b/package.json index 4472eff..6dea8fa 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@radix-ui/react-accordion": "^1.2.4", "@radix-ui/react-alert-dialog": "^1.1.7", "@radix-ui/react-checkbox": "^1.1.5", + "@radix-ui/react-collapsible": "^1.1.4", "@radix-ui/react-dialog": "^1.1.7", "@radix-ui/react-dropdown-menu": "^2.1.7", "@radix-ui/react-label": "^2.1.3",