mirror of
https://git.coastit.co.za/caitlin/CRM_ENVR.git
synced 2026-07-10 11:15:43 +02:00
195 lines
6.6 KiB
TypeScript
195 lines
6.6 KiB
TypeScript
"use client"
|
|
|
|
import { useState } from "react"
|
|
import Link from "next/link"
|
|
import { usePathname } from "next/navigation"
|
|
import { motion, AnimatePresence } from "framer-motion"
|
|
import { cn } from "@/lib/utils"
|
|
import { Button } from "@/components/ui/button"
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
|
|
import {
|
|
LayoutDashboard,
|
|
Users,
|
|
Settings,
|
|
ChevronLeft,
|
|
ChevronRight,
|
|
Building2,
|
|
PanelLeftClose,
|
|
} from "lucide-react"
|
|
import { COMPANY_NAME } from "@/lib/constants"
|
|
|
|
const navItems = [
|
|
{ href: "/dashboard", label: "Dashboard", icon: LayoutDashboard },
|
|
{ href: "/leads", label: "Leads", icon: Users },
|
|
{ href: "/users", label: "Users", icon: Building2 },
|
|
{ href: "/settings", label: "Settings", icon: Settings },
|
|
]
|
|
|
|
interface SidebarProps {
|
|
collapsed: boolean
|
|
onToggle: () => void
|
|
mobileOpen: boolean
|
|
onMobileClose: () => void
|
|
}
|
|
|
|
export function Sidebar({ collapsed, onToggle, mobileOpen, onMobileClose }: SidebarProps) {
|
|
const pathname = usePathname()
|
|
|
|
const sidebarContent = (
|
|
<div
|
|
className={cn(
|
|
"flex h-full flex-col bg-sidebar text-sidebar-foreground transition-all duration-300",
|
|
collapsed ? "w-16" : "w-64"
|
|
)}
|
|
>
|
|
{/* Logo */}
|
|
<div className={cn("flex h-16 items-center border-b border-sidebar-border px-4", collapsed ? "justify-center" : "justify-between")}>
|
|
<Link href="/" className="flex items-center gap-3 overflow-hidden">
|
|
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary">
|
|
<span className="text-sm font-bold text-primary-foreground">C</span>
|
|
</div>
|
|
<AnimatePresence mode="wait">
|
|
{!collapsed && (
|
|
<motion.span
|
|
initial={{ opacity: 0, x: -10 }}
|
|
animate={{ opacity: 1, x: 0 }}
|
|
exit={{ opacity: 0, x: -10 }}
|
|
transition={{ duration: 0.15 }}
|
|
className="text-sm font-semibold whitespace-nowrap"
|
|
>
|
|
{COMPANY_NAME}
|
|
</motion.span>
|
|
)}
|
|
</AnimatePresence>
|
|
</Link>
|
|
{!collapsed && (
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={onToggle}
|
|
className="h-6 w-6 text-sidebar-foreground/60 hover:text-sidebar-foreground"
|
|
>
|
|
<PanelLeftClose className="h-4 w-4" />
|
|
</Button>
|
|
)}
|
|
</div>
|
|
|
|
{/* Navigation */}
|
|
<nav className="flex-1 space-y-1 p-3">
|
|
{navItems.map((item) => {
|
|
const isActive = pathname === item.href || (item.href !== "/" && pathname.startsWith(item.href))
|
|
return collapsed ? (
|
|
<TooltipProvider key={item.href} delayDuration={0}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Link
|
|
href={item.href}
|
|
className={cn(
|
|
"flex h-10 w-10 items-center justify-center rounded-lg transition-colors",
|
|
isActive
|
|
? "bg-sidebar-primary text-sidebar-primary-foreground"
|
|
: "text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
|
)}
|
|
>
|
|
<item.icon className="h-5 w-5" />
|
|
</Link>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="right" className="ml-2">
|
|
{item.label}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
) : (
|
|
<Link
|
|
key={item.href}
|
|
href={item.href}
|
|
className={cn(
|
|
"flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors",
|
|
isActive
|
|
? "bg-sidebar-primary text-sidebar-primary-foreground"
|
|
: "text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
|
)}
|
|
>
|
|
<item.icon className="h-5 w-5 shrink-0" />
|
|
<motion.span
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
className="truncate"
|
|
>
|
|
{item.label}
|
|
</motion.span>
|
|
</Link>
|
|
)
|
|
})}
|
|
</nav>
|
|
|
|
{/* Collapse toggle at bottom (only in collapsed mode) */}
|
|
{collapsed && (
|
|
<div className="border-t border-sidebar-border p-3">
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
onClick={onToggle}
|
|
className="h-10 w-10 text-sidebar-foreground/60 hover:text-sidebar-foreground"
|
|
>
|
|
<ChevronRight className="h-4 w-4" />
|
|
</Button>
|
|
</div>
|
|
)}
|
|
|
|
{/* User info */}
|
|
<div className={cn("border-t border-sidebar-border p-3", collapsed && "flex justify-center")}>
|
|
{collapsed ? (
|
|
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-sidebar-accent">
|
|
<span className="text-sm font-medium text-sidebar-accent-foreground">SC</span>
|
|
</div>
|
|
) : (
|
|
<div className="flex items-center gap-3">
|
|
<div className="flex h-9 w-9 items-center justify-center rounded-full bg-sidebar-accent">
|
|
<span className="text-sm font-medium text-sidebar-accent-foreground">SC</span>
|
|
</div>
|
|
<div className="flex-1 overflow-hidden">
|
|
<p className="text-sm font-medium truncate">Sarah Chen</p>
|
|
<p className="text-xs text-sidebar-foreground/60 truncate">Admin</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
|
|
return (
|
|
<>
|
|
{/* Desktop sidebar */}
|
|
<aside className="hidden lg:fixed lg:inset-y-0 lg:z-30 lg:flex">
|
|
{sidebarContent}
|
|
</aside>
|
|
|
|
{/* Mobile sidebar overlay */}
|
|
<AnimatePresence>
|
|
{mobileOpen && (
|
|
<>
|
|
<motion.div
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
onClick={onMobileClose}
|
|
className="fixed inset-0 z-40 bg-black/60 lg:hidden"
|
|
/>
|
|
<motion.aside
|
|
initial={{ x: -300 }}
|
|
animate={{ x: 0 }}
|
|
exit={{ x: -300 }}
|
|
transition={{ type: "spring", damping: 30, stiffness: 300 }}
|
|
className="fixed inset-y-0 left-0 z-50 lg:hidden"
|
|
>
|
|
{sidebarContent}
|
|
</motion.aside>
|
|
</>
|
|
)}
|
|
</AnimatePresence>
|
|
</>
|
|
)
|
|
}
|