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 | import React from 'react'; import { Link, usePage } from '@inertiajs/react'; import { Button } from '@/Components/ui/Button'; import { Input } from '@/Components/ui/Input'; import { Badge } from '@/Components/ui/Badge'; import { Avatar, AvatarImage, AvatarFallback } from '@/Components/ui/Avatar'; import { Separator } from '@/Components/ui/Separator'; import { cn } from '@/lib/utils'; import { Search, Bell, Settings, User, LogOut, Moon, Sun, Menu, ChevronDown, } from 'lucide-react'; interface Notification { id: string; title: string; message: string; time: string; read: boolean; type: 'info' | 'warning' | 'error' | 'success'; } interface DashboardHeaderProps { title?: string; showSearch?: boolean; showNotifications?: boolean; showThemeToggle?: boolean; notifications?: Notification[]; onMenuClick?: () => void; onThemeToggle?: () => void; isDarkMode?: boolean; className?: string; } export function DashboardHeader({ title, showSearch = true, showNotifications = true, showThemeToggle = true, notifications = [], onMenuClick, onThemeToggle, isDarkMode = false, className, }: DashboardHeaderProps) { const { auth } = usePage<any>().props; const [isUserMenuOpen, setIsUserMenuOpen] = React.useState(false); const [isNotificationsOpen, setIsNotificationsOpen] = React.useState(false); const unreadCount = notifications.filter(n => !n.read).length; const getUserInitials = (name: string) => { return name .split(' ') .map(n => n[0]) .join('') .toUpperCase() .slice(0, 2); }; const getNotificationIcon = (type: Notification['type']) => { const icons = { info: '🔵', warning: '🟡', error: '🔴', success: '🟢', }; return icons[type]; }; return ( <header className={cn('bg-background border-b border-border', className)}> <div className="flex items-center justify-between px-6 py-3"> {/* Left Section */} <div className="flex items-center space-x-4"> {onMenuClick && ( <Button variant="ghost" size="sm" onClick={onMenuClick} className="md:hidden" > <Menu className="h-4 w-4" /> </Button> )} {title && ( <div> <h1 className="text-lg font-semibold text-foreground">{title}</h1> </div> )} </div> {/* Center Section - Search */} {showSearch && ( <div className="hidden md:flex flex-1 max-w-md mx-4"> <div className="relative w-full"> <Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" /> <Input type="search" placeholder="Search..." className="pl-10 bg-muted/50 border-0" /> </div> </div> )} {/* Right Section */} <div className="flex items-center space-x-2"> {/* Theme Toggle */} {showThemeToggle && onThemeToggle && ( <Button variant="ghost" size="sm" onClick={onThemeToggle} className="hidden sm:flex" > {isDarkMode ? ( <Sun className="h-4 w-4" /> ) : ( <Moon className="h-4 w-4" /> )} </Button> )} {/* Notifications */} {showNotifications && ( <div className="relative"> <Button variant="ghost" size="sm" onClick={() => setIsNotificationsOpen(!isNotificationsOpen)} className="relative" > <Bell className="h-4 w-4" /> {unreadCount > 0 && ( <Badge variant="destructive" className="absolute -top-1 -right-1 h-5 w-5 rounded-full p-0 text-xs flex items-center justify-center" > {unreadCount > 9 ? '9+' : unreadCount} </Badge> )} </Button> {/* Notifications Dropdown */} {isNotificationsOpen && ( <div className="absolute right-0 mt-2 w-80 bg-background border border-border rounded-md shadow-lg z-50"> <div className="p-4 border-b border-border"> <h3 className="font-semibold text-foreground">Notifications</h3> </div> <div className="max-h-64 overflow-y-auto"> {notifications.length > 0 ? ( notifications.slice(0, 5).map((notification) => ( <div key={notification.id} className={cn( 'p-3 border-b border-border last:border-b-0 hover:bg-muted/50', !notification.read && 'bg-muted/30' )} > <div className="flex items-start space-x-3"> <span className="text-lg"> {getNotificationIcon(notification.type)} </span> <div className="flex-1 min-w-0"> <p className="text-sm font-medium text-foreground"> {notification.title} </p> <p className="text-xs text-muted-foreground mt-1"> {notification.message} </p> <p className="text-xs text-muted-foreground mt-1"> {notification.time} </p> </div> </div> </div> )) ) : ( <div className="p-4 text-center text-muted-foreground"> No notifications </div> )} </div> {notifications.length > 5 && ( <div className="p-3 border-t border-border"> <Button variant="ghost" size="sm" className="w-full"> View all notifications </Button> </div> )} </div> )} </div> )} <Separator orientation="vertical" className="h-6" /> {/* User Menu */} <div className="relative"> <Button variant="ghost" onClick={() => setIsUserMenuOpen(!isUserMenuOpen)} className="flex items-center space-x-2 px-2" > <Avatar className="h-7 w-7"> <AvatarImage src={auth.user.avatar} alt={auth.user.name} /> <AvatarFallback className="text-xs"> {getUserInitials(auth.user.name)} </AvatarFallback> </Avatar> <span className="hidden sm:block text-sm font-medium"> {auth.user.name} </span> <ChevronDown className="h-3 w-3" /> </Button> {/* User Dropdown */} {isUserMenuOpen && ( <div className="absolute right-0 mt-2 w-48 bg-background border border-border rounded-md shadow-lg z-50"> <div className="p-3 border-b border-border"> <p className="text-sm font-medium text-foreground"> {auth.user.name} </p> <p className="text-xs text-muted-foreground"> {auth.user.email} </p> </div> <div className="py-1"> <Link href={route('profile.edit')} className="flex items-center px-3 py-2 text-sm text-foreground hover:bg-muted" > <User className="h-4 w-4 mr-2" /> Profile </Link> <Link href="#" className="flex items-center px-3 py-2 text-sm text-foreground hover:bg-muted" > <Settings className="h-4 w-4 mr-2" /> Settings </Link> <Separator className="my-1" /> <Link href={route('logout')} method="post" as="button" className="flex items-center w-full px-3 py-2 text-sm text-foreground hover:bg-muted" > <LogOut className="h-4 w-4 mr-2" /> Sign out </Link> </div> </div> )} </div> </div> </div> </header> ); } |