Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | 1x 1x 1x 1x 1x 1x 1x | /**
* Shared Sidebar Navigation Components
*
* Reusable building blocks for main sidebar and settings sidebar navigation.
*/
import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import { ChevronDown, Lock, LucideIcon } from 'lucide-react';
interface SidebarSectionProps {
title?: string;
children: React.ReactNode;
isCollapsed?: boolean;
className?: string;
}
/**
* Section wrapper with optional header
*/
export const SidebarSection: React.FC<SidebarSectionProps> = ({
title,
children,
isCollapsed = false,
className = '',
}) => {
return (
<div className={`space-y-1 ${className}`}>
{title && !isCollapsed && (
<h3 className="px-4 pt-1 pb-1.5 text-xs font-semibold uppercase tracking-wider text-white/40">
{title}
</h3>
)}
{title && isCollapsed && (
<div className="mx-auto w-8 border-t border-white/20 my-2" />
)}
{children}
</div>
);
};
interface SidebarItemProps {
to: string;
icon: LucideIcon;
label: string;
isCollapsed?: boolean;
exact?: boolean;
disabled?: boolean;
badge?: string | number;
variant?: 'default' | 'settings';
locked?: boolean;
}
/**
* Navigation item with icon
*/
export const SidebarItem: React.FC<SidebarItemProps> = ({
to,
icon: Icon,
label,
isCollapsed = false,
exact = false,
disabled = false,
badge,
variant = 'default',
locked = false,
}) => {
const location = useLocation();
const isActive = exact
? location.pathname === to
: location.pathname.startsWith(to);
const baseClasses = 'flex items-center gap-3 py-2.5 text-sm font-medium rounded-lg transition-colors';
const collapsedClasses = isCollapsed ? 'px-3 justify-center' : 'px-4';
// Different color schemes for main nav vs settings nav
const colorClasses = variant === 'settings'
? isActive
? 'bg-brand-50 text-brand-700 dark:bg-brand-900/30 dark:text-brand-400'
: locked
? 'text-gray-400 hover:text-gray-500 hover:bg-gray-50 dark:text-gray-500 dark:hover:text-gray-400 dark:hover:bg-gray-800'
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-50 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-800'
: isActive
? 'bg-white/10 text-white'
: locked
? 'text-white/40 hover:text-white/60 hover:bg-white/5'
: 'text-white/70 hover:text-white hover:bg-white/5';
const disabledClasses = variant === 'settings'
? 'text-gray-300 dark:text-gray-600 cursor-not-allowed'
: 'text-white/30 cursor-not-allowed';
const className = `${baseClasses} ${collapsedClasses} ${disabled ? disabledClasses : colorClasses}`;
if (disabled) {
return (
<div className={className} title={label}>
<Icon size={20} className="shrink-0" />
{!isCollapsed && <span className="flex-1">{label}</span>}
{badge && !isCollapsed && (
<span className="px-2 py-0.5 text-xs rounded-full bg-white/10">{badge}</span>
)}
</div>
);
}
return (
<Link to={to} className={className} title={label}>
<Icon size={20} className="shrink-0" />
{!isCollapsed && (
<span className="flex-1 flex items-center gap-1.5">
{label}
{locked && <Lock size={12} className="opacity-60" />}
</span>
)}
{badge && !isCollapsed && (
<span className="px-2 py-0.5 text-xs rounded-full bg-brand-100 text-brand-700 dark:bg-brand-900/50 dark:text-brand-400">
{badge}
</span>
)}
</Link>
);
};
interface SidebarDropdownProps {
icon: LucideIcon;
label: string;
children: React.ReactNode;
isCollapsed?: boolean;
defaultOpen?: boolean;
isActiveWhen?: string[];
}
/**
* Collapsible dropdown section
*/
export const SidebarDropdown: React.FC<SidebarDropdownProps> = ({
icon: Icon,
label,
children,
isCollapsed = false,
defaultOpen = false,
isActiveWhen = [],
}) => {
const location = useLocation();
const [isOpen, setIsOpen] = React.useState(
defaultOpen || isActiveWhen.some(path => location.pathname.startsWith(path))
);
const isActive = isActiveWhen.some(path => location.pathname.startsWith(path));
return (
<div>
<button
onClick={() => setIsOpen(!isOpen)}
className={`flex items-center gap-3 py-2.5 text-sm font-medium rounded-lg transition-colors w-full ${
isCollapsed ? 'px-3 justify-center' : 'px-4'
} ${
isActive
? 'bg-white/10 text-white'
: 'text-white/70 hover:text-white hover:bg-white/5'
}`}
title={label}
>
<Icon size={20} className="shrink-0" />
{!isCollapsed && (
<>
<span className="flex-1 text-left">{label}</span>
<ChevronDown
size={16}
className={`shrink-0 transition-transform ${isOpen ? 'rotate-180' : ''}`}
/>
</>
)}
</button>
{isOpen && !isCollapsed && (
<div className="ml-4 mt-1 space-y-0.5 border-l border-white/20 pl-4">
{children}
</div>
)}
</div>
);
};
interface SidebarSubItemProps {
to: string;
icon: LucideIcon;
label: string;
}
/**
* Sub-item for dropdown menus
*/
export const SidebarSubItem: React.FC<SidebarSubItemProps> = ({
to,
icon: Icon,
label,
}) => {
const location = useLocation();
const isActive = location.pathname === to;
return (
<Link
to={to}
className={`flex items-center gap-3 py-2 text-sm font-medium rounded-lg transition-colors px-3 ${
isActive
? 'bg-white/10 text-white'
: 'text-white/60 hover:text-white hover:bg-white/5'
}`}
title={label}
>
<Icon size={16} className="shrink-0" />
<span>{label}</span>
</Link>
);
};
interface SidebarDividerProps {
isCollapsed?: boolean;
}
/**
* Visual divider between sections
*/
export const SidebarDivider: React.FC<SidebarDividerProps> = ({ isCollapsed }) => {
return (
<div className={`my-4 ${isCollapsed ? 'mx-3' : 'mx-4'} border-t border-white/10`} />
);
};
interface SettingsSidebarSectionProps {
title: string;
children: React.ReactNode;
}
/**
* Section for settings sidebar (different styling)
*/
export const SettingsSidebarSection: React.FC<SettingsSidebarSectionProps> = ({
title,
children,
}) => {
return (
<div className="space-y-0.5">
<h3 className="px-4 pt-0.5 pb-1 text-xs font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500">
{title}
</h3>
{children}
</div>
);
};
interface SettingsSidebarItemProps {
to: string;
icon: LucideIcon;
label: string;
description?: string;
locked?: boolean;
}
/**
* Settings navigation item with optional description and lock indicator
*/
export const SettingsSidebarItem: React.FC<SettingsSidebarItemProps> = ({
to,
icon: Icon,
label,
description,
locked = false,
}) => {
const location = useLocation();
const isActive = location.pathname === to || location.pathname.startsWith(to + '/');
return (
<Link
to={to}
className={`flex items-start gap-2.5 px-4 py-1.5 text-sm rounded-lg transition-colors ${
isActive
? 'bg-brand-50 text-brand-700 dark:bg-brand-900/30 dark:text-brand-400'
: locked
? 'text-gray-400 hover:text-gray-500 hover:bg-gray-50 dark:text-gray-500 dark:hover:text-gray-400 dark:hover:bg-gray-800'
: 'text-gray-600 hover:text-gray-900 hover:bg-gray-50 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-800'
}`}
>
<Icon size={16} className="shrink-0 mt-0.5" />
<div className="flex-1 min-w-0">
<div className="flex items-center gap-1.5">
<span className="font-medium">{label}</span>
{locked && (
<Lock size={12} className="text-gray-400 dark:text-gray-500" />
)}
</div>
{description && (
<p className="text-xs text-gray-500 dark:text-gray-500 truncate">
{description}
</p>
)}
</div>
</Link>
);
};
|