-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbreadcrumb.tsx
74 lines (65 loc) · 1.96 KB
/
breadcrumb.tsx
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
import { Slot } from "@radix-ui/react-slot";
import { ChevronRightIcon, EllipsisIcon } from "lucide-react";
import type { ComponentProps } from "react";
import { cn } from "./cn";
function Breadcrumb({ ...rest }: ComponentProps<"nav">) {
return <nav aria-label="breadcrumb" {...rest} />;
}
function BreadcrumbList({ className, ...rest }: ComponentProps<"ol">) {
return (
<ol
className={cn(
"flex flex-wrap items-center gap-1.5 break-words text-muted-foreground text-sm sm:gap-2.5",
className,
)}
{...rest}
/>
);
}
function BreadcrumbItem({ className, ...rest }: ComponentProps<"li">) {
return <li className={cn("inline-flex items-center gap-1.5", className)} {...rest} />;
}
function BreadcrumbLink({ asChild, className, ...rest }: ComponentProps<"a"> & { asChild?: boolean }) {
const Comp = asChild ? Slot : "a";
return (
<Comp
data-testid="breadcrumb-link"
className={cn("transition-colors hover:text-foreground", className)}
{...rest}
/>
);
}
function BreadcrumbPage({ className, ...rest }: ComponentProps<"span">) {
return (
<span aria-disabled="true" role="link" aria-current="page" className={cn("text-foreground", className)} {...rest} />
);
}
function BreadcrumbSeparator({ children, className, ...rest }: ComponentProps<"li">) {
return (
<li role="presentation" aria-hidden="true" className={cn("[&>svg]:size-3.5", className)} {...rest}>
{children ?? <ChevronRightIcon />}
</li>
);
}
function BreadcrumbEllipsis({ className, ...rest }: ComponentProps<"span">) {
return (
<span
role="presentation"
aria-hidden="true"
className={cn("flex h-9 w-9 items-center justify-center", className)}
{...rest}
>
<EllipsisIcon className="h-4 w-4" />
<span className="sr-only">More</span>
</span>
);
}
export {
Breadcrumb,
BreadcrumbList,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbPage,
BreadcrumbSeparator,
BreadcrumbEllipsis,
};