-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add breadcrumbs hook, component to classic theme
- Loading branch information
1 parent
196c8ea
commit 14bd0e8
Showing
12 changed files
with
182 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
69 changes: 69 additions & 0 deletions
69
packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/index.tsx
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,69 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
ThemeClassNames, | ||
useDocsBreadcrumbs, | ||
useThemeConfig, | ||
} from '@docusaurus/theme-common'; | ||
import styles from './styles.module.css'; | ||
import clsx from 'clsx'; | ||
import {useLocation} from '@docusaurus/router'; | ||
|
||
export default function DocBreadcrumbs(): JSX.Element | null { | ||
const {pathname} = useLocation(); | ||
const breadcrumbs = useDocsBreadcrumbs(); | ||
const {breadcrumbs: enabled} = useThemeConfig(); | ||
|
||
function isExact( | ||
items: { | ||
href?: string; | ||
}[], | ||
) { | ||
return ( | ||
items.length === 1 && | ||
items[0].href?.replace(/\/$/, '') === pathname.replace(/\/$/, '') | ||
); | ||
} | ||
|
||
if ( | ||
!breadcrumbs.length || | ||
enabled === false || | ||
(enabled === 'nested' && isExact(breadcrumbs)) | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<nav | ||
className={clsx( | ||
ThemeClassNames.docs.docBreadcrumbs, | ||
styles.breadcrumbsContainer, | ||
)} | ||
aria-label="breadcrumbs"> | ||
<ul className="breadcrumbs"> | ||
{breadcrumbs.map((breadcrumb, idx) => ( | ||
<li key={idx} className="breadcrumbs__item"> | ||
{breadcrumb.href ? ( | ||
<a | ||
className={clsx('breadcrumbs__link', styles.breadcrumbItem)} | ||
href={breadcrumb.href}> | ||
{breadcrumb.label} | ||
</a> | ||
) : ( | ||
<span | ||
className={clsx('breadcrumbs__link', styles.breadcrumbItem)}> | ||
{breadcrumb.label} | ||
</span> | ||
)} | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/docusaurus-theme-classic/src/theme/DocBreadcrumbs/styles.module.css
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,26 @@ | ||
/** | ||
* 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 { | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.breadcrumbItem { | ||
--ifm-breadcrumb-size-multiplier: 0.75; | ||
margin-bottom: 0.5rem; | ||
background: var(--ifm-color-gray-100); | ||
} | ||
|
||
html[data-theme='dark'] .breadcrumbItem { | ||
background-color: var(--ifm-color-gray-900); | ||
} | ||
|
||
@media (min-width: 997px) { | ||
.breadcrumbItem { | ||
--ifm-breadcrumb-size-multiplier: 0.8; | ||
} | ||
} |
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
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
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
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