-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathAdminBreadcrumbs.tsx
More file actions
70 lines (62 loc) · 1.67 KB
/
AdminBreadcrumbs.tsx
File metadata and controls
70 lines (62 loc) · 1.67 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// app/admin/_components/admin-breadcrumbs.tsx
"use client";
import Link from "next/link";
import { useSelectedLayoutSegments } from "next/navigation";
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "ui/components/breadcrumb";
import { BreadcrumbLabels } from "@/lib/constants/admin";
import React from "react";
function formatSegment(segment: string) {
return (
BreadcrumbLabels[segment] ??
decodeURIComponent(segment)
.replace(/-/g, " ")
.replace(/\b\w/g, (char) => char.toUpperCase())
);
}
export function AdminBreadcrumbs() {
const segments = useSelectedLayoutSegments();
const visibleSegments = segments.filter(
(segment) => !segment.startsWith("(") && !segment.startsWith("@"),
);
const allSegments = ["admin", ...visibleSegments];
return (
<Breadcrumb>
<BreadcrumbList>
{allSegments.map((segment, index) => {
const href =
"/" + allSegments.slice(0, index + 1).join("/");
const isLast = index === allSegments.length - 1;
return (
<React.Fragment key={segment}>
<BreadcrumbItem
className={!isLast ? "hidden md:block" : ""}
>
{isLast ? (
<BreadcrumbPage className="text-base">
{formatSegment(segment)}
</BreadcrumbPage>
) : (
<BreadcrumbLink asChild>
<Link href={href} className="text-base">
{formatSegment(segment)}
</Link>
</BreadcrumbLink>
)}
</BreadcrumbItem>
{!isLast && (
<BreadcrumbSeparator className="hidden md:block" />
)}
</React.Fragment>
);
})}
</BreadcrumbList>
</Breadcrumb>
);
}