Skip to content

Commit ae72ed1

Browse files
committed
feat: sidebar active
1 parent 627fbb0 commit ae72ed1

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

src/components/sidebar.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
"use client"
1+
"use client";
22

33
import { ScrollArea } from "@/components/ui/scroll-area";
4-
54
import { GroupIcon, Lightbulb, UsersIcon } from "lucide-react";
65
import Link from "next/link";
7-
6+
import { usePathname } from "next/navigation";
87

98
export function Sidebar() {
9+
const pathname = usePathname();
10+
1011
const navigation = [
1112
{ name: "Users", href: "/users", icon: UsersIcon },
1213
{ name: "Teams", href: "/teams", icon: GroupIcon },
1314
{ name: "Ideas", href: "/idea", icon: Lightbulb },
1415
{ name: "Leaderboard", href: "/leaderboard", icon: Lightbulb },
15-
1616
];
1717

1818
return (
19-
<aside className="md:border-r md:border-gray-700 h-full w-64">
19+
<aside className="h-full w-64 md:border-r md:border-gray-700">
2020
<ScrollArea className="h-full">
2121
<div className="p-4">
22-
<Link href="/" className="text-2xl font-bold mb-6 block">
22+
<Link href="/" className="mb-6 block text-2xl font-bold">
2323
Devsoc Admin
2424
</Link>
2525
</div>
2626
<nav className="px-2 py-4">
27-
{navigation.map((item) => (
28-
<Link
29-
key={item.name}
30-
href={item.href}
31-
className="flex items-center space-x-2 px-3 py-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-200 font-medium text-gray-700 dark:text-gray-300"
32-
>
33-
<item.icon className="h-4 w-4" />
34-
<span>{item.name}</span>
35-
</Link>
36-
))}
27+
{navigation.map((item) => {
28+
const isActive = pathname === item.href;
29+
return (
30+
<Link
31+
key={item.name}
32+
href={item.href}
33+
className={`flex items-center space-x-2 rounded-md px-3 py-2 font-medium transition-colors duration-200 ${isActive ? "bg-gray-200 text-black dark:bg-gray-800 dark:text-white" : "text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700"}`}
34+
>
35+
<item.icon className="h-4 w-4" />
36+
<span>{item.name}</span>
37+
</Link>
38+
);
39+
})}
3740
</nav>
3841
</ScrollArea>
3942
</aside>
4043
);
41-
}
44+
}

0 commit comments

Comments
 (0)