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 | 7x 7x 7x 51x 306x 306x 51x 50x 50x 50x 50x 50x 1x 1x 3x | "use client";
import {
Activity,
BarChart3,
Bell,
BookOpen,
LayoutDashboard,
LifeBuoy,
ListChecks,
Menu,
PanelLeft,
RefreshCcw,
Settings,
UsersRound,
type LucideIcon,
} from "lucide-react";
import Link from "next/link";
import {useId, useState, type ReactNode} from "react";
import {ThemeToggle} from "@/components/dashboard/theme-toggle/theme-toggle";
import {Button} from "@/components/ui/button/button";
import {uiStyles} from "@/components/ui/style-primitives";
import {cn} from "@/lib/utils/utils";
export type DashboardSection = "overview" | "revenue" | "customers" | "delivery" | "health" | "settings";
type NavItem = {
href: string;
icon: LucideIcon;
label: string;
section: DashboardSection;
};
/** Props for the shared dashboard workspace shell. */
export type DashboardShellProps = {
activeSection: DashboardSection;
children: ReactNode;
description: string;
eyebrow: string;
isRefreshing?: boolean;
onRefresh?: () => void;
title: string;
};
const navItems: NavItem[] = [
{href: "/", icon: LayoutDashboard, label: "Overview", section: "overview"},
{href: "/revenue", icon: BarChart3, label: "Revenue", section: "revenue"},
{href: "/customers", icon: UsersRound, label: "Customers", section: "customers"},
{href: "/delivery", icon: ListChecks, label: "Delivery", section: "delivery"},
{href: "/health", icon: Activity, label: "Health", section: "health"},
{href: "/settings", icon: Settings, label: "Settings", section: "settings"},
];
const notifications = [
{
description: "Delivery has 3 blockers before the May customer health release.",
label: "Delivery risk",
tone: "text-amber-700 dark:text-amber-200",
},
{
description: "Past-due accounts need billing follow-up before renewal review.",
label: "Customer health",
tone: "text-rose-700 dark:text-rose-300",
},
{
description: "Expansion continues to outpace churn in the latest revenue period.",
label: "Revenue motion",
tone: "text-emerald-700 dark:text-emerald-300",
},
];
function NavigationLinks({
activeSection,
onNavigate,
layout = "sidebar",
}: {
activeSection: DashboardSection;
onNavigate?: () => void;
layout?: "mobile" | "sidebar";
}) {
return (
<>
{navItems.map((item) => {
const isActive = item.section === activeSection;
return (
<Link
aria-current={isActive ? "page" : undefined}
className={cn(
"flex h-10 items-center gap-3 rounded-md px-3 text-sm font-medium transition-colors",
layout === "sidebar" ? "w-full" : "min-w-0",
isActive
? "bg-cyan-50 text-cyan-800 dark:bg-cyan-950/40 dark:text-cyan-200"
: "text-slate-600 hover:bg-slate-100 hover:text-slate-950 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-white",
)}
href={item.href}
key={item.section}
onClick={onNavigate}
>
<item.icon aria-hidden="true" size={17}/>
<span className="truncate">{item.label}</span>
</Link>
);
})}
</>
);
}
function GuideLink({onNavigate}: { onNavigate?: () => void }) {
return (
<div className="mt-4 border-t border-slate-200 pt-4 sm:col-span-3 lg:col-span-1 dark:border-slate-800">
<Link
className="flex h-10 items-center gap-3 rounded-md px-3 text-sm font-medium text-slate-600 transition-colors hover:bg-slate-100 hover:text-slate-950 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-white"
href="/guide"
onClick={onNavigate}
>
<BookOpen aria-hidden="true" size={17}/>
<span>User guide</span>
</Link>
</div>
);
}
/** Shared product shell with real route navigation for all dashboard pages. */
export function DashboardShell({
activeSection,
children,
description,
eyebrow,
isRefreshing = false,
onRefresh,
title,
}: DashboardShellProps) {
const mobileNavId = useId();
const notificationsId = useId();
const [isMobileNavOpen, setIsMobileNavOpen] = useState(false);
const [isNotificationsOpen, setIsNotificationsOpen] = useState(false);
return (
<div className="min-h-screen bg-slate-100 text-slate-950 dark:bg-slate-950 dark:text-slate-50">
<a
className="sr-only z-50 rounded-md bg-white px-3 py-2 text-sm font-semibold text-slate-950 shadow-lg focus:not-sr-only focus:fixed focus:left-4 focus:top-4 dark:bg-slate-900 dark:text-white"
href="#dashboard-content"
>
Skip to dashboard content
</a>
<div className="mx-auto flex max-w-370 gap-6 px-4 py-4 sm:px-6 lg:px-8">
<aside
aria-label="Dashboard workspace"
className={cn("sticky top-4 hidden h-[calc(100vh-2rem)] w-64 shrink-0 p-4 lg:flex lg:flex-col", uiStyles.surface)}
>
<div className="flex items-center gap-3 px-2">
<div
className="flex h-10 w-10 items-center justify-center rounded-md bg-cyan-700 text-white dark:bg-cyan-400 dark:text-slate-950">
<PanelLeft aria-hidden="true" size={20}/>
</div>
<div>
<p className="font-semibold text-slate-950 dark:text-white">SaaS Pulse</p>
<p className="text-xs text-slate-500 dark:text-slate-400">Analytics console</p>
</div>
</div>
<nav aria-label="Dashboard navigation" className="mt-8 space-y-1">
<NavigationLinks activeSection={activeSection}/>
<GuideLink/>
</nav>
<div
className="mt-auto rounded-lg border border-slate-200 bg-slate-50 p-3 dark:border-slate-800 dark:bg-slate-950">
<div className="flex items-center gap-2 text-sm font-semibold text-slate-950 dark:text-white">
<LifeBuoy aria-hidden="true" size={16}/>
Ops note
</div>
<p className="mt-2 text-sm leading-5 text-slate-600 dark:text-slate-300">
Enterprise renewals and onboarding reviews are due this week.
</p>
</div>
</aside>
<main
aria-labelledby="dashboard-title"
className="min-w-0 flex-1 space-y-5"
id="dashboard-content"
tabIndex={-1}
>
<header className={cn("p-4 sm:p-5", uiStyles.surface)}>
<div className="flex flex-col gap-4 xl:flex-row xl:items-center xl:justify-between">
<div className="min-w-0">
<div
className="flex flex-wrap items-center gap-2 text-sm text-slate-500 dark:text-slate-400">
<span>Dashboard</span>
<span aria-hidden="true">/</span>
<span className="font-medium text-slate-700 dark:text-slate-200">
{eyebrow}
</span>
</div>
<h1 className="mt-2 text-3xl font-semibold text-slate-950 dark:text-white"
id="dashboard-title">
{title}
</h1>
<p className="mt-2 max-w-3xl text-sm leading-6 text-slate-600 dark:text-slate-300">
{description}
</p>
</div>
<div className="relative flex w-full flex-wrap items-center gap-2 sm:w-auto sm:justify-end">
<Button
aria-controls={mobileNavId}
aria-expanded={isMobileNavOpen}
className="min-w-24 lg:hidden"
onClick={() => setIsMobileNavOpen((current) => !current)}
title="Menu"
variant="secondary"
>
<Menu aria-hidden="true" size={17}/>
Menu
</Button>
<Button
aria-controls={notificationsId}
aria-expanded={isNotificationsOpen}
aria-label="Notifications"
onClick={() => setIsNotificationsOpen((current) => !current)}
size="icon"
title="Notifications"
variant="secondary"
>
<Bell aria-hidden="true" size={17}/>
</Button>
<ThemeToggle/>
{onRefresh ? (
<Button
aria-busy={isRefreshing}
disabled={isRefreshing}
onClick={onRefresh}
variant="primary"
>
<RefreshCcw
aria-hidden="true"
className={cn(isRefreshing && "animate-spin")}
size={16}
/>
Refresh
</Button>
) : null}
{isNotificationsOpen ? (
<section
aria-label="Notifications panel"
className={cn(
"absolute right-0 top-12 z-20 w-76 max-w-[calc(100vw-2rem)] p-3",
uiStyles.surface,
)}
id={notificationsId}
>
<div className="flex items-center justify-between gap-3">
<h2 className="text-sm font-semibold text-slate-950 dark:text-white">Notifications</h2>
<span
className="rounded-md bg-cyan-50 px-2 py-1 text-xs font-medium text-cyan-800 dark:bg-cyan-950/40 dark:text-cyan-200">
{notifications.length} active
</span>
</div>
<ul className="mt-3 space-y-2">
{notifications.map((notification) => (
<li className={cn("p-3", uiStyles.insetSurface)}
key={notification.label}>
<p className={cn("text-sm font-semibold", notification.tone)}>
{notification.label}
</p>
<p className="mt-1 text-sm leading-5 text-slate-600 dark:text-slate-300">
{notification.description}
</p>
</li>
))}
</ul>
</section>
) : null}
</div>
</div>
{isMobileNavOpen ? (
<nav
aria-label="Mobile dashboard navigation"
className="mt-4 grid gap-2 sm:grid-cols-3 lg:hidden"
id={mobileNavId}
>
<NavigationLinks
activeSection={activeSection}
layout="mobile"
onNavigate={() => setIsMobileNavOpen(false)}
/>
<GuideLink onNavigate={() => setIsMobileNavOpen(false)}/>
</nav>
) : null}
</header>
{children}
</main>
</div>
</div>
);
}
|