|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { useLocation, Link } from 'react-router-dom'; |
| 3 | +import * as LucideIcons from 'lucide-react'; |
3 | 4 | import { |
4 | 5 | Sidebar, |
5 | 6 | SidebarHeader, |
@@ -42,21 +43,27 @@ import { |
42 | 43 | } from 'lucide-react'; |
43 | 44 | import appConfig from '../../objectstack.config'; |
44 | 45 |
|
45 | | -// Icon Map |
46 | | -const ICONS: Record<string, any> = { |
47 | | - 'dashboard': LayoutDashboard, |
48 | | - 'users': Users, |
49 | | - 'user': Users, |
50 | | - 'check-square': CheckSquare, |
51 | | - 'activity': Activity, |
52 | | - 'briefcase': Briefcase, |
53 | | - 'file-text': FileText, |
54 | | - 'database': Database, |
55 | | -}; |
56 | | - |
| 46 | +// Helper to get icon from Lucide |
57 | 47 | function getIcon(name?: string) { |
58 | | - if (!name) return Database; |
59 | | - return ICONS[name] || Database; |
| 48 | + if (!name) return LucideIcons.Database; |
| 49 | + |
| 50 | + // 1. Try direct match (e.g. if user passed "User") |
| 51 | + if ((LucideIcons as any)[name]) { |
| 52 | + return (LucideIcons as any)[name]; |
| 53 | + } |
| 54 | + |
| 55 | + // 2. Try converting kebab-case to PascalCase (e.g. "shopping-cart" -> "ShoppingCart") |
| 56 | + const pascalName = name |
| 57 | + .split('-') |
| 58 | + .map(part => part.charAt(0).toUpperCase() + part.slice(1)) |
| 59 | + .join(''); |
| 60 | + |
| 61 | + if ((LucideIcons as any)[pascalName]) { |
| 62 | + return (LucideIcons as any)[pascalName]; |
| 63 | + } |
| 64 | + |
| 65 | + // 3. Fallback |
| 66 | + return LucideIcons.Database; |
60 | 67 | } |
61 | 68 |
|
62 | 69 | export function AppSidebar({ activeAppName, onAppChange }: { activeAppName: string, onAppChange: (name: string) => void }) { |
@@ -89,10 +96,8 @@ export function AppSidebar({ activeAppName, onAppChange }: { activeAppName: stri |
89 | 96 | {/* App Logo - use branding logo if available */} |
90 | 97 | {logo ? ( |
91 | 98 | <img src={logo} alt={activeApp.label} className="size-6 object-contain" /> |
92 | | - ) : activeApp.icon ? ( |
93 | | - React.createElement(getIcon(activeApp.icon), { className: "size-4" }) |
94 | 99 | ) : ( |
95 | | - <Database className="size-4" /> |
| 100 | + React.createElement(getIcon(activeApp.icon), { className: "size-4" }) |
96 | 101 | )} |
97 | 102 | </div> |
98 | 103 | <div className="grid flex-1 text-left text-sm leading-tight"> |
|
0 commit comments