1
- import React from "react"
2
1
import { useRouter } from "next/router"
3
2
import { useTranslation } from "next-i18next"
4
3
5
4
import type { Lang } from "@/lib/types"
6
5
7
- import { cn } from "@/lib/utils/cn"
8
6
import { isLangRightToLeft } from "@/lib/utils/translations"
9
7
10
- import { BaseLink } from "../ui/Link"
8
+ import {
9
+ Breadcrumb ,
10
+ BreadcrumbItem ,
11
+ BreadcrumbLink ,
12
+ BreadcrumbList ,
13
+ BreadcrumbPage ,
14
+ BreadcrumbProps ,
15
+ BreadcrumbSeparator ,
16
+ } from "../ui/breadcrumb"
11
17
12
- // Ref: https://ui.shadcn.com/docs/components/breadcrumb
13
- type RootBreadcrumbProps = React . ComponentPropsWithoutRef < "nav" >
14
-
15
- export type BreadcrumbsProps = RootBreadcrumbProps & {
18
+ export type BreadcrumbsProps = BreadcrumbProps & {
16
19
slug : string
17
20
startDepth ?: number
18
21
}
@@ -22,11 +25,6 @@ type Crumb = {
22
25
text : string
23
26
}
24
27
25
- const Breadcrumb = React . forwardRef < HTMLElement , RootBreadcrumbProps > (
26
- ( { ...props } , ref ) => < nav ref = { ref } aria-label = "breadcrumb" { ...props } />
27
- )
28
- Breadcrumb . displayName = "Breadcrumb"
29
-
30
28
// Generate crumbs from slug
31
29
// e.g. "/en/eth2/proof-of-stake/" will generate:
32
30
// [
@@ -40,13 +38,7 @@ Breadcrumb.displayName = "Breadcrumb"
40
38
// { fullPath: "/en/eth2/", text: "ETH2" },
41
39
// { fullPath: "/en/eth2/proof-of-stake/", text: "PROOF OF STAKE" },
42
40
// ]
43
-
44
- const Breadcrumbs = ( {
45
- slug,
46
- startDepth = 0 ,
47
- className = "" ,
48
- ...props
49
- } : BreadcrumbsProps ) => {
41
+ const Breadcrumbs = ( { slug, startDepth = 0 , ...props } : BreadcrumbsProps ) => {
50
42
const { t } = useTranslation ( "common" )
51
43
const { locale, asPath } = useRouter ( )
52
44
const dir = isLangRightToLeft ( locale ! as Lang ) ? "rtl" : "ltr"
@@ -74,44 +66,29 @@ const Breadcrumbs = ({
74
66
. slice ( startDepth )
75
67
76
68
return (
77
- < Breadcrumb
78
- className = { cn ( "flex flex-wrap items-center justify-start" , className ) }
79
- { ...props }
80
- >
81
- { crumbs . map ( ( { fullPath, text } ) => {
82
- const normalizePath = ( path ) => path . replace ( / \/ $ / , "" ) // Remove trailing slash
83
- const isCurrentPage = normalizePath ( slug ) === normalizePath ( fullPath )
84
- return (
85
- < div
86
- key = { fullPath }
87
- className = { cn (
88
- "inline-flex items-center tracking-wider" ,
89
- dir === "rtl" ? "flex-row-reverse" : ""
90
- ) }
91
- >
92
- { ! isCurrentPage && dir === "rtl" && (
93
- < span className = "me-[0.625rem] ms-[0.625rem] text-gray-400" >
94
- /
95
- </ span >
96
- ) }
97
- { isCurrentPage ? (
98
- < span className = "uppercase text-primary" > { text } </ span >
99
- ) : (
100
- < BaseLink
101
- href = { fullPath }
102
- className = "uppercase !text-body-medium no-underline hover:!text-primary"
103
- >
104
- { text }
105
- </ BaseLink >
106
- ) }
107
- { ! isCurrentPage && dir === "ltr" && (
108
- < span className = "me-[0.625rem] ms-[0.625rem] text-gray-400" >
109
- /
110
- </ span >
111
- ) }
112
- </ div >
113
- )
114
- } ) }
69
+ < Breadcrumb { ...props } dir = { dir } >
70
+ < BreadcrumbList >
71
+ { crumbs . map ( ( { fullPath, text } ) => {
72
+ const normalizePath = ( path ) => path . replace ( / \/ $ / , "" ) // Remove trailing slash
73
+ const isCurrentPage = normalizePath ( slug ) === normalizePath ( fullPath )
74
+ return (
75
+ < >
76
+ < BreadcrumbItem key = { fullPath } >
77
+ { isCurrentPage ? (
78
+ < BreadcrumbPage > { text } </ BreadcrumbPage >
79
+ ) : (
80
+ < BreadcrumbLink href = { fullPath } > { text } </ BreadcrumbLink >
81
+ ) }
82
+ </ BreadcrumbItem >
83
+ { ! isCurrentPage && (
84
+ < BreadcrumbSeparator className = "me-[0.625rem] ms-[0.625rem] text-gray-400" >
85
+ /
86
+ </ BreadcrumbSeparator >
87
+ ) }
88
+ </ >
89
+ )
90
+ } ) }
91
+ </ BreadcrumbList >
115
92
</ Breadcrumb >
116
93
)
117
94
}
0 commit comments