-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): doc navbar item type (#3539)
* provide DocNavbarItem type * update snapshots * Fix Docusaurus tabs CSS * revert navbar tabs css/style changes, instead apply simple navbar__link--active class + make it configurable * Update website/docs/theme-classic.md Co-authored-by: Alexey Pyltsyn <lex61rus@gmail.com> * add dropdownActiveClassDisabled option Co-authored-by: Alexey Pyltsyn <lex61rus@gmail.com>
- Loading branch information
Showing
12 changed files
with
198 additions
and
37 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
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
48 changes: 48 additions & 0 deletions
48
packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.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,48 @@ | ||
/** | ||
* 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 DefaultNavbarItem from './DefaultNavbarItem'; | ||
import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs'; | ||
import clsx from 'clsx'; | ||
import type {Props} from '@theme/NavbarItem/DocNavbarItem'; | ||
|
||
export default function DocNavbarItem({ | ||
docId, | ||
activeSidebarClassName, | ||
label: staticLabel, | ||
docsPluginId, | ||
...props | ||
}: Props): JSX.Element { | ||
const latestVersion = useLatestVersion(docsPluginId); | ||
const {activeVersion, activeDoc} = useActiveDocContext(docsPluginId); | ||
|
||
const version = activeVersion ?? latestVersion; | ||
|
||
const doc = version.docs.find((versionDoc) => versionDoc.id === docId); | ||
if (!doc) { | ||
throw new Error( | ||
`DocNavbarItem: couldn't find any doc with id=${docId} in version ${ | ||
version.name | ||
}. | ||
Available docIds=\n- ${version.docs.join('\n- ')}`, | ||
); | ||
} | ||
|
||
return ( | ||
<DefaultNavbarItem | ||
exact | ||
{...props} | ||
className={clsx(props.className, { | ||
[activeSidebarClassName]: | ||
activeDoc && activeDoc.sidebar === doc.sidebar, | ||
})} | ||
label={staticLabel ?? doc.id} | ||
to={doc.path} | ||
/> | ||
); | ||
} |
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.