Skip to content

Commit

Permalink
feat: render context-aware version dropdown (#235)
Browse files Browse the repository at this point in the history
Switches version dropdown based on currently active docs.

## Demo


https://github.com/user-attachments/assets/acddcbad-6450-4038-92dd-0cf10b3e96b4
  • Loading branch information
EstebanBorai authored Aug 26, 2024
1 parent 0d3201f commit 4c4ad0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ const config: Config = {
position: "right",
docsPluginId: "default",
},
// {
// type: "docsVersionDropdown",
// position: "right",
// docsPluginId: "sdf",
// },
{
type: "docsVersionDropdown",
position: "right",
docsPluginId: "sdf",
},
{
type: "custom-Discord",
position: "right",
Expand Down
22 changes: 22 additions & 0 deletions src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client';
import DocsVersionDropdownNavbarItem from '@theme-original/NavbarItem/DocsVersionDropdownNavbarItem';

import type DocsVersionDropdownNavbarItemType from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
import type {WrapperProps} from '@docusaurus/types';

type Props = WrapperProps<typeof DocsVersionDropdownNavbarItemType>;

export default function DocsVersionDropdownNavbarItemWrapper(props: Props): JSX.Element {
const activeDocContext = useActiveDocContext(props.docsPluginId);

if (!activeDocContext?.activeDoc) {
return null;
}

return (
<>
<DocsVersionDropdownNavbarItem {...props} />
</>
);
}

0 comments on commit 4c4ad0b

Please sign in to comment.