-
-
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(docs,theme-classic): docs breadcrumbs (#6517)
Co-authored-by: sebastienlorber <[email protected]>
- Loading branch information
1 parent
67918e3
commit 3629b5a
Showing
16 changed files
with
341 additions
and
1 deletion.
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
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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
/** | ||
* 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, {type ReactNode} from 'react'; | ||
import {ThemeClassNames, useSidebarBreadcrumbs} 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 = clsx('breadcrumbs__link', styles.breadcrumbsItemLink); | ||
return href ? ( | ||
<Link className={className} href={href}> | ||
{children} | ||
</Link> | ||
) : ( | ||
<span className={className}>{children}</span> | ||
); | ||
} | ||
|
||
// TODO move to design system folder | ||
function BreadcrumbsItem({ | ||
children, | ||
active, | ||
}: { | ||
children: ReactNode; | ||
active?: boolean; | ||
}): JSX.Element { | ||
return ( | ||
<li | ||
className={clsx('breadcrumbs__item', { | ||
'breadcrumbs__item--active': active, | ||
})}> | ||
{children} | ||
</li> | ||
); | ||
} | ||
|
||
function HomeBreadcrumbItem() { | ||
const homeHref = useBaseUrl('/'); | ||
return ( | ||
<BreadcrumbsItem> | ||
<BreadcrumbsItemLink href={homeHref}>🏠</BreadcrumbsItemLink> | ||
</BreadcrumbsItem> | ||
); | ||
} | ||
|
||
export default function DocBreadcrumbs(): JSX.Element | null { | ||
const breadcrumbs = useSidebarBreadcrumbs(); | ||
|
||
if (!breadcrumbs) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<nav | ||
className={clsx( | ||
ThemeClassNames.docs.docBreadcrumbs, | ||
styles.breadcrumbsContainer, | ||
)} | ||
aria-label="breadcrumbs"> | ||
<ul className="breadcrumbs"> | ||
<HomeBreadcrumbItem /> | ||
{breadcrumbs.map((item, idx) => ( | ||
<BreadcrumbsItem key={idx} active={idx === breadcrumbs.length - 1}> | ||
<BreadcrumbsItemLink href={item.href}> | ||
{item.label} | ||
</BreadcrumbsItemLink> | ||
</BreadcrumbsItem> | ||
))} | ||
</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: 0.4rem; | ||
} | ||
|
||
.breadcrumbsItemLink { | ||
--ifm-breadcrumb-size-multiplier: 0.7 !important; | ||
margin-bottom: 0.4rem; | ||
background: var(--ifm-color-gray-100); | ||
} | ||
|
||
html[data-theme='dark'] .breadcrumbsItemLink { | ||
background-color: var(--ifm-color-gray-900); | ||
} | ||
|
||
@media (min-width: 997px) { | ||
.breadcrumbsItemLink { | ||
--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
Oops, something went wrong.