-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.tsx
More file actions
98 lines (89 loc) · 3.17 KB
/
Copy pathSidebar.tsx
File metadata and controls
98 lines (89 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { NavLink } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { LayoutDashboard, Globe, Bot, Settings2, Link, Settings, FileCode2, BookOpen, Cloud } from 'lucide-react'
import { cn } from '@/lib/utils'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
interface NavItem {
path: string
icon: React.ElementType
labelKey: string
}
const navItems: NavItem[] = [
{ path: '/dashboard', icon: LayoutDashboard, labelKey: 'nav.dashboard' },
{ path: '/providers', icon: Globe, labelKey: 'nav.providers' },
{ path: '/custom-configs', icon: Settings2, labelKey: 'nav.customConfigs' },
{ path: '/config-templates', icon: FileCode2, labelKey: 'nav.configTemplates' },
{ path: '/rule-providers', icon: BookOpen, labelKey: 'nav.ruleProviders' },
{ path: '/hosted-rule-sets', icon: Cloud, labelKey: 'nav.hostedRuleSets' },
{ path: '/subscriptions', icon: Link, labelKey: 'nav.subscriptions' },
{ path: '/user-agents', icon: Bot, labelKey: 'nav.userAgents' },
{ path: '/settings', icon: Settings, labelKey: 'nav.settings' },
]
interface SidebarProps {
onNavClick?: () => void
collapsed?: boolean
labelsVisible?: boolean
}
export function Sidebar({ onNavClick, collapsed = false, labelsVisible = !collapsed }: SidebarProps) {
const { t } = useTranslation()
const navContent = (
<nav className={cn('flex flex-col gap-1 p-2', collapsed && 'items-center')}>
{navItems.map((item) => {
const Icon = item.icon
const label = t(item.labelKey)
const link = (
<NavLink
key={item.path}
to={item.path}
onClick={onNavClick}
aria-label={collapsed ? label : undefined}
className={({ isActive }) =>
cn(
'flex items-center rounded-md text-sm font-medium transition-colors',
collapsed ? 'h-10 w-10 justify-center' : 'gap-3 px-3 py-2.5',
isActive
? 'bg-primary text-primary-foreground'
: 'text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground'
)
}
>
<Icon className="h-4 w-4 shrink-0" />
<span
className={cn(
'whitespace-nowrap transition-opacity duration-150',
collapsed && 'sr-only',
!collapsed && (labelsVisible ? 'opacity-100 delay-75' : 'opacity-0')
)}
aria-hidden={!collapsed && !labelsVisible}
>
{label}
</span>
</NavLink>
)
if (collapsed) {
return (
<Tooltip key={item.path}>
<TooltipTrigger asChild>
<div>{link}</div>
</TooltipTrigger>
<TooltipContent side="right" sideOffset={10}>
{label}
</TooltipContent>
</Tooltip>
)
}
return (
link
)
})}
</nav>
)
if (collapsed) {
return (
<TooltipProvider delayDuration={0} skipDelayDuration={0}>
{navContent}
</TooltipProvider>
)
}
return navContent
}