-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsite-header.tsx
More file actions
53 lines (49 loc) · 1.6 KB
/
site-header.tsx
File metadata and controls
53 lines (49 loc) · 1.6 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
"use client"
import { usePathname } from "next/navigation"
import { Separator } from "@/components/ui/separator"
import { SidebarTrigger } from "@/components/ui/sidebar"
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
function getBreadcrumbs(pathname: string) {
const segments = pathname.split("/").filter(Boolean)
return segments.map((segment, index) => {
const href = "/" + segments.slice(0, index + 1).join("/")
const label = segment.charAt(0).toUpperCase() + segment.slice(1)
const isLast = index === segments.length - 1
return { href, label, isLast }
})
}
export function SiteHeader() {
const pathname = usePathname()
const breadcrumbs = getBreadcrumbs(pathname)
return (
<header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-2 h-4" />
<Breadcrumb>
<BreadcrumbList>
{breadcrumbs.map((crumb, index) => (
<span key={crumb.href} className="flex items-center gap-1.5">
{index > 0 && <BreadcrumbSeparator />}
<BreadcrumbItem>
{crumb.isLast ? (
<BreadcrumbPage>{crumb.label}</BreadcrumbPage>
) : (
<BreadcrumbLink href={crumb.href}>
{crumb.label}
</BreadcrumbLink>
)}
</BreadcrumbItem>
</span>
))}
</BreadcrumbList>
</Breadcrumb>
</header>
)
}