1
- // Swizzled from facebook/docusaurus@44ebe73e506fb3e09540c7650a6b2db0a1a435a0
2
- // To get updated version:
3
- // 1. `cd packages/docs`
4
- // 2. `npm run swizzle`
5
- // 3. Select `@docusaurus/theme-classic`
6
- // 4. Select `DocBreadcrumbs (Unsafe)`
7
- // 5. Select `Eject (Unsafe)`
8
- // Only change is adding getHrefFromItem
9
-
10
- /**
11
- * Copyright (c) Facebook, Inc. and its affiliates.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file in the root directory of this source tree.
15
- */
16
-
17
1
import React from 'react' ;
18
- import { ThemeClassNames , useSidebarBreadcrumbs , useHomePageRoute } from '@docusaurus/theme-common' ;
19
- import styles from './styles.module.css' ;
20
- import clsx from 'clsx' ;
2
+ import { useSidebarBreadcrumbs , useHomePageRoute } from '@docusaurus/theme-common' ;
21
3
import Link from '@docusaurus/Link' ;
22
- import useBaseUrl from '@docusaurus/useBaseUrl' ; // TODO move to design system folder
23
-
24
- function BreadcrumbsItemLink ( { children, href } ) {
25
- const className = 'breadcrumbs__link' ;
26
- return href ? (
27
- < Link className = { className } href = { href } itemProp = "item" >
28
- < span itemProp = "name" > { children } </ span >
29
- </ Link >
30
- ) : (
31
- < span className = { className } itemProp = "item name" >
32
- { children }
33
- </ span >
34
- ) ;
35
- } // TODO move to design system folder
36
-
37
- function BreadcrumbsItem ( { children, active, index } ) {
38
- return (
39
- < li
40
- itemScope
41
- itemProp = "itemListElement"
42
- itemType = "https://schema.org/ListItem"
43
- className = { clsx ( 'breadcrumbs__item' , {
44
- 'breadcrumbs__item--active' : active ,
45
- } ) }
46
- >
47
- { children }
48
- < meta itemProp = "position" content = { String ( index + 1 ) } />
49
- </ li >
50
- ) ;
51
- }
52
-
53
- function HomeBreadcrumbItem ( ) {
54
- const homeHref = useBaseUrl ( '/' ) ;
55
- return (
56
- < li className = "breadcrumbs__item" >
57
- < Link className = { clsx ( 'breadcrumbs__link' , styles . breadcrumbsItemLink ) } href = { homeHref } >
58
- 🏠
59
- </ Link >
60
- </ li >
61
- ) ;
62
- }
63
4
64
5
export default function DocBreadcrumbs ( ) {
65
6
const breadcrumbs = useSidebarBreadcrumbs ( ) ;
@@ -70,21 +11,33 @@ export default function DocBreadcrumbs() {
70
11
}
71
12
72
13
return (
73
- < nav className = { clsx ( ThemeClassNames . docs . docBreadcrumbs , styles . breadcrumbsContainer ) } aria-label = "breadcrumbs" >
74
- < ul className = "breadcrumbs" itemScope itemType = "https://schema.org/BreadcrumbList" >
75
- { homePageRoute && < HomeBreadcrumbItem /> }
14
+ < nav aria-label = "breadcrumbs" >
15
+ < ul className = "breadcrumbs" >
16
+ < li className = "breadcrumbs__item" >
17
+ < Link className = "breadcrumbs__link" href = { homePageRoute . path } >
18
+ 🏠
19
+ </ Link >
20
+ </ li >
76
21
{ breadcrumbs . map ( ( item , idx ) => (
77
- < BreadcrumbsItem key = { idx } active = { idx === breadcrumbs . length - 1 } index = { idx } >
78
- < BreadcrumbsItemLink href = { idx < breadcrumbs . length - 1 ? getHrefFromItem ( item ) : undefined } >
79
- { item . label }
80
- </ BreadcrumbsItemLink >
81
- </ BreadcrumbsItem >
22
+ < li key = { idx } className = { getItemClassNames ( breadcrumbs , idx ) } >
23
+ < Link className = "breadcrumbs__link" href = { getHrefFromItem ( item ) } >
24
+ < span > { item . label } </ span >
25
+ </ Link >
26
+ </ li >
82
27
) ) }
83
28
</ ul >
84
29
</ nav >
85
30
) ;
86
31
}
87
32
33
+ function getItemClassNames ( breadcrumbs , idx ) {
34
+ const classes = [ 'breadcrumbs__item' ] ;
35
+ if ( idx === breadcrumbs . length - 1 ) {
36
+ classes . push ( 'breadcrumbs__item--active' ) ;
37
+ }
38
+ return classes . join ( ' ' ) ;
39
+ }
40
+
88
41
function getHrefFromItem ( item ) {
89
42
return item . customProps ?. breadcrumbLink || item . href ;
90
43
}
0 commit comments