11import Link from 'next/link' ;
22import { useRouter } from 'next/router' ;
3- import { Home , LayoutDashboard , Network , Search } from 'lucide-react' ;
3+ import { Home , LayoutDashboard , Network , Search , ChevronLeft , ChevronRight } from 'lucide-react' ;
44import { Button } from "@/components/ui/button" ;
55import { ScrollArea } from "@/components/ui/scroll-area" ;
6+ import { useState } from 'react' ;
67
78const Sidebar = ( ) => {
89 const router = useRouter ( ) ;
10+ const [ collapsed , setCollapsed ] = useState ( false ) ;
911
1012 const menuItems = [
1113 {
@@ -36,12 +38,24 @@ const Sidebar = () => {
3638 }
3739 return router . pathname . startsWith ( path ) ;
3840 } ;
41+
42+ const toggleSidebar = ( ) => {
43+ setCollapsed ( ! collapsed ) ;
44+ } ;
3945
4046 return (
41- < div className = " h-full min-h-screen w-64 border-r" >
47+ < div className = { ` h-full min-h-screen ${ collapsed ? 'w-16' : 'w-64' } border-r transition-all duration-300 relative` } >
4248 < div className = "space-y-4 py-4" >
43- < div className = "px-4 py-2" >
44- < h2 className = "text-xl font-semibold tracking-tight" > VisualTreeSearch</ h2 >
49+ < div className = { `px-4 py-2 flex ${ collapsed ? 'justify-center' : 'justify-between' } items-center` } >
50+ { ! collapsed && < h2 className = "text-xl font-semibold tracking-tight" > VisualTreeSearch</ h2 > }
51+ < Button
52+ variant = "ghost"
53+ size = "icon"
54+ className = "absolute -right-3 top-5 bg-white dark:bg-gray-800 border shadow-sm z-10"
55+ onClick = { toggleSidebar }
56+ >
57+ { collapsed ? < ChevronRight className = "h-4 w-4" /> : < ChevronLeft className = "h-4 w-4" /> }
58+ </ Button >
4559 </ div >
4660 < ScrollArea className = "h-[calc(100vh-8rem)]" >
4761 < nav className = "grid gap-1 px-2" >
@@ -50,11 +64,12 @@ const Sidebar = () => {
5064 key = { item . name }
5165 asChild
5266 variant = { isActive ( item . href ) ? "secondary" : "ghost" }
53- className = "w-full justify-start"
67+ className = { `w-full ${ collapsed ? 'justify-center' : 'justify-start' } ` }
68+ title = { collapsed ? item . name : '' }
5469 >
5570 < Link href = { item . href } >
56- < item . icon className = " mr-2 h-4 w-4" />
57- { item . name }
71+ < item . icon className = { ` ${ collapsed ? '' : ' mr-2' } h-4 w-4` } />
72+ { ! collapsed && item . name }
5873 </ Link >
5974 </ Button >
6075 ) ) }
0 commit comments