mirror of
https://github.com/Snigdha-OS/documentation.git
synced 2025-09-16 20:44:56 +02:00
83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
/**
|
|
* 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 {useThemeConfig, ErrorCauseBoundary} from '@docusaurus/theme-common';
|
|
import {
|
|
splitNavbarItems,
|
|
useNavbarMobileSidebar,
|
|
} from '@docusaurus/theme-common/internal';
|
|
import NavbarItem from '@theme/NavbarItem';
|
|
import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle';
|
|
import SearchBar from '@theme/SearchBar';
|
|
import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle';
|
|
import NavbarLogo from '@theme/Navbar/Logo';
|
|
import NavbarSearch from '@theme/Navbar/Search';
|
|
import styles from './styles.module.css';
|
|
function useNavbarItems() {
|
|
// TODO temporary casting until ThemeConfig type is improved
|
|
return useThemeConfig().navbar.items;
|
|
}
|
|
function NavbarItems({items}) {
|
|
return (
|
|
<>
|
|
{items.map((item, i) => (
|
|
<ErrorCauseBoundary
|
|
key={i}
|
|
onError={(error) =>
|
|
new Error(
|
|
`A theme navbar item failed to render.
|
|
Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:
|
|
${JSON.stringify(item, null, 2)}`,
|
|
{cause: error},
|
|
)
|
|
}>
|
|
<NavbarItem {...item} />
|
|
</ErrorCauseBoundary>
|
|
))}
|
|
</>
|
|
);
|
|
}
|
|
function NavbarContentLayout({left, right}) {
|
|
return (
|
|
<div className="navbar__inner">
|
|
<div className="navbar__items">{left}</div>
|
|
<div className="navbar__items navbar__items--right">{right}</div>
|
|
</div>
|
|
);
|
|
}
|
|
export default function NavbarContent() {
|
|
const mobileSidebar = useNavbarMobileSidebar();
|
|
const items = useNavbarItems();
|
|
const [leftItems, rightItems] = splitNavbarItems(items);
|
|
const searchBarItem = items.find((item) => item.type === 'search');
|
|
return (
|
|
<NavbarContentLayout
|
|
left={
|
|
// TODO stop hardcoding items?
|
|
<>
|
|
{!mobileSidebar.disabled && <NavbarMobileSidebarToggle />}
|
|
<NavbarLogo />
|
|
<NavbarItems items={leftItems} />
|
|
</>
|
|
}
|
|
right={
|
|
// TODO stop hardcoding items?
|
|
// Ask the user to add the respective navbar items => more flexible
|
|
<>
|
|
<NavbarItems items={rightItems} />
|
|
<NavbarColorModeToggle className={styles.colorModeToggle} />
|
|
{!searchBarItem && (
|
|
<NavbarSearch>
|
|
<SearchBar />
|
|
</NavbarSearch>
|
|
)}
|
|
</>
|
|
}
|
|
/>
|
|
);
|
|
}
|