2026-03-25 09:24:37 +08:00
|
|
|
import type { LucideIcon } from "lucide-react";
|
2026-05-06 23:14:30 +08:00
|
|
|
import {
|
|
|
|
|
FolderOpen,
|
|
|
|
|
Grid3x3,
|
|
|
|
|
HelpCircle,
|
|
|
|
|
LayoutGrid,
|
|
|
|
|
PenTool,
|
|
|
|
|
Settings,
|
|
|
|
|
Workflow,
|
|
|
|
|
} from "lucide-react";
|
2026-03-22 03:01:23 +08:00
|
|
|
import { Link, useLocation } from "react-router-dom";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-05-05 21:45:51 +08:00
|
|
|
import { OtterLogo } from "../common/otter-logo";
|
2026-03-22 03:01:23 +08:00
|
|
|
|
|
|
|
|
interface SidebarItem {
|
|
|
|
|
icon: LucideIcon;
|
|
|
|
|
label: string;
|
|
|
|
|
href?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const topItems: SidebarItem[] = [
|
|
|
|
|
{ icon: LayoutGrid, label: "Tools", href: "/" },
|
2026-03-22 04:42:31 +08:00
|
|
|
{ icon: Grid3x3, label: "Grid", href: "/fullscreen" },
|
2026-03-22 03:01:23 +08:00
|
|
|
{ icon: Workflow, label: "Automate", href: "/automate" },
|
2026-05-06 23:14:30 +08:00
|
|
|
{ icon: PenTool, label: "Editor", href: "/editor" },
|
2026-03-22 03:01:23 +08:00
|
|
|
{ icon: FolderOpen, label: "Files", href: "/files" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const bottomItems: SidebarItem[] = [
|
2026-03-22 21:25:14 +08:00
|
|
|
{ icon: HelpCircle, label: "Help" },
|
2026-03-22 03:01:23 +08:00
|
|
|
{ icon: Settings, label: "Settings" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
interface SidebarProps {
|
|
|
|
|
onSettingsClick: () => void;
|
2026-03-22 21:25:14 +08:00
|
|
|
onHelpClick: () => void;
|
2026-03-26 01:10:13 +08:00
|
|
|
/** Called when a nav link is clicked (e.g., to close mobile sidebar). */
|
|
|
|
|
onNavClick?: () => void;
|
2026-03-22 04:42:31 +08:00
|
|
|
/** When true, renders in expanded mode (for mobile overlay). */
|
|
|
|
|
expanded?: boolean;
|
2026-03-22 03:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 01:10:13 +08:00
|
|
|
export function Sidebar({
|
|
|
|
|
onSettingsClick,
|
|
|
|
|
onHelpClick,
|
|
|
|
|
onNavClick,
|
|
|
|
|
expanded = false,
|
|
|
|
|
}: SidebarProps) {
|
2026-03-22 03:01:23 +08:00
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
|
|
const renderItem = (item: SidebarItem, isActive: boolean) => {
|
2026-03-22 04:42:31 +08:00
|
|
|
const content = expanded ? (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex items-center gap-3 px-4 py-2.5 rounded-lg cursor-pointer transition-colors",
|
|
|
|
|
isActive
|
|
|
|
|
? "bg-primary text-primary-foreground"
|
2026-03-25 09:24:37 +08:00
|
|
|
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
2026-03-22 04:42:31 +08:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<item.icon className="h-5 w-5" />
|
|
|
|
|
<span className="text-sm font-medium">{item.label}</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
2026-03-22 03:01:23 +08:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex flex-col items-center gap-1 p-2 rounded-lg cursor-pointer transition-colors",
|
|
|
|
|
isActive
|
|
|
|
|
? "bg-primary text-primary-foreground"
|
2026-03-25 09:24:37 +08:00
|
|
|
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
2026-03-22 03:01:23 +08:00
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<item.icon className="h-6 w-6" />
|
|
|
|
|
<span className="text-[10px] font-medium">{item.label}</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (item.label === "Settings") {
|
|
|
|
|
return (
|
2026-03-26 01:10:13 +08:00
|
|
|
<button key={item.label} type="button" onClick={onSettingsClick} className="w-full">
|
2026-03-22 03:01:23 +08:00
|
|
|
{content}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-22 21:25:14 +08:00
|
|
|
if (item.label === "Help") {
|
|
|
|
|
return (
|
2026-03-26 01:10:13 +08:00
|
|
|
<button key={item.label} type="button" onClick={onHelpClick} className="w-full">
|
2026-03-22 21:25:14 +08:00
|
|
|
{content}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-03-22 03:01:23 +08:00
|
|
|
return (
|
2026-03-26 01:10:13 +08:00
|
|
|
<Link key={item.label} to={item.href || "/"} onClick={onNavClick}>
|
2026-03-22 03:01:23 +08:00
|
|
|
{content}
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-22 04:42:31 +08:00
|
|
|
if (expanded) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col p-3 gap-1">
|
2026-03-25 09:24:37 +08:00
|
|
|
{topItems.map((item) => renderItem(item, location.pathname === item.href))}
|
2026-03-22 04:42:31 +08:00
|
|
|
<div className="border-t border-border my-2" />
|
|
|
|
|
{bottomItems.map((item) => renderItem(item, false))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 03:01:23 +08:00
|
|
|
return (
|
|
|
|
|
<aside className="flex flex-col items-center w-16 bg-sidebar border-r border-border py-3 gap-1 shrink-0">
|
2026-05-05 21:45:51 +08:00
|
|
|
<div className="mb-2 flex items-center justify-center">
|
2026-05-07 19:41:30 +08:00
|
|
|
<OtterLogo className="h-7 w-7 text-primary" />
|
2026-05-05 21:45:51 +08:00
|
|
|
</div>
|
|
|
|
|
<div className="border-t border-border w-10 mb-2" />
|
2026-03-22 03:01:23 +08:00
|
|
|
<div className="flex flex-col gap-1 flex-1">
|
2026-03-25 09:24:37 +08:00
|
|
|
{topItems.map((item) => renderItem(item, location.pathname === item.href))}
|
2026-03-22 03:01:23 +08:00
|
|
|
</div>
|
|
|
|
|
<div className="border-t border-border w-10 my-2" />
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
{bottomItems.map((item) => renderItem(item, false))}
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
);
|
|
|
|
|
}
|