@@ -13,49 +13,27 @@ interface BreadcrumbProps {
1313}
1414
1515export default function Breadcrumb ( { items, onNavigate } : BreadcrumbProps ) {
16- // On mobile, show only the last item or truncate
17- const displayItems = items . length > 2 ? [ items [ 0 ] , ...items . slice ( - 2 ) ] : items ;
18-
1916 return (
2017 < nav className = "flex items-center gap-1 overflow-x-auto px-2 py-2 sm:gap-2 sm:px-4" aria-label = "Breadcrumb" >
2118 < ol className = "flex min-w-0 items-center gap-1 sm:gap-2" role = "list" >
22- { items . length > 2 && (
23- < >
24- < li className = "flex items-center gap-1 sm:gap-2" >
25- < button
26- type = "button"
27- onClick = { ( ) => onNavigate ( items [ 0 ] . path ) }
28- className = "cursor-pointer truncate text-sm text-gray-600 hover:text-black"
29- >
30- { items [ 0 ] . name }
31- </ button >
19+ { items . map ( ( item , index ) => (
20+ < li key = { `${ item . path } -${ index } ` } className = "flex items-center gap-1 sm:gap-2" >
21+ { index > 0 && (
3222 < ChevronRightIcon className = "h-4 w-4 flex-shrink-0 text-gray-400" />
33- </ li >
34- < li className = "text-sm text-gray-400" > ...</ li >
35- </ >
36- ) }
37- { displayItems . slice ( items . length > 2 ? 1 : 0 ) . map ( ( item , index ) => {
38- const actualIndex = items . length > 2 ? items . length - 2 + index : index ;
39- // Use a combination of path and index to ensure unique keys
40- return (
41- < li key = { `${ item . path } -${ actualIndex } ` } className = "flex items-center gap-1 sm:gap-2" >
42- { actualIndex > 0 && (
43- < ChevronRightIcon className = "h-4 w-4 flex-shrink-0 text-gray-400" />
44- ) }
45- < button
46- type = "button"
47- onClick = { ( ) => onNavigate ( item . path ) }
48- className = { `cursor-pointer truncate text-sm ${ actualIndex === items . length - 1
49- ? "font-medium text-black"
50- : "text-gray-600 hover:text-black"
51- } `}
52- aria-current = { actualIndex === items . length - 1 ? "page" : undefined }
53- >
54- { item . name }
55- </ button >
56- </ li >
57- ) ;
58- } ) }
23+ ) }
24+ < button
25+ type = "button"
26+ onClick = { ( ) => onNavigate ( item . path ) }
27+ className = { `cursor-pointer truncate text-sm ${ index === items . length - 1
28+ ? "font-medium text-black"
29+ : "text-gray-600 hover:text-black"
30+ } `}
31+ aria-current = { index === items . length - 1 ? "page" : undefined }
32+ >
33+ { item . name }
34+ </ button >
35+ </ li >
36+ ) ) }
5937 </ ol >
6038 </ nav >
6139 ) ;
0 commit comments