-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breadcrumbs on all pages, category indexes
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, {type ReactNode} from 'react'; | ||
import { | ||
ThemeClassNames, | ||
useSidebarBreadcrumbs, | ||
useHomePageRoute, | ||
} from '@docusaurus/theme-common'; | ||
import styles from './styles.module.css'; | ||
import clsx from 'clsx'; | ||
import Link from '@docusaurus/Link'; | ||
import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
|
||
// TODO move to design system folder | ||
function BreadcrumbsItemLink({ | ||
children, | ||
href, | ||
}: { | ||
children: ReactNode; | ||
href?: string; | ||
}): JSX.Element { | ||
const className = 'breadcrumbs__link'; | ||
return href ? ( | ||
<Link className={className} href={href} itemProp="item"> | ||
<span itemProp="name">{children}</span> | ||
</Link> | ||
) : ( | ||
<span className={className} itemProp="item name"> | ||
{children} | ||
</span> | ||
); | ||
} | ||
|
||
// TODO move to design system folder | ||
function BreadcrumbsItem({ | ||
children, | ||
active, | ||
index, | ||
}: { | ||
children: ReactNode; | ||
active?: boolean; | ||
index: number; | ||
}): JSX.Element { | ||
return ( | ||
<li | ||
itemScope | ||
itemProp="itemListElement" | ||
itemType="https://schema.org/ListItem" | ||
className={clsx('breadcrumbs__item', { | ||
'breadcrumbs__item--active': active, | ||
})}> | ||
{children} | ||
<meta itemProp="position" content={String(index + 1)} /> | ||
</li> | ||
); | ||
} | ||
|
||
function HomeBreadcrumbItem() { | ||
const homeHref = useBaseUrl('/'); | ||
return ( | ||
<li className="breadcrumbs__item"> | ||
<Link | ||
className={clsx('breadcrumbs__link', styles.breadcrumbsItemLink)} | ||
href={homeHref}> | ||
🏠 | ||
</Link> | ||
</li> | ||
); | ||
} | ||
|
||
export default function DocBreadcrumbs(): JSX.Element | null { | ||
const breadcrumbs = useSidebarBreadcrumbs(); | ||
const homePageRoute = useHomePageRoute(); | ||
|
||
if (!breadcrumbs) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<nav | ||
className={clsx( | ||
ThemeClassNames.docs.docBreadcrumbs, | ||
styles.breadcrumbsContainer, | ||
)} | ||
aria-label="breadcrumbs"> | ||
<ul | ||
className="breadcrumbs" | ||
itemScope | ||
itemType="https://schema.org/BreadcrumbList"> | ||
{homePageRoute && <HomeBreadcrumbItem />} | ||
{breadcrumbs.map((item, idx) => ( | ||
<BreadcrumbsItem | ||
key={idx} | ||
active={idx === breadcrumbs.length - 1} | ||
index={idx}> | ||
<BreadcrumbsItemLink | ||
href={item.href}> {/* papermc - breadcrumb links on all pages, even current */} | ||
{item.label} | ||
</BreadcrumbsItemLink> | ||
</BreadcrumbsItem> | ||
))} | ||
</ul> | ||
</nav> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.breadcrumbsContainer { | ||
--ifm-breadcrumb-size-multiplier: 0.8; | ||
margin-bottom: 0.8rem; | ||
} |